• 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 0.4] Copying item Attributes and loading them on another item

bodycarcoo11

Mapper
Joined
Apr 26, 2011
Messages
213
Reaction score
9
Location
USA
Hello,
Most of you know who am I the rest don't and it won't change the fact that i came with a good contribution for 0.4 TFS servers that can make it easily to replicate systems you are interested in, Tfs 0.4 lacks the function item:loadAttributes() or item:getAttributes() so we made it in a simple way to copy/paste the attributes you want

Lua:
attributes = {
  "attack",
  "defense",
  "armor",
  "criticalhitdamage",
  "criticalhitdamage",
  "damageincrease",
  "damagereduction",
  "dodge",
  "healingincrease",
  "damagepenetration",
  "lifeleech",
  "manaleech",
}


function loadItemAttributes(item, attributes)
  for key, value in ipairs(attributes) do
    if getItemAttribute(item.uid, key) == nil then
     doItemSetAttribute(item, key, value)
   end
 end
end

function saveItemAttributes(item)
  local data = {}
  for _, key in ipairs(attributes) do
    local value = getItemAttribute(item.uid, key)
    local itemInfo = getItemInfo(item.itemid)
    local itemValue = itemInfo and itemInfo[key]
    if value ~= nil then
      data[key] = value
    elseif itemValue ~= nil then
      data[key] = itemValue
    end
  end
  return data
end

to add more attributes add it in attributes table, attributes in the table will be saved from the item that passed through the funciton (needless to say item.uid)

good luck.
 
Back
Top