SpawnMonster
spawnMonster
IMPROVED FROM UPDATE 0.1.2
This function is available in earlier releases and has corrected or expanded behavior in G1R:MP 0.1.2 and later. The contract below describes the updated behavior.
Creates a server-owned monster and replicates it to interested players.
Syntax
string|false spawnMonster(string type, number x, number y, number z [, number yaw = 0] [, table options])
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
type |
string |
yes | A stable type key from Monster type catalog. |
x |
number |
yes | World X coordinate in metres. |
y |
number |
yes | World Y coordinate in metres. |
z |
number |
yes | World Z coordinate in metres. |
yaw |
number |
no | Initial yaw in degrees. |
options |
table |
no | Optional table. Set aggressive to false to create a passive monster. Set navigationCollisionMode to "combined", "builtin", or "custom"; the default is "combined".
|
Returns
Returns the new opaque monster identifier string, or false when validation or spawning fails.
Examples
Spawn a passive scavenger:
local monsterId = spawnMonster("scavenger", 15.0, -4.5, 2.0, 90, {
aggressive = false,
navigationCollisionMode = "combined",
})
if monsterId then
outputDebugString("Spawned monster " .. monsterId)
end
Notes
- Available only in server-side resource scripts.
- The server owns identity, AI state, targeting, health, damage, relevance, and late-join replication.
- The selected navigation collision mode is applied to initial placement. Pass it during spawn when replacing a known baked false positive with custom blockers.
- Spawning an unsupported type or exceeding the server monster limit returns false.
- See Monster type catalog for every currently supported type key.