Hi, could someone help with this slots script.. i get some syntax errors like
Slots.lua:5: unexpected symbol near `%'
SlotBot
-- Adaptation by OpiumVolage (01 July 2003) based on
-- retrobot? v0.99?
-- slots module
-- by tezlo
-- 2003
--
botName = "[operserv]"
--
function getid(table, name)
return table.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 table.insert(table, item) id = table.n
end return id
end
--
function OnTimer()
local i = 1 while tabSlots[i] do
local table = tabSlots[i]
if os.clock() >= table.iClock + tmrSlots then
if table.tItems.n == 0 then
SendPmToNick(table.sName, botName, "DC:CLP - N?o foram encontrados usu?rios com slots livres.|")
end
SendPmToNick(table.sName, botName, "DC:CLP - Verifica??o completa.|")
tos.remove(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 = string.find(args, " (%d+)/(%d+)"..string.char(5))
table.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
-- SendPM(item.sName, " Usu?rio "..%user.sName.." "..%free.."/"..%all.."|")
-- item.iClock = item.iClock - tmrSlots
-- elseif not item.sTarget and
if (tonumber(%free) >= item.iNR) then
SendPmToNick(item.sName, botName, "Usu?rio(a): "..%user.sName.." - Dispon?veis: "..%free.." - Total: "..%all.."|")
end
end end)
end
--
function doSlots(user, nr, nick)
SendToAll(botName, "DC:CLP - A efetuar verifica??o de slots dispon?veis no Hub, a pedido de um usu?rio(a) - [comando: !slots]")
SendToOps(botName,"OP MSG - A efetuar verifica??o de slots dispon?veis no Hub, por: "..user.sName..".")
user:SendPM(botName, ""..user.sName..", a verifica??o n?o pode ser efetuada a usu?rios em Modo Passivo.|")
user:SendPM(botName, "DC:CLP - Aguarde, verificando..|")
frmHub:EnableSearchData(1)
SendToAll("$Search Hub:"..Command.." T?F?0?1?.|")
putitem(tabSlots, { sName = user.sName, iClock = os.clock(), iNR = nr, tItems = {n=0} })
end
--
tmrSlots = 5 -- Number of seconds waiting for replys
tabSlots = {n=0}
Command = "!slots"
--
function ChatArrival(user, data)
if string.find(data, "%b<>%s+("..Command..").*|") then
s, e, nr = string.find(data, "%b<>%s+"..Command.."%s+([0-9]+)")
if s then nr = tonumber(nr) else nr = 1 end
doSlots(user, nr) return 1
end
if string.find(data, "^%$SR") then slotsOnHub(user, data) end
end
--
function Main()
SetTimer(tmrSlots*1000)
StartTimer()
end
--
Remove % from before variable names, so
"..%user.sName.."
will be"..user.sName.."
%var format upvalues are deprecated in lua5.
Tks bastya_elvtars, i will do that :)
Oooh I was so hopeful... I've been trying to convert this script since PtokaX went to lua5, and I was like "someone's made it! yippee!"
But I get the same error I had with my attempts: "Syntax error in ..\PtokaX_0.3.3.0.b16.06.nt.dgb\scripts\SlotsBot_Lua5.lua:20: attempt to call field `foreachi' (a nil value)"
Bwaaahahahaaa ;(
table.concat does not work either
Check this (http://board.univ-angers.fr/thread.php?threadid=4069&boardid=26&sid=801b349fc8fe7c01ea1ce016123a1d7e) thread.
Best regards.