PtokaX forum

Development Section => LUA & PtokaX-Scripting-Interface => Topic started by: 6Marilyn6Manson6 on 22 March, 2007, 16:19:57

Title: Doubt For HideShare by Mutor
Post by: 6Marilyn6Manson6 on 22 March, 2007, 16:19:57
I have find this script:

--[[
HideShare 1.0 LUA 5.0/5.1   06/13/06

By Mutor
Requested by Rotekoppen


Hide user shares per profile.
Stop the script to unhide shares.

Note:
Any script that modifies MyINFO is a resource
and bandwidth hog. This one is no different.

]]

Main = function()
--Set MyINFO delay in ms [1000 = 1 second]
SetTimer(500)
StartTimer()
--//--Set your profiles here.
--[Profile_Index] = {Hide Share?(0=show 1=hide), "Profile Name"},
HideProfiles = {
[-1] = {0,"Unregistered User"},
[0] = {1,"Master"},
[1] = {1,"Operator"},
[2] = {0,"Vip"},
[3] = {0,"Registered User"},
[4] = {1,"Moderator"},
[5] = {1,"NetFounder"},
}
gc,no = nil,table.getn
if _VERSION == "Lua 5.1" then
gc,no = "collect",table.maxn
end
end

MyINFOArrival = function(user,data)
StartTimer()
end
GetINFOArrival,NewUserConnected,OpConnected = MyINFOArrival,MyINFOArrival,MyINFOArrival

OnTimer = function()
for i = 1, no(GetProfiles()) do
if HideProfiles[i-1] and HideProfiles[i-1][1] == 1 then
for k,v in ipairs(frmHub:GetOnlineUsers(i-1)) do
local n,d,t,c,a,e,s = v["sName"], v["sDescription"] or "", v["sTag"] or "",
v["sConnection"] or "",tonumber(v["iMagicByte"]),v["sEmail"] or "","0"
SendToAll("$MyINFO $ALL "..n.." "..d..t.."$ $"..c.."$"..e.."$"..s.."$")
end
end
end
StopTimer()
collectgarbage(gc)
end

OnExit = function()
for k,v in ipairs(frmHub:GetOnlineUsers()) do
local user = GetItemByName(v["sName"])
SendToAll(user.sMyInfoString)
end
collectgarbage(gc)
end


I don't understand OnTimer function... why Mutor use:

OnTimer = function()
for i = 1, no(GetProfiles()) do
if HideProfiles[i-1] and HideProfiles[i-1][1] == 1 then
for k,v in ipairs(frmHub:GetOnlineUsers(i-1)) do
local n,d,t,c,a,e,s = v["sName"], v["sDescription"] or "", v["sTag"] or "",
v["sConnection"] or "",tonumber(v["iMagicByte"]),v["sEmail"] or "","0"
SendToAll("$MyINFO $ALL "..n.." "..d..t.."$ $"..c.."$"..e.."$"..s.."$")
end
end
end
StopTimer()
collectgarbage(gc)
end


and not:

OnTimer = function()
if HideProfiles and HideProfiles[1] == 1 then
for k,v in ipairs(frmHub:GetOnlineUsers) do
local n,d,t,c,a,e,s = v["sName"], v["sDescription"] or "", v["sTag"] or "",
v["sConnection"] or "",tonumber(v["iMagicByte"]),v["sEmail"] or "","0"
SendToAll("$MyINFO $ALL "..n.." "..d..t.."$ $"..c.."$"..e.."$"..s.."$")
end
end
StopTimer()
collectgarbage(gc)
end


Explain to me please :D
Title: Re: Doubt For HideShare by Mutor
Post by: NightLitch on 22 March, 2007, 21:39:44
Your code got some optimized there 6M6M6. It is better as you stated to put the check outside the loop rather then inside to check it over and over again...
Title: Re: Doubt For HideShare by Mutor
Post by: 6Marilyn6Manson6 on 23 March, 2007, 08:53:03
Okiz, now i'm understand. Thanks NightLitch and Mutor :)