• 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 Help with a simple Gather System TFS 1.2 Tables

Oneda

Aspiring Spriter
Joined
Dec 3, 2013
Messages
159
Solutions
2
Reaction score
104
Location
Brazil
Hey guys! I got a small problem here, I made a real simple base gather system for TFS 1.2, which has a table for bush IDs on it, and I just CANT remember how do I use tables at all.

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local bushIds = {2769, 2768}
   
    if target.itemid == bushIds then
        target:transform(2781)
        target:decay()
        player:addItem(5467)
        player:addItem(2244)
        return true
    end
    return destroyItem(player, target, toPosition)
end

The problem is, how should I use " if target.itemid == " to get the IDs from that bushIds table?
 
Solution
Code:
if table.contains(bushIds, target.itemid) then
if you are not modyfing bushids then move it outside of onUse function.
Code:
if table.contains(bushIds, target.itemid) then
if you are not modyfing bushids then move it outside of onUse function.
 
Solution
Code:
if table.contains(bushIds, target.itemid) then
if you are not modyfing bushids then move it outside of onUse function.

Alright, I tried it but it gave me a nil error, searched on google for TFS 1.2 functions and found out it has changed. Instead of table.contains I used isInArray and it worked just fine, thanks dude!

Final script if someone needs:
Lua:
local bushIds = {2769, 2768, 2767, 2771}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)   
    if isInArray(bushIds, target.itemid) then
        target:transform(2784)
        target:decay()
        player:addItem(5467)
        player:addItem(2244)
        return true
    end
    return destroyItem(player, target, toPosition)
end
 
Alright, I tried it but it gave me a nil error, searched on google for TFS 1.2 functions and found out it has changed. Instead of table.contains I used isInArray and it worked just fine, thanks dude!

Final script if someone needs:
Lua:
local bushIds = {2769, 2768, 2767, 2771}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)  
    if isInArray(bushIds, target.itemid) then
        target:transform(2784)
        target:decay()
        player:addItem(5467)
        player:addItem(2244)
        return true
    end
    return destroyItem(player, target, toPosition)
end

It's the same function, just renamed.
But it was changed in 1.3, so in 1.2 you have to use isInArray; Move isInArray to Lua by WibbenZ · Pull Request #2095 · otland/forgottenserver · GitHub
 
Back
Top