PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Snooze on 30 April, 2004, 13:34:08

Title: [Help]oDC hub/slot check
Post by: Snooze on 30 April, 2004, 13:34:08
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
Title:
Post by: plop on 30 April, 2004, 13:46:22
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
Title:
Post by: Snooze on 30 April, 2004, 13:55:21
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
Title:
Post by: nErBoS on 30 April, 2004, 14:57:45
Hi,

That sounds me the delay of MyInfoString, try to put in the beggining of DataArrival if (user.sMyInfoString ~= nil) then...

Best regards, nErBoS
Title:
Post by: NightLitch on 30 April, 2004, 15:06:44
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
Title:
Post by: NightLitch on 30 April, 2004, 15:12:07
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
Title:
Post by: Snooze on 30 April, 2004, 15:19:16
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 .. ?
Title:
Post by: Snooze on 30 April, 2004, 15:22:01
oops .. fixed the "elseif hubc > arg2 then
" part too... though still getting the same error ..

**Snooze
Title:
Post by: NightLitch on 30 April, 2004, 15:22:59
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
Title:
Post by: Snooze on 30 April, 2004, 15:27:43
Thats it !!! :D

Thanks plop, nErBoS and NightLitch :-)

You've just saved me tons of trouble :D



**Snooze
Title:
Post by: plop on 30 April, 2004, 15:50:38
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
Title:
Post by: Snooze on 30 April, 2004, 15:55:58
No problem at all plop .. i should really have found that error myself .. were goin "blind" on this piece of code :(

Thanks again :)

Snooze