PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Request for scripts => Topic started by: panthera on 24 May, 2011, 12:46:38

Title: Automatic Profile Manager
Post by: panthera on 24 May, 2011, 12:46:38
Hello,

My hub has the following Profiles
================================================
    [SHARE SIZE]                [TAG]
    ================================================
    125 GB                         STAR
    250 GB                         WOW
    500 GB                         VIP
    1 TB                             VVIP
    ================================================

I wanted a script which will automatically upgrade and downgrade users according to their Shares.

I found a script which upgrades but does not downgrade please make the required changes and post the whole script back.

Thanks In Advance.

Panthera

Script:

RegConnected = function(User)
if Core.GetUserValue(User,16) >= (500*(1024^3)) then       
local tCurProf = ProfMan.GetProfile(User.iProfile)
if tCurProf.sProfileName ~= "VIP" then                 
local tCurReg = RegMan.GetReg(User.sNick)
local tProfiles = ProfMan.GetProfiles()
for k in pairs(tProfiles) do
if tProfiles[k].sProfileName == "VIP" then     
RegMan.ChangeReg(tCurReg.sNick, tCurReg.sPassword, tProfiles[k].iProfileNumber)
Core.SendPmToUser(User,SetMan.GetString(21),"Your profile has been automatically updated to VIP.|")
end
end
end
end
end
Title: Re: Automatic Profile Manager
Post by: Hamachi on 24 May, 2011, 21:04:39
why downgrade  ?
Title: Re: Automatic Profile Manager
Post by: panthera on 25 May, 2011, 10:17:27
Quote from: Hamachi on 24 May, 2011, 21:04:39
why downgrade  ?

So tat if the share come down he/she will get the lower profile......as one can hash data to become vip then lower it down.which will cause Profile problems...unequal distribution.....so wanted to add downgrade system also...........


PaNtHeRa
Title: Re: Automatic Profile Manager
Post by: Madman on 02 September, 2011, 21:01:49
Give this a try...
I been out of PtokaX scripting for like a year or so, so script can be full of holes, errors, flawd logic and spelling misstakes and so on.
I'm to lazy to install a PtokaX on my pc, it's UNTESTED



tShareReg = {
[0] = {1,"FailSafe"}, -- DO NOT EDIT!
[1] = {125,"STAR"},
[2] = {250,"WOW"},
[3] = {500,"VIP"},
[4] = {1024,"VVIP"},
}

RegConnected = function(User)
local Size = ConvShare(User.iShareSize,"B")
local tCurProf = ProfMan.GetProfile(User.iProfile)

for i,t in ipairs(tShareReg) do
ShareRegProf = t[2] -- Should work as a failsafe if user exeades latest profile upgrade
if Size <= t[1] and Size >= tShareReg[i-1][1] then -- If share is less then current and higher then previous
ShareRegProf = t[2] -- Get new profilename
end
end
-- Time to set the ShareRegProf
if tCurProf.sProfileName ~= ShareRegProf and SharRegProf ~= "FailSafe" then
oldnr = tCurProf.iProfileNumber
local tCurReg = RegMan.GetReg(User.sNick)
local tProfiles = ProfMan.GetProfiles()
for k in pairs(tProfiles) do
if tProfiles[k].sProfileName == ShareRegProf then     
RegMan.ChangeReg(tCurReg.sNick, tCurReg.sPassword, tProfiles[k].iProfileNumber)
if tProfiles[k].iProfileNumber > oldnr then
UnD = "updated"
InD = "increased"
else
UnD = "downgraded"
InD = "decreased"
end
Core.SendPmToUser(User,SetMan.GetString(21),"Your profile has been automatically " .. UnD .. " to " .. ShareRegProf .. " due to your share has " .. InD .. ".|")
end
end
end

-- if Core.GetUserValue(User,16) >= (500*(1024^3)) then       
-- local tCurProf = ProfMan.GetProfile(User.iProfile)
-- if tCurProf.sProfileName ~= "VIP" then                 
-- local tCurReg = RegMan.GetReg(User.sNick)
-- local tProfiles = ProfMan.GetProfiles()
-- for k in pairs(tProfiles) do
-- if tProfiles[k].sProfileName == "VIP" then     
-- RegMan.ChangeReg(tCurReg.sNick, tCurReg.sPassword, tProfiles[k].iProfileNumber)
-- Core.SendPmToUser(User,SetMan.GetString(21),"Your profile has been automatically updated to VIP.|")
-- end
-- end
-- end
-- end
end

-- Lost credits for this func, but thanks to the creator of it =)
function ConvShare(iShareSize, Type) -- Convert Share Size...
while iShareSize >= 1024 and Type ~= "PB" do
if Type == "B" then
Type = "KB"
elseif Type == "KB" then
Type = "MB"
elseif Type == "MB" then
Type = "GB"
elseif Type == "GB" then
Type = "TB"
elseif Type == "TB" then
Type = "PB"
end
iShareSize = iShareSize/1024
end
return string.format("%.2f", iShareSize),Type
--return string.format("%.2f", iShareSize).." "..Type
end