12-25-2011, 09:28 PM
maybe can someone create an plugin to spawn mobs? it would be great if someone could do that.
spawnmob
|
12-25-2011, 09:28 PM
maybe can someone create an plugin to spawn mobs? it would be great if someone could do that.
02-16-2012, 03:16 AM
07-12-2013, 12:15 AM
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.
What I did wrong?
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 endIt 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
07-12-2013, 04:10 AM
I think becouse OtherPlayer and creeper both are a nil value.
07-12-2013, 04:12 AM
07-12-2013, 04:21 AM
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") Thanks given by: NiLSPACE
07-12-2013, 04:22 AM
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) Thanks given by: tonibm19
07-12-2013, 04:27 AM
I prefer to call the number "type", rather than "id". ID means unique, two spiders have different IDs 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.
07-12-2013, 05:01 AM
Patch:
StringToMobType.patch (Size: 6.44 KB / Downloads: 348) I didn't commit it becouse I'm not sure if I had to use int or something else. |
« Next Oldest | Next Newest »
|