Misc ESX codes ( Disable Spam Punching, Robberies command, Job Announcements )

Disable spam punching. you have to look at the player before punching

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        DisableControlAction(1, 140, true)
        if not IsPlayerTargettingAnything(PlayerId()) then
          DisableControlAction(1, 141, true)
          DisableControlAction(1, 142, true)
        end
    end
end)

Command to show what robberies players can do

local actions = {
    [2] = { 'atm hack'},
    [3] = { 'store robbery','atm hack' },
    [5] = { 'store robbery','atm hack','jewelry robbery','house robberies' }
}

-- Command to show what players can do based on the number of cops online
RegisterCommand('robberies', function(source, args, rawCommand)
    local playerPed = GetPlayerPed(source)
    local playerCoords = GetEntityCoords(playerPed)
    local policeCount = 0
    
    -- Loop through all players and count the number of police online
    for _, player in ipairs(GetPlayers()) do
        local targetPed = GetPlayerPed(player)
        local job = ESX.GetPlayerFromId(player).job.name
        
        if job == 'police' and #(playerCoords - GetEntityCoords(targetPed)) < 100 then
            policeCount = policeCount + 1
        end
    end
    
    -- Show the player what they can do based on the number of police online
    if actions[policeCount] == nil then
        TriggerClientEvent('chat:addMessage', source, { args = { '^1[!]', ' ^0You need more cops on duty to do any illegal activities!' } })
    else
        local actionsList = ''
        
        for _, action in ipairs(actions[policeCount]) do
            actionsList = actionsList .. action .. ', '
        end
        
        actionsList = string.sub(actionsList, 1, -3)
        
        TriggerClientEvent('chat:addMessage', source, { args = { '^1[!]', '^0 With ' .. policeCount .. ' cop(s) on duty, you can do: ' .. actionsList } })
    end
end, false)

Job announcements


local allowedJobs = {
    ['police'] = true, -- Police job is allowed to make announcements
    ['ambulance'] = true -- Ambulance job is allowed to make announcements
}

RegisterCommand('announce', function(source, args, rawCommand)
    local xPlayer = ESX.GetPlayerFromId(source)
    local job = xPlayer.job.name
    
    -- Check if the player's job is allowed to make announcements
    if not allowedJobs[job] then
        TriggerClientEvent('chat:addMessage', source, { args = { '^1[!]', '^0 You are not allowed to make announcements!' } })
        return
    end
    
    local message = table.concat(args, ' ')
    
    -- Check if the message is not empty
    if not message or message == '' then
        TriggerClientEvent('chat:addMessage', source, { args = { '^1[!]', '^0 You must provide a message to announce!' } })
        return
    end
    
    -- Check if the player has enough money in their bank account
    if xPlayer.getAccount('bank').money < 200 then
        TriggerClientEvent('chat:addMessage', source, { args = { '^1[!]', '^0 You do not have enough money to make an announcement!' } })
        return
    end
    
    -- Charge the player $200 from their bank account
    xPlayer.removeAccountMoney('bank', 200)
    
    -- Send the announcement to all players
    TriggerClientEvent('chat:addMessage', -1, { args = { '^2[Business Announcement]:', message } })
end, false)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.