hallo all
Will it's not really new lua function
some time ago i was want delete a item from all players when login by quest
but the problem was if the player is equip the item thos two function will not count it
so i just make new function for this
it's the same of the old function but thos can count the equip item
questlua_pc.cpp :
add thos :
now open char_item.cpp
find
open char.h
someone will say this is unusles
there too many ideas for it
e.g :
Also Can Be Used For the Monarch :
Here He Will Not Count Or Delete The Item If He IS Equip it
so We Have To Use The New Function For It
Also can Be Used For a lot of new things
Regards MrLibya
Will it's not really new lua function
some time ago i was want delete a item from all players when login by quest
but the problem was if the player is equip the item thos two function will not count it
PHP Code:
pc.count_item
pc.remove_item
PHP Code:
pc.count_item0
pc.removeitem0
questlua_pc.cpp :
add thos :
PHP Code:
int pc_count_item0(lua_State* L)
{
if (lua_isnumber(L, -1))
lua_pushnumber(L,CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem0((DWORD)lua_tonumber(L, -1)));
else if (lua_isstring(L, -1))
{
DWORD item_vnum;
if (!ITEM_MANAGER::instance().GetVnum(lua_tostring(L,1), item_vnum))
{
sys_err("QUEST count_item call error : wrong item name : %s", lua_tostring(L,1));
lua_pushnumber(L, 0);
}
else
{
lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem0(item_vnum));
}
}
else
lua_pushnumber(L, 0);
return 1;
}
int pc_remove_item0(lua_State* L)
{
if (lua_gettop(L) == 1)
{
DWORD item_vnum;
if (lua_isnumber(L,1))
{
item_vnum = (DWORD)lua_tonumber(L, 1);
}
else if (lua_isstring(L,1))
{
if (!ITEM_MANAGER::instance().GetVnum(lua_tostring(L,1), item_vnum))
{
sys_err("QUEST remove_item call error : wrong item name : %s", lua_tostring(L,1));
return 0;
}
}
else
{
sys_err("QUEST remove_item wrong argument");
return 0;
}
sys_log(0,"QUEST remove a item vnum %d of %s[%d]", item_vnum, CQuestManager::instance().GetCurrentCharacterPtr()->GetName(), CQuestManager::instance().GetCurrentCharacterPtr()->GetPlayerID());
CQuestManager::instance().GetCurrentCharacterPtr()->RemoveSpecifyItem0(item_vnum);
}
else if (lua_gettop(L) == 2)
{
DWORD item_vnum;
if (lua_isnumber(L, 1))
{
item_vnum = (DWORD)lua_tonumber(L, 1);
}
else if (lua_isstring(L, 1))
{
if (!ITEM_MANAGER::instance().GetVnum(lua_tostring(L,1), item_vnum))
{
sys_err("QUEST remove_item call error : wrong item name : %s", lua_tostring(L,1));
return 0;
}
}
else
{
sys_err("QUEST remove_item wrong argument");
return 0;
}
DWORD item_count = (DWORD) lua_tonumber(L, 2);
sys_log(0, "QUEST remove items(vnum %d) count %d of %s[%d]",
item_vnum,
item_count,
CQuestManager::instance().GetCurrentCharacterPtr()->GetName(),
CQuestManager::instance().GetCurrentCharacterPtr()->GetPlayerID());
CQuestManager::instance().GetCurrentCharacterPtr()->RemoveSpecifyItem0(item_vnum, item_count);
}
return 0;
}
PHP Code:
{ "count_item0", pc_count_item0 },
{ "removeitem0", pc_remove_item0 },
PHP Code:
find
int CHARACTER::CountSpecifyItem(DWORD vnum) const
after this function add :
int CHARACTER::CountSpecifyItem0(DWORD vnum) const
{
int count = 0;
LPITEM item;
for (int i = 0; i < INVENTORY_AND_EQUIP_SLOT_MAX; ++i)
{
item = GetFullInventoryItem(i);
if (NULL != item && item->GetVnum() == vnum)
{
// °³ہخ »َء،؟، µî·دµب ¹°°اہج¸é ³ر¾î°£´ظ.
if (m_pkMyShop && m_pkMyShop->IsSellingItem(item->GetID()))
{
continue;
}
else
{
count += item->GetCount();
}
}
}
return count;
}
void CHARACTER::RemoveSpecifyItem0(DWORD vnum, DWORD count)
{
if (0 == count)
return;
for (UINT i = 0; i < INVENTORY_AND_EQUIP_SLOT_MAX; ++i)
{
if (NULL == GetFullInventoryItem(i))
continue;
if (GetFullInventoryItem(i)->GetVnum() != vnum)
continue;
if (count >= GetFullInventoryItem(i)->GetCount())
{
count -= GetFullInventoryItem(i)->GetCount();
GetFullInventoryItem(i)->SetCount(0);
if (0 == count)
return;
}
else
{
GetFullInventoryItem(i)->SetCount(GetFullInventoryItem(i)->GetCount() - count);
return;
}
}
// ؟¹؟ـأ³¸®°، ¾àاد´ظ.
if (count)
sys_log(0, "CHARACTER::RemoveSpecifyItem cannot remove enough item vnum %u, still remain %d", vnum, count);
}
PHP Code:
LPITEM CHARACTER::GetInventoryItem(WORD wCell) const
after it add :
LPITEM CHARACTER::GetFullInventoryItem(WORD wCell) const
{
return GetItem(TItemPos(EQUIPMENT, wCell));
}
PHP Code:
find :
LPITEM GetInventoryItem(WORD wCell) const;
add after it
LPITEM GetFullInventoryItem(WORD wCell) const;
find
void RemoveSpecifyItem(DWORD vnum, DWORD count = 1);
add after it
void RemoveSpecifyItem0(DWORD vnum, DWORD count = 1);
find
int CountSpecifyItem(DWORD vnum) const;
add after it
int CountSpecifyItem0(DWORD vnum) const;
there too many ideas for it
e.g :
PHP Code:
quest gm_item_check begin
state start beign
when login with not pc.is_gm() begin
if pc.count_item0(xx) > 0 then --- will count the item in INVENTORY AND EQUIP //
say("You Are Not Allowed To Have This Item")
pc.removeitem0(xx ,1) --- if He Have 2 From This Item He Will Delete the own in INVENTORY And If He Only Have 1 And He IS Equip It Item will Be Delete
pc.removeitem0(xx) -- same of The First
pc.removeitem0(xx, pc.count_item0(xx)) -- He Will Delete IT all
end
end
end
end
PHP Code:
if pc.count_item(11971) > 0 or pc.count_item(11972) > 0 or pc.count_item(11973) > 0 or pc.count_item(11974) > 0 then
if pc.get_part(PART_MAIN) > 11970 and pc.get_part(PART_MAIN) < 11975 then
syschat(" الرجاء عدم ارتداء عتاد الملك .")
syschat(" أنت غير مؤهل لارتدائها. ")
else
local armor = 11971 + pc.get_job()
pc.removeitem(armor)
syschat(" تم ازالة درع الهوانغ الخاص بك. ")
end
end
so We Have To Use The New Function For It
Also can Be Used For a lot of new things
Regards MrLibya