PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: jiten on 02 March, 2005, 20:44:30

Title: SendToVips ?
Post by: jiten on 02 March, 2005, 20:44:30
Well, I have a question. How do I convert this code to LUA 5 ? The problem is that the SendToVips isn't working anymore.


BotName = "?bot?"

controltrigs={["join"]=1,["login"]=2,["hub"]=3}

supervip = {}
fSuperVip = "logs/svip.txt" -- Path of file that contains SuperVips

function ChatArrival(user,data)
if not user.bOperator then
LoadFromFile(fSuperVip)
for key, value in controltrigs do
if( string.find( string.lower(data), key) ) then
s,e,onlymes = string.find(data, "%b<> (.*)")
SendPmToOps (BotName, "Control: <"..user.sName.."> ("..user.sIP..") told in main: "..onlymes.."")
SendToVips("Control: <"..user.sName.."> ("..user.sIP..") told in main: "..onlymes)
end
end
end
end

function ToArrival(user,data)
local _, _, to, from, msg = string.find(data, "^%$To:%s+(%S+)%s+From:%s+(%S+)%s-%$%b<>%s+(.*)|")
local nick = GetItemByName(to)
if not user.bOperator then
for key, value in controltrigs do
if( string.find( string.lower(data), key) ) then
s,e,whoTo,from,mes = string.find(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.*)")  
SendPmToOps (BotName, "Control: <"..user.sName.."> ("..user.sIP..") said to <"..to.."> in PVT this: "..mes.."")
SendToVips("Control: <"..user.sName.."> ("..user.sIP..") said to <"..to.."> in PVT this: "..mes)
end
end
end
end

function SendToVips(msg)
local usr,aux
for usr, aux in supervip do
if (GetItemByName(usr) ~= nil) then
GetItemByName(usr):SendPM(BotName, msg)
end
end
end

function LoadFromFile(file)
local f,e = io.open( file, "r" )
if f then
local r = f:read( "*a" )
f:close()
return r
else
return nil,"loadfile failed: "..e
end
end


Thanks in advance.
Best regards,

jiten
Title:
Post by: NightLitch on 02 March, 2005, 20:56:34
here you go:


SendToVips = function(from,message)
for _,Users in GetUsersByProfile("VIP") do
SendToNick(Users, "<"..from.."> "..message)
end
end

SendPmToVips = function(from,message)
for _,Users in GetUsersByProfile("VIP") do
SendPmToNick(Users, from, message)
end
end


I guess I should work... not tested by Am pretty sure it should work.

// NL
Title:
Post by: jiten on 03 March, 2005, 08:59:49
Hi there NL. Well, I guess i didn't explain exactly what this script was meant for, so I'm going to post all of the script (the first post is edited).
This script warns the Operators and the KVIPs about certain triggers. The KVIP nicks are stored in a file - logs/svip.txt - like this:

supervip = {["kviptest"]=1,}

Thanks in advance.
Best regards,

jiten
Title: Ptaczek, PPK hear us mighty hubdevelopers ..
Post by: Herodes on 03 March, 2005, 09:01:24
Please add a "SendToLevel" and a "SendPmToLevel" function.
As you can see sacrifices have already begun ...

( Ooh and a way to get a table of all the connected userobjects too pretty pls ;)
Title:
Post by: jiten on 04 March, 2005, 09:00:19
Hi there...
Well, I tried to use NL's SendToVips and SendPmToVips but I get this error when typing any of the triggers:

Syntax ...ktop\16.04rls\scripts\warnvip.lua_5.0.lua:165: attempt to concatenate local `message' (a nil value)

Thanks in advance.
Best regards,

jiten
Title:
Post by: NightLitch on 04 March, 2005, 09:05:35
QuoteOriginally posted by jiten
Hi there...
Well, I tried to use NL's SendToVips and SendPmToVips but I get this error when typing any of the triggers:

Syntax ...ktop\16.04rls\scripts\warnvip.lua_5.0.lua:165: attempt to concatenate local `message' (a nil value)

Thanks in advance.
Best regards,

jiten

By the look of my code there should be no problem, have you used the function correct ???

SendToVips(BotName, "Your Message to VIP's here")

SendPmToVips(BotName, "Your Message to VIP's here")
Title:
Post by: jiten on 04 March, 2005, 09:32:32
Oops! The code was OK. Guess I was in the moon  ;)
But, there's one problem. The message should be sent to the users stored in this file, so called KVIPs: "logs/svip.txt" and not to every VIP.
Best regards.
Title:
Post by: Dessamator on 06 March, 2005, 20:46:15
yah, i tried it also doesnt seem to b able to read nicks in a table something to do with the
Quotefor _,Users in supervip do
, dunno mayb im wrong
Title:
Post by: nErBoS on 08 March, 2005, 17:55:59
Hi,

The problem is on the LoadFile function, you are only reading the file not loading the code...

BotName = "?bot?"

controltrigs={["join"]=1,["login"]=2,["hub"]=3}

supervip = {}
fSuperVip = "logs/svip.txt" -- Path of file that contains SuperVips

function ChatArrival(user,data)
if not user.bOperator then
LoadFromFile(fSuperVip)
for key, value in controltrigs do
if( string.find( string.lower(data), key) ) then
s,e,onlymes = string.find(data, "%b<> (.*)")
SendPmToOps (BotName, "Control: <"..user.sName.."> ("..user.sIP..") told in main: "..onlymes.."")
SendToVips("Control: <"..user.sName.."> ("..user.sIP..") told in main: "..onlymes)
end
end
end
end

function ToArrival(user,data)
local _, _, to, from, msg = string.find(data, "^%$To:%s+(%S+)%s+From:%s+(%S+)%s-%$%b<>%s+(.*)|")
local nick = GetItemByName(to)
if not user.bOperator then
for key, value in controltrigs do
if( string.find( string.lower(data), key) ) then
s,e,whoTo,from,mes = string.find(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.*)")  
SendPmToOps (BotName, "Control: <"..user.sName.."> ("..user.sIP..") said to <"..to.."> in PVT this: "..mes.."")
SendToVips("Control: <"..user.sName.."> ("..user.sIP..") said to <"..to.."> in PVT this: "..mes)
end
end
end
end

function SendToVips(msg)
local usr,aux
for usr, aux in supervip do
if (GetItemByName(usr) ~= nil) then
GetItemByName(usr):SendPM(BotName, msg)
end
end
end

function LoadFromFile(file)
local handle = io.open(file,"r")
        if (handle ~= nil) then
                dofile(file)
handle:flush()
handle:close()
        end
end

Best regards, nErBoS
Title:
Post by: Dessamator on 08 March, 2005, 23:12:54
yap nerbos u were right, it works perfectly now, thanks  :D
Title:
Post by: jiten on 09 March, 2005, 12:24:12
Thanks for the help, nErBoS.
Now it's working perfectly.