PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: blackwings on 02 March, 2005, 22:02:33

Title: Problem with My LUA 5 Slot checker
Post by: blackwings on 02 March, 2005, 22:02:33
I'm making a slots checker. But I have one problem, the max slot check doesn't work :( I log in with 5 slots, but even so it says I have to many slots open (max is 30 as you see.)

The min version works as it should anyway :)

-- Simple Slot checker by blackwings LUA 5
-- version 1.0

Bot = "#slot-checker"

-- ["Profile"] = {minSlot,maxSlot},
tlSlots = {
[2] = {"2","30"},
[3] = {"2","30"},
[-1] = {"2","30"},
}

function MyINFOArrival(user,data)
if tlSlots[user.iProfile] then
local s,e,tag=string.find(user.sMyInfoString, "(%b<>)%$")
if tag ~= nil then
s,e,slots = string.find(tag,"S:(%d+)")
return slotchecking(user,slots)
end
end
end

function slotchecking(user,slots)
local minSlot = tlSlots[user.iProfile][1]
local maxSlot = tlSlots[user.iProfile][2]
if slots < minSlot then
user:SendData(Bot, "Minimum "..minSlot.." slots!!!")
user:Disconnect()
elseif slots > maxSlot then
user:SendData(Bot, "Maximum "..maxSlot.." slots!!!")
user:Disconnect()
end
end
Title:
Post by: bastya_elvtars on 02 March, 2005, 22:08:06
Posting my myinfo parsing routine in lua4. Please convert and adapt it.

-- myinfo scanning routine
-- bastya_elvtars
-- used code from consolemoon by [NL]Pur

checks.scanmyinfo=function(myinfo) ----------
local _,_,Hubs,Slots,speed = strfind(myinfo, "H:([^,]+),S:(%d+).*>$ $([^$]+)[^$]%$")
local Guest,Reg,OP,slots,hubs,ratio
local Maxslotsforconn,Ratioforconn,Maxhubsforconn,minlimitforconn=slotperhub[speed].max_slots,slotperhub[speed].min_ratio,slotperhub[speed].max_hubs,slotperhub[speed].min_limit
local _,_,limit1=strfind(myinfo,"[BLU]:(%d+)")
local _,_,limit2 = strfind(myinfo,"F:%d+/(%d+)")
local _,_,temp = strfind(myinfo, "$(%d+)%$")
if tonumber (Hubs) then
if Hubs=="0" then
Guest,Reg,OP= "0", "1" , "0"
else
Guest,Reg,OP=  Hubs, "0", "0"
end
else
_,_, Guest,Reg,OP = strfind(Hubs,"(%d+)/(%d+)/(%d+)")
end
if ophubscount==1 then
hubs = tonumber(Guest)+tonumber(Reg)+tonumber(OP)
slots=tonumber(Slots)
ratio=slots/hubs
else
hubs = tonumber(Guest)+tonumber(Reg)
slots=tonumber(Slots)
if hubs==0 then
ratio=slots
else
ratio=slots/hubs
end
end
local Share = format("%0.2f", tonumber(temp)/gb)
if limit1 then
return hubs,slots,Guest,Reg,OP,speed,limit1,Maxslotsforconn,Ratioforconn,Maxhubsforconn,minlimitforconn,ratio,Share
elseif limit2 then
return hubs,slots,Guest,Reg,OP,speed,limit2,Maxslotsforconn,Ratioforconn,Maxhubsforconn,minlimitforconn,ratio,Share
else
return hubs,slots,Guest,Reg,OP,speed,nil,Maxslotsforconn,Ratioforconn,Maxhubsforconn,minlimitforconn,ratio,Share
end
end
Title:
Post by: blackwings on 02 March, 2005, 22:25:54
ok, didn't understand to much of it.

the parts with share,hubs,limit1,limit2 and temp has nothing to do with my script.

The only thing that has to do with my script is the "slots=tonumber(Slots)" .

But I'm not sure how I should use it.
Title:
Post by: bastya_elvtars on 02 March, 2005, 22:36:38
I just presented a generic way to show how slots count can be determined. If you do not want to use it, you won't. But the expression 'thank you' is always worth using. I have talked about this before.
Title:
Post by: blackwings on 02 March, 2005, 22:44:56
QuoteOriginally posted by bastya_elvtars
I just presented a generic way to show how slots count can be determined. If you do not want to use it, you won't. But the expression 'thank you' is always worth using. I have talked about this before.
sorry, I appreciate you giving it to me. I didn't mean to sound rude.

Anyway, checked at your script again and now my script works perfectly :D
Title:
Post by: bastya_elvtars on 02 March, 2005, 22:55:07
local _,_,Slots = string.find(myinfo, "S:(%d+)")
Let's repeat what we have learned from last time:
we search for a string value in the myinfo that consists of 1 or more digits (%d+) and comes after S:.

Hope I was clear.

And yes, you sometimes seem rude. It does not matter for me, but I like to see people who are happy that I helped them. And your words seem sometimes hmm... dissatisfied.
Title:
Post by: blackwings on 02 March, 2005, 23:00:08
QuoteOriginally posted by bastya_elvtars
local _,_,Slots = string.find(myinfo, "S:(%d+)")
Let's repeat what we have learned from last time:
we search for a string value in the myinfo that consists of 1 or more digits (%d+) and comes after S:.

Hope I was clear.

And yes, you sometimes seem rude. It does not matter for me, but I like to see people who are happy that I helped them. And your words seem sometimes hmm... dissatisfied.
well, maybe I will try to sound less "objective" next time I post :)

Anyway, my script works now and I thank you for your help :D