I've made this little hub/slot check :
--------oDC Check----------
if not (user.bOperator) then
ratio = tonumber(frmHub:GetSlotRatio())
arg = frmHub:GetRedirectAddress()
arg2 = frmHub:GetMaxHubs()
arg3 = frmHub:GetMinSlots()
if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
s,e,hubs1,hubs2,hubs3 = strfind(data,"H:([^$])/([^$])/([^$])")
s,e,slots = strfind(data,"S:([^$])")
hubc = (hubs1 + hubs2 + hubs3)
if tonumber(slots) < (ratio*hubc) then
user:SendData(Bot, "Your are in violation with this hubs Hub/Slot Ratio: '"..ratio.." Slot per Hub' - With your current hubcount you must open no less than Slots: "..hubc * ratio)
user:SendData("$ForceMove "..arg)
elseif hubc > arg2 then
user:SendData(Bot, "Your are in violation with this hubs Max Hub Rule: Max "..arg2.." Hubs.")
user:SendData("$ForceMove "..arg)
elseif slots < arg3 then
user:SendData(Bot, "Your are in violation with this hubs Min Slot Rule: Min "..arg3.." Slots.")
user:SendData("$ForceMove "..arg)
end
end
end
--------oDC Check----------
It's a part of my DataArrival.
My problem is that im getting this error when running it in a public hub with ALOT of connect attempts..
Error:
Syntax error: attempt to perform arithmetic on global `hubs1' (a nil value)
Though when running it in my test hub it works just fine ...
Any ideas on how to fix this error ?
**Snooze
give this a try.
it works on both the old and new style hub tag, if the new tag is found it converts it 2 the old style.
hubs = 0
s,e,thubs,slots = strfind(tag, "H:([%d%/]+),S:(%d+)%S*>")
if tonumber(thubs) == nil then
gsub(thubs, "(%d+)", function (num)
hubs = hubs +tonumber(num)
end)
else
hubs = tonumber(thubs)
end
slots = tonumber(slots)
plop
Thanks for you quick reply plop :)
I hope this what what you had in mind:
--------oDC Check----------
if not (user.bOperator) then
ratio = tonumber(frmHub:GetSlotRatio())
arg = frmHub:GetRedirectAddress()
arg2 = frmHub:GetMaxHubs()
arg3 = frmHub:GetMinSlots()
hubs = 0
s,e,thubs,slots = strfind(tag, "H:([%d%/]+),S:(%d+)%S*>")
if tonumber(thubs) == nil then
gsub(thubs, "(%d+)", function (num)
hubs = hubs +tonumber(num)
end)
else
hubs = tonumber(thubs)
end
slots = tonumber(slots)
if tonumber(slots) < (ratio*hubc) then
user:SendData(Bot, "Your are in violation with this hubs Hub/Slot Ratio: '"..ratio.." Slot per Hub' - With your current hubcount you must open no less than Slots: "..hubc * ratio)
user:SendData("$ForceMove "..arg)
elseif hubc > arg2 then
user:SendData(Bot, "Your are in violation with this hubs Max Hub Rule: Max "..arg2.." Hubs.")
user:SendData("$ForceMove "..arg)
elseif slots < arg3 then
user:SendData(Bot, "Your are in violation with this hubs Min Slot Rule: Min "..arg3.." Slots.")
user:SendData("$ForceMove "..arg)
end
end
--------oDC Check----------
This way i get the following error:
Syntax error: bad argument #1 to `strfind' (string expected, got function)
stack traceback:
1: function `strfind' [C]
2: function `DataArrival' at line 440
Any ideas ?
**Snooze
Hi,
That sounds me the delay of MyInfoString, try to put in the beggining of DataArrival if (user.sMyInfoString ~= nil) then...
Best regards, nErBoS
Here use this one:
--------oDC Check----------
if not (user.bOperator) then
ratio = tonumber(frmHub:GetSlotRatio())
arg = frmHub:GetRedirectAddress()
arg2 = frmHub:GetMaxHubs()
arg3 = frmHub:GetMinSlots()
hubs = 0
-- HERE IS YOUR PROBLEM, you had tag here it should be data.
-- s,e,thubs,slots = strfind(tag, "H:([%d%/]+),S:(%d+)%S*>")
s,e,thubs,slots = strfind(data, "H:([%d%/]+),S:(%d+)%S*>")
-- HERE IS YOUR PROBLEM, you had tag here it should be data.
if tonumber(thubs) == nil then
gsub(thubs, "(%d+)", function (num)
hubs = hubs +tonumber(num)
end)
else
hubs = tonumber(thubs)
end
slots = tonumber(slots)
if tonumber(slots) < (ratio*hubc) then
user:SendData(Bot, "Your are in violation with this hubs Hub/Slot Ratio: '"..ratio.." Slot per Hub' - With your current hubcount you must open no less than Slots: "..hubc * ratio)
user:SendData("$ForceMove "..arg)
elseif hubc > arg2 then
user:SendData(Bot, "Your are in violation with this hubs Max Hub Rule: Max "..arg2.." Hubs.")
user:SendData("$ForceMove "..arg)
elseif slots < arg3 then
user:SendData(Bot, "Your are in violation with this hubs Min Slot Rule: Min "..arg3.." Slots.")
user:SendData("$ForceMove "..arg)
end
end
--------oDC Check----------
/NightLitch
I asuming you have this in your code I fixed above the function you needed help with.
if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
/NightLitch
Thanks guys ..
what i have now is this:
--------oDC Check----------
if not (user.bOperator) then
ratio = tonumber(frmHub:GetSlotRatio())
arg = frmHub:GetRedirectAddress()
arg2 = frmHub:GetMaxHubs()
arg3 = frmHub:GetMinSlots()
hubs = 0
if ( strsub(data, 1, 12) == "$MyINFO $ALL" ) then
s,e,thubs,slots = strfind(data, "H:([%d%/]+),S:(%d+)%S*>")
if tonumber(thubs) == nil then
gsub(thubs, "(%d+)", function (num)
hubs = hubs +tonumber(num)
end)
else
hubs = tonumber(thubs)
end
slots = tonumber(slots)
if slots < (ratio*hubs) then
user:SendData(Bot, "Your are in violation with this hubs Hub/Slot Ratio: '"..ratio.." Slot per Hub' - With your current hubcount you must open no less than Slots: "..hubs * ratio)
user:SendData("$ForceMove "..arg)
elseif hubc > arg2 then
user:SendData(Bot, "Your are in violation with this hubs Max Hub Rule: Max "..arg2.." Hubs.")
user:SendData("$ForceMove "..arg)
elseif slots < arg3 then
user:SendData(Bot, "Your are in violation with this hubs Min Slot Rule: Min "..arg3.." Slots.")
user:SendData("$ForceMove "..arg)
end
end
end
--------oDC Check----------
This gives me:
Syntax error: attempt to compare nil with number
stack traceback:
1: function `DataArrival' at line 453
i cant really see where that nil should come from ... looks like its all covered now .. ?
oops .. fixed the "elseif hubc > arg2 then
" part too... though still getting the same error ..
**Snooze
You get that nil when a user logs in without a proper tag -notag-
you need to resolve the nil like this:
s,e,thubs,slots = strfind(data, "H:([%d%/]+),S:(%d+)%S*>")
if thubs==nil or slots==nil then
user:SendData(Bot, "You are hiding your tag !!")
user:Disconnect()
end
if tonumber(thubs) == nil then
gsub(thubs, "(%d+)", function (num)
hubs = hubs +tonumber(num)
end)
else
hubs = tonumber(thubs)
end
Thats it !!! :D
Thanks plop, nErBoS and NightLitch :-)
You've just saved me tons of trouble :D
**Snooze
yw snooze.
sorry about that small error on "tag", i just copyed that piece of code from a bot i made in the past for trucker.
didn't think of the fact that i handle the tag slightly different then most of you guy's.
plop
No problem at all plop .. i should really have found that error myself .. were goin "blind" on this piece of code :(
Thanks again :)
Snooze