[Release] [ESX] loffe_robbery

Can you make an alarm trigger for police when they starting to rob like a blips on map

2 Likes

Well, theft time is just an animation, I guess you can just slow it down

1 Like

There is already an alarm? They get a photo and a waypoint

1 Like

Lets say there are 2 or more people infront of the cashier, When he drops the money, all of them will get a randomized number of cash.

Yes i mean the alarm will trigger when they starting to aim at NPC, not wait until the blue bar finished.

@Poppy
Yes, of course, this is what you’ll need to do:

Go to client.lua and paste this code: TriggerServerEvent('loffe_robbery:alarm', i) after row 254, should look like this:

if canRob == true then
TriggerServerEvent('loffe_robbery:alarm', i)
robbing = true
Citizen.CreateThread(function()

Go to server.lua and remove row 62-68

Go to server.lua and paste this code anywhere in server.lua:

RegisterServerEvent('loffe_robbery:alarm')
AddEventHandler('loffe_robbery:alarm', function(store)
    local src = source
    local xPlayers = ESX.GetPlayers()
    for i = 1, #xPlayers do
        local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
        if xPlayer.job.name == 'police' then
            TriggerClientEvent('loffe_robbery:msgPolice', xPlayer.source, store, src)
        end
    end
end)

I’m not sure if this will work, but it should work

1 Like

You will have to change TriggerServerEvent(‘loffe_robbery:alarm’) to TriggerServerEvent(‘loffe_robbery:alarm’, i) then it will work.

And you can rob with 2 players at the exact same time.

1 Like

Yes, working now perfectly! Thank you.

The reason is the flag set for robbing goes to everyone on the server… so if you have 15 people connected - the server is sending all the clients the rob command. This makes it so each player if they are close see’s the robbery animation which is nice, but it also will mean the npc would drop 15 bags on the ground and each person would only see 1… and be able to pick up that 1. The way around this would be set a flag when the robbery starts that says who is doing the robbery… and when the bag is picked up check to make sure it is that person- if it is send server command to delete all bags… and then pass that client side so all clients clean up the bags dropped.

The reason this happens is you have the createped isnetworked = false, so people only see 1 clerk in the store - but they each see a different clerk. You can see this in action if 2 people go into the store at same time, while one person starts the robbery… the 2nd person will just see the npc standing there doing nothing until the scared meter has gone away. If you change the -1 in the triggerclientevent so multi bags do not drop… it will only show the animations for the person that is doing the actual robbery which negates the real potential of this script.

I know isnetwork is false, I did that because it was the easiest, simplest way I could come up with, however when someone picks up a bag it triggers a server event that removes the bag for everyone.

Well, I guess I will rewrite the script to use isnetwork on the ped since its probably alot easier to sync for everyone

Ok… we tested last night… with 2 of us standing next to each other while i robbed the store… and both picked up the bag. I like that the animation shows to all clients… makes it alot better for rp if the police show up and see the robbery happening, just need to keep the 2nd person from picking up the bag at the same time as first. I robbed the store got 4.7k - the guy standing next to me got 8k.

Bar from this small issue the script looks outstanding.

SpikE

When I delete line 62-68 in server.lua the following appears:

When you deleted it should look like this.

RegisterServerEvent('loffe_robbery:rob')
AddEventHandler('loffe_robbery:rob', function(store)
    local src = source
    Config.Shops[store].robbed = true
    TriggerClientEvent('loffe_robbery:rob', -1, store)
    Wait(30000)
    TriggerClientEvent('loffe_robbery:robberyOver', src)

    local second = 1000
    local minute = 60 * second
    local hour = 60 * minute
    local cooldown = Config.Shops[store].cooldown
    local wait = cooldown.hour * hour + cooldown.minute * minute + cooldown.second * second
    Wait(wait)
    Config.Shops[store].robbed = false
    for k, v in pairs(deadPeds) do if k == store then table.remove(deadPeds, k) end end
    TriggerClientEvent('loffe_robbery:resetStore', -1, store)
end)

then add the alarm somewhere

RegisterServerEvent('loffe_robbery:alarm')
AddEventHandler('loffe_robbery:alarm', function(store)
    local src = source
    local xPlayers = ESX.GetPlayers()
    for i = 1, #xPlayers do
        local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
        if xPlayer.job.name == 'police' then
            TriggerClientEvent('loffe_robbery:msgPolice', xPlayer.source, store, src)
        end
    end
end)
1 Like

scripting it for isnetwork is alot more work… but does make it sync alot better… but everyone will be spawning one. So if you have 5 people on the server… will have 5 npc’s spawned at each location. I am working on a script that will handle npc spawing and pass control to others on disconnect so only 1 spawns at a time but so far its being a pain.

SpikE

@SpikE_Odets
What you could do is check for the closest ped to where its supposed to spawn, see if it is the correct hash and if it doesnt find something it creates a new ped.

You could also use https://runtime.fivem.net/doc/natives/#_0xA11700682F3AD45C I think

I tried that but they still seemed to spawn, and i think its becaues the client script loads up and spawns the npc’s before the network is fully connected and causes double spawns.

I think the way to do it is to have first person that spawns on the server spawn all… set in a config that they have been spawned… and anyone else that spawns in will ignore the spawnped function. Doing this as long as the first person is on the server the npc’s will be there… and everyone will see them. But as soon as he disconnects the npc’s will be marked as no longer needed and if the area gets unloaded and you come back will not be there. Need to pass ownership of the mission entity on disconnect which is what i am working on now.

SpikE

@SpikE_Odets
Well, you will need to do

while not NetworkIsSessionStarted() do Wait(0) end

before loading everything

And when the first person spawns the ped, it sends the NetworkGetNetworkIdFromEntity(ped) to the server, then do an event listener for when a player joins and send the ped networkid, the client will then do NetworkGetEntityFromNetworkId(id)

(I think it will work if you do that loop before checking)

I will have a look at that… thnx for the info… Do you know if this will keep the mission entity active after the person that sets it as mission entity disconnects? i am looking at that part now to pass control of mission entity to next person on list but if this does it without having to pass control all is good.

Way to test is to spawn a mission entity ped… and have someone else join the server… they wil see the ped… then you disconnect and have them drive around the map and come back and the ped hopefully will still be there with the method you mentioned. I have my script only spawing one ped… when someone joins the server already by using server config so im not getting duplicates anymore… but if that person leaves the server all the peds despawn… trying to keep that from happening by having server check for playerdropped and if its the player that spawned peds - then get playerlist send clientevent to first player on list to take control of all npcs… and they will cycle thru the config to get coords of each spawned npc and use getclosestped and NetworkRequestControlOfEntity to take control or if the entity is not there… just spawn new one so it is there.

Thanks for this Loffe! Any way to make the process of robbing longer?

1 Like

Atm you would need to slow down the animation speed etc, however I’m going to make a new update to this script (complete rewrite) and in there you will be able to change speed etc.