Custom Hack

On this page, I'll give you snippets on how to add custom hack to Hacker V.

Config (shared/cfg.lua)

In this file, find the following lines and uncomment them. You can use this in every custom hack you add.

['custom_hack'] = {
    ['objects'] = {'prop_bin_01a'},
    ['offset'] = vector3(-0.25, -0.8, 0.25),
    ['label'] = '[E] Hack the garbage',
    ['icon'] = 'fa-solid fa-terminal',
    ['event'] = 'hackermod:client:hackGarbage', ['eventType'] = 'client',
    ['canInteract'] = function(entity)
        return not interactableObjects['custom_hack'][GetEntityCoords(entity)]
    end,
    ['cooldown'] = 0,
    ['requiredBotnet'] = 0,
},

These lines, add a new option to hack interactions. This table should be under cfg['interactions']. You can change orderly,

  • Which objects you want to be hacked

  • UI attach offset

  • UI label

  • UI icon

  • Event and type to be triggered

  • Can interact function

  • Hack cooldown

  • Required count of botnets.

Custom hack (client/custom_hack.lua)

In this file, you can create event for custom hack you added. I will explain it to you with an example case for you to understand the logic.

RegisterNetEvent('hackermod:client:hackGarbage', function(type, entity)
    Citizen.CreateThread(function()
        triggerCallback('hackermod:server:checkAction', function(status)
            if status then
                TriggerServerEvent('hackermod:server:sync', 'interactableObject', {type, GetEntityCoords(entity)})
                keepAnimTask = true
                DrawBusySpinner('Connecting to garbage', 5)
                local minigame = Minigame(3, 3)
                if minigame then
                    local randomMoney = math.random(100, 500)
                    TriggerServerEvent('hackermod:server:cash', randomMoney)
                    print('you won')
                else
                    TriggerServerEvent('hackermod:server:sync', 'interactableObject', {type, GetEntityCoords(entity)})
                    print('you failed')
                end
                keepAnimTask = false
            end
        end, type)
    end)
end)
  • When an event is triggered, the event function written to cfg comes with two parameters. type and entity. Type is hack type, entity is local entity ID.

  • We are creating a new thread so that it does not affect other loops in the script. (Citizen.CreateThread)

  • We check the cooldown of the action and the required count of botnets for the player. (triggerCallback)

  • We are disable the object for other players. (Other players will see "Already Hacked." text. (hackermod:server:sync', 'interactableObject')

  • We set this variable to 'true' so that the phone stays on your hand for the duration of the action. (keepAnimTask)

  • We create a 5 second wait for action. (DrawBusySpinner())

  • We create minigame for action. (Minigame())

  • If the minigame is completed successfully, the event that will give money to the player will be triggered, otherwise the object will be active again so that other players can hack it. (if-else block)

  • At the end of the action, we take the phone out of the player's view. (keepAnimTask)

Last updated