SpawnMonster: Difference between revisions

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search
Update Lua API reference
Document G1R:MP 0.1.2 navigation collision API
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<!-- This page is generated automatically from the function definition: spawnMonster. -->
= spawnMonster =
= spawnMonster =
<div style="background:#fff5f5; border:1px solid #d13b3b; border-left:5px solid #d13b3b; color:#111111; padding:0.85rem 1rem; margin:0.75rem 0 1rem;">
<div style="color:#111111; font-weight:bold; letter-spacing:0.04em;">IMPROVED FROM UPDATE 0.1.2</div>
<div style="color:#111111; margin-top:0.25rem;">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.</div>
</div>
Creates a server-owned monster and replicates it to interested players.
Creates a server-owned monster and replicates it to interested players.


Line 22: Line 26:
| <code>yaw</code> || <code>number</code> || no || Initial yaw in degrees.
| <code>yaw</code> || <code>number</code> || no || Initial yaw in degrees.
|-
|-
| <code>options</code> || <code>table</code> || no || Optional table. Set <code>aggressive</code> to false to create a passive monster.
| <code>options</code> || <code>table</code> || no || Optional table. Set <code>aggressive</code> to false to create a passive monster. Set <code>navigationCollisionMode</code> to <code>"combined"</code>, <code>"builtin"</code>, or <code>"custom"</code>; the default is <code>"combined"</code>.
|}
|}


Line 31: Line 35:
Spawn a passive scavenger:
Spawn a passive scavenger:
<syntaxhighlight lang="lua" line>
<syntaxhighlight lang="lua" line>
local monsterId = spawnMonster("scavenger", 15.0, -4.5, 2.0, 90, { aggressive = false })
local monsterId = spawnMonster("scavenger", 15.0, -4.5, 2.0, 90, {
    aggressive = false,
    navigationCollisionMode = "combined",
})
if monsterId then
if monsterId then
     outputDebugString("Spawned monster " .. monsterId)
     outputDebugString("Spawned monster " .. monsterId)
Line 40: Line 47:
* Available only in server-side resource scripts.
* Available only in server-side resource scripts.
* The server owns identity, AI state, targeting, health, damage, relevance, and late-join replication.
* 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.
* Spawning an unsupported type or exceeding the server monster limit returns false.
* See [[Monster type catalog]] for every currently supported type key.
* See [[Monster type catalog]] for every currently supported type key.


[[Category:Lua Functions]]
[[Category:Server Functions]]
[[Category:Server Functions]]
[[Category:World Functions]]
[[Category:World Functions]]
[[Category:Monster Functions]]
[[Category:Monster Functions]]

Latest revision as of 13:52, 4 September 2026

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.