spawnmob
#1
maybe can someone create an plugin to spawn mobs? it would be great if someone could do that.
Reply
Thanks given by:
#2
(12-25-2011, 09:28 PM)STR_Warrior Wrote: maybe can someone create an plugin to spawn mobs? it would be great if someone could do that.

??
Reply
Thanks given by:
#3
I'll try to do that, but as you knoe I'm a noob so maybe I can't. Some time ago I made a
half-done plugin that let you to spawn spiders, creepers and other monsters so maybe I can do it. I'll try to make it like bukkit essentials spawnmob.
Reply
Thanks given by:
#4
What I did wrong? Huh
function HandleSpawnMobCommand ( Player, Split, World, OtherPlayer )
    if Split[2] == nil then
        Player:SendMessage( "Usage: /spawnmob <mobtype> <player>" )
        return true
    end
    if Split[2] == creeper and Split[3] == nil then
        Player:GetWorld():SpawnMob( Player:GetPosX(), Player:GetPosY(), Player:GetPosZ(), 50 )
        Player:SendMessage( "Creeper spawned!" )
        return true
    end
    if Split[2] == creeper and Split[3] == OtherPlayer then
        OtherPlayer:GetWorld():SpawnMob( OtherPlayer:GetPosX(), OtherPlayer:GetPosY(), OtherPlayer:GetPosZ(), 50 )
        Player:SendMessage( "Creeper spawned!" )
        return true
    end
end
It gives me errors:
[20:01:28] LUA: Plugins/SpawnMob/main.lua:12: attempt to call method 'SendMessage' (a nil value)
[20:01:28] LUA error in cPlugin_NewLua::HandleCommand. Stack size: 3
and
[20:01:28] LUA: Plugins/SpawnMob/main.lua:12: attempt to call method 'GetWorld' (a nil value)
[20:01:28] LUA error in cPlugin_NewLua::HandleCommand. Stack size: 3
Reply
Thanks given by:
#5
I think becouse OtherPlayer and creeper both are a nil value.
Reply
Thanks given by:
#6
(07-12-2013, 04:10 AM)STR_Warrior Wrote: I think becouse OtherPlayer and creeper both are a nil value.
but if I execute /spawnmob creeper it should spawn a creeper on player pos (player who executes command) and it says GetWorld is a nil value.
Reply
Thanks given by:
#7
Are you sure you have the arguments alright? The command handler callbacks take only two arguments, the first one is the split command, the second one is the cPlayer. Your function has more args and mixed up.

Secondly, to compare strings, you need to put them in quotes properly:
if (Split[2] == "creeper")
Reply
Thanks given by: NiLSPACE
#8
I don't see anywhere what OtherPlayer is. Its just a nil value I think. I usely use something like this: I quickly created it so there could be some mistakes in it.
function ReturnMobIDFromString(Mob)
	if Mob == nil then
		return;
	end
	Mob = string.upper(Mob)
	elseif Mob == "CREEPER" then
		return 50
	elseif Mob == "SKELETON" then
		return 52
	elseif Mob == "SPIDER" then
		return 52
	elseif Mob == "GIANT" then
		return 53
	elseif Mob == "ZOMBIE" then
		return 52
	-- ETC.
	end
end

Mob = ReturnMobIDFromString(Split[2])
if Mob == nil then
	Player:SendMessage("Mob not found")
	return true
end
if Split[3] ~= nil then
	cRoot:Get():ForEachPlayer(
	function(OtherPlayer)
	if OtherPlayer:GetName() == Split[3] then
		OtherPlayer:GetWorld():SpawnMob(Player:GetPosX(), Player:GetPosY(), Player:GetPosZ(), Mob)
	end)
	return true
end
Player:GetWorld():SpawnMob(Player:GetPosX(), Player:GetPosY(), Player:GetPosZ(), Mob)
Reply
Thanks given by: tonibm19
#9
I prefer to call the number "type", rather than "id". ID means unique, two spiders have different IDsTongue So why not call the function StringToMobType(). If you write it in C/C++, you can also make it built in into MCS as an API (see StringToDamageType and DamageTypeToString functions in BlockID.cpp for inspiration)

Instead of doing a ForEachPlayer(), you can also do DoWithPlayer() that calls the callback only once. But then, if you have multiple players of the same name (perfectly legal in MCS), only the first one would match.
Reply
Thanks given by:
#10
Patch:
.patch   StringToMobType.patch (Size: 6.44 KB / Downloads: 350)
I didn't commit it becouse I'm not sure if I had to use int or something else.
Reply
Thanks given by:




Users browsing this thread: 10 Guest(s)