ixHal
May 21, 2019, 12:13pm
1
So I’m making a script for bank robbing and I have it so the door opens client side, How do i make it so the server checks if it is open or not? since i want multiple people to be able to go down to the vault, i currently have this in my client main:
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
DrawMarker(20, 262.0, 223.08, 107.28, 0.0, 0.0, 0.0, 180.0, 0.0, 0.0, 0.5, 0.5, 0.5, 255, 0, 0, 55, true, true, 2, false, nil, nil, false)
BankDoor = GetClosestObjectOfType(262.1981, 222.5188, 106.4296, 100.0, 746855201, 0, 0, 0)
FreezeEntityPosition(BankDoor, IsLocked)
--GetEntityHeading(BankDoor)
--SetEntityHeading(BankDoor, DoorH)
end
end)
My server main is empty atm.
Any help is greatly appreciated
Cheers
KASH
May 21, 2019, 2:17pm
2
So what you can do is make an toggle door lock event, you don’t have to put it in a while loop by the way, you can use it in these events
client:
-- Set status for every client
RegisterNetEvent('bankrobbing:SetDoorStatus')
AddEventHandler('bankrobbing:SetDoorStatus', function(LockStatus)
BankDoor = GetClosestObjectOfType(262.1981, 222.5188, 106.4296, 100.0, 746855201, 0, 0, 0)
FreezeEntityPosition(BankDoor, LockStatus)
end)
server:
local DoorStatus = true
RegisterServerEvent('bankrobbing:ToggleDoorStatus')
AddEventHandler('bankrobbing:ToggleDoorStatus', function()
DoorStatus = not Doorstatus
TriggerClientEvent('bankrobbing:SetDoorStatus', -1, DoorStatus)
end)
and then you can just trigger it by: TriggerServerEvent('bankrobbing:ToggleDoorStatus')
ixHal
May 21, 2019, 2:50pm
3
Thanks for the reply!
Will try this as soon as i can thank you so much for the help!
ixHal
May 21, 2019, 3:28pm
4
So I’ve done what you said and tried it but the door is not locking now, ive also added a draw marker into the Handler like this
RegisterNetEvent('bankrob:SetDoorStatus')
AddEventHandler('bankrob:SetDoorStatus', function(LockStatus)
DrawMarker(20, 262.0, 223.08, 107.28, 0.0, 0.0, 0.0, 180.0, 0.0, 0.0, 0.5, 0.5, 0.5, 255, 0, 0, 55, true, true, 2, false, nil, nil, false)
BankDoor = GetClosestObjectOfType(262.1981, 222.5188, 106.4296, 100.0, 746855201, 0, 0, 0)
FreezeEntityPosition(BankDoor, LockStatus)
end)
and no marker shows so im guessing ive done something wrong?
KASH
May 21, 2019, 4:16pm
5
Ye, a marker need to be in the whileloop however the bankdoor and freezeentity don’t
ixHal
May 21, 2019, 4:36pm
6
KASH:
local DoorStatus = true RegisterServerEvent(‘bankrobbing:ToggleDoorStatus’) AddEventHandler(‘bankrobbing:ToggleDoorStatus’, function() DoorStatus = not Doorstatus TriggerClientEvent(‘bankrobbing:SetDoorStatus’, -1, DoorStatus) end)
did you make a mistake with the LockStatus and DoorStatus should they be the same or? i just dont understand it, the door is not locked by default, and after i trigger nothing happens.
ixHal
May 21, 2019, 8:28pm
7
Never mind ive solved it, I have the door (entity) frozen in a loop and the trigger just changes the heading of the door now thanks for showing me the right direction buddy