Sign in to follow this  
kowixd

[HELP]Lag in Top 30 script

Recommended Posts

Hello
Every time I open the panel it causes lag
..

I would also like to list the top list

Please Help

I do not have much knowledge in this

function onWasted(_,killer,_,body)
if(killer and getElementType(killer)=="player" and killer~=source)then
addPlayerKillCount(killer)
end
end
addEventHandler("onPlayerWasted",root,onWasted)

function addPlayerKillCount(p)
local acc = getPlayerAccount(p)
if(acc and isGuestAccount(acc)==false)then 
local pk = tonumber((getAccountData(acc,"Players Kills"))) or 0
setAccountData(acc,"Players Kills",pk+1)
end
end

function onChangeNick(old,new)
local acc = getPlayerAccount(source)
if(acc and isGuestAccount(acc)==false)then 
local nickAcc = string.gsub(new,"#%x%x%x%x%x%x","")
setAccountData(acc,"PlayerName",nickAcc)
end
end
addEventHandler("onPlayerChangeNick",root,onChangeNick)


function createTopSystem()
local allAccounts = getAccounts()
local sendTable = {}
local data = 0
for k,v in ipairs(allAccounts) do
local name = getAccountName(v)
data = tonumber(getAccountData(v,"Players Kills") or 0)or 0
if(data>0)then
table.insert(sendTable,{["playerName"] = name,["Value"] = data})
end
end
table.sort(sendTable,function(a,b) return tonumber(a["Value"] or 0)>tonumber(b["Value"] or 0) end)
table.setMaxIndex(sendTable,30)
for i=1,#sendTable do
local acc = getAccount(sendTable[i]["playerName"])
local accRealName = getAccountData(acc,"PlayerName")
if(accRealName and tostring(accRealName)~="false")then 
sendTable[i]["playerName"] = accRealName
end
end
triggerClientEvent(client,"onClientReceiveTopListTable",client,sendTable)
end

function table.setMaxIndex(t,n)
if(#t>n)then 
while(#t>n)do
table.remove(t)
end
end
end

addEvent("onTopPlayerListRequest", true)
addEventHandler("onTopPlayerListRequest", root, 
	function()
		createTopSystem( source )
	end
)

client.lua

local rankTable = {}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        JanelaPrincipal = guiCreateWindow(0.34, 0.18, 0.35, 0.61, "TOP 30 PLAYERS KILLS", true)
		guiSetAlpha(JanelaPrincipal, 1.00)
		guiSetProperty(JanelaPrincipal, "CaptionColour", "FFF00AF3")
        guiWindowSetMovable(JanelaPrincipal, false)
        guiWindowSetSizable(JanelaPrincipal, false)
        Gridilist = guiCreateGridList(0.04, 0.1, 0.93, 0.83, true, JanelaPrincipal)
		local column = guiGridListAddColumn(Gridilist, "Rank", 0.20 )
        local column1 = guiGridListAddColumn(Gridilist, "Player Name", 0.5)
        local column2 = guiGridListAddColumn(Gridilist, "Kills", 0.2)
		for i = 1,30 do
local row = guiGridListAddRow ( Gridilist )
guiGridListSetItemText (Gridilist, row, column, "" .. i .. "-", false, false )
guiGridListSetItemText (Gridilist, row, column1, "N/A", false, false )
guiGridListSetItemText (Gridilist, row, column2, "N/A", false, false )
guiGridListSetItemColor(Gridilist, row, column, 255, 0, 0)
guiGridListSetItemColor(Gridilist, row, column1, 255, 255, 0)
guiGridListSetItemColor(Gridilist, row, column2, 0, 180, 255)
end
		guiSetVisible(JanelaPrincipal,false)	
end)



addEvent("onClientReceiveTopListTable",true)
addEventHandler("onClientReceiveTopListTable",root,
function(t)
rankTable = t
UpdateTopList()
end)

function UpdateTopList()
guiGridListClear(Gridilist)
local row = guiGridListAddRow ( Gridilist )
for k,v in ipairs(rankTable) do
--local row = guiGridListAddRow ( Gridilist ) 
--guiGridListSetItemText ( Gridilist, row, 1, "" .. i .. "-", false, false )
guiGridListSetItemText(Gridilist,row,2,v["playerName"],false,false)
guiGridListSetItemText(Gridilist,row,3,v["Value"],false,false)
guiGridListSetItemColor(Gridilist, row, 2, 255, 255, 0)
guiGridListSetItemColor(Gridilist, row, 3, 0, 180, 255)
end
end

function ToggleTopGui()
local guiS = guiGetVisible(JanelaPrincipal)
guiSetVisible(JanelaPrincipal,not guiS)
showCursor(not guiS)
guiSetInputEnabled(not guiS)
triggerServerEvent("onTopPlayerListRequest",localPlayer)
end
bindKey("F10","down",ToggleTopGui)

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.