Create a Custom Action
How to create new actions for the NPCs
`custom/client/actions.lua`function CustomFollow(networkId, playerIdentifier, hasWeapon)
-- Transform the network ID into local Ped
local targetPed = NetToPed(networkId)
-- Validates that player is carrying a weapon and code is only executed to the player who trigger the action
if hasWeapon and playerIdentifier == GetClientIdentifier() then
-- Perform the action
TaskFollowToOffsetOfEntity(targetPed, PlayerPedId(), 1.0, -1.0, 0.0, 5.0, -1, 2.0, true)
end
end`custom/server/actions.lua`RegisterNetEvent("sse_npc_interaction:robberySuccess", function(pedNetworkID)
local src = source
local currentTime = os.time()
if not Robberies[pedNetworkID] or currentTime - Robberies[pedNetworkID] > Config.NPCRobberyTimeout then
for itemName, itemValue in pairs(Config.NPCRobberyItems) do
-- Roll a random number between 1 and 100
local roll = math.random(1, 100)
if roll <= itemValue.probability then
AddItem(GetPlayer(src), itemName, math.random(itemValue.min, itemValue.max))
end
end
Robberies[pedNetworkID] = currentTime
else
TriggerClientEvent("sse_npc_interaction:clientNotification", src, Translations["title"], Translations["action-npc-robbery-already-robbed"], "info")
end
end)Last updated