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

doItemSetAttribute

brunolopes

New Member
Joined
Nov 8, 2009
Messages
49
Reaction score
1
I recently discovered that the LUA function doItemSetAttribute(uid) cannot do calculations right.

If you write this, eg:

Code:
doItemSetAttribute(itemEx.uid, "attack", getItemInfo(itemEx.itemid).attack*1.86)

The result will be, probably, decimal.

And the function will not work, in other words, the function will not change the attack of weapon.

But if you write this, eg:

Code:
doItemSetAttribute(itemEx.uid, "attack", getItemInfo(itemEx.itemid).attack + 3)

The result will be exact. And the function changes the attack...

Is there anyway to fix this function? :eek:

Sorry for the english :(
 
hmm, if you earlier used doItemSetAttribute the getItemAttribute seems to work, but if item have defauld attributes you have to use getItemInfo(at least it seems so in item upgrade script, not tested by printing values)
 
hmm, if you earlier used doItemSetAttribute the getItemAttribute seems to work, but if item have defauld attributes you have to use getItemInfo(at least it seems so in item upgrade script, not tested by printing values)
getItemInfo(itemid)
:C
 
FIXED, with source edit though :S

For all those who cannot execute the "setItemAttribute / getItemAttribute" functions!


It's just a temporary solution but it works though.

Open up your luascript.cpp and paste this:

Code:
    //getItemAttr(uid, attr)
	lua_register(m_luaState, "getItemAttr", LuaScriptInterface::luaGetItemAttribute);

    //setItemAttr(uid, attr)
	lua_register(m_luaState, "setItemAttr", LuaScriptInterface::luaSetItemAttribute);

also this:
Code:
int32_t LuaScriptInterface::luaGetItemAttribute(lua_State *L) //by Kratos
{
    //getItemAttr(uid, val)
    std::string attr = popString(L);
    uint32_t uid = popNumber(L);
    
    ScriptEnviroment* env = getScriptEnv();
    
    Item* item = env->getItemByUID(uid);
    
    if(!item)
    {
        reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
  ///////////////////////////////////// string:
    if(attr == "name")
    {
    lua_pushstring(L, item->getName().c_str());
    return 1;
    }  

    if(attr == "pluralname")
    {
    lua_pushstring(L, item->getPluralName().c_str());
    return 1;
    }     

    if(attr == "specialdescr")
    {
    lua_pushstring(L, item->getSpecialDescription().c_str());
    return 1;        
    }
 
    if(attr == "text")
    {
    lua_pushstring(L, item->getText().c_str());
    return 1;
    }
    
    if(attr == "writer")
    {
    lua_pushstring(L, item->getWriter().c_str());
    return 1;
    }
  ///////////////////////////////////// int:  
    if(attr == "itemid")
    {
    lua_pushnumber(L, item->getID());
    return 1;
    }
    
    if(attr == "aid")
    {
    lua_pushnumber(L, item->getActionId());
    return 1;
    }
    
    if(attr == "uid")
    {
    lua_pushnumber(L, item->getUniqueId());
    return 1;
    }
    
    if(attr == "charges")
    {
    lua_pushnumber(L, item->getCharges());
    return 1;
    }
    
    if(attr == "fluidtype")
    {
    lua_pushnumber(L, item->getFluidType());
    return 1;
    }
    
    if(attr == "duration")
    {
    lua_pushnumber(L, item->getDuration());
    return 1;
    }
    
    if(attr == "dduration")
    {
    lua_pushnumber(L, item->getDefaultDuration());
    return 1;
    }
   
    if(attr == "throw_range")
    {
    lua_pushnumber(L, item->getThrowRange());
    return 1;
    }
    
    if(attr == "shoot_range")
    {
    lua_pushnumber(L, item->getShootRange());
    return 1;
    }
    
    if(attr == "atk")
    {
    lua_pushnumber(L, item->getAttack());
    return 1;
    }
    
    if(attr == "arm")
    {
    lua_pushnumber(L, item->getArmor());
    return 1;
    }
    
    if(attr == "def")
    {
    lua_pushnumber(L, item->getDefense());
    return 1;
    }   
    
        
    if(attr == "slot_position")
    {
    if(item->getSlotPosition() & SLOTP_NECKLACE)
    lua_pushnumber(L,1);    
    if(item->getSlotPosition() & SLOTP_HEAD)
    lua_pushnumber(L,2);
    if(item->getSlotPosition() & SLOTP_BACKPACK)
    lua_pushnumber(L,3);
    if(item->getSlotPosition() & SLOTP_LEFT)
    lua_pushnumber(L,4);
    if(item->getSlotPosition() & SLOTP_ARMOR)
    lua_pushnumber(L,5);
    if(item->getSlotPosition() & SLOTP_RIGHT)
    lua_pushnumber(L,6);
    if(item->getSlotPosition() & SLOTP_RING)
    lua_pushnumber(L,7);
    if(item->getSlotPosition() & SLOTP_LEGS)
    lua_pushnumber(L,8);
    if(item->getSlotPosition() & SLOTP_AMMO)
    lua_pushnumber(L,9);
    if(item->getSlotPosition() & SLOTP_FEET)
    lua_pushnumber(L,10);
    return 1;
    }
    
    if(attr == "hitchance")
    {
    lua_pushnumber(L, item->getHitChance());
    return 1;
    }
    
    if(attr == "maxwritelen")
    {
    lua_pushnumber(L, item->getMaxWriteLength());
    return 1;
    }
    
    if(attr == "count")
    {
    lua_pushnumber(L, item->getItemCount());
    return 1;
    }   
    
    
       
 ///////////////////////////////////////////// boolean:
 
    if(attr == "ispushable")
    {
    lua_pushboolean(L, item->isPushable());
    return 1;        
    }   

    if(attr == "isreadable")
    {
    lua_pushboolean(L, item->isReadable());
    return 1;        
    }  
    
    if(attr == "iscanwritetext")
    {
    lua_pushboolean(L, item->canWriteText());
    return 1;        
    }  
    
    if(attr == "isblocking")
    {
    lua_pushboolean(L, item->isBlocking());
    return 1;        
    }  
    
    if(attr == "isstackable")
    {
    lua_pushboolean(L, item->isStackable());
    return 1;        
    }      
    
    if(attr == "isrune")
    {
    lua_pushboolean(L, item->isRune());
    return 1;        
    }  
    
    if(attr == "isfluidcont")
    {
    lua_pushboolean(L, item->isFluidContainer());
    return 1;        
    }   
    
    if(attr == "isalwaysontop")
    {
    lua_pushboolean(L, item->isAlwaysOnTop());
    return 1;        
    }  
    
    if(attr == "isgroundtile")
    {
    lua_pushboolean(L, item->isGroundTile());
    return 1;        
    }  
    
    if(attr == "issplash")
    {
    lua_pushboolean(L, item->isSplash());
    return 1;        
    }      
    
    if(attr == "ismagicfield")
    {
    lua_pushboolean(L, item->isMagicField());
    return 1;        
    }  
    
    if(attr == "isnotmoveable")
    {
    lua_pushboolean(L, item->isNotMoveable());
    return 1;        
    }       
    
    if(attr == "ispickupable")
    {
    lua_pushboolean(L, item->isPickupable());
    return 1;        
    }  
    
    if(attr == "isweapon")
    {
    lua_pushboolean(L, item->isWeapon());
    return 1;        
    }  
    
  
     
       
        
    if(attr == "isrotateable")
    {
    lua_pushboolean(L, item->isRoteable());
    return 1;        
    }  
    
    if(attr == "isdoor")
    {
    lua_pushboolean(L, item->isDoor());
    return 1;        
    }          
    
    if(attr == "isbed")
    {
    lua_pushboolean(L, item->isBed());
    return 1;        
    }          
 
    if(attr == "iskey")
    {
    lua_pushboolean(L, item->isKey());
    return 1;        
    }     
    
        
    
           
         
   
    
    std::cout << "[LuaScriptInterface::luaGetItemAttribute]: invalid item attribute." << std::endl;  

}

int32_t LuaScriptInterface::luaSetItemAttribute(lua_State *L) //by Kratos
{
    //setItemAttr(uid, "attr", val)
    
    uint32_t intval = popNumber(L);
    std::string attr = 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;
    }

    
   //////////////////////////////////// int:
                                        
    if(attr == "aid")
    {
    item->setActionId(intval);
    return 1;        
    }
    
    if(attr == "uid")
    {
    item->setUniqueId(intval);
    return 1;        
    }
    
      
    if(attr == "fluidtype")
    {
    item->setFluidType(intval);
    return 1;        
    }

    if(attr == "duration")
    {
    item->setDuration(intval);
    return 1;        
    }
  
    if(attr == "dduration")
    {
    item->setDefaultDuration();
    return 1;        
    }  
    
    if(attr == "itemcount")
    {
    item->setItemCount(intval);
    return 1;        
    }
    
  
 
    std::cout << "[LuaScriptInterface::luaSetItemAttribute]: invalid item attribute." << std::endl;                                     
    return 1;
}

and finally in luascript.h this:
Code:
static int32_t luaGetItemAttribute(lua_State *L); //by kratos
static int32_t luaSetItemAttribute(lua_State *L); //by kratos

ALL CREDITS TO KRATOS @ OTFANS!
I JUST MODIFIED THE SCRIPT TO THE
NEWER TFS VERSIONS!


You can use getItemAttr and setItemAttr to change the attribute of items.
 
Back
Top