PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Help with scripts => Topic started by: Alone on 10 March, 2008, 14:42:37

Title: How do it?
Post by: Alone on 10 March, 2008, 14:42:37
Hello.. I have a question. I write little script

function ChatArrival(user,data)
Core.GetUserAllData(user)
local data = string.sub(data,1,-2)
local s,e,cmd =string.find(data, "%b<>%s+(%S+)")
if cmd == "!booring" then
name = user.sNick
tv = 0
return true
end
if tv == 0 and name == user.sNick then
Core.SendToAll("*booring "..data.."")
return true
end

But only one user at time can use them. I want, what more then one user can use this script. How to do it?
Title: Re: How do it?
Post by: Madman on 10 March, 2008, 16:34:16
You need to add the user in to a table...

Just ask and i'll help...
Title: Re: How do it?
Post by: Alone on 11 March, 2008, 16:14:49
Hello again, i'm write this script with using with table, but before i read Your post. Sorry for old code. All works good, but i don't now how to remove nick from table. This is my code

--Insert user nick in table by command (!booring)
local data = string.sub(data,1,-2)
local s,e,cmd =string.find(data, "%b<>%s+(%S+)")
if cmd == "!booring" then
table.insert (sSettings.uNick, user.sNick)
table.insert (sSettings.uMode, "1")
return true
end
if cmd == "!withoutint" then
table.insert (sSettings.uNick, user.sNick)
table.insert (sSettings.uMode, "0")
return true
end
--Find user nick and mode in table
local s,e,cmd =string.find(data, "%b<>%s+(%S+)")
for i = 1,table.maxn(sSettings.uNick) do
for i = 1,table.maxn(sSettings.uMode) do
        disp = sSettings.uNick[i]
disp2 = sSettings.uMode[i]
if user.sNick == disp and disp2 == "0"  then
for j = 1,table.maxn(sSettings.uNick) do
table.remove(sSettings.uNick, i)
end
end
        if user.sNick == disp and disp2 == "1"  then
Core.SendToAll("*booring "..data.."")
return true
end

I think, that problem with this happend because

if cmd == "!withoutint" then
table.insert (sSettings.uNick, user.sNick)
table.insert (sSettings.uMode, "0")
return true
end

After this command user.sNick and uMode writing in table how a new element.
How remove mode(*booring) from user? I don't find any information about search in table.