Spawn Mob problem - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: Spawn Mob problem (/thread-1616.html) |
Spawn Mob problem - StevasaurousREX - 10-10-2014 Im trying to create a plugin that spawns a mob via command, having downloaded the newest version from the website this is the error message I am receiving and my code. Code: Warn [15:45:42] LUA: Plugins/mine/spawnmob.lua:30: error in function 'SpawnMob'. function HandleSpawnMobCommand(Split, Player) -- Make sure there are a correct number of arguments. if ((#Split ~= 2) and (#Split ~=3)) then Player:SendMessage("Usage: /spawnmob <mobname> [number]" ) return true end -- Mob name as typed in by the player local MobName = Split[2] -- Mob Type based local MobType = cMonster:StringToMobType(Split[2]) if MobType == -1 then Player:SendMessage("Mob " .. MobName .. " not found") return true end if Split[3] ~= nil then -- Don't allow more then 10 mobs to be spawned at once. local ammount = tonumber(Split[3]) if ammount > 10 then Player:SendMessage("Max mob spawn is 10.") ammount = 10 end for i=0,ammount do Player:GetWorld():SpawnMob(Player:GetPosX(), Player:GetPosY(), Player:GetPosZ(), MobType) end Player:SendMessage("Spawned " .. ammount .. " " .. MobName .. "s") return true else Player:GetWorld():SpawnMob(Player:GetPosX(), Player:GetPosY(), Player:GetPosZ(), MobType) Player:SendMessage("Spawned 1 " .. MobName) end return true; end RE: Spawn Mob problem - xoft - 10-10-2014 This looks really weird, I'll try to reproduce the bug on my dev machine. RE: Spawn Mob problem - VeryBlackMan - 12-17-2014 Has you solved this Bug? I've the same Problem on Windows and Linux with 64 Bit. Code: function CitizenCommand(Split, Player) Log File Code: [18:52:33] Stack trace: RE: Spawn Mob problem - xoft - 12-17-2014 Sorry, I must have forgotten, it's not reported on GitHub so it's easy to miss. RE: Spawn Mob problem - Howaner - 12-17-2014 This is a bug in tolua ... Code: int tolua_iseMonsterType (lua_State* L, int lo, int def, tolua_Error* err) RE: Spawn Mob problem - worktycho - 12-18-2014 I've found the source of the bug. When generating the min and max I assumed we would only ever assign literal numbers to enum values, not other constexpr values. So when generating the range check it uses the tonumber of the text strings to generate the max. I'm not sure how to solve this because tolua does not have the awareness of the c++ code to solve this problem generally. To solve the problem generally would require a full c++ parser/type checker, due to templates and c++11 constexpr. (If you're willing to bundle/require clang and the rust runtime, I might write an alternative to tolua that can provide the general solution) In the special case of using enum values in the global namespace where the enum values are exposed to the lua API, this could possibly be solved by having tolua lookup the values. This would involve exposing the E_META_SPAWNEGG enum values to lua, admittedly documented as not part of the API. An alternate solution that would require more significant changes to tolua internally would be to implement the previous solution and also add a marker to allow tolua to parse an enum, but not to generate bindings for it. This would solve the special case of using enum values in the global namespace. RE: Spawn Mob problem - xoft - 12-18-2014 Don't generate a min-max check (because it will fail for MonsterType anyway, it has "holes" in the values range), generate a switch-check - one big switch with a case for each value, and a default printing an error. The only problem here is multiple aliases for the same value, we'll probably have to solve that one somehow (a new comment, "// tolua-ignoreenum"? ) RE: Spawn Mob problem - worktycho - 12-19-2014 (12-18-2014, 10:24 PM)xoft Wrote: Don't generate a min-max check (because it will fail for MonsterType anyway, it has "holes" in the values range), generate a switch-check - one big switch with a case for each value, and a default printing an error. The only problem here is multiple aliases for the same value, we'll probably have to solve that one somehow (a new comment, "// tolua-ignoreenum"? ) A new comment would involve significant changes to tolua internals. |