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.
Sure! Below is an MTA: San Andreas (MTA:SA) Lua script that shows the cursor when the map is opened, waits for the player to click on the map, converts the click coordinates to in-game world coordinates, and then teleports the player to the clicked location.
lua
-- Client-side script
local isMapOpen = false
function toggleMap()
if isMapOpen then
showCursor(false)
isMapOpen = false
else
showCursor(true)
isMapOpen = true
end
end
bindKey("F11", "down", toggleMap) -- Bind the map toggle to F11 key
function onMapClick(button, state, absoluteX, absoluteY)
if isMapOpen and button == "left" and state == "down" then
local screenX, screenY = guiGetScreenSize()
local mapX, mapY = absoluteX / screenX, absoluteY / screenY
local worldX, worldY = mapToWorld(mapX, mapY)
if worldX and worldY then
triggerServerEvent("teleportPlayerTo", resourceRoot, worldX, worldY)
end
end
end
addEventHandler("onClientClick", root, onMapClick)
function mapToWorld(mapX, mapY)
-- These values are based on the GTA:SA map's scale and offset
local worldX = (mapX * 6000) - 3000
local worldY = 3000 - (mapY * 6000)
return worldX, worldY
end
-- Server-side script
function teleportPlayerTo(worldX, worldY)
local player = client
local z = getGroundPosition(worldX, worldY, 1000) + 1
setElementPosition(player, worldX, worldY, z)
end
addEvent("teleportPlayerTo", true)
addEventHandler("teleportPlayerTo", resourceRoot, teleportPlayerTo)
Explanation:
Client-side:
toggleMap: Toggles the map visibility using the F11 key.
onMapClick: Handles the player's click on the map when it's open. It converts the click's screen coordinates to map coordinates and then to world coordinates.
mapToWorld: Converts the normalized map coordinates (0 to 1) to in-game world coordinates based on GTA:SA's map scale and offset.
teleportPlayerTo event (Server-side): The server receives the world coordinates and teleports the player to the specified location.
Server-side:
teleportPlayerTo: Teleports the player to the calculated world coordinates with a safe Z-coordinate, which is determined using getGroundPosition.
Notes:
This script assumes a simple linear conversion from map coordinates to world coordinates. Adjust the scale and offset in mapToWorld if necessary based on your map's exact settings.
The Z-coordinate is calculated using getGroundPosition, which finds the ground level at the specified X, Y coordinates.
Ensure that you place the client-side code in a file with the .lua extension and the server-side code in a separate .lua file, and include them properly in your meta.xml.
“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/01m850tv9pgt2w45jzjsqf30ra