• 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 TFS 1.2 Container:getItem(index) help.

Theralion

New Member
Joined
Feb 12, 2016
Messages
8
Reaction score
0
Hi there i' ve got a container with 1 item in it. Is this function supposed to give my character this item? Or just send item's values so i can do something like:

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

local reward = item:getItem(0)

player:addItem(reward,1)

If yes then it doesn't debug but it doesn't work too. I am using a chest so my item is container. When i am trying to do
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. item:getItem(0) .. '.')

or getItem(1) i get error in console. Why? My container(item) has 1 item so it shouldn't debug a text with item:getItem(0) or (1).
 
Hi there i' ve got a container with 1 item in it. Is this function supposed to give my character this item? Or just send item's values so i can do something like:

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

local reward = item:getItem(0)

player:addItem(reward,1)

If yes then it doesn't debug but it doesn't work too. I am using a chest so my item is container. When i am trying to do
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. item:getItem(0) .. '.')

or getItem(1) i get error in console. Why? My container(item) has 1 item so it shouldn't debug a text with item:getItem(0) or (1).

The error is because you're trying to concatenate text and an item userdata. Of course its not going to work.

You should do item:getItem(0):getName() to get the name

And for the add item it should be "player:addItem(reward:getId(), 1)"
 
The error is because you're trying to concatenate text and an item userdata. Of course its not going to work.

You should do item:getItem(0):getName() to get the name

And for the add item it should be "player:addItem(reward:getId(), 1)"

Ok i was really stupid yesterday. item:getItem(0) wasn't a string in any form for me to print :D .
But i don't understand the part player:addItem(reward:getId(),1) . That means a player will be rewarded with an item which id is the same as id of the container right? What i thought would happen is that my player will get the exact same copy of container item as a reward. It is very required because i need the text on reward item. And when i use your function the text disappears( because i just get the same id right? ) . I don't see any function to edit item text so i thought i would need to do it this way, but i am still stuck as your method doesn't bring out the text to reward.
Even though thank you for making me understand a little bit more about lua.

Need to check how clone works and more about item metatables, but i don't see a light of hope at the moment :D

EDIT2: Trying to see if clone() and moveToCylinder are going to make the job done

EDIT3: reward:setAttribute(ITEM_ATTRIBUTE_TEXT,'blalbalba') is working. I used reward:setAttribute(text,'blabla') before and i thought there isn't a function to set text to item in TFS 1.2. I feel so embarassed.I looked to source to check some functions and here we go...

Now i don't even need to place reward in chest and no reason to check for container. Just
player:addItem(ID,1)
reward:setAttribute(ITEM_ATTRIBUTE_TEXT,'blablalba')
and i'm done.
At least i have learned something :P. Thanks for all support
 
Last edited:
Back
Top