PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: [HE]Newbie on 21 March, 2006, 16:33:28

Title: RegToStay
Post by: [HE]Newbie on 21 March, 2006, 16:33:28
-- [ Can someon1 convert this to LUA5, Thnx ] --

-- By [UK]Madman
-- References - Lua Language Board

var = {["bot"] = "RegToStayBot", ["time"] = 1, ["command"] = "?notreg"} --time is in mins before redirect
times = {}
hubs =? { "Holland-Extreme1.no-ip.info:411", "nlgezel.hopto.org:411"} -- list of possible hubs

function Main()
frmHub:RegBot(var.bot)
SetTimer(60000*(tonumber(var.time)/4))
StartTimer()
end

function NewUserConnected(Curuser)
if Curuser.iProfile == -1 then
times[Curuser.sName] = var.time
Curuser:SendData (var.bot, "You have to register to stay in this hub, you currently have: "..var.time.." mins to register!")
end
end

function UserDisconnected (Curuser)
times[Curuser.sName] = Nil
end

function OnTimer()
for key, value in times do
value = value - (var.time/4)
times[key] = value

if value == 0 then tokick = GetItemByName(key)
times[tokick] = nil
tokick:SendData (var.bot, "You did not register, so are now being redirected!")
tohub = random(getn(hubs))
tokick:SendData("$ForceMove "..hubs[tohub])

elseif value == (var.time - tonumber(var.time)/2) then towarn = GetItemByName(key)
towarn:SendData (var.bot, "You have not registered, you will be redirected in: "..value.." mins unless you register!")
end
end
end


function DataArrival(Curuser,data)
data = strsub(data, 1, strlen(data)-1)
if strsub(data, 1, 1) == "<" then
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if cmd == var.command and Curuser.bOperator then
Curuser:SendPM (var.bot, "The following users are currently not regged:")
for key, value in times do
Curuser:SendPM (var.bot, key.." Has approx "..value.." mins till being redirected!")
end
return 1
end
end
end


Title: Re: RegToStay
Post by: Markitos on 30 March, 2006, 08:17:28
--[[
By [UK]Madman
References - Lua Language Board
Markitos: Now works with all prefixes - 30/03/06
-- Lua5/Lua 5.1 support - 30/03/06
]]--

var = {
["bot"] = "RegToStayBot",
["time"] = 1, --time is in mins before redirect
["command"] = "notreg",
}
times = {}
hubs =  { "Holland-Extreme1.no-ip.info:411", "nlgezel.hopto.org:411"} -- list of possible hubs

function Main()
frmHub:RegBot(var.bot)
SetTimer(60000*(tonumber(var.time)/4))
StartTimer()
end

function NewUserConnected(Curuser)
if Curuser.iProfile == -1 then
times[Curuser.sName] = var.time
Curuser:SendData (var.bot, "You have to register to stay in this hub, you currently have: "..var.time.." mins to register!")
end
end

function UserDisconnected (Curuser)
times[Curuser.sName] = Nil
end

function OnTimer()
for key, value in pairs(times) do
value = value - (var.time/4)
times[key] = value
if value == 0 then tokick = GetItemByName(key)
times[tokick] = nil
tokick:SendData (var.bot, "You did not register, so are now being redirected!")
tohub = random(table.getn(hubs))
tokick:SendData("$ForceMove "..hubs[tohub])
elseif value == (var.time - tonumber(var.time)/2) then towarn = GetItemByName(key)
towarn:SendData (var.bot, "You have not registered, you will be redirected in: "..value.." mins unless you register!")
end
end
end


function ChatArrival(Curuser,data)
data = string.sub(data, 1, string.len(data)-1)
s,e,cmd = string.find(data, "%b<>%s+[%!%+%#%?](%S+)")
if cmd == var.command and Curuser.bOperator then
Curuser:SendPM (var.bot, "The following users are currently not regged:")
for key, value in pairs(times) do
Curuser:SendPM (var.bot, key.." Has approx "..value.." mins till being redirected!")
end
return 1
end
end
Title: Re: RegToStay
Post by: Markitos on 30 March, 2006, 18:58:37
Quote from: Mutor on 30 March, 2006, 16:52:05
For what its worth simple scripts like this can easily be made 5.0/5.1
compatible with the same effort as is required to convert 4.x to 5.0.

Consider using the optimized table loops [ipairs for arrays, pairs for tables]
that are available in 5.0 and required for 5.1. In this way, the script may be used
in both LUA versions. There are a few other things to consider for 5.1 but loops
are the biggest consideration.

Food for thought
edited...