SpawnTestItem: Difference between revisions

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search
Document server-owned monsters and interactions
 
Document Lua APIs available or improved from G1R:MP 0.1.2
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<!-- This page is generated automatically from the function definition: spawnTestItem. -->
= spawnTestItem =
= spawnTestItem =
<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>
Spawns the catalog-backed synchronized test apple near a player.
Spawns the catalog-backed synchronized test apple near a player.


== Syntax ==
== Syntax ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool spawnTestItem(int playerId [, number heightOffset = 0])
bool spawnTestItem(int playerId [, number heightOffset])
</syntaxhighlight>
</syntaxhighlight>


Line 14: Line 18:
| <code>playerId</code> || <code>int</code> || yes || The connected player identifier.
| <code>playerId</code> || <code>int</code> || yes || The connected player identifier.
|-
|-
| <code>heightOffset</code> || <code>number</code> || no || Optional vertical offset in metres, clamped to the validated test range.
| <code>heightOffset</code> || <code>number</code> || no || Optional finite vertical offset in metres from -100 through 100. Values outside this range are rejected. Omit it to request ground snapping; an explicit 0 keeps the player's snapshot height without ground snapping.
|}
|}


== Returns ==
== Returns ==
Returns <code>true</code> when the authoritative spawn request is accepted; otherwise returns <code>false</code>.
Returns <code>true</code> after the server accepts and creates the test item; otherwise returns <code>false</code>.


== Examples ==
== Examples ==
Spawn a pickup at the invoking player's feet:
Spawn the fixed test apple near the invoking player and snap it to the ground:
<syntaxhighlight lang="lua" line>
<syntaxhighlight lang="lua" line>
addCommandHandler("spawnitem", function(playerId)
addCommandHandler("spawntestitem", function(playerId)
     if not spawnTestItem(playerId) then
     if not spawnTestItem(playerId) then
         outputChatBox("The item could not be spawned.", playerId)
         outputChatBox("The item could not be spawned.", playerId)
Line 32: Line 36:
== Notes ==
== Notes ==
* Available only in server-side resource scripts.
* Available only in server-side resource scripts.
* Each accepted call spawns exactly one apple 0.7 metres in front of the player's latest replicated position and facing direction.
* The server owns the item identity, revision, visibility, pickup validation, inventory award, and late-join state.
* The server owns the item identity, revision, visibility, pickup validation, inventory award, and late-join state.
* This function deliberately spawns only the validated test apple. It is not a generic arbitrary asset loader.
* This compatibility and test helper deliberately spawns only the validated apple. Use <code>spawnItem</code> when selecting an allowlisted item key.


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

Latest revision as of 18:40, 3 September 2026

spawnTestItem

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.

Spawns the catalog-backed synchronized test apple near a player.

Syntax

bool spawnTestItem(int playerId [, number heightOffset])

Parameters

Name Type Required Description
playerId int yes The connected player identifier.
heightOffset number no Optional finite vertical offset in metres from -100 through 100. Values outside this range are rejected. Omit it to request ground snapping; an explicit 0 keeps the player's snapshot height without ground snapping.

Returns

Returns true after the server accepts and creates the test item; otherwise returns false.

Examples

Spawn the fixed test apple near the invoking player and snap it to the ground:

addCommandHandler("spawntestitem", function(playerId)
    if not spawnTestItem(playerId) then
        outputChatBox("The item could not be spawned.", playerId)
    end
end)

Notes

  • Available only in server-side resource scripts.
  • Each accepted call spawns exactly one apple 0.7 metres in front of the player's latest replicated position and facing direction.
  • The server owns the item identity, revision, visibility, pickup validation, inventory award, and late-join state.
  • This compatibility and test helper deliberately spawns only the validated apple. Use spawnItem when selecting an allowlisted item key.