PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: ConejoDelMal on 10 April, 2005, 22:53:58

Title: again help needed
Post by: ConejoDelMal on 10 April, 2005, 22:53:58
I am having a bit of a problem, since the latest ptokax, i cant seem to have motd displayed before the scripts, is there something i should add to the scripts? (simple ones, like onjoin)

thx
Title:
Post by: Dessamator on 10 April, 2005, 23:05:29
yaps u need some sort of timer, to delay the script onjoin msg
u could try something like this ::
 
tDelay={}
function Main()
SetTimer(1000)
StartTimer()
end

function NewUserConnected(user)
tDelay[user.sName] ={}
tDelay[user.sName]["time"] = "1"
end

function OnTimer()
for i,v in tDelay do
tDelay[i]["time"]= tDelay[i]["time"]-1
if tDelay[i]["time"] ==0 then
-----> put ur code here <----------
                                end
                 end
end

 
Title:
Post by: ConejoDelMal on 10 April, 2005, 23:24:39
ok, but i'm a bit lost here... when i have a script like:
Bot = "-=Brainu=-"



function NewUserConnected(user)

if user.iProfile == 4 then
SendToAll(Bot, "O Networker -= "..user.sName.." =- entrou no Hub")
end

if user.iProfile == 1 then
SendToAll(Bot, "O Operador -= "..user.sName.." =- entrou no Hub")
end

if user.iProfile == 0 then
SendToAll(Bot, "O Admin -= "..user.sName.." =- entrou no Hub")
end

if user.iProfile == 2 then
SendToAll(Bot, "O ViP -= "..user.sName.." =- entrou no Hub")
end

if user.iProfile == 5 then
SendToAll(Bot, "O Master -= "..user.sName.." =- entrou no Hub")
end

if (user.sName == "{HubListPinger}") then
SendToAll(Bot, "O Bot "..user.sName.." entrou no Hub.")
SendToAll(Bot, "A Lista de Users em [URL]www.lusoleader.co.nr[/URL] foi Actualizada")
end
end

function UserDisconnected(user)

if user.iProfile == 4 then
SendToAll(Bot, "O Networker-= "..user.sName.." =- saiu do Hub")
end

if user.iProfile == 1 then
SendToAll(Bot, "O Operador -= "..user.sName.." =- saiu do Hub")
end

if user.iProfile == 0 then
SendToAll(Bot, "O Admin -= "..user.sName.." =- saiu do Hub")
end

if user.iProfile == 2 then
SendToAll(Bot, "O ViP -= "..user.sName.." =- saiu do Hub")
end

if user.iProfile == 5 then
SendToAll(Bot, "O Master -= "..user.sName.." =- saiu do Hub")
end

if (user.sName == "{HubListPinger}") then
SendToAll(Bot, "O Bot "..user.sName.." saiu do Hub.")
end
end

OpConnected=NewUserConnected

OpDisconnected=UserDisconnected

how does it stays in the end?
Title:
Post by: Herodes on 10 April, 2005, 23:56:04
try this ..
--- touched by Herodes
-- to provide an example of delayed messages..

Bot = "-=Brainu=-"
tDelay = {}

function Main()
SetTimer(1000)
StartTimer()
end

function OnTimer()
for i,v in tDelay do
v[3] = v[3] - 1
if v[3] == 0 then
SendToAll( v[2], v[1] )
end
tDelay[i] = nil
end
end

function AddDelayedMessage( msg, delay )
table.insert( tDelays, { msg, Bot, delay or 1 } )
end

function NewUserConnected(user)
local tProfiles = {
[0] = "O Admin -= "..user.sName.." =- entrou no Hub",
[1] = "O Operador -= "..user.sName.." =- entrou no Hub",
[2] = "O ViP -= "..user.sName.." =- entrou no Hub",
[4] = "O Networker -= "..user.sName.." =- entrou no Hub",
[5] = "O Master -= "..user.sName.." =- entrou no Hub",
}
if tProfiles[user.iProfile] then
AddDelayedMessage( tProfiles[user.iProfile] )
elseif (user.sName == "{HubListPinger}") then
AddDelayedMessage( "O Bot {HubListPinger} entrou no Hub." )
AddDelayedMessage( "A Lista de Users em [URL]www.lusoleader.co.nr[/URL] foi Actualizada" )
end
end

function UserDisconnected(user)
local tProfiles = {
[0] = "O Admin -= "..user.sName.." =- saiu do Hub",
[1] = "O Operador -= "..user.sName.." =- saiu do Hub",
[2] = "O ViP -= "..user.sName.." =- saiu do Hub",
[4] = "O Networker-= "..user.sName.." =- saiu do Hub",
[5] = "O Master -= "..user.sName.." =- saiu do Hub",
}
if tProfiles[user.iProfile] then
AddDelayedMessage( tProfiles[user.iProfile] )
elseif (user.sName == "{HubListPinger}") then
AddDelayedMessage( "O Bot {HubListPinger} saiu do Hub." )
end
end

OpConnected=NewUserConnected
OpDisconnected=UserDisconnected
Title:
Post by: Dessamator on 11 April, 2005, 00:27:23
or this::


--By Dessamator
Bot = "-=Brainu=-"
tDelay={}
function Main()
SetTimer(1000)
StartTimer()
end

function NewUserConnected(user)
if not(user.iProfile=="3") and user.bRegistered  then
tDelay[user.sName] ={}
tDelay[user.sName]["time"] = "1"
end
end

function OnTimer()
local Profiles ={ [0] = "Admin",
  [1] = "Operador",
  [2] = "Vip",
  [3] = "",
  [4] = "Networker",
  [5] = "Master",
}
for i,v in tDelay do
tDelay[i]["time"] = tDelay[i]["time"]- 1
if tDelay[i]["time"] ==0 then
if not(GetItemByName(i).iProfile=="3" or nil)  then
SendToAll(Bot,"O "..Profiles[GetItemByName(i).iProfile].." "..i.." =- entrou no Hub")
elseif (GetItemByName(i).sName == "{HubListPinger}") then
SendToAll( "O Bot {HubListPinger} entrou no Hub." )
end
                end
        end
end


function UserDisconnected(user)
local Profiles ={ [0] = "Admin",
  [1] = "Operador",
  [2] = "Vip",
  [3] = "",
  [4] = "Networker",
  [5] = "Master",
}
if not(user.iProfile=="3") and user.bRegistered  then
SendToAll(Bot, "O "..Profiles[user.iProfile].." =- saiu do Hub")
elseif (user.sName == "{HubListPinger}") then
temp="O Bot {HubListPinger} entrou no Hub."
temp=temp.."A Lista de Users em [URL]www.lusoleader.co.nr[/URL] foi Actualizada"
SendToAll(temp)
end
tDelay[user.sName]["time"] = nil
end

OpConnected=NewUserConnected
OpDisconnected=UserDisconnected


Less repitition, :D
Title:
Post by: Herodes on 11 April, 2005, 00:43:07
You are missing very important aspects.

1)having the tables local in the functions enables you to not store them in the mem.
2)Doing it the way I propose you can customise the messages.
3) having a function to insert the data in a table in, again, the proposed format, makes it possible to extend it to include more stuff like a Botname, a different time delay etc.
4) I noticed that you are not emptying ( =nil ) the index of the table eventhough it has completed its mission. that could cause considerable mem usage, at least in a high-traffic hub ..

Watch both scripts through, and look out for the points I am mentioning ..
Title:
Post by: bastya_elvtars on 11 April, 2005, 01:39:57
Just do an x=os.clock() and wait until os.clox()-x==2 or something else. This is a better way than starting timer on every join, but this is only my 2 cents...
Title:
Post by: ConejoDelMal on 11 April, 2005, 01:53:36
thx a lot, i will try it, but maybe i still annoy you with this  :P

*Edited*
Herodes, in your script i get this:
in_out.lua:23: bad argument #1 to `insert' (table expected, got nil)
Title:
Post by: bastya_elvtars on 11 April, 2005, 03:08:26
replace tDelays to tDelay and it will work.
Title:
Post by: ConejoDelMal on 11 April, 2005, 03:19:07
QuoteOriginally posted by bastya_elvtars
replace tDelays to tDelay and it will work.

thx a lot! really didnt noticed that one...
and btw, tried to make it the way you said, or better, still trying without sucess..

And Dessamator, yours worked fine aswell, but if it uses more mem, i prefer not to thx anyway :)

*Edited*
I have another question, when you want to send a delayed message to a new connecting user, how do you make it? tried as previous, but it cant identify the user.sName, i guess its because its delayed :P
This one is about a OnJoin, a simple one with nick, ip, share and status of the user only
Title:
Post by: jiten on 11 April, 2005, 08:42:45
Are you trying to convert BrainMaster?
Title:
Post by: Dessamator on 11 April, 2005, 10:39:42
QuoteOriginally posted by Herodes
You are missing very important aspects.

1)having the tables local in the functions enables you to not store them in the mem.
2)Doing it the way I propose you can customise the messages.
3) having a function to insert the data in a table in, again, the proposed format, makes it possible to extend it to include more stuff like a Botname, a different time delay etc.
4) I noticed that you are not emptying ( =nil ) the index of the table eventhough it has completed its mission. that could cause considerable mem usage, at least in a high-traffic hub ..

Watch both scripts through, and look out for the points I am mentioning ..

for point 1, i do agree, but i just did it that way to avoid repetition,
for point 2, well i just did it in a way which he asked he never asked for customization, and possibly he doesnt need it !!
for point 3, i do agree again, but well, he didnt ask for it,
point 4 agreed also and done !!, post edited above
Title:
Post by: Dessamator on 11 April, 2005, 10:41:28
QuoteOriginally posted by bastya_elvtars
Just do an x=os.clock() and wait until os.clox()-x==2 or something else. This is a better way than starting timer on every join, but this is only my 2 cents...

hmm, good idea ill try it l8r !!
Title:
Post by: Dessamator on 11 April, 2005, 13:06:10
well bastya, i tried the os.clocks, but in the same function newuserconnected, it always sent the msg before the motd, havent tried it on a different function, anyways, heres a way of doing it without using using a timer or the os.clocks , ::::::::::::


--By Dessamator
Bot = "-=Brainu=-"
function Main()
end

function NewUserConnected(user)
local Profiles ={ [0] = "Admin",
   [1] = "Operador",
   [2] = "Vip",
   [3] = "",
   [4] = "Networker",
   [5] = "Master",
}
if not(user.iProfile=="3") and user.bRegistered  then
temp="O "..Profiles[user.iProfile].." "..user.sName.." =- entrou no Hub"
elseif (user.sName == "{HubListPinger}") then
temp="O Bot {HubListPinger} entrou no Hub."
end

end

function MyINFOArrival(User, Data)
if not(temp==nil) then
SendToAll(Bot,temp)
temp=nil
        end
end

function UserDisconnected(user)
local Profiles ={ [0] = "Admin",
   [1] = "Operador",
   [2] = "Vip",
   [3] = "",
   [4] = "Networker",
   [5] = "Master",
}

if not(user.iProfile=="3") and user.bRegistered  then
SendToAll(Bot, "O "..Profiles[user.iProfile].." =- saiu do Hub")
elseif (user.sName == "{HubListPinger}") then
temp="O Bot {HubListPinger} entrou no Hub."
temp=temp.."A Lista de Users em [URL]www.lusoleader.co.nr[/URL] foi Actualizada"
SendToAll(temp)
end
end

OpConnected=NewUserConnected
OpDisconnected=UserDisconnected
Title:
Post by: jiten on 11 April, 2005, 14:05:25
Nice tricks  :D
Title:
Post by: bastya_elvtars on 11 April, 2005, 14:08:00
Here is a script, using tezlo's routine. Sorry, it is not fully converted, I just scavanged it.

-- chatdelay by tezlo

list = {}
delay = 2
-- in seconds


function DataArrival(user, data)
if string.sub(data, 1, 1) == "<" and not user.bOperator then
local time, now = list[user.sName], os.clock()
if time and time+delay > now then
user:SendData(">> wait")
return 1
else
list[user.sName] = now
end
end
Title:
Post by: Dessamator on 11 April, 2005, 14:43:51
QuoteOriginally posted by bastya_elvtars
Here is a script, using tezlo's routine. Sorry, it is not fully converted, I just scavanged it.

-- chatdelay by tezlo

list = {}
delay = 2
-- in seconds


function DataArrival(user, data)
if string.sub(data, 1, 1) == "<" and not user.bOperator then
local time, now = list[user.sName], os.clock()
if time and time+delay > now then
user:SendData(">> wait")
return 1
else
list[user.sName] = now
end
end

nop i converted it and tried it, doesnt work, or mayb i just dont know how to do that !!
Title:
Post by: Herodes on 11 April, 2005, 14:54:12
btw keep in mind that we are talking about a 2ms delay .. maybe it isn't enough .. I really find that using the OnTimer would by far the simplest and more efficient way to do such thing ..
Title:
Post by: Dessamator on 11 April, 2005, 15:15:12
QuoteOriginally posted by Herodes
btw keep in mind that we are talking about a 2ms delay .. maybe it isn't enough .. I really find that using the OnTimer would by far the simplest and more efficient way to do such thing ..

hmm, but that response is directed to my newest script or to bastya's unworking script??????

mine is cooler, hehe, no timers no delays, no extra tables !!!
Title:
Post by: Herodes on 11 April, 2005, 15:18:26
QuoteOriginally posted by Dessamator
QuoteOriginally posted by Herodes
btw keep in mind that we are talking about a 2ms delay .. maybe it isn't enough .. I really find that using the OnTimer would by far the simplest and more efficient way to do such thing ..
hmm, but that response is directed to my newest script or to bastya's unworking script??????
directed to the method bastya proposes and the way you have tried to implement it.
Title:
Post by: Dessamator on 11 April, 2005, 15:24:02
QuoteOriginally posted by Herodes
QuoteOriginally posted by Dessamator
QuoteOriginally posted by Herodes
btw keep in mind that we are talking about a 2ms delay .. maybe it isn't enough .. I really find that using the OnTimer would by far the simplest and more efficient way to do such thing ..
hmm, but that response is directed to my newest script or to bastya's unworking script??????
directed to the method bastya proposes and the way you have tried to implement it.

hmm ok, i tried more than 2ms(a second), but even so, it always displayed after the motd, which leads me to believe, that maybe the whole newuserarrival is processed before the motd, and never after, just a guess!
Title:
Post by: Herodes on 11 April, 2005, 15:32:02
QuoteOriginally posted by Dessamator
hmm ok, i tried more than 2ms(a second), but even so, it always displayed after the motd, which leads me to believe, that maybe the whole newuserarrival is processed before the motd, and never after, just a guess!
Have no doubts. that is the way that the procedure works. meant for saving the motd bandwidth if a user has to be disconnected on entry.
Title:
Post by: Dessamator on 11 April, 2005, 15:56:59
QuoteOriginally posted by Herodes
QuoteOriginally posted by Dessamator
hmm ok, i tried more than 2ms(a second), but even so, it always displayed after the motd, which leads me to believe, that maybe the whole newuserarrival is processed before the motd, and never after, just a guess!
Have no doubts. that is the way that the procedure works. meant for saving the motd bandwidth if a user has to be disconnected on entry.

yah it figures, i tried using a loop, with a big delay, i tried to use it the way bastya suggested, but the info always got sent b4 the motd, so i solved it by using myinfoarrival.

But heres another question, whats the hierarchy(from first to last) in those arrivals, from what i can c on the ptokax, first of all is the Supports, Key , validatenick, getnicklist, and myinfo, what about the rest?
Title:
Post by: Herodes on 11 April, 2005, 18:05:50
QuoteOriginally posted by Dessamator
yah it figures, i tried using a loop, with a big delay, i tried to use it the way bastya suggested, but the info always got sent b4 the motd, so i solved it by using myinfoarrival.
Basically waiting for the time to change isn't helping,.. thats because you are literally and simply 'waiting'. What you really need is make a check on if a certain time period has been spent.

for the DC Protocol parsing order :
I am not aware the order in which it is working and I suppose that it shoulde be different for client supporting various DC Protocol enhancements like for example Quicklist.

The only way you can test it is make a script with all of them and log in a table ( with table.insert so that you still have ordered entries ) and then trigger a listing from it and see what happened..