• 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.4 Script Table and Texto

lazarus321

Member
Joined
May 8, 2017
Messages
222
Reaction score
23
Hi all,
Does anyone know how I could do to present the text with all possible variations if my variable nx1, nx2, nx3, nx4, nx5, nx6 and nx7 is different from 0?
I tried to do this but it's getting too long and it's not getting all the variations.

LUA:
local t1 = {}
    local t2 = {}
    local t3 = {}
    local t4 = {}
    local t5 = {}
    local t6 = {}
    local t7 = {}
   
    local rx1 = 4
    local rx2 = 7
    local rx3 = 1
    local rx4 = 5
    local rx5 = 3
    local rx6 = 9
    local rx7 = 2
   
    local nx1 = 4
    local nx2 = 10
    local nx3 = 0
    local nx4 = 3
    local nx5 = 10
    local nx6 = 0
    local nx7 = 50
   
    if nx1 ~= 0 then
        dt = 0
        for i = 1, rx1, 1 do
            local i = math.random(1,nx1)
            t1[i] = i
            dt = dt + t1[i]
        end
    end  
   
    player:sendTextMessage(MESSAGE_ATTENTION, nx1 .. "x" .. nx1 .. " . " .. nx2 .. "x" .. nx2 .. " . " .. nx4 .. "x" .. nx4 .. " . " .. nx5 .. "x" .. nx5 .. " . " .. nx7 .. "x" .. nx7)
 
Hi all,
Does anyone know how I could do to present the text with all possible variations if my variable nx1, nx2, nx3, nx4, nx5, nx6 and nx7 is different from 0?
I tried to do this but it's getting too long and it's not getting all the variations.

LUA:
local t1 = {}
    local t2 = {}
    local t3 = {}
    local t4 = {}
    local t5 = {}
    local t6 = {}
    local t7 = {}
  
    local rx1 = 4
    local rx2 = 7
    local rx3 = 1
    local rx4 = 5
    local rx5 = 3
    local rx6 = 9
    local rx7 = 2
  
    local nx1 = 4
    local nx2 = 10
    local nx3 = 0
    local nx4 = 3
    local nx5 = 10
    local nx6 = 0
    local nx7 = 50
  
    if nx1 ~= 0 then
        dt = 0
        for i = 1, rx1, 1 do
            local i = math.random(1,nx1)
            t1[i] = i
            dt = dt + t1[i]
        end
    end 
  
    player:sendTextMessage(MESSAGE_ATTENTION, nx1 .. "x" .. nx1 .. " . " .. nx2 .. "x" .. nx2 .. " . " .. nx4 .. "x" .. nx4 .. " . " .. nx5 .. "x" .. nx5 .. " . " .. nx7 .. "x" .. nx7)

Not sure about it but probably using a function for generate the random value so rx will loop the number of times, nx the upper limit of the random value, something like

LUA:
function valueOfRxNx(rx, nx)
    local t = {}
    local dt = 0
    for i = 1, rx do
        local randomValue = math.random(1, nx)
        t[i] = randomValue
        dt = dt + randomValue
    end
    return dt
end

then check each nx, inserting the values on the table (table.inster / table.concat ) and send the information to player example:

Code:
local resultNxRx= {}

if nx1 ~= 0 then 
    local dt1 = valueOfRxNx(rx1, nx1)
    table.insert(resultNxRx, nx1 .. "x" .. nx1)
end

-- Same for next one if nx2 ~= 0 then.. nx3... nx7

-- a message for show the result Nx Rx to player used a MESSAGE_INFO_DESCR, in case just change it,
local finalMessage = table.concat(resultNxRx, " . ")
player:sendTextMessage(MESSAGE_INFO_DESCR, finalMessage)
 
Back
Top