admin_minimap_teleport.lua

main 64 lines · 1.7 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1-- Left-click on the minimap teleports gamemasters and above.
2-- The client (gamelib/ui/uiminimap.lua) only sends the request after the
3-- server says on login that this player is allowed to use it.
4local OPCODE_ADMIN_MINIMAP_TELEPORT = 215
5
6local function canUseMinimapTeleport(player)
7 return player:getGroup():getAccess()
8end
9
10local loginEvent = CreatureEvent("AdminMinimapTeleportLogin")
11
12function loginEvent.onLogin(player)
13 player:registerEvent("AdminMinimapTeleportOpcode")
14 player:sendExtendedOpcode(OPCODE_ADMIN_MINIMAP_TELEPORT, json.encode({
15 action = "access",
16 enabled = canUseMinimapTeleport(player)
17 }))
18 return true
19end
20
21loginEvent:register()
22
23local opcodeEvent = CreatureEvent("AdminMinimapTeleportOpcode")
24
25function opcodeEvent.onExtendedOpcode(player, opcode, buffer)
26 if opcode ~= OPCODE_ADMIN_MINIMAP_TELEPORT then
27 return true
28 end
29
30 if not canUseMinimapTeleport(player) then
31 return true
32 end
33
34 local ok, data = pcall(json.decode, buffer)
35 if not ok or type(data) ~= "table" or data.action ~= "teleport" or type(data.position) ~= "table" then
36 return true
37 end
38
39 local x = tonumber(data.position.x)
40 local y = tonumber(data.position.y)
41 local z = tonumber(data.position.z)
42 if not x or not y or not z then
43 return true
44 end
45
46 local destination = Position(math.floor(x), math.floor(y), math.floor(z))
47 if not Tile(destination) then
48 player:sendCancelMessage("There is no tile there.")
49 return true
50 end
51
52 local ghost = player:isInGhostMode()
53 if not ghost then
54 player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
55 end
56 player:teleportTo(destination)
57 if not ghost then
58 destination:sendMagicEffect(CONST_ME_TELEPORT)
59 end
60 return true
61end
62
63opcodeEvent:register()
64
Top