• 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+ How to get the amount of an item inside a chest in a lua function

Joined
Dec 7, 2016
Messages
22
Reaction score
6
Sorry if this is dumb, I'm still learning lua and how to make lua functions for my TFS 1.3 distro.

I decided to ditch the default reward system for TFS 1.3 and make my own, I want to give crystal coins as a reward and I want to give 10 CCs to the player.
Now, I already figured out how to get the items inside a chest, I just need to find out how to get the count of said item.

Here is what I wrote so far...
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local size = isContainer(item.uid) and getContainerSize(item.uid) or 0
    for i = 0, size do
        local tmp = getContainerItem(item.uid, i)
        if(tmp.itemid > 0) then
            player:addItem(tmp.itemid, 1)
        end
    end

    return true
end
The function is still missing player messages but that's not an issue, I already know how to do it.

I don't want to hard code this amount inside the lua function because I'll be setting up the rewards inside the map and triggering their scripts using actionids and uniqueids.

What I need to do is find out how many coins I have inside that chest so that I can give that to the player.

Do you guys have any idea how to do it?

Also, is there a list of properties that an Item has? I already know about the list of functions available on TFS 1.3, but I'd like a simple list of properties for objects.
 
May I ask, how did you find this method?

Also, if it's not much to ask, what's the difference between using . and : while working with objects, I have an idea of how they work, but I just don't know why they work like that. lol
I found it by seeing it in the forum, but here's a list of metamethod functions [Lua] //Combat Combat() combat:execute(creature, variant) combat:setArea(area) com - Pastebin.com (https://pastebin.com/nws8xHmK)

As for your second question Difference between . and : in Lua (https://stackoverflow.com/questions/4911186/difference-between-and-in-lua)
 
Also, if it's not much to ask, what's the difference between using . and : while working with objects, I have an idea of how they work, but I just don't know why they work like that. lol

Simple: One implies the variable self is already set internally, the other does not.

foo:bar(3,4) == foo.bar(foo,3,4)
 

Awesome, EXACTLY what I needed, thank you so much!

Simple: One implies the variable self is already set internally, the other does not.

foo:bar(3,4) == foo.bar(foo,3,4)

Ok, that's what I was thinking, thank you for clarifying.
 
Back
Top