88*
99**************************************]]
1010
11- aWarpForm = nil
11+ aWarpForm = nil
12+ aWarpToPositionForm = nil
1213
1314function 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
4751end
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+
49134function 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
58147end
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
71173end
0 commit comments