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

[TFS 1.1] attributes functions from 0.3.7

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,323
Solutions
26
Reaction score
2,690
Location
Poland
Attributes functions known from 0.3.7.
getItemAttribute(uid, key) advantages over Item(uid):getAttribute(key):
- It returns item name instead of empty string if it wasn't modified
- It returns item values instead of 0 if they weren't modified

Installation:
method a) If you use this(recommended): [TFS 1.x] lib folder in "data" like 0.4 by Zbizu
create item_attributes.lua in data\lib\ and paste that script inside that file

method b) If you don't use lib folder, just add that at end of global.lua
Code:
function getItemAttribute(uid, key)
   local i = ItemType(Item(uid):getId())
   local string_attributes = {
     [ITEM_ATTRIBUTE_NAME] = i:getName(),
     [ITEM_ATTRIBUTE_ARTICLE] = i:getArticle(),
     [ITEM_ATTRIBUTE_PLURALNAME] = i:getPluralName(),
     ["name"] = i:getName(),
     ["article"] = i:getArticle(),
     ["pluralname"] = i:getPluralName()
   }

   local numeric_attributes = {
     [ITEM_ATTRIBUTE_WEIGHT] = i:getWeight(),
     [ITEM_ATTRIBUTE_ATTACK] = i:getAttack(),
     [ITEM_ATTRIBUTE_DEFENSE] = i:getDefense(),
     [ITEM_ATTRIBUTE_EXTRADEFENSE] = i:getExtraDefense(),
     [ITEM_ATTRIBUTE_ARMOR] = i:getArmor(),
     [ITEM_ATTRIBUTE_HITCHANCE] = i:getHitChance(),
     [ITEM_ATTRIBUTE_SHOOTRANGE] = i:getShootRange(),
     ["weight"] = i:getWeight(),
     ["attack"] = i:getAttack(),
     ["defense"] = i:getDefense(),
     ["extradefense"] = i:getExtraDefense(),
     ["armor"] = i:getArmor(),
     ["hitchance"] = i:getHitChance(),
     ["shootrange"] = i:getShootRange()
   }
   
   local attr = Item(uid):getAttribute(key)
   if tonumber(attr) then
     if numeric_attributes[key] then
       return attr ~= 0 and attr or numeric_attributes[key]
     end
   else
     if string_attributes[key] then
       if attr == "" then
         return string_attributes[key]
       end
     end
   end
return attr
end

function doItemSetAttribute(uid, key, value)
   return Item(uid):setAttribute(key, value)
end

function doItemEraseAttribute(uid, key)
   return Item(uid):removeAttribute(key)
end
 
Where u put that? sorry i am new in the tfs 1.x
u add it inside of global.lua
but if you are new to tfs you won't need this. it's just functions that allows you to make a couple of scripts easier, so if u dont know whats its used for its useless for u xD
 
It's working on TFS 1.2, just adding at the end of the global.lua!
Thanks!
 
can you please explain why it does inside the game? what i should see different?
 
can you please explain why it does inside the game? what i should see different?
This does nothing inside of the game, its a library, containing modified functions to add more a bit more information received when using the functions.

Please stop bumping 5 year old threads.

I shared with you once the place to start learning lua, it doesn't take much effort or time to understand, and if you do, then you will not need to wait for someone to answer questions like this one.
 
This does nothing inside of the game, its a library, containing modified functions to add more a bit more information received when using the functions.

Please stop bumping 5 year old threads.

I shared with you once the place to start learning lua, it doesn't take much effort or time to understand, and if you do, then you will not need to wait for someone to answer questions like this one
i tried to read bro but for example all i read didnt tell me how to do a lever script for getting items, you know to explain me how or send me a link that tells how? i created a "first items room" and i want to put some levers that will give items
 
Back
Top