Skip to content

Commit 9dfc910

Browse files
committed
Don't spam OnVehicleDeath events, fix SpawnPlayer so a samp workaround to skip the selection screen works, fix GetActorFacingAngle, add GetActorPos, handle vehicle leave events when a vehicle is destroyed by other means such as a command, add 'debug' client command to toggle debug view.
1 parent 064b6af commit 9dfc910

File tree

7 files changed

+50
-15
lines changed

7 files changed

+50
-15
lines changed

amx/client/client.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ addEventHandler('onClientResourceStart', resourceRoot,
4545
function()
4646
triggerServerEvent('onLoadedAtClient', resourceRoot, localPlayer)
4747
setTimer(checkTextLabels, 500, 0)
48+
setDebugViewActive(true)
4849
end,
4950
false
5051
)
@@ -56,6 +57,12 @@ addEventHandler('onClientResourceStop', resourceRoot,
5657
false
5758
)
5859

60+
function enableDebug()
61+
local state = not isDebugViewActive()
62+
setDebugViewActive(state)
63+
end
64+
addCommandHandler("debug", enableDebug)
65+
5966
function setAMXVersion(ver)
6067
g_AMXVersion = ver
6168
end

amx/client/util.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ function serverAMXEvent(eventName, ...)
6666
server.procCallOnAll(eventName, ...)
6767
end
6868

69-
setDebugViewActive(true)
70-
7169
function drawBorderText(text, x, y, color, scalex, scaley, font, outlinesize, outlinecolor)
7270
local alpha = math.floor(color / 16777216)
7371
outlinesize = outlinesize or 2

amx/server/events.lua

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ addEventHandler('onPlayerSpawn', root,
258258
function()
259259
local playerID = getElemID(source)
260260
local playerdata = g_Players[playerID]
261-
if playerdata.doingclasssel or playerdata.beingremovedfromvehicle or playerdata.spawnedfromgamemodeinit then
261+
if playerdata.doingclasssel or playerdata.spawnedfromgamemodeinit then
262262
if playerdata.spawnedfromgamemodeinit ~= nil then
263263
playerdata.spawnedfromgamemodeinit = nil
264264
end
@@ -380,6 +380,24 @@ addEventHandler('onPlayerQuit', root,
380380
-------------------------------
381381
-- Vehicles
382382

383+
addEventHandler('onResourceStart', resourceRoot,
384+
function()
385+
setTimer ( checkIfLeftVehicleByOtherMeans, 1000, 0 )
386+
end,
387+
false
388+
)
389+
390+
function checkIfLeftVehicleByOtherMeans() --If the player is slapped, or the vehicle is destroyed by a command, we need to handle such
391+
for i, data in pairs(g_Players) do
392+
local state = getPlayerState(data.elem)
393+
if state == PLAYER_STATE_DRIVER or state == PLAYER_STATE_PASSENGER then
394+
if not isPedInVehicle(data.elem) then
395+
setPlayerState(data.elem, PLAYER_STATE_ONFOOT)
396+
end
397+
end
398+
end
399+
end
400+
383401
function respawnStaticVehicle(vehicle)
384402
if not isElement(vehicle) then
385403
return
@@ -392,6 +410,7 @@ function respawnStaticVehicle(vehicle)
392410
killTimer(g_Vehicles[vehID].respawntimer)
393411
end
394412
g_Vehicles[vehID].respawntimer = nil
413+
g_Vehicles[vehID].vehicleIsAlive = true
395414
local spawninfo = g_Vehicles[vehID].spawninfo
396415
spawnVehicle(vehicle, spawninfo.x, spawninfo.y, spawninfo.z, 0, 0, spawninfo.angle)
397416
procCallInternal(amx, 'OnVehicleSpawn', vehID)
@@ -442,14 +461,12 @@ addEventHandler('onVehicleStartEnter', root,
442461
addEventHandler('onVehicleExit', root,
443462
function(player, seat, jacker)
444463
local vehID = getElemID(source)
445-
446464
if isPed(player) then
447465
local pedID = getElemID(player)
448466
g_Bots[pedID].vehicle = nil
449467
setBotState(player, PLAYER_STATE_ONFOOT)
450468
return
451469
end
452-
453470
local playerID = getElemID(player)
454471
g_Players[playerID].vehicle = nil
455472
setPlayerState(player, PLAYER_STATE_ONFOOT)
@@ -494,13 +511,18 @@ addEventHandler('onVehicleExplode', root,
494511
function()
495512
local vehID = getElemID(source)
496513

497-
procCallOnAll('OnVehicleDeath', vehID, 0) -- NOES, MY VEHICLE DIED
514+
--So the OnVehicleDeath event only gets called once
515+
if g_Vehicles[vehID] and g_Vehicles[vehID].vehicleIsAlive then
516+
procCallOnAll('OnVehicleDeath', vehID, 0) -- NOES, MY VEHICLE DIED
498517

499-
if g_Vehicles[vehID] and g_Vehicles[vehID].respawntimer then
500-
killTimer(g_Vehicles[vehID].respawntimer)
501-
g_Vehicles[vehID].respawntimer = nil
518+
if g_Vehicles[vehID].respawntimer then
519+
killTimer(g_Vehicles[vehID].respawntimer)
520+
g_Vehicles[vehID].respawntimer = nil
521+
end
522+
523+
g_Vehicles[vehID].vehicleIsAlive = false
524+
g_Vehicles[vehID].respawntimer = setTimer(respawnStaticVehicle, g_Vehicles[vehID].respawndelay, 1, source)
502525
end
503-
g_Vehicles[vehID].respawntimer = setTimer(respawnStaticVehicle, g_Vehicles[vehID].respawndelay, 1, source)
504526
end
505527
)
506528

amx/server/natives/a_actors.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ function SetActorFacingAngle(amx, actor, ang)
3434
end
3535

3636
function GetActorFacingAngle(amx, actor, refAng)
37-
local rX, rY, rZ = getElementRotation(vehicle)
37+
local rX, rY, rZ = getElementRotation(actor)
3838
writeMemFloat(amx, refAng, rZ)
3939
end
4040

41+
function GetActorPos(amx, actor, refX, refY, refZ)
42+
local x, y, z = getElementPosition(actor)
43+
writeMemFloat(amx, refX, x)
44+
writeMemFloat(amx, refY, y)
45+
writeMemFloat(amx, refZ, z)
46+
end
47+
4148
-- stub
4249
function SetActorInvulnerable(amx)
4350
notImplemented('SetActorInvulnerable')

amx/server/natives/a_samp.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ function AddStaticVehicleEx(amx, model, x, y, z, angle, color1, color2, respawnD
305305
if respawnDelay < 0 then
306306
respawnDelay = 120
307307
end
308+
g_Vehicles[vehID].vehicleIsAlive = true
308309
g_Vehicles[vehID].respawndelay = respawnDelay*1000
309310
g_Vehicles[vehID].spawninfo = { x = x, y = y, z = z, angle = angle }
310311
if ManualVehEngineAndLights then
@@ -499,8 +500,9 @@ function SendRconCommand(amx, command)
499500
print(doRCON(command))
500501
end
501502

503+
--Call requestSpawn instead so we clear up any binds (since there's a workaround in SA-MP to skip the spawn selection screen, and I use this workaround)
502504
function SpawnPlayer(amx, player)
503-
spawnPlayerBySelectedClass(player)
505+
requestSpawn(player, false, false)
504506
end
505507

506508
-- GetPlayerNetworkStats

amx/server/natives/a_vehicles.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ function SetVehicleToRespawn(amx, vehicle)
114114
removePedFromVehicle(player)
115115
end
116116
end
117-
local spawninfo = g_Vehicles[getElemID(vehicle)].spawninfo
118-
spawnVehicle(vehicle, spawninfo.x, spawninfo.y, spawninfo.z, 0, 0, spawninfo.angle)
117+
respawnStaticVehicle(vehicle)
119118
end
120119

121120
function LinkVehicleToInterior(amx, vehicle, interior)

amx/server/syscalls.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,6 @@ g_SAMPSyscallPrototypes = {
755755
SetPlayerDrunkLevel = {'p', 'i'},
756756
SelectTextDraw = {'p', 'x'},
757757
CancelSelectTextDraw = {'p'},
758-
GetActorPos = {'i', 'r', 'r', 'r'}, --r since the vals should be passed by ref
759758
GetPVarsUpperIndex = {'p'},
760759
GetPVarNameAtIndex = {'p', 'i', 'r', 'i'},
761760
SetVehicleParamsCarWindows = {'v', 'i', 'i', 'i', 'i'},
@@ -794,6 +793,7 @@ g_SAMPSyscallPrototypes = {
794793
SetActorFacingAngle = {'y', 'f'},
795794
SetActorHealth = {'y', 'f'},
796795
SetActorInvulnerable = {},
796+
GetActorPos = {'y', 'r', 'r', 'r'}, --r since the vals should be passed by ref
797797
SetActorPos = {'y', 'f', 'f', 'f'},
798798
SetActorVirtualWorld = {'y', 'i'},
799799

0 commit comments

Comments
 (0)