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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.