@@ -189,31 +189,25 @@ RegisterNetEvent("EasyAdmin:requestSpectate", function(playerServerId, playerDat
189189 local tgtCoords = playerData .coords
190190
191191 if ((not tgtCoords ) or (tgtCoords .z == 0.0 )) then tgtCoords = GetEntityCoords (GetPlayerPed (GetPlayerFromServerId (playerServerId ))) end
192- if playerServerId == GetPlayerServerId (PlayerId ()) then
193- if oldCoords then
194- RequestCollisionAtCoord (oldCoords .x , oldCoords .y , oldCoords .z )
195- Wait (500 )
196- SetEntityCoords (playerPed , oldCoords .x , oldCoords .y , oldCoords .z , 0 , 0 , 0 , false )
197- oldCoords = nil
198- end
199- spectatePlayer (localPlayerPed ,GetPlayerFromServerId (PlayerId ()),GetPlayerName (PlayerId ()))
200- frozen = false
201- FreezeMyself (false )
202- return
203- else
204- if not oldCoords then
205- oldCoords = GetEntityCoords (PlayerPedId ())
206- end
192+
193+ if not IsSpectating then
194+ oldCoords = GetEntityCoords (PlayerPedId ())
207195 end
196+
208197 SetEntityCoords (localPlayerPed , tgtCoords .x , tgtCoords .y , tgtCoords .z - 10.0 , 0 , 0 , 0 , false )
209198 frozen = true
210199 FreezeMyself (true )
211200 stopSpectateUpdate = true
212201 local playerId = GetPlayerFromServerId (playerServerId )
202+ local timer = 0
213203 repeat
214204 Wait (200 )
215205 playerId = GetPlayerFromServerId (playerServerId )
216- until ((GetPlayerPed (playerId ) > 0 ) and (playerId ~= - 1 ))
206+ timer = timer + 1
207+ until ( (GetPlayerPed (playerId ) > 0 ) and (playerId ~= - 1 ) or timer > 25 )
208+ if timer >= 25 then
209+ return
210+ end
217211 spectatePlayer (GetPlayerPed (playerId ),playerId ,GetPlayerName (playerId ))
218212 stopSpectateUpdate = false
219213end )
@@ -388,7 +382,7 @@ function spectatePlayer(targetPed,target,name)
388382 SetEntityCollision (playerPed , false , false )
389383 SetEntityInvincible (playerPed , true )
390384 NetworkSetEntityInvisibleToNetwork (playerPed , true )
391- Citizen . Wait (200 ) -- to prevent target player seeing you
385+ Wait (200 ) -- to prevent target player seeing you
392386 if targetPed == playerPed then
393387 Wait (500 )
394388 targetPed = GetPlayerPed (target )
@@ -404,14 +398,13 @@ function spectatePlayer(targetPed,target,name)
404398 RequestCollisionAtCoord (oldCoords .x , oldCoords .y , oldCoords .z )
405399 Wait (500 )
406400 SetEntityCoords (playerPed , oldCoords .x , oldCoords .y , oldCoords .z , 0 , 0 , 0 , false )
407- oldCoords = nil
408401 end
409402 NetworkSetInSpectatorMode (false , targetPed )
410403 StopDrawPlayerInfo ()
411404 TriggerEvent (" EasyAdmin:showNotification" , GetLocalisedText (" stoppedSpectating" ))
412405 frozen = false
413406 FreezeMyself (false )
414- Citizen . Wait (200 ) -- to prevent staying invisible
407+ Wait (200 ) -- to prevent staying invisible
415408 SetEntityVisible (playerPed , true , 0 )
416409 SetEntityCollision (playerPed , true , true )
417410 SetEntityInvincible (playerPed , false )
0 commit comments