Cuberite Forum
Spawn Custom Mob Example - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Development (https://forum.cuberite.org/forum-13.html)
+--- Thread: Spawn Custom Mob Example (/thread-2942.html)



Spawn Custom Mob Example - djlw78 - 04-30-2017

I was looking into cMonster API and I wanted an example for how you would assign properties to a created monster. I tried to look in essentials at the spawn mob command for an example but it just spawns the mob it doesn't try to apply properties. 

If the example could contain: Setting the speed of the mob to zero it would be appreciated.


RE: Spawn Custom Mob Example - Seadragon91 - 04-30-2017

I wrote a example that spawns a sheep and set's the speed to zero.

Register the command handler in a plugin:
Code:
cPluginManager:BindCommand("/spawnmob", "spawnmob", CommandSpawnMob, "spawns a mob")


Code:
function CommandSpawnMob(a_Split, a_Player) -- I created a command handler, that will spawn a sheep and sets the speed to 0.
    local mobID = a_Player:GetWorld():SpawnMob(a_Player:GetPosX(), a_Player:GetPosY(), a_Player:GetPosZ(), mtSheep) -- Spawns a sheep at player's position
    
    assert(mobID ~= -1, "Mob spawn failed") -- This can happen, if for example a plugin denies the spawning of monsters
    
    a_Player:GetWorld():DoWithEntityByID(mobID,
        function(Entity)
            Entity:SetRelativeWalkSpeed(0)
        end)
    
    
    a_Player:SendMessage("Spawned sheep.")
    return true
end


Sources:
cMonster
SpawnMob
DoWithEntityByID


RE: Spawn Custom Mob Example - Seadragon91 - 04-30-2017

I just see that SpawnMob from cWorld has cMonster as a param type, that should be eMonsterType.


RE: Spawn Custom Mob Example - xoft - 04-30-2017

The tolua.cast should not be needed, Cuberite should already provide the correct class to the callback.


RE: Spawn Custom Mob Example - Seadragon91 - 04-30-2017

Didn't know, will remove it.

Edit: Done


RE: Spawn Custom Mob Example - djlw78 - 05-01-2017

The only problem is they still can kinda move and be pushed. I'd want them to be stone.


EDIT: "stone" - unmoving.