er2.createProp 8
Places a map prop in the world at runtime, like createConquestProp, with two extras: optional network synchronisation and an optional spawn callback.networked = false (default): the prop is local. Call it on every client with identical values, exactly as you would createConquestProp; in generated modes the prop belongs to the current world layout, so a Conquest regeneration removes it.networked = true: only the master client creates the prop, everyone else receives it automatically, including players who join later. These props do not belong to the Conquest world: they stay until the end of the battle, and the same is true offline, where the call simply spawns locally with the same persistence. Every networked prop stays cached in the room for late joiners, so use it for set pieces measured in tens of props, not for mass generation.onSpawned runs only on the caller, once its own instance actually exists (spawning is asynchronous): it receives the prop as the same object prop scripts see as myself, so you can set destruction phases, crate contents, an onDestroyed listener, and so on. The function itself never travels over the network: on the other clients the prop just appears. Note that remove() on a networked prop only removes the caller's local copy.
Return value
| Return Type | Description |
|---|---|
| bool | True if the request was accepted. The prop itself is loaded asynchronously, so a true here means "id is valid and work has started", not "it is already on the ground". False if the id is unknown, points at a vehicle, or networked was requested by a client that is not the master. |
Parameters
| Parameter | Type | Description |
|---|---|---|
| 1 | string | The prop to place, using the keys of the prop database. Vehicle ids are refused here: for those use spawnConquestVehicle. |
| 2 | vec3 | Where to put it, in world coordinates. Nothing is clamped to the ground: pass the height you want, using er2.getTerrainHeight if you want it to sit on the terrain. |
| 3 | vec3 | Rotation in Euler degrees. Use vec3(0, angle, 0) to just turn it on the spot. |
| 4 | bool | Optional, default false. True: the master client alone creates the prop for every player, late joiners included, and it persists until the end of the battle. On non-master clients the call is refused with a console warning. |
| 5 | function | Optional. function(prop) called on the caller only, once its local instance has spawned; never called if the spawn fails. The prop argument is the same object prop scripts see as myself, but it acts on the caller's local instance: on a networked prop, remove() and destruction phases affect the caller alone. Yielding helpers (sleep, spawnSoldier and friends) cannot be used inside the callback. Always pass networked explicitly when you use this parameter: er2.createProp(id, pos, rot, false, callback). |
Examples
Victory set piece at battle end (networked props)
-- Last phase script: when the Allies win, the master decorates the
-- hilltop for the outro. networked=true replicates the props on every
-- client, late joiners included. battle_ended fires once per battle.
er2.setCallback("battle_ended", function(winner, forced)
-- networked spawns are master-only anyway: this just avoids the warning
if not er2.isMasterClient() then return end
if not er2.isAllied(winner) then return end
er2.createProp("FlagRipped_usa", vec3(1203.0, 42.5, 880.0), vec3(0, 160, 0), true)
er2.createProp("Crate_Medium_GRM", vec3(1199.5, 42.4, 879.0), vec3(0, 25, 0), true)
er2.createProp("Barrel_Drum", vec3(1200.0, 42.3, 877.8), vec3(0, 0, 0), true)
end)Configure a prop on spawn (onSpawned callback)
-- A medical supply point: the crate is spawned locally by every client
-- (networked=false, identical values everywhere), and onSpawned configures
-- it once the instance actually exists, since spawning is asynchronous.
-- The prop argument is the same object prop scripts see as myself.
-- Note: sleep() and other yielding helpers cannot be used inside it.
er2.createProp("AmmoCrate", vec3(1210.0, 42.6, 884.0), vec3(0, 90, 0), false,
function(prop)
prop:setCrateContent({ "bandages", "syringe" })
prop:setCrateDelay(8)
end)Texture a generic flag prop (texture API)
-- Textures are handles: load one once and pass it around. The same
-- prop works with a faction flag or any image from the mission folder.
local flagTex = er2.getFactionFlag("UnitedStates_allies")
-- local flagTex = er2.loadTexture("flags/my_banner.png")
er2.createProp("FlagWaving_1", vec3(100.0, 25.0, 200.0), vec3(0, 90, 0), false,
function(prop)
prop:setAlbedo(flagTex)
end)
-- In a prop script placed in the mission editor the prop is "myself",
-- and the texture is re-applied automatically when it streams back in:
-- myself:setAlbedo(er2.getFactionFlag("Germany_axis"))