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

Lua attribute itemtype

Fortera Global

Intermediate OT User
Joined
Nov 20, 2015
Messages
1,180
Solutions
2
Reaction score
117
I'm trying to make sure the item has the weight attribute and I did not succeed

Code:
attempt to call method 'hasAttribute' (a nil value)

tfs 1,2

Lua:
function onSay(player, words, param)
    local itemType = ItemType(param)
  
    if itemType:getId() == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "There is no item with that name.")
        return false  
    end
  
    -- PROBLEM IS HERE hasAttribute
    if itemType and not itemType:hasAttribute(ITEM_ATTRIBUTE_WEIGHT) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot add this item.")
        return false
    end
  
    if itemType:getId() == 0 then
        itemType = ItemType(tonumber(param))
        if itemType:getName() == '' and itemType:getId() == '' then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "There is no item with that name.")
            return false
        end
    end
     
    return false
end
 
Solution
the problem is the itemType,
in onMove in player.lua this work


like:

Lua:
if item:hasAttribute(ITEM_ATTRIBUTE_WEIGHT) then
As far as I did read in the issue open posted by bayview, they say that method is only supposed to be used with custom attributes. Weight is an item attribute, and you should be able to do itemType:getWheight or item:getWeight...
the problem is the itemType,
in onMove in player.lua this work


like:

Lua:
if item:hasAttribute(ITEM_ATTRIBUTE_WEIGHT) then
As far as I did read in the issue open posted by bayview, they say that method is only supposed to be used with custom attributes. Weight is an item attribute, and you should be able to do itemType:getWheight or item:getWeight...
 
Solution
As far as I did read in the issue open posted by bayview, they say that method is only supposed to be used with custom attributes. Weight is an item attribute, and you should be able to do itemType:getWheight or item:getWeight...

if itemType:getWheight() < 1 then

attempt to call method 'getWheight' (a nil value)


hmm the correctly is: getWeight

thanks I think it works
 
Mmh strange. Both itemType and item have that method. try to make sure ItemType is not null


Edit, theres a typo in my post and yours. its weight, not wheight
 
Back
Top