• 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 I need help with script

Azerty

Active Member
Joined
Apr 15, 2022
Messages
316
Solutions
4
Reaction score
32
I'm trying to create a script in which I need to repeat this part of the code several times, but I know that TFS has a limit on repeating, for example "local", is there any way to insert the information into just one variable?

Lua:
local t = {
    Position(30629, 32466, 9),
    Position(30628, 32466, 9),
    Position(30627, 32466, 9),
    Position(30626, 32458, 9),
    Position(30626, 32457, 9),
    Position(30626, 32457, 9)
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 9826 then
        local tile = t[1]:getTile()
        if tile then
            local stone = tile:getItemById(1304)
            if stone then
                stone:remove()
                t[1]:sendMagicEffect(CONST_ME_POFF)
            end
        end

        local tile = t[2]:getTile()
        if tile then
            local stone = tile:getItemById(1304)
            if stone then
                stone:remove()
                t[2]:sendMagicEffect(CONST_ME_POFF)
            end
        end

        local tile = t[3]:getTile()
        if tile then
            local stone = tile:getItemById(1304)
            if stone then
                stone:remove()
                t[3]:sendMagicEffect(CONST_ME_POFF)
            end
        end
...

And yes, I already managed to reach the repetition limit trying to do it my way haha
 
I'm not sure if that's what you mean. Here is an example of using several variables in one "local"
https://www.lua.org/cgi-bin/demo
Untitled.png


Lua:
local t = {
s ={
{string = "text one", number = 1},
{string = "text two", number = 2},
{string = "text three", number = 3}
},
d = os.date,
r = math.random(10),
l = 5,
}
for i = 1, #t.s do
print(t.s[i]. number.." = "..t.s[1].string)
end
local t2 = "Today is "..t.d("%x").."\nYour lucky number is "..t.r
if t.r > t.l then
print(t2.." - You win, congratulations!")
else
print(t2)
end
 
I'm not sure if that's what you mean. Here is an example of using several variables in one "local"
https://www.lua.org/cgi-bin/demo


Lua:
local t = {
s ={
{string = "text one", number = 1},
{string = "text two", number = 2},
{string = "text three", number = 3}
},
d = os.date,
r = math.random(10),
l = 5,
}
for i = 1, #t.s do
print(t.s[i]. number.." = "..t.s[1].string)
end
local t2 = "Today is "..t.d("%x").."\nYour lucky number is "..t.r
if t.r > t.l then
print(t2.." - You win, congratulations!")
else
print(t2)
end
I tried following the example but I can't get it to work
 
Maybe this
Lua:
local t ={
pos= {
    Position(30629, 32466, 9),
    Position(30628, 32466, 9),
    Position(30627, 32466, 9),
    Position(30626, 32458, 9),
    Position(30626, 32457, 9),
    Position(30626, 32457, 9)
},
id = 9826,
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == t.id then
for i = 1, 6 do
        local tile = t.pos[i]:getTile()
        if tile then
            local stone = tile:getItemById(1304)
            if stone then
                stone:remove()
                t.pos[i]:sendMagicEffect(CONST_ME_POFF)
            end
        end
end
 
Back
Top