User Tools

Site Tools


script:world_event:spawncreature

World:spawnCreature

 World:spawnCreature(x,y,z,creatureid,quantity) 

How to use

Where:

  • x number: The x coordinate where the creature will be spawned.
  • y number: The y coordinate where the creature will be spawned.
  • z number: The z coordinate where the creature will be spawned.
  • creatureid number: The ID of the creature that will be spawned.
  • quantity number: The number of creatures to be spawned.

And returns:

  • ErrorCode.Ok number: 0 if execution was succesful and 1001 if the execution failed.
  • Objids table: The IDs of the generated creatures.

Use example

When the player clicks the beehive block. 3 bees will be spawned and they will become the pets of the person who clicked.

local beehiveId = 134
local beeId = 3418
 
ScriptSupportEvent:registerEvent([=[Player.ClickBlock]=], function(e) 
 
    local playerid = e['eventobjid']
    local blockid = e['blockid']
    local x,y,z = e['x'], e['y'], e['z']
 
    local _, playernick = Player:getNickname(playerid)
 
    if blockid == beehiveId then
        local _, objids = World:spawnCreature(x,y,z, beeId, 3)
 
        for i, curObjid in ipairs(objids) do 
 
            Actor:setnickname(curObjid, playernick .. "'s bee")
            Actor:shownickname(curObjid, true)
 
        end
 
    end
end)
script/world_event/spawncreature.txt · Last modified: 2024/09/29 06:41 by hhuxx