Jump to content

[AYUDA] Top 30 de asesinatos, kills


kowixd

Recommended Posts

Hola, quisiera hacer un top 30 de los jugadores con mas kills, pero de esto desconosco hice algo pero, no tiene logica alguna.. en especial en el server.lua

Si me podrian dejar un par de comentarios explicando cada cosa estaria agradecido.

local Key = "F10" --- bind key

HD = {
    gridlist = {},
    S3D = {},
    q = {}
}

function centerWindow(center_window)
    local screenW,screenH=guiGetScreenSize()
    local windowW,windowH=guiGetSize(center_window,false)
    local x,y = (screenW-windowW)/2,(screenH-windowH)/2
    guiSetPosition(center_window,x,y,false)
end

HD.wnd = guiCreateWindow(415, 146, 450, 505, "Top 30 Kill Script || ", false)
guiWindowSetSizable(HD.wnd, false)
guiSetAlpha(HD.wnd, 1.00)
guiSetProperty(HD.wnd, "CaptionColour", "FFF00FFF")
centerWindow(HD.wnd)
HD.gridlist[1] = guiCreateGridList(18, 36, 430, 500, false, HD.wnd)
local column = guiGridListAddColumn(HD.gridlist[1], "Rank", 0.20 )
local column1 = guiGridListAddColumn(HD.gridlist[1], "Player Name", 0.30 ) 
local column2 = guiGridListAddColumn(HD.gridlist[1], "Total Kill", 0.20 ) 
local column3 = guiGridListAddColumn(HD.gridlist[1], "Total Deaths", 0.20 ) 
for i = 1,30 do
local row = guiGridListAddRow ( HD.gridlist[1] )
guiGridListSetItemText ( HD.gridlist[1], row, column, "" .. i .. "-", false, false )
guiGridListSetItemText ( HD.gridlist[1], row, column1, "N/A", false, false )
guiGridListSetItemText ( HD.gridlist[1], row, column2, "N/A", false, false )
guiGridListSetItemText ( HD.gridlist[1], row, column3, "N/A", false, false )
guiGridListSetItemColor(HD.gridlist[1], row, column1, 255, 255, 0)
guiGridListSetItemColor(HD.gridlist[1], row, column2, 0, 180, 255)
guiGridListSetItemColor(HD.gridlist[1], row, column3, 0, 180, 255)
guiGridListSetItemColor(HD.gridlist[1], row, column, 255, 0, 0)
end
guiSetVisible(HD.wnd, not guiGetVisible(HD.wnd))

bindKey (Key, "down",
	function()
		guiSetVisible(HD.wnd, not guiGetVisible(HD.wnd))
		showCursor(guiGetVisible(HD.wnd))
		triggerServerEvent("onTopPlayerListRequest", localPlayer)
	end
)

function convertNumber ( number )  
	local formatted = number  
	while true do      
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')    
		if ( k==0 ) then      
			break   
		end  
	end  
	return formatted
end

function updateTopList(playerName, Value, i)
local row = guiGridListAddRow ( HD.gridlist[1] )
guiGridListSetItemText ( HD.gridlist[1], row, column, "" .. i .. "-", false, false )
guiGridListSetItemText ( HD.gridlist[1], row, column1, tostring(playerName), false, false )
guiGridListSetItemText ( HD.gridlist[1], row, column2, convertNumber(Value), false, false )
guiGridListSetItemColor(HD.gridlist[1], row, column1, 255, 255, 0)
guiGridListSetItemColor(HD.gridlist[1], row, column2, 0, 180, 255)
guiGridListSetItemColor(HD.gridlist[1], row, column, 255, 0, 0)
end
addEvent("onClientReceiveTopListTable", true)
addEventHandler("onClientReceiveTopListTable", root, updateTopList)

function update()
guiGridListClear(HD.gridlist[1])
end
addEvent("deltTop", true)
addEventHandler("deltTop", root, update)
addEventHandler( 'onResourceStart', getResourceRootElement(getThisResource()),
	function( )
		outputChatBox("==[ Top-30 Kill Script | By K0w1 ]==", root, 255, 125, 0,true)
		outputChatBox("==[ Press F10 To Open Top-30 Top-Kill Script ]==", root, 50, 255, 0,true)
	end
)




function onWasted(_,killer,_,body)
if(killer and getElementType(killer)=="player" and killer~=source)then
addPlayerKillCount(killer)
addWastedCount(source)
end
if(killer and getElementType(killer)~="player" and killer~=source)then
addWastedCount(source)
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,"Kills"))) or 0
setAccountData(acc,"Kills",pk+1)
end
end


function addWastedCount(p)
local acc = getPlayerAccount(p)
if(acc and isGuestAccount(acc)==false)then 
local w = tonumber((getAccountData(acc,"Wasted"))) or 0
setAccountData(acc,"Wasted",w+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)


addEvent("onTopPlayerListRequest",true)
addEventHandler("onTopPlayerListRequest",root,
function ( player, text )
	if not isElement( player ) then
		return
	end
	local name = getAccountName(player)
	local sendTable = {}
	data = tonumber(getAccountData(player,"Kills") or 0)or 0
	for i = 1, #data do
		table.insert(sendTable,{["playerName"] = name,["Value"] = data})
	end
	if #CreatTop >0 then
		table.sort(sendTable,function(a,b) return tonumber(a["Value"] or 0)>tonumber(b["Value"] or 0) end)
	setTimer(
	function()
		for k, data in ipairs(sendTable) do
			if k == 1 then
				triggerClientEvent (player,"deltTop",player)
			end	
			triggerClientEvent (player,"onClientReceiveTopListTable",player,tostring(data.name),tostring(data.score),tonumber(k))
			if k == 30 then
					table.remove(sendTable)
				break
			end
		end
	end,
		500,
	1
	)
	end
end)

 

Link to comment

ahora eh conseguido que solamente los que estan conectados aparescan en el top, pero quiero que aparescan los que lo no estan tambien

_getPlayerName = getPlayerName
function getPlayerName(player)
	return string.gsub(_getPlayerName(player), "#%x%x%x%x%x%x", "" )
end

function getPlayersSortByaScore( )
	local TopScore = { }
	for _, aPlayer in next, getElementsByType 'player' do
		table.insert (
		TopScore,
		{
			player = aPlayer,
			aScore = getElementData ( aPlayer, 'Players Kills' ) or 0
		}
	)
	end
		table.sort( 
		TopScore,
		function( a, b )
			return( tonumber( a.aScore ) or 0 ) > ( tonumber( b.aScore ) or 0 )
		end
	)
	return TopScore
end


-------lllllllllllllll-------------

local Key = "F10" --- bind key

HD = {
    gridlist = {}
}

function centerWindow(center_window)
    local screenW,screenH=guiGetScreenSize()
    local windowW,windowH=guiGetSize(center_window,false)
    local x,y = (screenW-windowW)/2,(screenH-windowH)/2
    guiSetPosition(center_window,x,y,false)
end

HD.wnd = guiCreateWindow(415, 146, 450, 505, "Top 30 Kill script", false)
guiWindowSetSizable(HD.wnd, false)
guiSetAlpha(HD.wnd, 1.00)
guiSetProperty(HD.wnd, "CaptionColour", "FF2f00fFf")
centerWindow(HD.wnd)
HD.gridlist[1] = guiCreateGridList(18, 32, 430, 500, false, HD.wnd)
local column = guiGridListAddColumn(HD.gridlist[1], "Rank", 0.20 ) 
local column1 = guiGridListAddColumn(HD.gridlist[1], "Player Name", 0.40 ) 
local column2 = guiGridListAddColumn(HD.gridlist[1], "Total Kill", 0.30 ) 
guiSetVisible(HD.wnd, not guiGetVisible(HD.wnd))

bindKey (Key, "down",
	function()
		guiSetVisible(HD.wnd, not guiGetVisible(HD.wnd))
		showCursor(guiGetVisible(HD.wnd))
	end
)

function convertNumber ( number )  
	local formatted = number  
	while true do      
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')    
		if ( k==0 ) then      
			break   
		end  
	end  
	return formatted
end

setTimer ( 
function ( )
guiGridListClear( HD.gridlist[1] )
local g = getPlayersSortByaScore( )
for i = 1, 30 do
local row = guiGridListAddRow ( HD.gridlist[1] )
    if ( g [ i ] )then
        guiGridListSetItemText ( HD.gridlist[1], row, column, "" .. i .. "-", false, false )
        guiGridListSetItemText ( HD.gridlist[1], row, column1, getPlayerName ( g [ i ].player ), false, false )
        guiGridListSetItemText ( HD.gridlist[1], row, column2, convertNumber( g [ i ].aScore ), false, false )
        guiGridListSetItemColor(HD.gridlist[1], row, column1, 0, 255, 0)
        guiGridListSetItemColor(HD.gridlist[1], row, column2, 0, 180, 255)
        guiGridListSetItemColor(HD.gridlist[1], row, column, 255, 0, 0)
    end
end
end
, 1000, 0 )

server.lua

function onWasted(_,killer,_,body)
if(killer and getElementType(killer)=="player" and killer~=source)then
setElementData ( killer, "Players Kills", ( getElementData ( killer, "Players Kills" ) or 0 )+1 )
end
end
addEventHandler("onPlayerWasted",root,onWasted)	

addEventHandler ( "onPlayerQuit", root,
	function ( )
		local playerAcc = getPlayerAccount ( source )
		if playerAcc and not isGuestAccount ( playerAcc ) then
			local score = getElementData ( source, "Players Kills" )
			if score then
				setAccountData ( playerAcc, "Players Kills", score )
			end		
		end
	end
)

addEventHandler ( "onPlayerLogin", root,
	function ( _, playerAcc )
		local score = getAccountData ( playerAcc, "Players Kills" )
		if score then
			setTimer ( setElementData, 1000, 1, source, "Players Kills", score )
		end	
	end
)

 

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...