code an MTA SA code to show the cursor when the map is opened, wait for a player to click -> convert his click cords on the map to in-game world cords -> teleport the player there
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
To achieve this in MTA: San Andreas (Multi Theft Auto: San Andreas), you can use Lua scripting. Here's a script that will handle showing the cursor when the map is opened, converting the clicked coordinates on the map to in-game world coordinates, and then teleporting the player to those coordinates.
Step 1: Create the meta.xml file
This file will define your resource and include the script files.
-- teleport.lua (Client-side script)
-- Function to handle when the map is opened
function onMapOpened()
showCursor(true) -- Show the cursor when the map is opened
addEventHandler("onClientClick", root, onMapClick) -- Listen for map clicks
end
-- Function to handle when the map is closed
function onMapClosed()
showCursor(false) -- Hide the cursor when the map is closed
removeEventHandler("onClientClick", root, onMapClick) -- Stop listening for map clicks
end
-- Function to handle the map click
function onMapClick(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedWorld)
if button == "left" and state == "up" then
local mapX, mapY = getCursorPosition() -- Get the cursor position on the map
if mapX and mapY then
local worldX, worldY = getWorldFromMapPosition(mapX, mapY) -- Convert map coordinates to world coordinates
if worldX and worldY then
triggerServerEvent("teleportPlayerToPosition", localPlayer, worldX, worldY, worldZ) -- Trigger server-side teleport event
end
end
end
end
-- Function to convert map coordinates to world coordinates
function getWorldFromMapPosition(mapX, mapY)
local mapW, mapH = guiGetScreenSize()
local worldX = mapX * 6000 - 3000
local worldY = mapY * 6000 - 3000
return worldX, worldY
end
-- Event listeners for map open/close
addEventHandler("onClientMapStart", root, onMapOpened)
addEventHandler("onClientMapStop", root, onMapClosed)
Step 3: Create a server.lua script to handle teleporting the player
lua
-- server.lua (Server-side script)
function teleportPlayerToPosition(worldX, worldY, worldZ)
if client then
local player = client
local z = getGroundPosition(worldX, worldY, 500) -- Get the ground position at the given coordinates
if z then
setElementPosition(player, worldX, worldY, z + 1) -- Teleport the player slightly above the ground
else
outputChatBox("Invalid teleport coordinates.", player, 255, 0, 0)
end
end
end
addEvent("teleportPlayerToPosition", true)
addEventHandler("teleportPlayerToPosition", root, teleportPlayerToPosition)
Step 4: Update the meta.xml to include the server script
onMapOpened: When the map is opened, the cursor is shown, and an event handler is added to listen for clicks on the map.
onMapClosed: When the map is closed, the cursor is hidden, and the event handler is removed.
onMapClick: This function handles the click event on the map. It gets the cursor's position, converts it to world coordinates, and triggers a server-side event to teleport the player.
getWorldFromMapPosition: Converts the map's cursor position to world coordinates.
Server-Side Script (server.lua):
teleportPlayerToPosition: This function is called when the client triggers the teleport event. It calculates the ground position and teleports the player to the clicked location.
This script should be placed in the appropriate resource directory in your MTA: SA server. After starting the resource, players should be able to open the map, click on a location, and get teleported to that location in the game world.
“code an MTA SA code to show the cursor when the map is opened, wait for a player to….” Conversation with chatgpt-4o-latest, from the LMArena Human Preference 100K dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m850p2h3h3gffcvbp78prnrx