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

Problem with "getItemAttribute"!!

Sytoxian

New Member
Joined
Aug 19, 2010
Messages
40
Reaction score
1
Hello, I'vea problem and found no solution in the forum. This line of my code causes error messages.
Code:
function onEquip(cid, item, slot)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This item has " .. getItemAttribute(item.uid,"armor") .. " armor.")
    return true
end

Error Message:
Code:
[29/06/2014 23:11:40] [Error - MoveEvents Interface]
[29/06/2014 23:11:40] data/movements/scripts/upgrades.lua:onEquip
[29/06/2014 23:11:40] Description:
[29/06/2014 23:11:40] data/movements/scripts/upgrades.lua:4: attempt to concatenate a nil value
[29/06/2014 23:11:40] stack traceback:
[29/06/2014 23:11:40]    data/movements/scripts/upgrades.lua:4: in function <data/movements/scripts/upgrades.lua:1>

The "getItemDescriptions(uid)" function causes the same error message.
 
Yes but i need the item.uid.
when i use this codeit causes the error message "attempt to index a boolean value".
Code:
function onEquip(cid, item, slot)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This item has " .. getItemInfo(item.uid).armor .. " armor.")
return true
end
 
Because ive another script that increases a few attributes of the item. do i use 'item.itemid' so it is loaded from the items.xml so that the attached attributes are not included as well. So i need somthing with item.uid.
 
The getItemInfo(item.itemid) is used when the item has no attribute upgrades yet.
Because if you try to get an attribute from an item which has no attribute yet, it'll give you the nil error, do it like this.
Code:
local attr = getItemAttribute(item.uid,"armor")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This item has " .. attr ~= nil and attr or getItemInfo(item.itemid).armor .. " armor.")
 
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "This item has " ..(type(item.uid) == "number" and getItemAttribute(item.uid, "armor") or getItemInfo(item.itemid).armor).. " armor.")

Edit: didn't see other post.
You can do it both ways.
 
When i do it like Limos way i get this error:
Code:
[01/07/2014 14:57:12] [Error - MoveEvents Interface]
[01/07/2014 14:57:12] data/movements/scripts/upgrades.lua:onEquip
[01/07/2014 14:57:12] Description:
[01/07/2014 14:57:12] (luaGetItemAttribute) Item not found

[01/07/2014 14:57:12] [Error - MoveEvents Interface]
[01/07/2014 14:57:12] data/movements/scripts/upgrades.lua:onEquip
[01/07/2014 14:57:12] Description:
[01/07/2014 14:57:12] (luaGetItemAttribute) Item not found

Before i equip the item i use another script which changes a attribute.
Code:
doItemSetAttribute(item, "armor", 23)
 
Last edited:
Which server do you use? Works fine for me on TFS 0.3.6.
Can you post the script how it looks like now?

You can also try it the way Evil Hero posted, then just add ( ) in the textmessage.
Like this:
Code:
"This item has " .. (attr ~= nil and attr or getItemInfo(item.itemid).armor) .. " armor."
 
My server is called "[8.54] The Forgotten Server 0.3.6pl1 (Crying Damson)".
Same problem with Evil Heros solution. Any ideas? :/
 
instead of "armor" its actually "description".
First the script that changes the attribute:
Code:
attributes = {
   ["the reaper"] = {skill1 = 'Melee Skills', skill2 = 'Magic Level'},
   ["berserk"] = {skill1 = 'Melee Skills', skill2 = 'Crit Chance'},
   ["the forest runner"] = {skill1 = 'Distance Skills', skill2 = 'Crit Chance'},
   ["magic blasting"] = {skill1 = 'Distance Skills', skill2 = 'Magic Level'},
   ["magic defense"] = {skill1 = 'Shielding Skills', skill2 = 'Magic Level'},
   ["healthy defense"] = {skill1 = 'Shielding Skills', skill2 = 'Healthpercent'},
   ["magic"] = {skill1 = 'Magic Level', skill2 = 'Manapoints'}
  }
   for k, v in pairs(attributes) do
     if attribute == k then
       item = doPlayerAddItem(cid, item, 1)
       doItemSetAttribute(item, "description", "("..v.skill1.." +"..value1..")("..v.skill2.." +"..value2..")")
       doItemSetAttribute(item, "name", ""..getItemNameById(t[1]).." of ".. k ..".")
     end
   end

and secondly, the script that retrieves the attribute:

Code:
function onEquip(cid, item, slot)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "" ..(type(item.uid) == "number" and getItemAttribute(item.uid, "description") or getItemInfo(item.itemid).description).. "")
   return true
end

sorry for this cunfusion
 
try:
Code:
local attr = getItemAttribute(item,"description")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (attr ~= nil and attr or getItemInfo(item.itemid).description))
it's either
Code:
getItemAttribute(item,"description")
or
getItemAttribute(item,"desc")
not sure which one tbh.
 
Back
Top