• 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!

C++ getPlayerItem by slot(SOLVED)

kubernik

Active Member
Joined
Jul 4, 2014
Messages
99
Solutions
7
Reaction score
38
Hello, someone can tell me how to check item on slot in c++?
i want to check helmet in c++, but i don't know how.. :c
It must be in c++!

someone? help? please? :c
 
Solution
Lua:
local armor_id     = 13539
local legs_id     = 13540
function onEquip(cid, item, slot)
    if(slot == 7) or (slot == 4) then
        if getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid == legs_id and (getPlayerSlotItem(cid, CONST_SLOT_ARMOR).itemid == armor_id) then
                print(getPlayerSlotItem(cid, CONST_SLOT_ARMOR).itemid)
                print(getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid)
                doItemSetAttribute(item.uid, "skillfist", 20)
                doCreatureAddHealth(cid, 1)
                doCreatureAddMana(cid, 1)
        end
    end
    return true
end
printed:
13539
13540
and give me hp and mana
item descripton (Arm:30, attack speed +20).
character stats:
10 fist
after relogin...
Hello, someone can tell me how to check item on slot in c++?
i want to check helmet in c++, but i don't know how.. :c
It must be in c++!

someone? help? please? :c
It depends on what file you are in. If it's in player.cpp it should be:
C++:
Item* itemHead = inventory[CONST_SLOT_HEAD];
 
@Apollos
Thanks, i will trying with this later.
I need this code to make little change in movement.cpp

@Off Topic
At the beginning I added this code: Feature - Attributes MOD (https://otland.net/threads/attributes-mod.156649/)
BUT... When i make any code in movement(in LUA)
for example:
Lua:
 --DONT WORK(does not give the skill to character, but on item description work)
    function onEquip(cid, item, slot)
        if getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid == xxxx then
            doItemSetAttribute(item.uid, "skillfist", 22)
        end
    return true
    end

Lua:
 --WORK(give the skill to character and description work)
    function onEquip(cid, item, slot)
            doItemSetAttribute(item.uid, "skillfist", 22)
    return true
    end

i trying with
doCreatureAddHealth(cid, 1) in first code, but this do not help me.

I finally added function in luascripts.cpp

C++:
int32_t LuaScriptInterface::luaDoUpdateStats(lua_State* L)
{
    //luaDoUpdateStats(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID((uint32_t)popNumber(L));
    if(player)
    {
        Item* item = NULL;

        for(int32_t slot = SLOT_FIRST; slot < SLOT_LAST; ++slot)
        {
            if(!(item = player->getInventoryItem((slots_t)slot)))
                continue;[/B]

          item->__startDecaying();
            g_moveEvents->onPlayerEquip(player, item, (slots_t)slot, false); // true/fales -- tested
            player->sendStats();
            std::cout << "sendStats" << std::endl; //work
        }
                lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    return 1;
}

To reload items worn by player, but this function dont help me XD
player get health form doCreatureAddHealth(cid, 1) on item, but doItemSetAttribute(item.uid, "skillfist", 20)
it still does not work(work only on relogin).

anyone have any ideas?
 
@Apollos
Thanks, i will trying with this later.
I need this code to make little change in movement.cpp

@Off Topic
At the beginning I added this code: Feature - Attributes MOD (https://otland.net/threads/attributes-mod.156649/)
BUT... When i make any code in movement(in LUA)
for example:
Lua:
 --DONT WORK(does not give the skill to character, but on item description work)
    function onEquip(cid, item, slot)
        if getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid == xxxx then
            doItemSetAttribute(item.uid, "skillfist", 22)
        end
    return true
    end

Lua:
 --WORK(give the skill to character and description work)
    function onEquip(cid, item, slot)
            doItemSetAttribute(item.uid, "skillfist", 22)
    return true
    end

i trying with
doCreatureAddHealth(cid, 1) in first code, but this do not help me.

I finally added function in luascripts.cpp

C++:
int32_t LuaScriptInterface::luaDoUpdateStats(lua_State* L)
{
    //luaDoUpdateStats(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID((uint32_t)popNumber(L));
    if(player)
    {
        Item* item = NULL;

        for(int32_t slot = SLOT_FIRST; slot < SLOT_LAST; ++slot)
        {
            if(!(item = player->getInventoryItem((slots_t)slot)))
                continue;[/B]

          item->__startDecaying();
            g_moveEvents->onPlayerEquip(player, item, (slots_t)slot, false); // true/fales -- tested
            player->sendStats();
            std::cout << "sendStats" << std::endl; //work
        }
                lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    return 1;
}

To reload items worn by player, but this function dont help me XD
player get health form doCreatureAddHealth(cid, 1) on item, but doItemSetAttribute(item.uid, "skillfist", 20)
it still does not work(work only on relogin).

anyone have any ideas?
Use print functions in Lua to test to see what the functions are returning instead of adding a health gain function.
For example:
Lua:
print(getPlayerSlotItem(cid, CONST_SLOT_LEGS))

Also are you just trying to have these legs add an attribute to itself when it's equipped? Or is the legs being equipped determining if another item equipped will gain an attribute?
 
Lua:
local armor_id     = 13539
local legs_id     = 13540
function onEquip(cid, item, slot)
    if(slot == 7) or (slot == 4) then
        if getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid == legs_id and (getPlayerSlotItem(cid, CONST_SLOT_ARMOR).itemid == armor_id) then
                print(getPlayerSlotItem(cid, CONST_SLOT_ARMOR).itemid)
                print(getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid)
                doItemSetAttribute(item.uid, "skillfist", 20)
                doCreatureAddHealth(cid, 1)
                doCreatureAddMana(cid, 1)
        end
    end
    return true
end
printed:
13539
13540
and give me hp and mana
item descripton (Arm:30, attack speed +20).
character stats:
10 fist
after relogin
30 fist

on use my function
printed again:
13539
13540
and give me hp and mana
but character stats:
10fist too...

with this.. same like up.
Lua:
local legs_id     = 13540
function onEquip(cid, item, slot)
    if(slot == 7)then
        if getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid == legs_id then
                --print(getPlayerSlotItem(cid, CONST_SLOT_ARMOR).itemid)
                print(getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid)
                doItemSetAttribute(item.uid, "skillfist", 20)
                doCreatureAddHealth(cid, 1)
                doCreatureAddMana(cid, 1)
        end
    end
    return true
end



Im trying to add A bonus to A set of 2 items. Example. You have 2 items each gives you 2 skills but when equipped at the same time they give you extra bonus... Like Sets system
 
Last edited:
Lua:
local armor_id     = 13539
local legs_id     = 13540
function onEquip(cid, item, slot)
    if(slot == 7) or (slot == 4) then
        if getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid == legs_id and (getPlayerSlotItem(cid, CONST_SLOT_ARMOR).itemid == armor_id) then
                print(getPlayerSlotItem(cid, CONST_SLOT_ARMOR).itemid)
                print(getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid)
                doItemSetAttribute(item.uid, "skillfist", 20)
                doCreatureAddHealth(cid, 1)
                doCreatureAddMana(cid, 1)
        end
    end
    return true
end
printed:
13539
13540
and give me hp and mana
item descripton (Arm:30, attack speed +20).
character stats:
10 fist
after relogin
30 fist

on use my function
printed again:
13539
13540
and give me hp and mana
but character stats:
10fist too...

with this.. same like up.
Lua:
local legs_id     = 13540
function onEquip(cid, item, slot)
    if(slot == 7)then
        if getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid == legs_id then
                --print(getPlayerSlotItem(cid, CONST_SLOT_ARMOR).itemid)
                print(getPlayerSlotItem(cid, CONST_SLOT_LEGS).itemid)
                doItemSetAttribute(item.uid, "skillfist", 20)
                doCreatureAddHealth(cid, 1)
                doCreatureAddMana(cid, 1)
        end
    end
    return true
end



I try to add a bonus to one item when there are 2 items. for example. you have 2 items created, they give you 2 skills, but you get an extra 2 for getting them
It still seems like you are writing useless lines in this script, I may be wrong but it's difficult to understand what you want. Something like this might be a better option:
Lua:
local legs_id = 13540
function onEquip(cid, item, slot)
    if slot == CONST_SLOT_LEGS and item.itemid == legs_id then
        doItemSetAttribute(item.uid, "skillfist", 20)
    end
    return true
end
And if this is what you are wanting to do have you considered setting the item's attribute gain within items.xml, so you don't have to do it within a Lua script?

When it comes to relogging working as opposed to after the onEquip. You're on the right track with updating the player stats, you need to track down when the onEquip happens and check if it's updating the players stats after the Lua call to the onEquip script. It would be helpful to know what distro you're using too. You should be including this with every question to getting better help.
 
Solution
What the heck?
i just used your code and it work <.<
I suffered seven hours because of that code... trying to do something in c++
but... i did something wrong in LUA? O.O
kill.. me XD
 
Last edited:
Back
Top