• 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.X+ TFS 1.2 item/itemType

Itutorial

Legendary OT User
Joined
Dec 23, 2014
Messages
2,339
Solutions
68
Reaction score
1,024
Using itemtype:getAttack() or item:getAttribute("attack") both return 0.

This goes for defense, and a few others as-well. Does anyone know why it would return 0?

I am using the onMoveItem event.
 
Code:
local weapon = creature:getSlotItem(CONST_SLOT_LEFT).itemid
local it = ItemType(weapon)
local attack = it:getAttack()
 
Solution
Yeah, let me explain again. I know how to check an items attack but for some reason it is returning 0 as its value.

Edit: Well, turns out the problem was I was using userdata when calling the itemtype... I tired it again by calling the ItemType with the items id and it worked.

So the fix is: Dont use userdata to get an itemtype use the ID. Sadly, I knew this but didn't think about it.
 
Yeah, let me explain again. I know how to check an items attack but for some reason it is returning 0 as its value.

Edit: Well, turns out the problem was I was using userdata when calling the itemtype... I tired it again by calling the ItemType with the items id and it worked.

So the fix is: Dont use userdata to get an itemtype use the ID. Sadly, I knew this but didn't think about it.

Thats exactly what i posted. If you read carefully my code, means that im getting from and itemid. ItemType() returns the kind of item is it, weapon or whatever, you need an actual id which has attack.
 
Thats exactly what i posted. If you read carefully my code, means that im getting from and itemid. ItemType() returns the kind of item is it, weapon or whatever, you need an actual id which has attack.

Yes, reading your code is what allowed me to realize what needed to be done. I would have marked it as best answer but there was no explanation of the difference in what I was trying to do and what you did. So, I explained what the problem was and what needed to be done to solve it. That is why I marked mine as best answer.
 
Thats exactly what i posted. If you read carefully my code, means that im getting from and itemid. ItemType() returns the kind of item is it, weapon or whatever, you need an actual id which has attack.
true but your code could error because you don't check if the weapon exists before indexing it
Lua:
local weapon = creature:getSlotItem(CONST_SLOT_LEFT)
if weapon then
    local attack = weapon:getType():getAttack()
end
 
How dare you change the best answer. The best answer is the one that explains the problem, why it is happening, and how to fix it. Not just throwing code out.

After looking at the sources you can do 1 of 3 things:

local itemtype = ItemType(item:getName())
local itemtype = ItemType(item.itemid)
local itemtype = item:getType()

All of which just as good.
 
i marked his post because it was the first answer that would solve the thread's issue
you can clearly see why it works in the code, it's because it uses item id to construct ItemType instead of an item userdata
don't need to explain the obvious
 
Yes, someone who understands the difference and the importance for each way something is done can see it easily.

There is no obvious reason sending an items userdata wouldn't work to construct the ItemType. Especially because other classes can be defined with userdata such as: Player, Npc, Creature, and Monster.

Just because you think it is obvious because you can see the immediate difference doesn't mean it is so for everyone. So again, the best answer should always be the one that explains the problem, reason, solution.
 
Yes, someone who understands the difference and the importance for each way something is done can see it easily.

There is no obvious reason sending an items userdata wouldn't work to construct the ItemType. Especially because other classes can be defined with userdata such as: Player, Npc, Creature, and Monster.

Just because you think it is obvious because you can see the immediate difference doesn't mean it is so for everyone. So again, the best answer should always be the one that explains the problem, reason, solution.
Stop arguing, there is really no point, the answer that is the best is already marked and its correct. Fix your attitude and let other be good too, because as far as I see in any of your post, you are seeing yourself as someone more than you really are.
 
Stop arguing, there is really no point, the answer that is the best is already marked and its correct. Fix your attitude and let other be good too, because as far as I see in any of your post, you are seeing yourself as someone more than you really are.

I don't care which one is marked as best. It seems _Static and I have a different idea on which one should be marked as best. I am simply trying to understand his reasoning behind marking a post that leads to the right answer, but not an answer itself.

I am glad Aeronx posted because it probably would have taken me a bit more time to figure out (I assumed if i had something like that wrong there would be an error).

There is no argument here, I am simply wondering if he agrees that in most cases the answer that is descriptive would be better than just throwing code out.

I am not sure what attitude you are referring too but you might want to fix your house before judging another.

As a member of the support team I wouldn't recommend attacking forum users like that. Not that I am in any position to tell you how to compose yourself on a forum you have higher status on but if I owned a forum and one of the mods were to demonstrate what you just did I might rethink his adequacy as one of my forums representative.
 
I really dont care if my answer is the correct one at all! Its true that mine lacks the explanation, but i thought it was not necessary.

Anyway, im glad it helped. Im no guru, and most of what i know is because i asked you all so.. :)
 
if you really care about it that much i'll remark yours, i just figured since he posted the code that is the solution (that's my reasoning) i marked his instead
 
I don't care which one is marked as best. It seems _Static and I have a different idea on which one should be marked as best. I am simply trying to understand his reasoning behind marking a post that leads to the right answer, but not an answer itself.

I am glad Aeronx posted because it probably would have taken me a bit more time to figure out (I assumed if i had something like that wrong there would be an error).

There is no argument here, I am simply wondering if he agrees that in most cases the answer that is descriptive would be better than just throwing code out.

I am not sure what attitude you are referring too but you might want to fix your house before judging another.

As a member of the support team I wouldn't recommend attacking forum users like that. Not that I am in any position to tell you how to compose yourself on a forum you have higher status on but if I owned a forum and one of the mods were to demonstrate what you just did I might rethink his adequacy as one of my forums representative.
And you showed your attitude once again in the end of your last post. What did I demonstrate? btw. Nice one „attacking users” XD
P.S read @Aeronx post above and try to compare it to your posts (I’m not talking only about this thread). That’s all I wanted to say to you, reading your posts for a while, no drama, no hate, just an opinion, you get easily offended tho for no reason at all.
 
Last edited:
Back
Top