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

Enchantments Script (Give items attributes)

SnorkY

Veteran OT User
Joined
Nov 28, 2007
Messages
1,395
Reaction score
264
Hello. I'm using OTHire and trying to create a Script that let's me enchant a item.

I currently have a functions that transformator the old itemID into the new itemID. The problem wih this script is that I have to create a new itemID for every item I want to enchant, which gets very annoying.

I want the transformed item to have the same itemID, but with a boost to f.e it's attack for a period of time.

I looked around but I did not find a lua function in OTHire that adds an attribute to an item onUse, so I ask here if anyone knows what needs to be added into the source code to create such a function.

Thanks.
 
Forexample functions called:

addItemAttack(key, value)
addItemMagicLevel(key, value)

Imported via sources.
 
you don't have doItemSetAttribute(uid, key, value)?

i can look in 0.4 sources for the code

edit:
Code:
int32_t LuaInterface::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 = popBoolean(L);
    else if(lua_isstring(L, -1))
        value = popString(L);
    else
    {
        lua_pop(L, 1);
        errorEx("Invalid data type");

        lua_pushboolean(L, false);
        return 1;
    }

    std::string key = popString(L);
    ScriptEnviroment* env = getEnv();

    Item* item = env->getItemByUID(popNumber(L));
    if(!item)
    {
        errorEx(getError(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)
            {
                errorEx("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;
}
 
you don't have doItemSetAttribute(uid, key, value)?

i can look in 0.4 sources for the code

edit:
Code:
int32_t LuaInterface::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 = popBoolean(L);
    else if(lua_isstring(L, -1))
        value = popString(L);
    else
    {
        lua_pop(L, 1);
        errorEx("Invalid data type");

        lua_pushboolean(L, false);
        return 1;
    }

    std::string key = popString(L);
    ScriptEnviroment* env = getEnv();

    Item* item = env->getItemByUID(popNumber(L));
    if(!item)
    {
        errorEx(getError(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)
            {
                errorEx("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;
}

Ah, Nice! No, i dont have that function :(


Do you have any other useful functions for othire?

Thanks alot!
 
Last edited:
DoItemSetAttribute(key, value) set's an int value of an item, right?

Preferably, i'd like a function that adds additional attack or whatever, in a similar way:

if success -> WeaponAttack = WeaponAttack + 2.

My plan is to have the ability to boost a weapon multiple times by using "enchantment scrolls" :p

0 scrolls -> giant sword = 46 atk
1 scroll -> giant sword = 48 atk
2 scrolls -> giant sword = 50 atk
etc

Does this work?

if success -> DoItemSetAttribute(key, value+2)
 
DoItemSetAttribute(key, value) set's an int value of an item, right?

Preferably, i'd like a function that adds additional attack or whatever, in a similar way:

if success -> WeaponAttack = WeaponAttack + 2.

My plan is to have the ability to boost a weapon multiple times by using "enchantment scrolls" :p

0 scrolls -> giant sword = 46 atk
1 scroll -> giant sword = 48 atk
2 scrolls -> giant sword = 50 atk
etc

Does this work?

if success -> DoItemSetAttribute(key, value+2)
yes, you can use getItemAttribute
Code:
int32_t LuaInterface::luaGetItemAttribute(lua_State* L)
{
    //getItemAttribute(uid, key)
    std::string key = popString(L);
    ScriptEnviroment* env = getEnv();

    Item* item = env->getItemByUID(popNumber(L));
    if(!item)
    {
        errorEx(getError(LUA_ERROR_ITEM_NOT_FOUND));
        lua_pushnil(L);
        return 1;
    }

    boost::any value = item->getAttribute(key);
    if(value.empty())
        lua_pushnil(L);
    else if(value.type() == typeid(std::string))
        lua_pushstring(L, boost::any_cast<std::string>(value).c_str());
    else if(value.type() == typeid(int32_t))
        lua_pushnumber(L, boost::any_cast<int32_t>(value));
    else if(value.type() == typeid(float))
        lua_pushnumber(L, boost::any_cast<float>(value));
    else if(value.type() == typeid(bool))
        lua_pushboolean(L, boost::any_cast<bool>(value));
    else
        lua_pushnil(L);

    return 1;
}
so it would be like
doItemSetAttribute(item.uid, 'attack', getItemAttribute(item.uid, 'attack') + 2)
 
yes, you can use getItemAttribute
Code:
int32_t LuaInterface::luaGetItemAttribute(lua_State* L)
{
    //getItemAttribute(uid, key)
    std::string key = popString(L);
    ScriptEnviroment* env = getEnv();

    Item* item = env->getItemByUID(popNumber(L));
    if(!item)
    {
        errorEx(getError(LUA_ERROR_ITEM_NOT_FOUND));
        lua_pushnil(L);
        return 1;
    }

    boost::any value = item->getAttribute(key);
    if(value.empty())
        lua_pushnil(L);
    else if(value.type() == typeid(std::string))
        lua_pushstring(L, boost::any_cast<std::string>(value).c_str());
    else if(value.type() == typeid(int32_t))
        lua_pushnumber(L, boost::any_cast<int32_t>(value));
    else if(value.type() == typeid(float))
        lua_pushnumber(L, boost::any_cast<float>(value));
    else if(value.type() == typeid(bool))
        lua_pushboolean(L, boost::any_cast<bool>(value));
    else
        lua_pushnil(L);

    return 1;
}
so it would be like
doItemSetAttribute(item.uid, 'attack', getItemAttribute(item.uid, 'attack') + 2)

Thank you very much! I will try out these when i get home :D
 
Back
Top