PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Finished Scripts => Topic started by: Tw?sT?d-d?v on 21 October, 2007, 22:04:16

Title: Top Leecher [New API]
Post by: Tw?sT?d-d?v on 21 October, 2007, 22:04:16

--By Dessamator
--Top Leecher

-- Added by Mozzilla? - 16 November 2006
-- Choice as to which profile gets checked
--// Converted to NEW API by Tw?sT?d-d?v?l (21/10/07)

min = 1 -- time to wait b4 reporting top leecher

bot = "TopLeecher" -- bots name

-- Set check on or off for a given profile [0 = don't check    1 = check]
cChecks = {
[-1] = 1, --Unregistered User
[0] = 1, --Master
[1] = 0, --Operator
[2] = 1, --VIP
[3] = 1, --Registered User
}

function OnStartup()

tmr = TmrMan.AddTimer(60*1000*min)
end

function OnTimer(tmr)
local hubs = 0
for pos, user in pairs(Core.GetOnlineUsers(true)) do
if cChecks[user.iProfile] == 1 then
local prof = (ProfMan.GetProfile(user.iProfile) and ProfMan.GetProfile(user.iProfile).sProfileName) or "Unregistered User"
if user.iHubs > hubs then
temp="\r\n\r\nCongratulations "..prof.." "..user.sNick..", you are the top leecher in "..SetMan.GetString(0)..".\r\n\tAt this very moment you are in "..user.iHubs.." hubs with "..user.iSlots.." slots open!"
hubs = user.iHubs
end
end
end
Core.SendToAll("<"..bot.."> "..temp)
temp, hubs= nil, nil
end
Title: Re: Top Leecher [New API]
Post by: ]-[?LL?L?L??nG?L on 19 February, 2008, 15:25:17
I have an error with this script hun

on this line        Core.SendToAll("<"..bot.."> "..temp)

and this error   [14:24] Syntax topleecherNEW API.lua:37: attempt to concatenate global 'temp' (a nil value)
Title: Re: Top Leecher [New API]
Post by: Tw?sT?d-d?v on 19 February, 2008, 18:05:57
I dont get ant errors with script running here ......

[16:59] Leecher.lua loaded.
[16:59] No syntax errors in script file Leecher.lua
[16:59] Script started.



[17:00:36] <TopLeecher>

Congratulations Unregistered User ania123, you are the top leecher in Twisteds-Soul.
At this very moment you are in 81 hubs with 5 slots open!
[17:01:36] <TopLeecher>

Congratulations Unregistered User ania123, you are the top leecher in Twisteds-Soul.
At this very moment you are in 81 hubs with 5 slots open!
[17:02:36] <TopLeecher>

Congratulations Unregistered User ania123, you are the top leecher in Twisteds-Soul.
At this very moment you are in 81 hubs with 5 slots open!
[17:03:36] <TopLeecher>

Congratulations Unregistered User ania123, you are the top leecher in Twisteds-Soul.
At this very moment you are in 81 hubs with 5 slots open!
[17:04:36] <TopLeecher>

Congratulations Unregistered User ania123, you are the top leecher in Twisteds-Soul.
At this very moment you are in 81 hubs with 5 slots open!
[17:05:36] <TopLeecher>

Congratulations Unregistered User ania123, you are the top leecher in Twisteds-Soul.
At this very moment you are in 81 hubs with 5 slots open!


Maybe some1 else can see a prob here
Title: Re: Top Leecher [New API]
Post by: ]-[?LL?L?L??nG?L on 19 February, 2008, 23:00:32
Thank you heeps for the help hun after all that you found out it was my client...... so beware those of you with crap clients  ;D ;D ;D
Title: Re: Top Leecher [New API]
Post by: Snooze on 20 February, 2008, 17:28:26
You could add nil checks on those values your script is depending on..

/Snooze
Title: Re: Top Leecher [New API]
Post by: Tw?sT?d-d?v on 20 February, 2008, 20:16:51
--// Rewritten some code Thx CenoByte for tips


--By Dessamator
--Top Leecher

-- Added by Mozzilla? - 16 November 2006
-- Choice as to which profile gets checked
--// Converted to NEW API by Tw?sT?d-d?v?l (21/10/07)
--// Rewritten some code Thx CenoByte for tips
----------------------------------------------------------------

min = 1 -- time to wait b4 reporting top leecher

bot = "TopLeecher" -- bots name

-- Set check on or off for a given profile [0 = don't check    1 = check]
cChecks = {
[-1] = 1, --Unregistered User
[0] = 0, --Master
[1] = 0, --Operator
[2] = 1, --VIP
[3] = 1, --Registered User
}
-----------------------------------------------------------------
function OnStartup()
tmr = TmrMan.AddTimer(60*1000*min)
end

function OnTimer(tmr)
local hubs,temp=0,""
for pos, user in pairs(Core.GetOnlineUsers(true)) do
                 if cChecks[user.iProfile] == 1 then
local prof = (ProfMan.GetProfile(user.iProfile) and ProfMan.GetProfile(user.iProfile).sProfileName) or "Unregistered User"
if Core.GetUserValue(user,17) > hubs then
temp="\r\n\r\nCongratulations "..prof.." "..user.sNick..", you are the top leecher in "..(SetMan.GetString(0) or "<no_hub_name>")..".\r\n\tAt this very moment you are in "..(Core.GetUserValue(user,17) or "n/a").." hubs with "..(Core.GetUserValue(user,21) or "n/a").." slots open!"
                        end
                 end
        end
Core.SendToAll("<"..bot.."> "..temp)
end
Title: Re: Top Leecher [New API]
Post by: Pothead on 23 June, 2008, 13:32:08
Couple of comments . . ..
If you swap these two lines around, it should be "slightly" more efficient :)

local prof = (ProfMan.GetProfile(user.iProfile) and ProfMan.GetProfile(user.iProfile).sProfileName) or "Unregistered User"
if Core.GetUserValue(user,17) > hubs then


From seeing this in action in a hub, it goes wrong, i believe always showing the last person who connects . . ..
i believe this is because "hubs" never gets set, like it did in the original, and to sort it this should be added in the middle-ish area. (after the > hubs line).

hubs = Core.GetUserValue(user,17)

:)