PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: DorianG on 12 February, 2004, 10:21:46

Title: Help me A Redirect For Too open Slot
Post by: DorianG on 12 February, 2004, 10:21:46
I want to do an autoredirect of user that have many slots opened. I have tried to create it but i haven't understood like the redirect works in general :)
Can you help me?
Please, if is possible, write me the shorts examples.
Title:
Post by: nErBoS on 12 February, 2004, 11:56:23
Hi,

Hope it helps...

--Requested by DorianG
--Made by nErBoS

Bot = "MmSlot-Checker"

minSlot = 3
maxSlot = 5
addredirect = "llllaa.mine.nu"

function Main()
SetTimer(3*1000)
frmHub:RegBot(Bot)
end

--This function takes more memory, but searches the user slots when they speak or refresh userlist, in case if you want to remove.
function DataArrival(user, data) --remove from here
local _,b, slt = strfind(user.sMyInfoString,"S:(%x+)")
slt = slt*1
if (slt < minSlot) then
user:SendPM(Bot, "You must have "..minSlot.." slot open at least.")
user:SendPM(Bot, "You are been redirected...")
user:SendData("$ForceMove "..addredirect)
elseif (slt > maxSlot) then
user:SendPM(Bot, "You must have "..maxSlot.." slot open in max.")
user:SendData("$ForceMove "..addredirect)
user:SendPM(Bot, "You are been redirected...")
end
end --to here

-- This function only checks when the users connects
function NewUserConnected(user, data)
if strfind(user.sMyInfoString, "S:%x+") then
local _,b, slt = strfind(user.sMyInfoString,"S:(%x+)")
slt = slt*1
if (slt < minSlot) then
user:SendPM(Bot, "You must have "..minSlot.." slot open at least.")
user:SendData("$ForceMove "..addredirect)
user:SendPM(Bot, "You are been redirected...")
elseif (slt > maxSlot) then
user:SendPM(Bot, "You must have "..maxSlot.." slot open in max.")
user:SendData("$ForceMove "..addredirect)
user:SendPM(Bot, "You are been redirected...")
end
end
end

It's working but you will get this error on the script editor...

Syntax Error: attempt to perform arithmetic on local `slt' (a nil value)

I gone to see what is it.

Best regrads, nErBoS
Title:
Post by: DorianG on 12 February, 2004, 13:50:12
I have tried your script.
the script is good. But the problem about "slt" i haven't solved.
But i have replied to thank you :D
If i'll find the error, i post you the solution here ;)
Title:
Post by: NightLitch on 12 February, 2004, 14:42:49
This is how your dataArrival should look like:
function DataArrival(user, data) --remove from here
if (strsub(data,1,7) == "$MyINFO") then
local _,b, slt = strfind(data,"S:(%x+)")
if (slt == nil) then
user:SendPM(Bot, "You are hiding your tag for checking slots.")
user:SendPM(Bot, "You are Disconnected...")
user:Disconnect()
elseif (slt < minSlot) then
user:SendPM(Bot, "You must have "..minSlot.." slot open at least.")
user:SendPM(Bot, "You are been redirected...")
user:SendData("$ForceMove "..addredirect)
elseif (slt > maxSlot) then
user:SendPM(Bot, "You must have "..maxSlot.." slot open in max.")
user:SendData("$ForceMove "..addredirect)
user:SendPM(Bot, "You are been redirected...")
end
end
end --to here

hope you don't minded I posted the hole solusion.
Title:
Post by: DorianG on 12 February, 2004, 15:56:53
Thanks NightLitch you are very glad.
But Also your script give me an error. So i have made a change and i have add a line, so don't give me problem. :D

function DataArrival(user, data) --remove from here
if (strsub(data,1,7) == "$MyINFO") then
local _,b, slt = strfind(data,"S:(%x+)")
slt = slt*1
if (slt == nil) then
user:SendPM(Bot, "You are hiding your tag for checking slots.")
user:SendPM(Bot, "You are Disconnected...")
user:Ban()
elseif (slt < minSlot) then
user:SendPM(Bot, "You must have "..minSlot.." slot open at least.")
user:SendPM(Bot, "You are been redirected...")
user:SendData("$ForceMove "..addredirect)
elseif (slt > maxSlot) then
user:SendPM(Bot, "You must have "..maxSlot.." slot open in max.")
user:SendData("$ForceMove "..addredirect)
user:SendPM(Bot, "You are been redirected...")
end
end
end --to here
Title:
Post by: DorianG on 12 February, 2004, 16:31:43
If you have Ptokax 0.330 you could try this script. :D

function DataArrival(user, data) --remove from here
if (strsub(data,1,7) == "$MyINFO") then
local _,b, slt = strfind(data,"S:(%x+)")
local minSlot = frmHub:GetMinSlots()
local maxSlot = frmHub:GetMaxSlots()
slt = slt*1
if (slt == nil) then
user:SendPM(Bot, "You are hiding your tag for checking slots.")
user:SendPM(Bot, "You are Disconnected...")
user:Ban()
elseif (slt < minSlot) then
user:SendPM(Bot, "You must have "..minSlot.." slot open at least.")
user:SendPM(Bot, "You are been redirected...")
user:SendData("$ForceMove "..addredirect)
elseif (slt > maxSlot) then
user:SendPM(Bot, "You must have "..maxSlot.." slot open in max.")
user:SendData("$ForceMove "..addredirect)
user:SendPM(Bot, "You are been redirected...")
end
end
end --to here


-- This function only checks when the users connects
function NewUserConnected(user, data)
if strfind(user.sMyInfoString, "S:(%x+)") then
local _,b,slt = strfind(user.sMyInfoString,"S:(%x+)")
local minSlot = frmHub:GetMinSlots()
local maxSlot = frmHub:GetMaxSlots()
slt = slt*1
if (slt < minSlot) then
user:SendPM(Bot, "You must have "..minSlot.." slot open at least.")
user:SendData("$ForceMove "..addredirect)
user:SendPM(Bot, "You are been redirected...")
elseif (slt > maxSlot) then
user:SendPM(Bot, "You must have "..maxSlot.." slot open in max.")
user:SendData("$ForceMove "..addredirect)
user:SendPM(Bot, "You are been redirected...")
elseif (slt == nil) then
user:SendPM(Bot, "You have an invalid Client, please download a legal client.")
user:Ban()
end
end
end
Title:
Post by: NightLitch on 12 February, 2004, 16:31:55
why the:  slt = slt*1

what do you have it for ??

one thing I noticed change:

local _,b, slt = strfind(data,"S:(%x+)")

to

local _,b, slt = strfind(data,"S:(%d+)")

that should solve it.

but my most concern is to:

slt = slt*1

/NL
Title:
Post by: DorianG on 12 February, 2004, 19:36:41
The motive i dont know. but it, to the beginning gave me an error, I then have added slt = slt*1 :D and the Bot it has not given me more problems. ;)
if i can... Because have you changed
local _,b, slt = strfind(data,"S:(%x+)")

to

local _,b, slt = strfind(data,"S:(%d+)") ????
Title:
Post by: NightLitch on 12 February, 2004, 20:44:40
this is how I would do it, and there should not be any errors here. I changed Ban() to Disconnected()

becouse you don't need to ban ppl for hiding the tag just disconnect with a msg and they can come back with a accepted Tag.

here my code:
function DataArrival(user, data) --remove from here
if (strsub(data,1,7) == "$MyINFO") then
local _,b, slt = strfind(data,"S:(%d+)")
local minSlot = frmHub:GetMinSlots()
local maxSlot = frmHub:GetMaxSlots()
if (slt == nil or slt == "") then
user:SendPM(Bot, "You are hiding your tag for checking slots.")
user:SendPM(Bot, "You are Disconnected...")
user:Disconnect()
elseif (slt < minSlot) then
user:SendPM(Bot, "You must have "..minSlot.." slot open at least.")
user:SendPM(Bot, "You are been redirected...")
user:SendData("$ForceMove "..addredirect)
elseif (slt > maxSlot) then
user:SendPM(Bot, "You must have "..maxSlot.." slot open in max.")
user:SendData("$ForceMove "..addredirect)
user:SendPM(Bot, "You are been redirected...")
end
end
end --to here


-- This function only checks when the users connects
function NewUserConnected(user, data)
local _,b,slt = strfind(user.sMyInfoString,"S:(%d+)")
local minSlot = frmHub:GetMinSlots()
local maxSlot = frmHub:GetMaxSlots()
if (slt == nil or slt == "") then
user:SendPM(Bot, "You are hiding your tag for checking slots.")
user:SendPM(Bot, "You are Disconnected...")
user:Disconnect()
elseif (slt < minSlot) then
user:SendPM(Bot, "You must have "..minSlot.." slot open at least.")
user:SendData("$ForceMove "..addredirect)
user:SendPM(Bot, "You are been redirected...")
elseif (slt > maxSlot) then
user:SendPM(Bot, "You must have "..maxSlot.." slot open in max.")
user:SendData("$ForceMove "..addredirect)
user:SendPM(Bot, "You are been redirected...")
end
end

/NL
Title:
Post by: nErBoS on 13 February, 2004, 02:43:24
Like litch said, and well said, where you have...

local _,b, slt = strfind(user.sMyInfoString,"S:(%x+)")
put this..
local _,b, slt = strfind(user.sMyInfoString,"S:(%d)")

And where you have this...

slt = slt*1
put this..

slt = tonumber(slt)
Thanks for the correction litch :)

About error is being discusted in the developing scripts to see why does it sends that error, but the script works.

Best regrads, nErBoS
Title:
Post by: DorianG on 13 February, 2004, 10:14:02
Yes I like :D, it has stayed indeed interesting the development :)
However I still have not understood how come you have put this:
local _,b, slt = strfind(user.sMyInfoString,"S:(%d)")
instead of
local _,b, slt = strfind(user.sMyInfoString,"S:(%x+)")

I thank you for the consideration :D
Title:
Post by: nErBoS on 14 February, 2004, 00:27:09
Hi,

Well like the good manual says :)  ...

%x
- represents all hexadecimal digits.

%d
- represents all digits.


for more information use this link..

http://www.lua.org/manual/4.0/manual.html#pm

Best regards, nErBoS
Title:
Post by: NightLitch on 14 February, 2004, 01:05:14
well you simply just need to catch the nil value:

value == nil then
do code here

Why this occur is becouse a user logs in without having a tag or hiding it, thats when the nil error comes up for you. Hope this helped or if you have come to that solusion yourself.

Best regards /NL
Title:
Post by: nErBoS on 14 February, 2004, 01:53:12
Once more thanks for the explanion NightLitch

Best regrads, nErBoS
Title:
Post by: DorianG on 14 February, 2004, 12:38:48
thank you. Good explanation.
Brief but precise :D