PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: BrokenBrick on 22 October, 2003, 00:28:14

Title: Slot Finder
Post by: BrokenBrick on 22 October, 2003, 00:28:14
This is not my own, and I can't remember who wrote it, but here goes
________________________________________

BotName = "Slotter"

tabSlots = {n=0}
tmrSlots = 4

function DataArrival(user, data)
if( strsub(data, 1, 1) == "<" ) then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if (cmd == "!slots") then
s,e,cmd,nr = strfind(data,"%b<>%s+(%S+)%s*(.*)")
user:SendPM(BotName, "***** Checking ***** (Active Users Only)")

-- new user to keep track of, also save the time we started
tinsert(tabSlots, { sName = user.sName, iClock = clock(), tItems = {} })
SendToAll("$Search Hub:"..BotName.." T?F?0?1?.|")
return 1
end
end

if (strsub(data, 1, 3) == "$SR") then -- incoming search results.. lets extract info about free slots
local s, e, free, all = strfind(data, " (%d+)/(%d+)"..strchar(5))
local i = 1 while tabSlots do
local table = tabSlots
if not table.tItems[user.sName] then -- first results from user.sName
table.tItems[user.sName] = free.."/"..all
if (nr == "" and free ~= "0") then SendPmToNick(table.sName, BotName, ""..user.sName.." has "..free.." slots of "..all)
elseif (nr ~= "" and all >= nr) then SendToNick(table.sName, " user ~ "..user.sName.." ~ "..all)
end
end

if clock() >= table.iClock + tmrSlots then -- listing timeout
if getn(table.tItems) == 0 then SendPmToNick(table.sName, BotName, "List Complete")
elseif getn(table.tItems) >= nr then SendToNick(table.sName, " No users with that kind of slots found", pm)
end
SendPmToNick(table.sName, BotName, "End") tremove(tabSlots, i)
else i = i + 1 end
end
end
end
Title:
Post by: sladdi on 31 October, 2003, 23:30:24
and how does this work? i mean how do i look for free slots?
Title:
Post by: [T-G-T]M@sto on 31 October, 2003, 23:31:29
QuoteOriginally posted by sladdi
and how does this work? i mean how do i look for free slots?
if (cmd == "!slots") then
Title:
Post by: sladdi on 31 October, 2003, 23:38:35
thank you..
Title: Slot Finder by ???
Post by: [G-T-E]Gate? on 18 November, 2003, 09:25:38
JO BrokenBrick.
 About ur Slot Finder script.
Ran the script and only get this reply and I know that many users have open slots. Any suggetsions.>>
 Private message from ?SlotSearch?: ***** Checking ***** (Active Users Only)

THanks..
Title:
Post by: tezlo on 18 November, 2003, 10:12:42
yeh.. get this one (http://board.univ-angers.fr/thread.php?threadid=512&boardid=13&sid=e527ac0aaae735cb38a9c62648ec6175#3)
Title: tezlo Your Suggestion
Post by: [G-T-E]Gate? on 18 November, 2003, 10:24:56
Thanks , Just ran it but get the folowing , >>
Syntax Error: attempt to call field `EnableSearchData' (a nil value)
Title:
Post by: tezlo on 18 November, 2003, 10:29:33
upgrade to testdrive
or find the line where it says
 frmHub:EnableSearchData(1)
and comment it out..
 --frmHub:EnableSearchData(1)
Title:
Post by: [G-T-E]Gate? on 18 November, 2003, 10:41:01
Great again Thanks loads..
Title: Free Slots Bot
Post by: Gnuff? on 22 November, 2003, 18:57:51
This one works with (+slots), but stille only on active users, but shows all free slots



-- SlotsBot for PtokaX DC Hub 0.3.2.6 Test Drive 4

-- On command +slots, sends a search and checks the results for free slots & total number of slots

-- Sends the results in PM from Hub bot

-- Adaptation by OpiumVolage (01 July 2003) based on

-- retrobot? v0.99?

-- slots module

-- by tezlo

-- 2003

-- Twiddled a bit to have results sent in PM - by bolamix 1 July 2003



-- unused sTarget left for future syntax parsing.



botName = "[SlotsCounter]"



-- library



function getid(table, name)

return foreachi(table, function(id, item) if item.sName == %name then return id end end)

end



function putitem(table, item)

if not item then return end

local id = getid(table, item.sName)

if id then table[id] = item

else tinsert(table, item) id = table.n

end return id

end





-- events



function OnTimer()

local i = 1 while tabSlots do

local table = tabSlots

if clock() >= table.iClock + tmrSlots then

if table.tItems.n == 0 then SendPmToNick(table.sName, botName, "No users with free slots found|") end

SendPmToNick(table.sName, botName, "Done|")

tremove(tabSlots, i)

if tabSlots.n == 0 then frmHub:EnableSearchData(0) end

else i = i + 1 end

end

end



function slotsOnHub(user, args)

local s, e, free, all = strfind(args, " (%d+)/(%d+)"..strchar(5))

foreachi(tabSlots, function(id, item)

if not getid(item.tItems, %user.sName) then

putitem(item.tItems, { sName = %user.sName, sValue = %free.."/"..%all })

-- if item.sTarget and (%user.sName == item.sTarget) then

-- SendToNick(item.sName, " user "..%user.sName.." "..%free.."/"..%all.."|")

-- item.iClock = item.iClock - tmrSlots

-- elseif not item.sTarget and

if (tonumber(%free) >= item.iNR) then

SendPmToNick(item.sName, botName, " user "..%user.sName.." "..%free.."/"..%all.."|")

end

end end)

end



function doSlots(user, nr, nick)

user:SendPM(botName, "Checking..|")

frmHub:EnableSearchData(1)

SendToAll("$Search Hub:"..Command.." T?F?0?1?.|")

putitem(tabSlots, { sName = user.sName, iClock = clock(), iNR = nr, tItems = {n=0} })

-- putitem(tabSlots, { sName = user.sName, sTarget = nick, iClock = clock(), iNR = nr, tItems = {n=0} })

end





-- init



tmrSlots = 5 -- Number of seconds waiting for replys

tabSlots = {n=0}

Command = "+slots"



function DataArrival(user, data)

if strfind(data, "%b<>%s+("..Command..").*|") then

s, e, nr = strfind(data, "%b<>%s+"..Command.."%s+([0-9]+)")

if s then nr = tonumber(nr) else nr = 1 end

doSlots(user, nr) return 1

end

if strfind(data, "^%$SR") then slotsOnHub(user, data) end

end



function Main()

SetTimer(tmrSlots*1000)

StartTimer()

end