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
Makes an NPC. It exists at once, and the first nearby player's game takes it over within about half a second.
| Field | Type | Description |
|---|---|---|
| model | string | A ped model name |
| coords | vector3|vector4|table | Where; 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 |
| conditions | table? | { invincible, canMove, reacts, flees }, default false, true, false, false. flees (run, not fight) needs reacts = true |
| weapon | string|table? | A weapon name (GTA's or a streamed add-on), or { name, ammo } |
| armour | number? | 0–100 |
| look | table? | 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, gateAt | boolean?, 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.tag | string? | Your run tag (ReleaseTag) |
| opts.hostileTo | table? | { people = { serverId | { charId = n } } }: fights the nearest of them online and not down. { except = { ... } }: everyone else, only with opts.range |
| opts.fightBack | boolean? | Fights its attacker (default true) until they go down or a minute after their last hit |
| opts.corpseMs | number? | How long a body stays (default 60000; 0 = until removed) |
| opts.range | number? | 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.group | string? | Up to 128 characters: hurt one (even with one fatal shot) and every NPC of yours in the group fights back |
npcId, netId, or false, reasonlocal 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 } } })
Removes one of your NPCs; its owner's game deletes the ped.
true, or false, reasonChanging what it does
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).
| patch | Type | Description |
|---|---|---|
| attack | table | 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 |
| post | coords? | A new spot to walk to and stand or guard at. With interior = true it's inside an MLO |
| gateAt | coords? | Where to look for that MLO, if not at the post (the spot a group gathers round) |
| pace | string? | 'walk' (default) or 'run' |
| follow | serverId | false | Walks after that player, waiting while they're gone or down. false stops it: set post too, or it walks back |
| flee | serverId | false | Runs from that player, fighting nobody |
| anim | table | false | { dict, clip } or { scenario }, looped where it stands |
true, or false, reasonexports.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 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)
GetNpc.