Jump to content

[Ayuda] Top Player Killers


Narutimmy

Recommended Posts

Podrías comenzar por usar 'getAccounts' y 'table.sort'.

encontre este en el forum pero solo muestra de los que estan conectados.

------------------- 
  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 
    
   WindowTOP = guiCreateWindow(328, 125, 613, 514, "", false) 
   guiSetProperty(WindowTOP, "CaptionColour", "FF00FF00") 
   guiSetVisible(WindowTOP, false) 
   guiWindowSetSizable(WindowTOP, false) 
   guiWindowSetMovable(WindowTOP, false) 
   centerWindow ( WindowTOP ) 
   GridListTOP = guiCreateGridList(9, 27, 594, 477, false, WindowTOP) 
   guiGridListAddColumn(GridListTOP, "Rank", 0.2) 
   guiGridListAddColumn(GridListTOP, "Name", 0.2) 
   ---guiGridListAddColumn(GridListTOP, "Money", 0.2) 
   guiGridListAddColumn(GridListTOP, "Kills", 0.2) 
   ---guiGridListAddColumn(GridListTOP, "Deaths", 0.1) 
    
function U ( ) 
    guiGridListClear ( GridListTOP ) 
    local players = getPlayersSortByKills ( ) 
    for i = 1, 30 do 
        if ( players [ i ] )then 
            local row = guiGridListAddRow ( GridListTOP ) 
            guiGridListSetItemText( GridListTOP, row, 1, i ..'-', false, false ) 
            guiGridListSetItemColor( GridListTOP, row, 1, 0, 0, 255 )   
            guiGridListSetItemText( GridListTOP, row, 2, getPlayerName ( players [ i ].element ), false, false ) 
            guiGridListSetItemColor( GridListTOP, row, 2, 255, 255, 0 ) 
            guiGridListSetItemText( GridListTOP, row, 3, tostring ( players [ i ].kills ), false, false ) 
            guiGridListSetItemColor ( GridListTOP, row, 3, 255, 0, 0 ) 
            ---guiGridListSetItemText ( GridListTOP, row, 4, tostring ( players [ i ].deaths ), false, false ) 
            guiGridListSetItemColor ( GridListTOP, row, 4,  250, 154, 255 )               
        end 
    end 
end 
  
function getPlayersSortByKills ( ) 
    local players = { } 
    for _, player in ipairs ( getAccounts () ) do 
        table.insert ( 
            players, 
            { 
                element = player, 
                kills = getElementData ( player, "Kills" ) or 0, 
                deaths = getElementData ( player, "Deaths" ) or 0, 
            } 
        ) 
    end 
  
    table.sort ( 
        players, 
        function ( a, b ) 
            return ( tonumber ( a.kills ) or 0 ) > ( tonumber ( b.kills ) or 0 ) 
        end 
    ) 
  
    return players 
end 
  
bindKey ( "F3" , "down" , 
    function () 
        if guiGetVisible ( WindowTOP , true ) then 
            guiSetVisible ( WindowTOP , false ) 
            showCursor ( false ) 
            outputChatBox ( "Closed" , 255 , 0 , 0 , true ) 
        else 
            guiSetVisible ( WindowTOP , true ) 
            showCursor ( true ) 
            outputChatBox ( "Opened" , 0 , 255 , 0 , true ) 
            U ( ) 
        end 
    end 
) 
  
  

Link to comment

Encontre este otro, pero me da error, y en la tabla todo dice "false"

en el sv:

JwQ0IO8.png

sv:

-------- 
addEventHandler( 'onResourceStart', getResourceRootElement(getThisResource()), 
    function( ) 
        outputChatBox(" Top-50 Players ", root, 255, 125, 0,true) 
        outputChatBox("Press F5 To Open top 50 Players", root, 50, 255, 0,true) 
    end 
) 
  
function getPlayerFromNamePart(name) 
    if name then 
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player 
            end 
        end 
    end 
    return false 
end 
  
function createTopSystem( player ) 
    if not isElement( player ) then 
        return 
    end 
    local Top = {} 
    for i = 1, #CreatTop do ---linea 743 
        table.insert(Top,{name = CreatTop[i].Name,score = CreatTop[i].Score}) 
    end 
    if #CreatTop >0 then 
        table.sort(Top, function(a,b) return (tonumber(a.score)or 0) > (tonumber(b.score)or 0) end) 
    setTimer( 
    function() 
        for k, data in ipairs(Top) do 
            if k == 1 then 
                triggerClientEvent (player,"deltTop",player) 
            end  
            triggerClientEvent (player,"updateTop",player,tostring(data.name),tostring(data.score),tonumber(k)) 
            triggerClientEvent (player,"updateTop",player,tostring(data.deaths),tostring(data.score),tonumber(k)) 
            triggerClientEvent (player,"updateTop",player,tostring(data.kills),tostring(data.score),tonumber(k)) 
            if k == 30 then 
                    table.remove(Top) 
                break 
            end 
        end 
    end, 
        500, 
    1 
    ) 
    end 
end 
  
function setAcontSqlData( player, top, name) 
    if not isElement( player ) then 
        return 
    end 
    if isGuestAccount ( getPlayerAccount ( player ) ) then return end 
    result = executeSQLQuery("SELECT * FROM `Kills` WHERE `Owner`=?", getAccountName(getPlayerAccount( player ))) 
    result = executeSQLQuery("SELECT * FROM `Deaths` WHERE `Owner`=?", getAccountName(getPlayerAccount( player ))) 
    if ( type ( result ) == "table" and #result == 0 ) or not result then 
        executeSQLQuery( 'INSERT INTO kills( Owner, Score , Name) VALUES( ?, ?, ? )', getAccountName(getPlayerAccount( player )), top, name) 
    else 
        if tonumber ( top ) < tonumber( result[1]["Score"] ) then top = result[1]["Score"] else top = top end 
        executeSQLQuery( 'UPDATE kills SET Score =?,Name =? WHERE Owner =?', top, name, getAccountName(getPlayerAccount( player ))) 
    end 
end 
  
addEventHandler("onElementDataChange",root, 
    function (data) 
        if ( data == "deaths" ) and getElementType(source) == "player" then 
            local deaths = getElementData(source,data) 
        end 
        if ( data == "kills" ) and getElementType(source) == "player" then 
            local kills = getElementData(source,data) 
        end         
    end 
) 
  
addEvent("getTop", true) 
addEventHandler("getTop", root, 
    function() 
        createTopSystem( source ) 
    end 
) 

Client:

local Key = "F3" --- bind key 
  
HD = { 
    gridlist = {50}, 
    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 50", false) 
guiWindowSetSizable(HD.wnd, false) 
guiSetAlpha(HD.wnd, 1.00) 
guiSetProperty(HD.wnd, "CaptionColour", "FF200AF3") 
centerWindow(HD.wnd) 
HD.gridlist[1] = guiCreateGridList(20, 34, 432, 502, false, HD.wnd) 
local column = guiGridListAddColumn(HD.gridlist[1], "Rank", 0.20 ) -- Create a 'rank' column in the list 
local column1 = guiGridListAddColumn(HD.gridlist[1], "Player Name", 0.40 ) -- Create a 'players' column in the list 
local column2 = guiGridListAddColumn(HD.gridlist[1], "Kills", 0.30 ) -- Create a 'Kills' column in the list 
local column3 = guiGridListAddColumn(HD.gridlist[1], "Deaths", 0.30 ) -- Create a 'Kills' column in the list 
for i = 1,50 do 
local row = guiGridListAddRow ( HD.gridlist[1] ) 
guiGridListSetItemText ( HD.gridlist[1], row, column, "" .. i .. "-", false, false ) 
guiGridListSetItemText ( HD.gridlist[1], row, column1, "false", false, false ) 
guiGridListSetItemText ( HD.gridlist[1], row, column2, "0", false, false ) 
guiGridListSetItemText ( HD.gridlist[1], row, column3, "0", 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 
guiSetVisible(HD.wnd, not guiGetVisible(HD.wnd)) 
  
bindKey (Key, "down", 
    function() 
        guiSetVisible(HD.wnd, not guiGetVisible(HD.wnd)) 
        showCursor(guiGetVisible(HD.wnd)) 
        triggerServerEvent("getTop", 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(name, top, i) 
local row = guiGridListAddRow ( HD.gridlist[1] ) 
guiGridListSetItemText ( HD.gridlist[1], row, column, "" .. i .. "-", false, false ) 
guiGridListSetItemText ( HD.gridlist[1], row, column1, tostring(name), false, false ) 
guiGridListSetItemText ( HD.gridlist[1], row, column2, tostring(kills), false, false ) 
guiGridListSetItemText ( HD.gridlist[1], row, column3, tostring(deaths), 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("updateTop", true) 
addEventHandler("updateTop", root, updateTopList) 
  
function update() 
guiGridListClear(HD.gridlist[1]) 
end 
addEvent("deltTop", true) 
addEventHandler("deltTop", root, update) 

Link to comment

¿Cuál es la linea 743 en ese pedazo de código?

¿Porque no utilizas la de AlGraB? Obviamente si nunca utilizaste alguna forma para guardar los kills desde que se registra por ejemplo un SQL, los kills solo contaran desde que agregues el panel.

Link to comment
¿Cuál es la linea 743 en ese pedazo de código?

¿Porque no utilizas la de AlGraB? Obviamente si nunca utilizaste alguna forma para guardar los kills desde que se registra por ejemplo un SQL, los kills solo contaran desde que agregues el panel.

en el codigo espesifique la line , necesito hacer uno nuevo porque tendra otro uso.

Link to comment
  • Recently Browsing   0 members

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