Hey everyone.
So I am reviewing some code for my doorlock system, and there seems to be something going on with the native of DoorSystemSetDoorState when trying to force it.
I have two server functions for handling the door locks: normal, and forced. Normal is for using the Press 'E' to Unlock
for doors in buildings like Pillbox or MRPD. The forced is for places like the back door for banks and such.
Server:
--Normal Unlocking
RegisterNetEvent('erp-doors:alterlockstate')
AddEventHandler('erp-doors:alterlockstate', function(num)
if doorInfo[num]['lock'] == 1 then doorInfo[num]['lock'] = 0 elseif doorInfo[num]['lock'] == 0 then doorInfo[num]['lock'] = 1 end
TriggerClientEvent('erp-doors:alterlockstateclient', -1, num, doorInfo[num]['lock'])
end)
--Forced Unlocking
RegisterNetEvent('erp-doors:forced:alterlockstate')
AddEventHandler('erp-doors:forced:alterlockstate', function(num, forcedstate)
doorInfo[num]['lock'] = tonumber(forcedstate)
TriggerClientEvent('erp-doors:alterlockstateclient', -1, num, doorInfo[num]['lock'])
end)
Client:
RegisterNetEvent("erp-doors:alterlockstateclient")
AddEventHandler("erp-doors:alterlockstateclient", function(value, lockstatus)
doorInfo[value]['lock'] = lockstatus
while not DoorSystemGetIsPhysicsLoaded(value) do
Wait(0)
end
DoorSystemSetDoorState(value, lockstatus, false, true)
end)
Door Config Example:
--Example of a door in the config
[615] = { ['coords'] = vector3(255.22830, 223.97600, 102.39320), ['lock'] = 1, ['doorType'] = 961976194, ['job'] = {"lspd","bcso","sast","sasp","doc","sapr","ambulance","pa","cmmc"}},
I am not sure why, but the normal works no problem. You unlock a door and it stays unlocked until someone locks it again.
But with the forced unlocking/locking, the door will 90% of the time unlock and then immediately lock again… OR it wouldn’t even unlock at all.
Is this something that anyone else has dealt with or am I going insane? Its very game-breaking when people have hacked the bank and can’t get the money because of the door not unlocking.
Any ideas or tips?
Thanks!