PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Finished Scripts => Topic started by: Daywalker? on 21 February, 2009, 16:50:06

Title: TriBlade [PX] [API 2]
Post by: Daywalker? on 21 February, 2009, 16:50:06
--// The TriBlade Redirect Array by Daywalker?
--//
--// LUA 5.1.3 TriBlade [PX] version 0.0 Beta
--//
--// LUA 5.1.3 TriBlade [PX] version 0.02
--//
--// What did i do:
--//
--// * Redirect user on share entering on MyINFO
--// * Added Table with hubinfo
--// * Added Timer to redirect users in timed session
--// * Added Amount for redirect users
--//
--// * fixed Redirect issue tnx to badboyyyyyy
--// 
--// +TODO: Make add, delete and info commands to handle new hubs
--// +TODO: Create folder and file to store hublist
--// +TODO: Store the counting also for info
--//

local Owner = "Daywalker?" --// duh..

local Bot = "Triblade" --// botname
local Description = "Go with the Flow..." --// botdesc
local Email = "wheredoigo@hotmail.com" --// botmail

local Menu = Bot --// Menu name for RC
local ShowMain = true --// for show redi in main set true else false
local Debug = true --// for show debug in main set true else false
local Redirect = true --// start redirect at startup

--// Reminder: For looping through the table keep the biggest hubshare on top!
tHublist = {
{iHubShare = 20, sAdd = "hub4.no-ip.com",sHub = "The Maxi Hub",sOwner = "BigShare"},
{iHubShare = 15, sAdd = "hub3.no-ip.com",sHub = "The Big Hub",sOwner = "OldBoy"},
{iHubShare = 10, sAdd = "hub2.no-ip.com",sHub = "The Good Hub",sOwner = "HubMan"},
{iHubShare = 5,sAdd = "hub1.no-ip.com",sHub = "The Mini Hub",sOwner = "MiniMe"},
{iHubShare = 0,sAdd = "dump.no-ip.com",sHub = "The Dump Hub",sOwner = "Bleh"},
}

local rAmount = 20 --// Set total of users you want to redirect in the timed session

--// time stuff
local minute = 60000
local hour = 60*minute
local day = 24*hour

local rInterval = hour --// Redirect users every xxxxx - ex: 2*hour is every 2 hours

--// Don't change code after this line, if you do then don't bother me with it :) \\--
local rCount,lCount = 0,0

OnStartup = function()
Core.RegBot(Bot, Description, Email, true)
TimerA = TmrMan.AddTimer(rInterval) --// start interval timer
Pfx = SetMan.GetString(29):sub(1,1)
OnError("*** TriBlade 0.02 for ".._VERSION.." made by Daywalker? has been started.")
collectgarbage("collect")
end

MyINFOArrival = function(user, data)
Core.GetUserAllData(user)
if Redirect then
Redirector(user,data) --// Use the Redirect function
end
end

UserConnected = function(user)
SendCmd(user)
end

OpConnected = UserConnected
RegConnected = UserConnected

ChatArrival = function(user, data)
local s,e,cmd = string.find( data, "%b<> %p(%w+)")
if cmd and tCom[cmd] then
local _,_,_,lev = tCom[cmd]()
if lev[user.iProfile] and lev[user.iProfile] == 1 then
local message = tCom[cmd](user,data,pre,cmd)
Core.SendToNick(user.sNick,"<"..Bot.."> "..message.."|")
collectgarbage("collect")
return true
end
end
end

ToArrival = function(user,data)
local s,e,to = string.find(data,"^$To: (%S+) From:")
local s,e,cmd = string.find( data, "%b<> %p(%w+)")
if cmd and tCom[cmd] then
local _,_,_,lev = tCom[cmd]()
if lev[user.iProfile] and lev[user.iProfile] == 1 then
if to and to == Bot then
Core.SendPmToNick(user.sNick,Bot,tCom[cmd](user,data,pre,cmd).."|")
end
collectgarbage("collect")
return true
end
end
end

OnExit = function()
OnError("*** TriBlade 0.02 for ".._VERSION.." made by Daywalker? has been stopped.")
end

Redirector = function(user,data)
local iShareSize = user.iShareSize
if tonumber(iShareSize) then
iShareSize = (tonumber(iShareSize)/(1024^3))
for i in ipairs(tHublist) do
if iShareSize > tHublist[i].iHubShare and (user.iProfile == -1 or not ProfMan.GetProfile(user.iProfile).tProfilePermissions.bIsOP) then
if rCount >= rAmount then
--// stop redirect
TmrMan.RemoveTimer(TimerA) --// remove interval timer
TimerA = TmrMan.AddTimer(rInterval) --// activate interval timer again
Redirect = false --// stop redirecting
if Debug then
OnError("*** TriBlade stopped redirecting users cause max amount is reached")
OnError("*** TriBlade will start again in "..minutestoh(rInterval/60000))
end
break
else
rCount = rCount + 1
lCount = lCount + 1
if ShowMain then
Core.SendToAll("<"..Bot.."> Redi ["..lCount.."]: "..user.sNick.." with "..string.format("%.2f",iShareSize)..
" GB share to "..tHublist[i].sHub.." @ "..tHublist[i].sAdd)
end
                                        Core.Redirect(user, tHublist[i].sAdd, "Redirected by Triblade Script made by Daywalker?")
break
end
end
end
end
end

OnTimer = function(tID)
if tID == TimerA then
--// reset the counter
rCount = 0
Redirect = true
if Debug then
OnError("*** TriBlade's resetting timer to begin value.")
OnError("*** TriBlade's resetting amount counter to zero.")
OnError("*** TriBlade started redirecting users cause of new timed session")
end
end
end

tCom = {
rhelp = function(user,data)
if user then
local x
local reply = "\r\n\r\n\tRedi Help:\r\n\r\n\tCommand\t\tDescription\r\n"..
"\t"..string.rep("?",40).."\r\n"
for i,v in pairs(tCom) do
local menu,desc,arg,lev = tCom[i]()
if lev[user.iProfile] and lev[user.iProfile] == 1 then
x = 1
reply = reply.."\t!"..string.format("%-15s",i).."\t"..desc.."\r\n"
end
end
if x then
return reply.."\n\t"..string.rep("?",40).."\r\n\r\n"
else
return "Sorry "..user.sNick.." Commands are disabled for your profile."
end
else
return "Redi Help ", "Help","", --// adjust this to your needs
--// Adjust To Your Profiles
{[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,}
end
end,
rhublist = function(user,data)
if user then
local x
local reply = "\r\n\r\n\tNetwork HubList:\r\n\r\n\tHub\t\tAdress\t\tOwner\t\tShareSize\r\n"..
"\t"..string.rep("?",60).."\r\n"
for i in ipairs(tHublist) do
x = 1
reply = reply.."\t"..tHublist[i].sHub.."\t"..tHublist[i].sAdd.."\t"..tHublist[i].sOwner.."\t\t"..tHublist[i].iHubShare.." GB\r\n"
end
if x then
return reply.."\n\t"..string.rep("?",60).."\r\n\r\n"
else
return "Sorry "..user.sNick.." Commands are disabled for your profile."
end
else
return "Hublist ", "Show network hublist","", --// adjust this to your needs
--// Adjust To Your Profiles
{[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,}
end
end,
rset = function(user,data)
if user then
local reply = "\r\n\r\n\tScript settings at this moment:\r\n\r\n\tKey\t\tValue\r\n"..
"\t"..string.rep("?",40).."\r\n"
reply = reply.."\tHub Owner\t"..Owner.."\r\n\n"
reply = reply.."\tName of the Bot\t"..Bot.."\r\n"
reply = reply.."\tBot's description\t"..Description.."\r\n"
reply = reply.."\tBot's Email\t"..Email.."\r\n"
reply = reply.."\tRC menu name\t"..Menu.."\r\n\n"
reply = reply.."\tShow msg in main\t"..tostring(ShowMain).."\r\n"
reply = reply.."\tShow debug\t"..tostring(Debug).."\r\n"
reply = reply.."\tRedirect Time\t"..minutestoh(rInterval/60000).."\r\n"
reply = reply.."\tMax Amount\t"..rAmount.." user(s)/timed session\r\n\n"
reply = reply.."\tTotal redi atm\t"..lCount.." user(s)\r\n"
return reply.."\n\t"..string.rep("?",40).."\r\n\r\n"
else
return "Botsettings ", "Show bot settings","", --// adjust this to your needs
--// Adjust To Your Profiles
{[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,}
end
end,
}

SendCmd = function(user)
local x
for i,v in pairs(tCom) do
local menu,desc,arg,lev = tCom[i]()
if lev[user.iProfile] and lev[user.iProfile] == 1 then
x = 1
Core.SendToNick(user.sNick,"$UserCommand 1 3 "..Menu.."\\"..menu.."\\"..
desc.."$<%[mynick]> "..Pfx..i..arg.."&#124;|")
end
end
if x then
local Prof
if user.iProfile ~= -1 then
Prof = ProfMan.GetProfile(user.iProfile).sProfileName
else
Prof = "Unregistered User"
end
end
collectgarbage("collect")
end

OnError = function(sErrorMsg)
Core.SendToNick(Owner,"<"..Bot.."> "..sErrorMsg)
end

minutestoh = function(minutes) -- gets minutes as arguments, returns a string with formatted time and 4 numbers as units
if frac(minutes) > 0.5 then
minutes=math.ceil(minutes) else minutes=math.floor(minutes)
end
local weeks,days,hours,mins
local msg=""
local a1,a2,a3=math.fmod(minutes,10080),math.fmod(minutes,1440),math.fmod(minutes,60)
if a1==minutes then
weeks=0 else weeks=math.floor(minutes/10080)
end
if a2==minutes then
days=0 else days=math.floor(a1/1440)
end
if a3==minutes then
hours=0 else hours=math.floor(a2/60)
end
mins=math.fmod(minutes,60)
local tmp = {
[" weeks "]=weeks,
[" days "]=days,
[" hours "]=hours,
[" minutes"]=mins
}
local tmp2={" weeks "," days "," hours "," minutes"}
for a,b in ipairs(tmp2) do
if tmp[b] > 0 then
msg=msg..tmp[b]..b
end
end
if msg=="" then
msg="0"
end
return msg,weeks,days,hours,mins
end

function frac(num) -- returns fraction of a number (RabidWombat)
return num - math.floor(num)
end


:D

// EDIT: fixed user.sNick in Core.Redirect()
// EDIT: fixed to user in Core.Redirect()
Title: Re: TriBlade [PX] [API 2]
Post by: badboyyyyyy on 22 February, 2009, 23:32:54
[00:32] Syntax F:\myhub\scripts\Triblade.lua:126: bad argument #1 to 'Redirect' (table expected, got string)
Title: Re: TriBlade [PX] [API 2]
Post by: Daywalker? on 22 February, 2009, 23:49:06
oops my bad,

updated script above :)
Title: Re: TriBlade [PX] [API 2]
Post by: badboyyyyyy on 23 February, 2009, 01:17:33
now work nice  ;D
Title: Re: TriBlade [PX] [API 2]
Post by: Black-Dragon on 18 June, 2012, 23:22:26
TriBlade.lua:222: attempt to concatenate upvalue 'Menu' (a nil value)  :-[
Title: Re: TriBlade [PX] [API 2]
Post by: Black-Dragon on 25 June, 2012, 23:53:41
hello all anyone help me?  ??? ??? ???
Title: Re: TriBlade [PX] [API 2]
Post by: the-master on 26 June, 2012, 16:33:57
Only Menu in the script is for usercommands, plz check your settings on top for typo's etc.