Jump to content

help in my cod


XPro

Recommended Posts

i need to get name player who have best killes in sniper (just the gun sniper)

addEventHandler("onPlayerWasted",getRootElement(), 
function ( ammo, attacker, weapon, bodypart ) 
    if attacker then 
        if ( attacker ~= source and getElementType ( attacker ) == "player" ) then 
        local playergun =  getWeaponNameFromID  ( attacker ) 
            if ( playergun == 34 ) then 
            setElementData ( attacker, "kills" ) 
                end 
            end 
        end 
    end 
) 
  
  
-- 
Snipers = { } 
  
addEventHandler("onElementDataChange",root, 
function (dataName) 
    if dataName == "kills" then 
        for _,v in ipairs (getElementsByType ("player")) do 
            table.insert ( Snipers, { getPlayerName(v), ( getElementData ( v, "kills" ) or 0 ) }) 
        end 
    table.sort (Snipers,function (v1, v2)return v1[2] > v2[2]end) 
    outputChatBox (Snipers[1][1].." - "..Snipers[1][2]) 
    end 
end ) 

cod no work

debug said = Bad argument @ 'getWeaponNameFromID' [Expected number at argument 1,got player ]

+ after fix the cod how to get sccore the player who have best killes sniper

because i need to get hes name + sccor

+ how to put hes name and sccore in GUI use gridlist + row ....?

+ soory for my bad english xD

Link to comment
local snipers = {} -- snipers table 
  
addEventHandler("onPlayerWasted",getRootElement(), 
    function ( ammo, attacker, weapon, bodypart ) 
        if attacker and getElementType ( attacker ) == "player" and attacker ~= source then 
            if tonumber(weapon) == 34 then 
                snipers[attacker] = (snipers[attacker] or 0) + 1 
            end 
        end 
    end 
) 
  
-- Table sort  
  
function topSniper() 
    sortedTopSniper = {} 
    for a, b in pairs(snipers) do 
        table.insert(sortedTopSniper, {getPlayerName(a), b}) 
    end 
    table.sort(sortedTopSniper, function(a,b) return a[2] > b[2] 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...