• 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!

[TalkAction] Global Table (solved)

StormRusher

New Member
Joined
Dec 23, 2009
Messages
138
Reaction score
0
How can i make a global table?

And how can i do to show this table content in a line, like:
if table = {"Maria", "Joao", "Pedro"}
show in a message like Maria, Joao, Pedro.

i tried to do like a variable, whitout "local", but when i tried to get the table in another script, doesnt work...

Thanks
 
Last edited:
Define the table in global.lua if you're using TFS 0.2, or in libs/constant.lua if you're using TFS 0.3

Oh, and for concatenating:
Lua:
local v, first = "", true
for i = 1, #table do
	v, first = v .. (first and "" or ", ") .. table[i], false
end
 
Last edited:
thanks a lot
but to return the table content in a message what should i do?

my table is "open1"
doPlayerSendTextMessage(cid, 27, ... ?)

:X
 
thanks a lot
but to return the table content in a message what should i do?

my table is "open1"
doPlayerSendTextMessage(cid, 27, ... ?)

:X
Code:
local v, first = "", true
for i = 1, #open1 do
        v, first = v .. (first and "" or ", ") .. open1[i], false
end
doPlayerSendTextMessage(cid, 27, v)
 
Worked fine, but i think i am doing something wrong when add values for the table.

I made this script:

Lua:
function onStepIn(cid, item, pos, fromPos)
local msg = "Welcome to Open!"
	if item.uid == 1040 and getPlayerGroupId(cid) < 3 then
		table.insert(open1, getPlayerName(cid))
		doPlayerSendTextMessage(cid, 20, msg)
	elseif item.uid == 1041 and getPlayerGroupId(cid) < 3 then
		table.insert(open2, getPlayerName(cid)) -- Player open no time2
		doPlayerSendTextMessage(cid, 20, msg)
	end
return TRUE
end

I wanna that when the player enters in a certain tile (uniqueid = 1041 or 1040) add his name in the table, if uid = 1040, add in table open1, if uid = 1041, add in table open2

Am i doing something wrong? :confused:
 
Last edited:
Code:
function onStepIn(cid, item, position, fromPosition)
	local t = item.uid == 1040 and open1 or item.uid == 1041 and open2
	if isInArray(t, getCreatureName(cid)) == FALSE and getPlayerGroupId(cid) < 3 then
		table.insert(t, getCreatureName(cid))
		doPlayerSendTextMessage(cid, 20, "Welcome to Open!")
	end
end
 
i dont know why isnt working,

i have the tables in constant.lua

open1 = {}
open2 = {}

the talkaction script is right, same as the movement...

i think have a problem when add values in a global table, because i tried to put some values on the table in constant.lua and returned right in the talkaction, dont i have to do something more?

does its possible to add values in a global table with table.insert ? :X
 
well i found another way to do what i want heh...

i used the online script what returns only playes with certain storage value. (the player obtain the value when entry in the tp)

Lua:
function onSay(cid, words, param, channel)
        local players = getPlayersOnline()
        local first_ = 0
        local second_ = 0
        local open1 = {}
        local open2 = {}
       
        for _, pid in ipairs(players) do
                if getPlayerStorageValue(pid, 10) == 1 and getPlayerGroupId(pid) < 3 and getPlayerStorageValue(pid, 1) == 1 then
                        first_ = first_ +1
                        table.insert(open1, getCreatureName(pid))
                end
               
                if getPlayerStorageValue(pid, 10) == 2 and getPlayerGroupId(pid) < 3 and getPlayerStorageValue(pid, 1) == 2 then
                        second_ = second_ +1
                        table.insert(open2, getCreatureName(pid))
                end
        end
       
        if table.maxn(open1) == 0 then
                table.insert(open1, "NOBODY")
        end
       
        if table.maxn(open2) == 0 then
                table.insert(open2, "NOBODY")
        end
       
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "EM/CO Team Open = "..first_.." ("..table.concat(open1 , ", ")..")\n        Anima Team Open  = "..second_.." ("..table.concat(open2 , ", ")..")")
        return true
end

(credits to hellboy)

anyway thanks for help :D

solved~~
 
Back
Top