Integration
The active limit is published on the vehicle's statebag as duckLimiter, so any other resource — HUD, police radar, dispatch, insurance script — can read it without touching this one.
Reading the limit
local limit = Entity(vehicle).state.duckLimiter
if limit and limit > 0 then
print(('vehicle is limited to %d'):format(limit))
end| Value | Meaning |
|---|---|
nil | No limiter has ever been engaged on this vehicle. |
0 | The limiter is off. |
> 0 | The active limit, in Config.Unit. |
The value is in whatever Config.Unit is set to. If your resource needs a fixed unit, convert on your side — the statebag deliberately follows the server's configured unit rather than a hidden internal one.
The statebag is replicated, so it can be read on both the client and the server.
Reacting to changes
AddStateBagChangeHandler('duckLimiter', nil, function(bagName, key, value)
local netId = bagName:gsub('entity:', '')
local vehicle = NetworkGetEntityFromNetworkId(tonumber(netId))
if not DoesEntityExist(vehicle) then return end
if value and value > 0 then
-- limiter engaged at `value`
else
-- limiter off
end
end)HUD example
Show the active limit on the driver's HUD:
CreateThread(function()
while true do
local vehicle = cache.vehicle
local limit = vehicle and Entity(vehicle).state.duckLimiter
if limit and limit > 0 then
-- draw your HUD element with `limit`
Wait(0)
else
Wait(500)
end
end
end)Security
The statebag is only ever written by the server. Before writing, the server verifies:
- The requesting player is the driver of that vehicle.
- The value is within
Config.MinLimitandConfig.MaxLimit. - The player has not written within
Config.RequestCooldownmilliseconds.
There is no event a client can call to set a limit on someone else's vehicle, or to set a value outside the configured bounds.
WARNING
Do not write to duckLimiter from your own resource. The limiter treats the statebag as its own output, so external writes will be overwritten and will not change how the vehicle actually behaves.