printed: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
13539
13540
and give me hp and mana
item descripton (Arm:30, attack speed +20).
character stats:
10 fist
after relogin...
It depends on what file you are in. If it's in player.cpp it should be: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
Item* itemHead = inventory[CONST_SLOT_HEAD];
--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
--WORK(give the skill to character and description work)
function onEquip(cid, item, slot)
doItemSetAttribute(item.uid, "skillfist", 22)
return true
end
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;
}
Use print functions in Lua to test to see what the functions are returning instead of adding a health gain function.@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?
print(getPlayerSlotItem(cid, CONST_SLOT_LEGS))
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
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
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:printed: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
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
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