PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: xjr13sp on 21 December, 2003, 11:01:02

Title: How to know shared slots
Post by: xjr13sp on 21 December, 2003, 11:01:02
Hi all,

I'd like to add a new command for my OPs.
A command wich give the number of a user's shared slots... as '+nbslots '

Is someone knows haw to parse the $SR command in order to find the good information?
Title:
Post by: plop on 21 December, 2003, 16:22:21
if you mean the amount of uploads slots then give this a try.
TheCommand = "+nbslots"

function DataArival(user, data)
   if user.bOperator ~= nil then
      if (strsub(data, 1, 1) == "<") then
         data = strsub(data, 1, (strlen(data)-1))
         s,e,cmd,who = strfind(data, "%b<>%s+(%S+)%s*(%S*)")
         if cmd == TheCommand then
            if who == "" then
               user:SendData("Slots", "I really need to know a username as i'm not psychic|")
            else
               victem = GetItemByName(who)
               if victem == nil then
                  user:SendData("Slots", who.." is not in the hub|")
               else
                  local _,b, slots = strfind(victem.sMyInfoString,"S:(%x+)")
                  if slots ~= nil then
                     user:SendData("Slots", who.." has "..slots.." upload slots|")
                  end
               end
            end
         end
      end
   end
end
if you want 2 see the amount of used/free slots i have some more work 2 do. lol

plop
Title:
Post by: xjr13sp on 21 December, 2003, 16:38:50
I think it's what I search for, but how does it work ?  :D
When I type '+nbslots' or '+nbslots xjr13sp 'in the main chat I have no responses  :(
Title:
Post by: plop on 21 December, 2003, 22:53:52
sorry spelling error on DataArrival   seems that that is spelled with 2 r's. lol
Bot = "Slots"

TheCommand = "+nbslots"

function DataArrival(user, data)
   if user.bOperator ~= nil then
      if (strsub(data, 1, 1) == "<") then
         data = strsub(data, 1, (strlen(data)-1))
         s,e,cmd,who = strfind(data, "%b<>%s+(%S+)%s*(%S*)")
         if cmd == TheCommand then
            if who == "" then
               user:SendData(Bot, "I really need to know a username as i'm not psychic|")
            else
               victem = GetItemByName(who)
               if victem == nil then
                  user:SendData(Bot, who.." is not in the hub|")
               else
                  local _,b, slots = strfind(victem.sMyInfoString,"S:(%x+)")
                  if slots ~= nil then
                     user:SendData(Bot, who.." has "..slots.." upload slots|")
                  end
               end
            end
            return 1
         end
      end
   end
end
plop
Title:
Post by: xjr13sp on 22 December, 2003, 18:55:55
Hi,

I tested your changes, but it doesn't work more  :(
I have this :

+nbslots
I really need to know a username as i'm not psychic
+nbslots ludo
(no response with this last command)
Title:
Post by: plop on 22 December, 2003, 19:20:40
funny works here.
next try, this gives output if no slots were found, maby it can help 2 find the error.
Bot = "Slots"

TheCommand = "+nbslots"

function DataArrival(user, data)
   if user.bOperator ~= nil then
      if (strsub(data, 1, 1) == "<") then
         data = strsub(data, 1, (strlen(data)-1))
         s,e,cmd,who = strfind(data, "%b<>%s+(%S+)%s*(%S*)")
         if cmd == TheCommand then
            if who == "" then
               user:SendData(Bot, "I really need to know a username as i'm not psychic|")
            else
               victem = GetItemByName(who)
               if victem == nil then
                  user:SendData(Bot, who.." is not in the hub|")
               else
                  local _,b, slots = strfind(victem.sMyInfoString,"S:(%d+)")
                  if slots ~= nil then
                     user:SendData(Bot, who.." has "..slots.." upload slots|")
                  else
                     user:SendData(Bot, who.." made me confused, couldn't find his slots|")
                  end
               end
            end
            return 1
         end
      end
   end
end
plop
Title:
Post by: xjr13sp on 23 December, 2003, 09:39:08
It seems to work prefectly!!
Thank you plop  :))