• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X getMonsterLevel

ConAn Edujawa

Member
Joined
Feb 23, 2015
Messages
454
Reaction score
15
im use 0.4 and i use this fuction Feature - Creatureevent OnGainExp (https://otland.net/threads/creatureevent-ongainexp.123221/)

and im add this for monster level

Lua:
int32_t LuaInterface::luaGetMonsterLevel(lua_State* L)
{
    // getMonsterLevel()
        ScriptEnviroment* env = getEnv();
    Creature* creature = env->getCreatureByUID(popNumber(L));
    const Monster* monster = creature->getMonster();
     if (monster) {
       lua_pushnumber(L, monster->getLevel());
       }
else{
        lua_pushnumber(L, -1);
    }
    return 1;
}

but when use this script always say 07:56 Congratulations, your 2 point!.
Code:
local config = {
    {"hero", 9512021, 12010, 4501021},
}
function onGainExp(cid, value)
    
local k,x = 108745, 0

for i = 1, #config do
    local name = getCreatureByName(config[i][1])
    local levelmonster = getMonsterLevel(name)
if levelmonster > 1 then
        local exp =math.floor(value*getMonsterLevel(name))
        doPlayerAddExp(cid, exp)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, ("Congratulations, your "..getMonsterLevel(name).." point!."))
end
end
return true
end
anyone know how to fix this and don't add exp
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,040
Solutions
105
Reaction score
1,097
Location
London
GitHub
MillhioreBT
the getMonsterLevel() function expects a number as a parameter, not a name or a text string.
You must pass the ID of the creature, so that it returns the result you are looking for

in your case, you can use name.uid by the way you have a big mess with the names of the xd variables

like this it makes more sense:
Lua:
local config = {
    {"hero", 9512021, 12010, 4501021},
}

function onGainExp(cid, value)
    local k,x = 108745, 0
    for i = 1, #config do
        local uid = getCreatureByName(config[i][1])
        local levelmonster = getMonsterLevel(uid)
        if levelmonster > 1 then
            local exp =math.floor(value*levelmonster)
            doPlayerAddExp(cid, exp)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, ("Congratulations, your "..levelmonster.." point!."))
        end
    end
    return true
end
 
Last edited:
OP
OP
ConAn Edujawa

ConAn Edujawa

Member
Joined
Feb 23, 2015
Messages
454
Reaction score
15
the getMonsterLevel() function expects a number as a parameter, not a name or a text string.
You must pass the ID of the creature, so that it returns the result you are looking for

in your case, you can use name.uid by the way you have a big mess with the names of the xd variables
but i uuse getCreatureByName(config[1]) i other script and work good here Lua - getMonsterLevel (https://otland.net/threads/getmonsterlevel.271958/post-2619394)
Post automatically merged:

the getMonsterLevel() function expects a number as a parameter, not a name or a text string.
You must pass the ID of the creature, so that it returns the result you are looking for

in your case, you can use name.uid by the way you have a big mess with the names of the xd variables

like this it makes more sense:
Lua:
local config = {
    {"hero", 9512021, 12010, 4501021},
}

function onGainExp(cid, value)
    local k,x = 108745, 0
    for i = 1, #config do
        local thing = getCreatureByName(config[i][1])
        local levelmonster = getMonsterLevel(thing.uid)
        if levelmonster > 1 then
            local exp =math.floor(value*levelmonster)
            doPlayerAddExp(cid, exp)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, ("Congratulations, your "..levelmonster.." point!."))
        end
    end
    return true
end
Lua:
[6:50:38.272] [Error - CreatureScript Interface]
[6:50:38.272] data/creaturescripts/scripts/expmonsterlevel.lua:onGainExp
[6:50:38.272] Description:
[6:50:38.272] data/creaturescripts/scripts/expmonsterlevel.lua:22: attempt to index local 'thing' (a number value)
[6:50:38.273] stack traceback:
[6:50:38.273]   data/creaturescripts/scripts/expmonsterlevel.lua:22: in function <data/creaturescripts/scripts/expmonsterlevel.lua:16>
 
Last edited:

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,040
Solutions
105
Reaction score
1,097
Location
London
GitHub
MillhioreBT
As expected, his onGainExp() method does not have enough information to implement a functional system in which you gain more experience according to some property obtained from the monster that he has killed.

so what you ask is impossible, but if you want you can think of something else, such as an extra multiplier according to some storage or some equipped object, etc ...
 
OP
OP
ConAn Edujawa

ConAn Edujawa

Member
Joined
Feb 23, 2015
Messages
454
Reaction score
15
As expected, his onGainExp() method does not have enough information to implement a functional system in which you gain more experience according to some property obtained from the monster that he has killed.

so what you ask is impossible, but if you want you can think of something else, such as an extra multiplier according to some storage or some equipped object, etc ...
noway to do it ?
 
Last edited:
Top