Hi! I am trying to implement mhacking to ATM holdup for ESX. With a little catch that allows to do this only if player have “hacking device” in his inventory.
Everything works, except with this item check, I don’t know how to call the mhacking trigger from server side (where should be decided, if hack will even begin).
Could anyone help me on this, please? I can trigger this from client side, but because I want to limit use of this, I guess I need to figure it out from server side of the script…
RegisterServerEvent('esx_atmholdup:rob')
AddEventHandler('esx_atmholdup:rob', function(robb)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local hack = xPlayer.getInventoryItem('hack')
local xPlayers = ESX.GetPlayers()
if Stores[robb] then
local store = Stores[robb]
if (os.time() - store.lastrobbed) < Config.TimerBeforeNewRob and store.lastrobbed ~= 0 then
TriggerClientEvent('esx:showNotification', source, _U('already_robbed') .. (Config.TimerBeforeNewRob - (os.time() - store.lastrobbed)) .. _U('seconds'))
return
end
local cops = 0
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
if xPlayer.job.name == 'police' then
cops = cops + 1
end
end
if rob == false then
if hack.count >= 1 then
if(cops >= Config.PoliceNumberRequired)then
rob = true
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
if xPlayer.job.name == 'police' then
TriggerClientEvent('esx:showNotification', xPlayers[i], _U('rob_in_prog') .. store.nameofstore)
TriggerClientEvent('esx_atmholdup:setblip', xPlayers[i], Stores[robb].position)
end
end
TriggerClientEvent('esx:showNotification', source, _U('started_to_rob') .. store.nameofstore .. _U('do_not_move'))
TriggerClientEvent('esx:showNotification', source, _U('alarm_triggered'))
TriggerClientEvent('esx:showNotification', source, _U('hold_pos'))
TriggerClientEvent('esx_atmholdup:currentlyrobbing', source, robb)
Stores[robb].lastrobbed = os.time()
robbers[source] = robb
local savedSource = source
if(robbers[savedSource])then
rob = false
TriggerClientEvent('esx_atmholdup:robberycomplete', savedSource, job)
if(xPlayer)then
local xPlayers = ESX.GetPlayers()
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
if xPlayer.job.name == 'police' then
TriggerClientEvent('esx:showNotification', xPlayers[i], _U('robbery_complete_at') .. store.nameofstore)
TriggerClientEvent('esx_atmholdup:killblip', xPlayers[i])
end
end
end
end
--TriggerEvent("mhacking:show")
--TriggerEvent("mhacking:start",1,30,mycb)
--TriggerClientEvent('esx_atmholdup:starthack')
true
else
TriggerClientEvent('esx:showNotification', source, _U('min_police') .. Config.PoliceNumberRequired .. _U('in_city'))
end
else
TriggerClientEvent('esx:showNotification', source, ('You do not have a hacking device!'))
end
else
TriggerClientEvent('esx:showNotification', source, _U('robbery_already'))
end
end
end)
There is also this function that worked on client side
function mycb(success, timeremaining)
if success then
print('Success with '..timeremaining..'s remaining.')
TriggerEvent('mhacking:hide')
TriggerServerEvent('esx_atmholdup:done')
ESX.ShowNotification(_U('paycheck'))
else
print('Failure')
TriggerEvent('mhacking:hide')
end
end
Error I am getting in console
InvokeNative: execution failed: Argument at index 1 was null.
Error running system event handling function for resource esx_atmholdup: citizen:/scripting/lua/scheduler.lua:41: Failed to execute thread: Execution of native 000000002f7a49e6 in script host failed.
stack traceback:
[C]: in upvalue '_in'
citizen:/scripting/lua/natives_server.lua:450: in function 'TriggerClientEventInternal'
(...tail calls...)
@esx_atmholdup/server/main.lua:111: in upvalue 'handler'
citizen:/scripting/lua/scheduler.lua:219: in function <citizen:/scripting/lua/scheduler.lua:218>
stack traceback:
[C]: in function 'error'
citizen:/scripting/lua/scheduler.lua:41: in field 'CreateThreadNow'
citizen:/scripting/lua/scheduler.lua:218: in function <citizen:/scripting/lua/scheduler.lua:182>
Thank you in advance for all responses!