Exports
Server and client exports and hooks for connecting your own scripts to Hunting.
Hook your own scripts into Hunting. Server exports only run from your server's code, so players can't call them.
A real GTA weapon needs none of this: add its name to cfg.settings.validWeapons in gg_hunting/config/shared/settings.lua and its kills count by themselves. Use registerKill for kills Hunting can't see, like a bow that shoots props.
Server
registerKill
Counts a hunting kill for a player. Added in 2.1.9.
local ok, result = exports.gg_hunting:registerKill(source, netId)
| Name | Type | Description |
|---|---|---|
source | number | The hunter's server ID |
netId | number | Network ID of the animal |
| Returns | Type | Description |
|---|---|---|
ok | boolean | true when the animal is now a valid kill the hunter can butcher |
result | table or string | The registered animal, or why the kill didn't count |
The hunter's game kills the animal, then Hunting runs its normal kill rules: hunting level, hunting zones, illegal-animal alerts, XP and challenges. The animal has to be one from config/shared/animals.lua and within 300 m of the hunter.
Important Every call counts as a real kill. Check the hit in your own server code first, as in the example below, and never pass a client event straight into this export.
getPlayerLevel
local level, progress = exports.gg_hunting:getPlayerLevel(source)
Returns the player's hunting level and their progress to the next level (0 to 100), or nil.
getPlayerExperience
local experience = exports.gg_hunting:getPlayerExperience(source)
Returns the player's total hunting experience, or nil.
Client
isInHuntingZone
local zoneId = exports.gg_hunting:isInHuntingZone()
Returns the ID of the open hunting zone the player is in, or false.
getPlayerLevel
local level, progress = exports.gg_hunting:getPlayerLevel()
The local player's hunting level and progress, the same as the server export.
Hooks
Hooks are functions in Hunting's own files that you fill in. Both files are open for editing.
gg_hunting/base/core/open/server/hooks.lua:
| Hook | When it runs |
|---|---|
hooks.hasHuntingLicense(source) | Hunting asks whether a player has a hunting license. Return true or false. By default it reads Hunting's own database. |
hooks.data.onKill(source, payload) | A player's kill counted |
hooks.data.onGather(source, payload) | A player gathered items from an animal |
hooks.data.onPurchase(source, payload) | A player bought something |
hooks.data.onSell(source, payload) | A player sold something |
payload is { target = string, amount = number }: the animal or item, and how many.
gg_hunting/base/core/open/client/hooks.lua:
| Hook | When it runs |
|---|---|
hooks.hasLicense() | A player opens the Hunting Lodge, Meat Locker or Trapper while require_license is on. It offers the license when they have none. Return false to keep the menu closed. |
Example: your own bow
Your archery script spots the hit on the client, sends it to your server, checks it there, then lets Hunting count it.
Client, in your archery script, when an arrow hits something:
local function onArrowHit(entity)
if not DoesEntityExist(entity) or not IsEntityAPed(entity) or IsPedAPlayer(entity) then return end
if not NetworkGetEntityIsNetworked(entity) then return end
TriggerServerEvent("my_archery:server:arrowHit", NetworkGetNetworkIdFromEntity(entity))
end
Server, in your archery script:
local lastShot = {}
RegisterNetEvent("my_archery:server:arrowHit", function(netId)
local src = source
-- One arrow at a time
local now = GetGameTimer()
if lastShot[src] and now - lastShot[src] < 1500 then return end
lastShot[src] = now
-- The animal has to exist and be in bow range of the shooter
local animal = NetworkGetEntityFromNetworkId(netId)
if animal == 0 or not DoesEntityExist(animal) then return end
if #(GetEntityCoords(GetPlayerPed(src)) - GetEntityCoords(animal)) > 80.0 then return end
local ok, result = exports.gg_hunting:registerKill(src, netId)
if not ok then
print(("[my_archery] kill not counted for %s: %s"):format(src, result))
end
end)
AddEventHandler("playerDropped", function()
lastShot[source] = nil
end)
Add your own bow check to the server part too, for example that the player has your bow item.
What the server checks
Since 2.1.9 the server checks every kill itself, so a player can't fake one:
- a weapon from
validWeapons, or the hunting crossbow, is in the hunter's hands - the animal is dead and within 300 m
- no more than 6 kills a minute per player
registerKill skips only the weapon check, because your own script has already checked the hit.
