Esc to clear, Enter to open the best match, click an export to open it in its page
World

NPCs

NPCs the server makes and looks after: guards, hostages, targets. WHIP keeps each doing what you set, so it never wanders off; yours go when your resource stops, or with a run's ReleaseTag.

Spawning

SpawnNpc(def, opts)SERVER#

Makes an NPC. It exists at once, and the first nearby player's game takes it over within about half a second.

FieldTypeDescription
modelstringA ped model name
coordsvector3|vector4|tableWhere; a vector4's w (or heading) faces it
behaviour'stand'|'guard'?stand (default) stays put; guard wanders near its spot. Either walks back after a fight
conditionstable?{ invincible, canMove, reacts, flees }, default false, true, false, false. flees (run, not fight) needs reacts = true
weaponstring|table?A weapon name (GTA's or a streamed add-on), or { name, ammo }
armournumber?0–100
looktable?A character editor look, checked like a character's save (10,000 bytes of JSON at most). The ped becomes the look's freemode model
interior, gateAtboolean?, coords?It stands inside an MLO: kept frozen until the interior loads. gateAt: where to look for the MLO, if not at its spot
opts.tagstring?Your run tag (ReleaseTag)
opts.hostileTotable?{ people = { serverId | { charId = n } } }: fights the nearest of them online and not down. { except = { ... } }: everyone else, only with opts.range
opts.fightBackboolean?Fights its attacker (default true) until they go down or a minute after their last hit
opts.corpseMsnumber?How long a body stays (default 60000; 0 = until removed)
opts.rangenumber?1–500 m: fights hostileTo only this near its spot, chases a shooter up to three times as far, then walks back. Left out, anywhere
opts.groupstring?Up to 128 characters: hurt one (even with one fatal shot) and every NPC of yours in the group fights back
Returns: npcId, netId, or false, reason
local npcId, netId = exports.whip_core:SpawnNpc({
    model = 's_m_y_dealer_01', coords = vector4(x, y, z, heading),
    behaviour = 'guard', weapon = 'WEAPON_PISTOL',
}, { tag = 'run:42', hostileTo = { people = { source } } })
DespawnNpc(npcId)SERVER#

Removes one of your NPCs; its owner's game deletes the ped.

Returns: true, or false, reason

Changing what it does

SetNpcState(npcId, patch)SERVER#

Changes what one of your NPCs does; whichever game runs it next carries on. patch also takes behaviour, hostileTo (false calms it and forgets its attackers), fightBack, conditions, interior and range (false: anywhere again).

patchTypeDescription
attacktable | false?What it attacks when it has nobody to fight: { net = a car's netId } or { at = coords } (a prop). Shoots, or walks up without a weapon; leaves a burnt-out car
postcoords?A new spot to walk to and stand or guard at. With interior = true it's inside an MLO
gateAtcoords?Where to look for that MLO, if not at the post (the spot a group gathers round)
pacestring?'walk' (default) or 'run'
followserverId | falseWalks after that player, waiting while they're gone or down. false stops it: set post too, or it walks back
fleeserverId | falseRuns from that player, fighting nobody
animtable | false{ dict, clip } or { scenario }, looped where it stands
Returns: true, or false, reason
exports.whip_core:SetNpcState(npcId, { hostileTo = { people = { source } } })   -- the alarm tripped
exports.whip_core:SetNpcState(hostageId, { follow = source, pace = 'run' })    -- the rescue

Reading and events

Events: whip_core:npc:spawned, :despawned { reason }, :damaged { amount, attacker }, :killed { killer, weapon, coords }.

GetNpc(ref) · GetNpcs({ tag })SERVER#

GetNpc returns a copy or nil: { npcId, owner, tag, model, netId, alive, health, armour, behaviour, conditions, targets, focus, range, group, killer, killedAt, weapon, coords, post, pace, follow, flee, interior }. killer is the server's reading (a car's driver for a run-over). ref is an npcId, or { entity = } or { netId = } while that is still the NPC's ped. GetNpcs returns yours, or one tag's.

local paid = {}
AddEventHandler('whip_core:npc:killed', function(e)
    local npc = exports.whip_core:GetNpc(e.npcId)   -- the server's reading, not the event's
    if not npc or npc.owner ~= GetCurrentResourceName() or paid[npc.npcId] then return end
    if not npc.alive and npc.killer then
        paid[npc.npcId] = true
        exports.whip_core:PayPlayer(npc.killer, 500, { reason = 'Bounty' })
    end
end)
Check a kill before paying. Any server resource can fire an event: ask GetNpc.