Acubens
Old Penguin
Im trying to add durability system to items, im using OTHire sources, but the lua function idk why isn't working, im not expert in c++ but im trying to
do the best xD
Function in ItemAttribute class:
Function added to item class:
Then when i use in action script this
It continues showing 500, that i have added on items.xml with:
@Nottinghster @Ezzz
do the best xD
Function in ItemAttribute class:
C++:
void setDurability(uint16_t n) {setIntAttr(ATTR_ITEM_DURABILITY, n); }
Function added to item class:
C++:
void Item::setItemDurability(uint16_t n)
{
ItemAttributes::setDurability(n);
}
C++:
int LuaScriptInterface::luaGetItemDurability(lua_State *L)
{
//getItemDurability(uid)
uint32_t uid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Item* item = env->getItemByUID(uid);
if(!item){
reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND));
lua_pushnil(L);
return 1;
}
lua_pushnumber(L, (int32_t) item->getDurability());
return 1;
}
C++:
int LuaScriptInterface::luaDoSetItemDurability(lua_State *L)
{
//doSetItemDurability(uid, charges)
uint32_t value = popNumber(L);
uint32_t uid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Item* item = env->getItemByUID(uid);
if(item){
// I added this function to item class but still not working.
item->setItemDurability(value);
// Debuging it gives all time the value that i have loaded by items.xml
std::cout << item->getDurability() << std::endl;
lua_pushboolean(L, true);
}
else{
reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}
Then when i use in action script this
Lua:
doSetItemDurability(item.uid, getItemDurability(item.uid) - 1)
It continues showing 500, that i have added on items.xml with:
XML:
<attribute key="durability" value="500"/>
@Nottinghster @Ezzz
Last edited: