Spawn Custom Mob Example
#1
Question 
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.
Reply
Thanks given by:
#2
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
Reply
Thanks given by:
#3
I just see that SpawnMob from cWorld has cMonster as a param type, that should be eMonsterType.
Reply
Thanks given by:
#4
The tolua.cast should not be needed, Cuberite should already provide the correct class to the callback.
Reply
Thanks given by:
#5
Didn't know, will remove it.

Edit: Done
Reply
Thanks given by:
#6
The only problem is they still can kinda move and be pushed. I'd want them to be stone.


EDIT: "stone" - unmoving.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)