spawnmob - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Requests (https://forum.cuberite.org/forum-3.html) +--- Thread: spawnmob (/thread-240.html) Pages:
1
2
|
spawnmob - NiLSPACE - 12-25-2011 maybe can someone create an plugin to spawn mobs? it would be great if someone could do that. RE: spawnmob - NiLSPACE - 02-16-2012 (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. ?? RE: spawnmob - tonibm19 - 07-12-2013 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. RE: spawnmob - tonibm19 - 07-12-2013 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 RE: spawnmob - NiLSPACE - 07-12-2013 I think becouse OtherPlayer and creeper both are a nil value. RE: spawnmob - tonibm19 - 07-12-2013 (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. RE: spawnmob - xoft - 07-12-2013 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") RE: spawnmob - NiLSPACE - 07-12-2013 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) RE: spawnmob - xoft - 07-12-2013 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. RE: spawnmob - NiLSPACE - 07-12-2013 Patch: StringToMobType.patch (Size: 6.44 KB / Downloads: 349) I didn't commit it becouse I'm not sure if I had to use int or something else. |