• 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.X] - Random Reward Chest not giving proper name.

Extrodus

|| Blazera.net ||
Joined
Dec 22, 2008
Messages
2,691
Solutions
7
Reaction score
549
Location
Canada
So I have a weird issue with this script I am creating that gives a random reward to the player. I am trying to make it send a text message to the player with a statement letting them know what item they have received.

In one line it states the proper item id, but when I try to get the item's name with that ID; it returns the item ID of the random reward chest itself "11401" or "Tibiora's Box" - this is a sample of what it looks like when using the item in game.

14:39 You have found Tibiora's box
14:39 You have found 9019 <-- which is a soul stone, not tibioras box.

So what I see from the problem, its getting the itemID of the item I am "using" in game, not the rewards name.. which doesnt make sense if the ID it is grabbing is 9019.

This is the script itself.

Code:
 local rewards = {
  { item = 9019, count = 1 },
  { item = 5809, count = 1 },
  { item = 8982, count = 1 }
}   
  function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
     local random = math.random(1, #rewards)
     player:addItem(rewards[random].item, rewards[random].count)
     player:sendTextMessage(36, 'You have found '.. item:getName(rewards[random].item) ..'')
     player:sendTextMessage(36, 'You have found '.. rewards[random].item ..'')
     return true
  end

Thanks to anyones eyes that spot the problem.
 
item:getName(rewards[random].item) -> ItemType(rewards[random].item):getName().

Edit: The second argument for the onUse callback is the Item userdata of the object you're using ingame, so it does make sense as to why the item name in the reward message is incorrect.
 
Back
Top