PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: DorianG on 18 February, 2004, 00:28:01

Title: Problem to start a command
Post by: DorianG on 18 February, 2004, 00:28:01
--**** Qui puoi cambiare il nome del Bot, l'operazione ? sconsigliata :)  ****--
BotName = "???[Bot]M?GAPLATZ???"
--****************************************************************************--
--****************************************************************************--
--**** Qui potete settare il numero di messaggi random che vengono  ****--
--**** spediti dal bot a delle categorie di utenti quando entrano    ****--
--**** dentro l'hub.  ****--
nummsgop = 9
nummsgvip = 6
--**** Qui puoi settare i prefissi dei comandi  ****--
prefix = "!"
prefix2 = "+"
--**** Qui puoi settare le parole chiavi per lanciare i vari comandi  ****--
help = prefix2.."help" --//Comando di aiuto
network = prefix.."network" --//Comando che da informazioni sul network
report = prefix.."report" --//Spedisce un PM a tutti gli Op
reportopchat = prefix.."opchat" --//Spedisce un PM in OpChat
infouser = prefix.."infouser" --//Spedisce informazioni su un utente
flood = prefix.."flood" --//Floodi un messaggio
ban = prefix.."ban" --//Banna un utente dall'hub
--**** Messaggi Settabili per tutte le occasioni  ****--
reporterrormsg = "Il comando digitato ? sbagliato "..report.." "
reporterroropchat = "Il comando digitato ? sbagliato "..reportopchat.." "
user = "L'utente"
because = "perch?:  "
Ban1 = "Non puoi toccare questo utente"
Ban2 = "Non puoi autodistruggerti"
Ban3 = "Hai sbagliato a digitare il comando digita "..ban.." "
Ban4 = "? stato bannato da:  "
Ban5 = "sei stato bannato da: "

dofile("files/MsgOp.lua")
dofile("files/MsgVip.lua")

function Main()
frmHub:RegBot(BotName)
end

function OpConnected(user)
reply = RandomOpMsg(user)
SendToAll(BotName,reply)
end

function NewUserConnected(user)
if (user.iProfile == 6) then
reply = RandomVipMsg(user)
SendToAll(BotName,reply)
end
end

function ReadLine(user)
while 1 do
local line = read()
if line == nil then
break
else
user:SendPM(BotName, line)
end
end
readfrom()
end

function Flood(user)
s,e,cmd,str,num,msg = strfind(data, "%b<>%s(%S+)%s(%S+)%s(%S+)%s(%S+)")
if cmd ~= nil and str ~= nil and num ~= nil and msg ~= nil then
SendToNick(user.sName, BotName, "Hai floodato "..str.." per "..num.." volte con il messaggio  "..msg)
count = tonumber(num)
for z = 1, count do
SendPmToNick(str, BotName, msg)
end
elseif str == user.sName then
SendToNick(user.sName, "Non puoi auto floodarti")
end
return 1
end

function Ban(user)
s,e,cmd,str,reason = strfind(data, "%b<>%s(%S+)%s(%S+)%s(%S+)")
if (str == Protect1 or str == Protect2 or str == Protect3) then
user:SendPM(BotName, Ban1)
elseif (str == user.sName) then
user:SendPM(BotName, Ban2)
elseif (str == nil) then
user:SendPM(BotName, Ban3)
else
local Userkick = GetItemByName(str)
SendToOps(BotName, user, str, Ban4, user.sName, because, reason)
Userkick:Ban()
SendPmToNick(str, BotName, Ban5, user.sName, because, reason)
end
return 1
end

function ReportMsg(user)
s,e,cmd,msg = strfind(data, "%b<>%s(%S+)%s(.+)")
if msg ~= nil then
SendPmToOps(BotName, msg "BY:  " ..user.sName)
SendPmToOps(BotName, "il suo IP ?:  " ..user.sIP)
else
SendToNick(user.sName, BotName, reporterrormsg)
end
return 1
end

function ReportOpChat(user)
s,e,cmd,msg = strfind(data, "%b<>%s(%S+)%s(.+)")
local OpChat = frmHub:GetOpChatName()
if msg ~= nil then
SendPmToNick(OpChat, BotName, msg)
else
user:SendPM(BotName, reporterroropchat)
end
return 1
end

function InfoUser(user)
s,e,cmd,str = strfind(data, "%b<>%s(%S+)%s(%S+)")
local usr = GetItemByName(str)
local message ="          ???US?R?~?INFO???     "
msg = message .."\r\n\t\t"
.. "Informazioni sull'utente: " ..usr.sName.."\r\n\t\t"
.. "IP: " ..usr.sIP.. "\t\r\n\t\t"
.. "Informazioni sulla Stringa: "..usr.sMyInfoString.."\t\r\n\t\t"
.. "Profilo:  "..usr.iProfile.."\t\r\n\t\t"
if str ~= nil then
user:SendPM(BotName, msg)
end
return 1
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<") then
data = strsub(data,1,strlen(data)-1)
local s,e,cmd = nil
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if cmd == help then
readfrom("files/HelpUser.txt")
ReadLine(user)
elseif cmd == network then
readfrom("files/Network.txt")
ReadLine(user)
elseif cmd == report then
ReportMsg(user)
elseif cmd == reportopchat then
ReportOpChat(user)
end
if user.iProfile == 1 then
if cmd == infouser then
InfoUser(user)
elseif cmd == flood then
Flood(user)
elseif cmd == ban then
Ban(user)
end
end
end
end
When i send a command in main chat. this command doesn't start.
why?
Title:
Post by: nErBoS on 18 February, 2004, 02:24:28
Hi,

Your problem is for example

function ReportMsg(user) -- only recives user ??? and Data ???
   
You are using data where
s,e,cmd,msg = strfind(data, "%b<>%s(%S+)%

so the function must have this...
function ReportMsg(user, data)

and when you call this function on the comand section put this ReportMsg(user, data) you have to indicate what are you sending to the function.

Best regards, nErBoS
Title:
Post by: DorianG on 18 February, 2004, 12:27:10
thank nerbos, but it isn't the complete solution to my problem.
Yes i have forgotten (user, data) but there is still something that doesn't return.
Because Ban, Flood, InfoUser, don't starts.

Thank Nerbos you are very  very glad :)
Title:
Post by: nErBoS on 18 February, 2004, 13:01:54
Hi,

Strange with me is working, try this...

--**** Qui puoi cambiare il nome del Bot, l'operazione ? sconsigliata :)  ****--
BotName = "???[Bot]M?GAPLATZ???"
-- ***************************************************************************
--
-- ***************************************************************************
--
--**** Qui potete settare il numero di messaggi random che vengono  ****--
--**** spediti dal bot a delle categorie di utenti quando entrano    ****--
--**** dentro l'hub.  ****--
nummsgop = 9
nummsgvip = 6
--**** Qui puoi settare i prefissi dei comandi  ****--
prefix = "!"
prefix2 = "+"
--**** Qui puoi settare le parole chiavi per lanciare i vari comandi  ****--
help = prefix2.."help" --//Comando di aiuto
network = prefix.."network" --//Comando che da informazioni sul network
report = prefix.."report" --//Spedisce un PM a tutti gli Op
reportopchat = prefix.."opchat" --//Spedisce un PM in OpChat
infouser = prefix.."infouser" --//Spedisce informazioni su un utente
flood = prefix.."flood" --//Floodi un messaggio
ban = prefix.."ban" --//Banna un utente dall'hub
--**** Messaggi Settabili per tutte le occasioni  ****--
reporterrormsg = "Il comando digitato ? sbagliato "..report.." "
reporterroropchat = "Il comando digitato ? sbagliato "..reportopchat.." "
user = "L'utente"
because = "perch?:  "
Ban1 = "Non puoi toccare questo utente"
Ban2 = "Non puoi autodistruggerti"
Ban3 = "Hai sbagliato a digitare il comando digita "..ban.." "
Ban4 = "? stato bannato da:  "
Ban5 = "sei stato bannato da: "

dofile("files/MsgOp.lua")
dofile("files/MsgVip.lua")

function Main()
frmHub:RegBot(BotName)
end

function OpConnected(user, data)
reply = RandomOpMsg(user)
SendToAll(BotName,reply)
end

function NewUserConnected(user, data)
if (user.iProfile == 6) then
reply = RandomVipMsg(user)
SendToAll(BotName,reply)
end
end

function ReadLine(user, data)
while 1 do
local line = read()
if line == nil then
break
else
user:SendPM(BotName, line)
end
end
readfrom()
end

function Flood(user, data)
s,e,cmd,str,num,msg = strfind(data, "%b<>%s(%S+)%s(%S+)%s(%S+)%s(%S+)")
if cmd ~= nil and str ~= nil and num ~= nil and msg ~= nil then
SendToNick(user.sName, BotName, "Hai floodato "..str.." per "..num.." volte con il messaggio  "..msg)
count = tonumber(num)
for z = 1, count do
SendPmToNick(str, BotName, msg)
end
elseif str == user.sName then
SendToNick(user.sName, "Non puoi auto floodarti")
end
return 1
end

function Ban(user, data)
s,e,cmd,str,reason = strfind(data, "%b<>%s(%S+)%s(%S+)%s(%S+)")
if (str == Protect1 or str == Protect2 or str == Protect3) then
user:SendPM(BotName, Ban1)
elseif (str == user.sName) then
user:SendPM(BotName, Ban2)
elseif (str == nil) then
user:SendPM(BotName, Ban3)
else
local Userkick = GetItemByName(str)
SendToOps(BotName, user, str, Ban4, user.sName, because, reason)
SendPmToNick(str, BotName, Ban5, user.sName, because, reason)
Userkick:Ban()
end
return 1
end

function ReportMsg(user, data)
s,e,cmd,msg = strfind(data, "%b<>%s(%S+)%s(.+)")
if msg ~= nil then
SendPmToOps(BotName, msg.."BY:  " ..user.sName)
SendPmToOps(BotName, "il suo IP ?:  " ..user.sIP)
else
SendToNick(user.sName, BotName, reporterrormsg)
end
return 1
end

function ReportOpChat(user, data)
s,e,cmd,msg = strfind(data, "%b<>%s(%S+)%s(.+)")
local OpChat = frmHub:GetOpChatName()
if msg ~= nil then
SendPmToNick(OpChat, BotName, msg)
else
user:SendPM(BotName, reporterroropchat)
end
return 1
end

function InfoUser(user, data)
s,e,cmd,str = strfind(data, "%b<>%s(%S+)%s(%S+)")
local usr = GetItemByName(str)
local message ="          ???US?R?~?INFO???     "
msg = message .."\r\n\t\t"
.. "Informazioni sull'utente: " ..usr.sName.."\r\n\t\t"
.. "IP: " ..usr.sIP.. "\t\r\n\t\t"
.. "Informazioni sulla Stringa: "..usr.sMyInfoString.."\t\r\n\t\t"
.. "Profilo:  "..usr.iProfile.."\t\r\n\t\t"
if str ~= nil then
user:SendPM(BotName, msg)
end
return 1
end

function DataArrival(user, data)
if (strsub(data,1,1)=="<") then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == help then
readfrom("files/HelpUser.txt")
ReadLine(user, data)
elseif cmd == network then
readfrom("files/Network.txt")
ReadLine(user, data)
elseif (cmd == report) then
ReportMsg(user, data)
elseif cmd == reportopchat then
ReportOpChat(user, data)
elseif user.iProfile == 1 then
if cmd == infouser then
InfoUser(user, data)
elseif cmd == flood then
Flood(user, data)
elseif cmd == ban then
Ban(user, data)
end
end
end
end

Best regards, nErBoS
Title:
Post by: DorianG on 18 February, 2004, 15:43:42
thank nerbos, but I had understood. The problems now are not with launch the commands, but that any commands me they don't work regularly as I would want. For example the Ban, the Flood and the infouser.
In the Ban if I ban myself, the Bot ban me and it sends me the message that I mistake to insert the command, when it really should send me "you can't ban you".
I am sorry to disturb you. You are very kind and patient with me.