Spawn Mob problem
#1
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'.
     argument #-1806946488 is array of '[no object]'; array of 'H‹\$@¸' expected.

Warn [15:45:42] Stack trace:
Warn [15:45:42]   [C](-1): SpawnMob
Warn [15:45:42]   Plugins/mine/spawnmob.lua(30): (no name)
Warn [15:45:42] Stack trace end
Warn [15:45:42] Error in plugin mine calling function <callback>()

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
Reply
Thanks given by:
#2
This looks really weird, I'll try to reproduce the bug on my dev machine.
Reply
Thanks given by:
#3
Has you solved this Bug? I've the same Problem on Windows and Linux with 64 Bit.

Code:
function CitizenCommand(Split, Player)

    LOG(Split[2])
    Mob = cMonster:StringToMobType(Split[2])
    if Mob == -1 then
        Player:SendMessageFailure("Unknown mob type")
    else
        Player:GetWorld():SpawnMob(Player:GetPosX() + 5, Player:GetPosY(), Player:GetPosZ() + 5, Mob)
    end
end

Log File
Code:
[18:52:33] Stack trace:
[18:52:33]   [C](-1): SpawnMob
[18:52:33]   Plugins/Citizen/command.lua(10): (no name)
[18:52:33] Stack trace end
[18:52:33] Error in plugin Citizen calling function <callback>()
Reply
Thanks given by:
#4
Sorry, I must have forgotten, it's not reported on GitHub so it's easy to miss.
Reply
Thanks given by:
#5
This is a bug in tolua ...

Code:
int tolua_iseMonsterType (lua_State* L, int lo, int def, tolua_Error* err)
{
if (!tolua_isnumber(L,lo,def,err)) return 0;
lua_Number val = tolua_tonumber(L,lo,def);
return val >= -1.0 && val <= 28.0;
}
Reply
Thanks given by:
#6
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.
Reply
Thanks given by:
#7
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"? Smile )
Reply
Thanks given by:
#8
(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"? Smile )

A new comment would involve significant changes to tolua internals.
Reply
Thanks given by:




Users browsing this thread: 6 Guest(s)