Helloo, i got a server based on avesta 7.6, and i want to add some TFS functions cuz they are really usefull for me, i will try to explain it as best as posible
i want to add the functions "doItemSetAttribute" and "getItemAttribute", the second one i have put in successfully without any problems, but to add "doItemSetAttribue" was little bit more harder, as you should know (if you has ever compiled TFS and readed the source code), that in item.cpp are defined the items attributes like "attack", "defense", "speed" and all of that and in avesta are NOT defined, so as a normal person i add those attributes, and i compiled my server and... everything fine, no error even on compiler or linker, everything was well, i open my server and everything is OK, so then i create a script using "doItemSetAttribute", and when use it my server crashed, ofc, is because i did something wrong with the code, but i really don't know what, so i'm here asking for some body to help me
Codes are here
Script code:
luascript.cpp part
AND MY ITEM.CPP AND ITEM.H IS TO DOWNLOAD
I know that is a looooooot of code, but i really need help with these, i don't know if add this function is impossible, but i'm here looking for answers, every comment will be usefull
thanks
i want to add the functions "doItemSetAttribute" and "getItemAttribute", the second one i have put in successfully without any problems, but to add "doItemSetAttribue" was little bit more harder, as you should know (if you has ever compiled TFS and readed the source code), that in item.cpp are defined the items attributes like "attack", "defense", "speed" and all of that and in avesta are NOT defined, so as a normal person i add those attributes, and i compiled my server and... everything fine, no error even on compiler or linker, everything was well, i open my server and everything is OK, so then i create a script using "doItemSetAttribute", and when use it my server crashed, ofc, is because i did something wrong with the code, but i really don't know what, so i'm here asking for some body to help me
Codes are here
Script code:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
doItemSetAttribute(item.uid, 'attack', 40)
end
luascript.cpp part
Code:
int32_t LuaScriptInterface::luaDoItemSetAttribute(lua_State* L)
{
//doItemSetAttribute(uid, key, value)
boost::any value;
if(lua_isnumber(L, -1))
{
float tmp = popFloatNumber(L);
if(std::floor(tmp) < tmp)
value = tmp;
else
value = (int32_t)tmp;
}
else if(lua_isboolean(L, -1))
value = popNumber(L);
else if(lua_isstring(L, -1))
value = popString(L);
else
{
lua_pop(L, 1);
reportErrorFunc("Invalid data type");
lua_pushboolean(L, false);
return 1;
}
std::string key = popString(L);
ScriptEnviroment* env = getScriptEnv();
Item* item = env->getItemByUID(popNumber(L));
if(!item)
{
reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND));
lua_pushboolean(L, false);
return 1;
}
if(value.type() == typeid(int32_t))
{
if(key == "uid")
{
int32_t tmp = boost::any_cast<int32_t>(value);
if(tmp < 1000 || tmp > 0xFFFF)
{
reportErrorFunc("Value for protected key \"uid\" must be in range of 1000 to 65535");
lua_pushboolean(L, false);
return 1;
}
item->setUniqueId(tmp);
}
else if(key == "aid")
item->setActionId(boost::any_cast<int32_t>(value));
else
item->setAttribute(key, boost::any_cast<int32_t>(value));
}
else
item->setAttribute(key, value);
lua_pushboolean(L, true);
return 1;
}
Code:
//doItemSetAttribute(uid, key, value)
lua_register(m_luaState, "doItemSetAttribute", LuaScriptInterface::luaDoItemSetAttribute);
AND MY ITEM.CPP AND ITEM.H IS TO DOWNLOAD
I know that is a looooooot of code, but i really need help with these, i don't know if add this function is impossible, but i'm here looking for answers, every comment will be usefull
thanks
Attachments
-
items.zip12.1 KB · Views: 0 · VirusTotal