SpawnTestItem: Difference between revisions
Jump to navigation
Jump to search
Complete Lua function catalog |
Document Lua APIs available or improved from G1R:MP 0.1.2 |
||
| Line 1: | Line 1: | ||
= 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 | 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 | | <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> | Returns <code>true</code> after the server accepts and creates the test item; otherwise returns <code>false</code>. | ||
== Examples == | == Examples == | ||
Spawn | Spawn the fixed test apple near the invoking player and snap it to the ground: | ||
<syntaxhighlight lang="lua" line> | <syntaxhighlight lang="lua" line> | ||
addCommandHandler(" | 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 | * 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:Lua 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
spawnItemwhen selecting an allowlisted item key.