Skip to content

Commit f83b292

Browse files
authored
admin & admin2: add warp player to map position (#206)
* Add warp Player to map position * add missing map image * implement to admin2 * remove debug line * replace tabs to spaces in admin2 * minimize camera fade for admin at auto z-coord detect * requested changes * Update admin_warp.lua * Update admin_warp.lua * modify warpPlayerToPosition to use `warpto` action in admin2 * some small modification - move `warp` outside from `warpPlayer` - fix admin can't see himself on warpto-playerlist - fix admin can't teleport player if he is in a vehicle * all previous do it in admin-resource too
1 parent 907c9c0 commit f83b292

File tree

9 files changed

+420
-188
lines changed

9 files changed

+420
-188
lines changed

[admin]/admin/client/gui/admin_warp.lua

+111-9
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@
88
*
99
**************************************]]
1010

11-
aWarpForm = nil
11+
aWarpForm = nil
12+
aWarpToPositionForm = nil
1213

1314
function aPlayerWarp ( player )
1415
if ( aWarpForm == nil ) then
1516
local x, y = guiGetScreenSize()
16-
aWarpForm = guiCreateWindow ( x / 2 - 110, y / 2 - 150, 200, 300, "Player Warp Management", false )
17-
aWarpList = guiCreateGridList ( 0.03, 0.08, 0.94, 0.73, true, aWarpForm )
17+
aWarpForm = guiCreateWindow ( x / 2 - 110, y / 2 - 150, 200, 330, "Player Warp Management", false )
18+
aWarpList = guiCreateGridList ( 0.03, 0.08, 0.94, 0.64, true, aWarpForm )
1819
guiGridListAddColumn( aWarpList, "Player", 0.9 )
19-
aWarpSelect = guiCreateButton ( 0.03, 0.82, 0.94, 0.075, "Select", true, aWarpForm )
20-
aWarpCancel = guiCreateButton ( 0.03, 0.90, 0.94, 0.075, "Cancel", true, aWarpForm )
20+
aWarpSelect = guiCreateButton ( 0.03, 0.74, 0.94, 0.07, "Select", true, aWarpForm )
21+
aWarpToPosition = guiCreateButton ( 0.03, 0.82, 0.94, 0.07, "To position", true, aWarpForm )
22+
aWarpCancel = guiCreateButton ( 0.03, 0.90, 0.94, 0.07, "Cancel", true, aWarpForm )
2123

2224
addEventHandler ( "onClientGUIDoubleClick", aWarpForm, aClientWarpDoubleClick )
2325
addEventHandler ( "onClientGUIClick", aWarpForm, aClientWarpClick )
@@ -27,7 +29,9 @@ function aPlayerWarp ( player )
2729
aWarpSelectPointer = player
2830
guiGridListClear ( aWarpList )
2931
for id, player in ipairs ( getElementsByType ( "player" ) ) do
30-
guiGridListSetItemPlayerName ( aWarpList, guiGridListAddRow ( aWarpList ), 1, getPlayerName ( player ), false, false )
32+
if ( player ~= aWarpSelectPointer ) then
33+
guiGridListSetItemPlayerName ( aWarpList, guiGridListAddRow ( aWarpList ), 1, getPlayerName ( player ), false, false )
34+
end
3135
end
3236
guiSetVisible ( aWarpForm, true )
3337
guiBringToFront ( aWarpForm )
@@ -46,26 +50,124 @@ function aPlayerWarpClose ( destroy )
4650
end
4751
end
4852

53+
54+
function aPlayerWarpToPosition ( )
55+
if ( aWarpToPositionForm == nil ) then
56+
local x, y = guiGetScreenSize()
57+
local h = y * 0.75
58+
aWarpToPositionForm = guiCreateWindow ( x / 2 - h / 2, y / 2 - h / 2, h, h + 40, "Player Warp To Position", false )
59+
aWarpToPositionMap = guiCreateStaticImage ( 10, 25, h - 20, h - 20, "client/images/map.png", false, aWarpToPositionForm )
60+
aWarpToPositionTeleport = guiCreateButton ( 10, h + 10, 80, 25, "Teleport", false, aWarpToPositionForm )
61+
aWarpToPositionCancel = guiCreateButton ( h - 90, h + 10, 80, 25, "Cancel", false, aWarpToPositionForm )
62+
aWarpToPositionX = guiCreateEdit ( 100, h + 10, 80, 25, "0", false, aWarpToPositionForm )
63+
aWarpToPositionY = guiCreateEdit ( 185, h + 10, 80, 25, "0", false, aWarpToPositionForm )
64+
aWarpToPositionZ = guiCreateEdit ( 270, h + 10, 80, 25, "3", false, aWarpToPositionForm )
65+
66+
addEventHandler ( "onClientGUIDoubleClick", aWarpToPositionForm, aClientWarpDoubleClick )
67+
addEventHandler ( "onClientGUIClick", aWarpToPositionForm, aClientWarpClick )
68+
--Register With Admin Form
69+
aRegister ( "PlayerWarpToPosition", aWarpToPositionForm, aPlayerWarpToPosition, aPlayerWarpToPositionClose )
70+
end
71+
guiSetVisible ( aWarpToPositionForm, true )
72+
guiBringToFront ( aWarpToPositionForm )
73+
end
74+
75+
function aPlayerWarpToPositionClose ( destroy )
76+
if ( ( destroy ) or ( aPerformanceWarp and guiCheckBoxGetSelected ( aPerformanceWarp ) ) ) then
77+
if ( aWarpToPositionForm ) then
78+
removeEventHandler ( "onClientGUIDoubleClick", aWarpToPositionForm, aClientWarpDoubleClick )
79+
removeEventHandler ( "onClientGUIClick", aWarpToPositionForm, aClientWarpClick )
80+
destroyElement ( aWarpToPositionForm )
81+
aWarpToPositionForm = nil
82+
end
83+
else
84+
guiSetVisible ( aWarpToPositionForm, false )
85+
end
86+
end
87+
88+
local function calculatePosition ( absX, absY )
89+
local x, y = guiGetPosition(aWarpToPositionForm, false)
90+
x, y = x + 10, y + 25
91+
local w, h = guiGetSize(aWarpToPositionMap, false)
92+
local tpX, tpY = ( absX - x ) / w * 6000 - 3000, - ( ( absY - y ) / h * 6000 - 3000 )
93+
local hit, _, _, tpZ = processLineOfSight ( tpX, tpY, 3000, tpX, tpY, -3000 )
94+
tpZ = hit and tpZ or "auto"
95+
guiSetText ( aWarpToPositionX, tpX ); guiSetText ( aWarpToPositionY, tpY ); guiSetText ( aWarpToPositionZ, tpZ )
96+
return tpX, tpY, tpY
97+
end
98+
99+
local function getTeleportPosition ( )
100+
return guiGetText ( aWarpToPositionX ), guiGetText ( aWarpToPositionY ), guiGetText ( aWarpToPositionZ )
101+
end
102+
103+
104+
local function warpToPosition ( player, x, y, z )
105+
if isElement(player) then
106+
local x, y, z = tonumber(x) or 0, tonumber(y) or 0, tonumber(z) or 0
107+
local distance = getElementDistanceFromCentreOfMassToBaseOfModel ( player )
108+
triggerServerEvent ( "aPlayer", localPlayer, player, "warpto", { x, y, z + distance + 0.25 } )
109+
aPlayerWarpToPositionClose ( false )
110+
aPlayerWarpClose ( false )
111+
end
112+
end
113+
114+
local function warpPlayerToPositionTrigger ( )
115+
local x, y, z = getTeleportPosition ( )
116+
if z == "auto" then
117+
local target = getPedOccupiedVehicle(localPlayer) or localPlayer
118+
fadeCamera ( false, 0 )
119+
setElementFrozen ( target, true )
120+
setCameraMatrix ( x, y, 0 )
121+
setTimer ( function ( )
122+
local hit, _, _, hitZ = processLineOfSight(x, y, 3000, x, y, -3000)
123+
setCameraTarget ( localPlayer )
124+
setElementFrozen ( target, false )
125+
fadeCamera ( true, 0.1 )
126+
if not hit then return end
127+
warpToPosition ( aWarpSelectPointer, x, y, hitZ )
128+
end, 100, 1 )
129+
else
130+
warpToPosition ( aWarpSelectPointer, x, y, z )
131+
end
132+
end
133+
49134
function aClientWarpDoubleClick ( button )
50135
if ( button == "left" ) then
51136
if ( source == aWarpList ) then
52137
if ( guiGridListGetSelectedItem ( aWarpList ) ~= -1 ) then
53-
triggerServerEvent ( "aPlayer", getLocalPlayer(), aWarpSelectPointer, "warpto", getPlayerFromNick ( guiGridListGetItemPlayerName ( aWarpList, guiGridListGetSelectedItem ( aWarpList ), 1 ) ) )
138+
if isElement(aWarpSelectPointer) then
139+
triggerServerEvent ( "aPlayer", localPlayer, aWarpSelectPointer, "warpto", getPlayerFromNick ( guiGridListGetItemPlayerName ( aWarpList, guiGridListGetSelectedItem ( aWarpList ), 1 ) ) )
140+
end
54141
aPlayerWarpClose ( false )
55142
end
143+
elseif ( source == aWarpToPositionMap ) then
144+
warpPlayerToPositionTrigger ( )
56145
end
57146
end
58147
end
59148

60-
function aClientWarpClick ( button )
149+
function aClientWarpClick ( button, state, absX, absY )
61150
if ( button == "left" ) then
151+
-- Player Warp Management
62152
if ( source == aWarpSelect ) then
63153
if ( guiGridListGetSelectedItem ( aWarpList ) ~= -1 ) then
64-
triggerServerEvent ( "aPlayer", getLocalPlayer(), aWarpSelectPointer, "warpto", getPlayerFromNick ( guiGridListGetItemPlayerName ( aWarpList, guiGridListGetSelectedItem ( aWarpList ), 1 ) ) )
154+
if isElement(aWarpSelectPointer) then
155+
triggerServerEvent ( "aPlayer", localPlayer, aWarpSelectPointer, "warpto", getPlayerFromNick ( guiGridListGetItemPlayerName ( aWarpList, guiGridListGetSelectedItem ( aWarpList ), 1 ) ) )
156+
end
65157
aPlayerWarpClose ( false )
66158
end
67159
elseif ( source == aWarpCancel ) then
68160
aPlayerWarpClose ( false )
161+
elseif ( source == aWarpToPosition ) then
162+
aPlayerWarpToPosition ( )
163+
164+
-- Player Warp To Position Map
165+
elseif ( source == aWarpToPositionMap ) then
166+
calculatePosition ( absX, absY )
167+
elseif ( source == aWarpToPositionTeleport ) then
168+
warpPlayerToPositionTrigger ( )
169+
elseif ( source == aWarpToPositionCancel ) then
170+
aPlayerWarpToPositionClose ( false )
69171
end
70172
end
71173
end

[admin]/admin/client/images/map.png

222 KB
Loading

[admin]/admin/meta.xml

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<config src="conf/ACL.xml" />
6262

6363
<!--Images-->
64+
<file src="client/images/map.png" />
6465
<file src="client/images/warning.png" />
6566
<file src="client/images/error.png" />
6667
<file src="client/images/question.png" />

[admin]/admin/server/admin_server.lua

+28-16
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,29 @@ function secondsToTimeDesc( seconds )
836836
return ""
837837
end
838838

839+
840+
function warp ( p, to )
841+
local x, y, z, r, dim, int
842+
if type ( to ) == "table" then
843+
x, y, z = unpack ( to )
844+
r, dim, int = 0, 0, 0
845+
else
846+
x, y, z = getElementPosition ( to )
847+
r = getPedRotation ( to )
848+
dim = getElementDimension ( to )
849+
int = getElementInterior ( to )
850+
end
851+
local target = getPedOccupiedVehicle ( p ) or p
852+
x = x - math.sin ( math.rad ( r ) ) * 2
853+
y = y + math.cos ( math.rad ( r ) ) * 2
854+
setTimer ( setElementPosition, 1000, 1, target, x, y, z + 1 )
855+
fadeCamera ( p, false, 1, 0, 0, 0 )
856+
setElementDimension ( target, dim )
857+
setElementInterior ( target, int )
858+
setTimer ( fadeCamera, 1000, 1, p, true, 1 )
859+
end
860+
861+
839862
addEvent ( "aPlayer", true )
840863
addEventHandler ( "aPlayer", _root, function ( player, action, data, additional, additional2 )
841864
if checkClient( "command."..action, source, 'aPlayer', action ) then return end
@@ -1105,25 +1128,14 @@ addEventHandler ( "aPlayer", _root, function ( player, action, data, additional,
11051128
action = nil
11061129
end
11071130
elseif ( action == "warp" ) or ( action == "warpto" ) then
1108-
function warpPlayer ( p, to )
1109-
function warp ( p, to )
1110-
local x, y, z = getElementPosition ( to )
1111-
local r = getPedRotation ( to )
1112-
x = x - math.sin ( math.rad ( r ) ) * 2
1113-
y = y + math.cos ( math.rad ( r ) ) * 2
1114-
setTimer ( setElementPosition, 1000, 1, p, x, y, z + 1 )
1115-
fadeCamera ( p, false, 1, 0, 0, 0 )
1116-
setElementDimension ( p, getElementDimension ( to ) )
1117-
setElementInterior ( p, getElementInterior ( to ) )
1118-
setTimer ( fadeCamera, 1000, 1, p, true, 1 )
1119-
end
1120-
if ( isPedInVehicle ( to ) ) then
1121-
local vehicle = getPedOccupiedVehicle ( to )
1131+
function warpPlayer ( p, to )
1132+
if ( isElement ( to ) and isPedInVehicle ( to ) ) then
1133+
local vehicle = getPedOccupiedVehicle ( to )
11221134
local seats = getVehicleMaxPassengers ( vehicle ) + 1
11231135
local i = 0
11241136
while ( i < seats ) do
11251137
if ( not getVehicleOccupant ( vehicle, i ) ) then
1126-
setTimer ( warpPedIntoVehicle, 1000, 1, p, vehicle, i )
1138+
setTimer ( warpPedIntoVehicle, 1000, 1, p, vehicle, i )
11271139
fadeCamera ( p, false, 1, 0, 0, 0 )
11281140
setTimer ( fadeCamera, 1000, 1, p, true, 1 )
11291141
break
@@ -1142,7 +1154,7 @@ addEventHandler ( "aPlayer", _root, function ( player, action, data, additional,
11421154
warpPlayer ( source, player )
11431155
else
11441156
warpPlayer ( player, data )
1145-
mdata = getPlayerName ( data )
1157+
mdata = type ( data ) == "table" and getZoneName ( unpack ( data ) ) or getPlayerName ( data )
11461158
end
11471159
else
11481160
action = nil

[admin]/admin2/client/images/map.png

222 KB
Loading

0 commit comments

Comments
 (0)