Jump to content

Functions


xeon17

Recommended Posts

Will this work ?

addEventHandler ( "onPlayerWasted", root, 
    function( totalAmmo, killer, killerWeapon, bodypart, stealth ) 
        if killer then 
            local account = getPlayerAccount ( killer ) 
            if killer ~= source then 
                setAccountData( account,"killsdeathsratio.Kills",tonumber( getAccountData( account,"killdeathsratio.Kills" ) or 0 ) +1 ) 
                setElementData( killer, "Kills", tonumber( getAccountData( account,"killsdeathsratio.Kills" ) ) ) 
                setElementData( killer, "Ratio, tonumber(getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) ) 
            end  
        else 
            local accountSource = getPlayerAccount ( source ) 
            setAccountData( accountSource,"killsdeathsratio.Deaths",tonumber( getAccountData(accountSource,"killsdeathsratio.Deaths") or 0 ) +1 ) 
            setElementData( source, "Deaths, tonumber( getAccountData( accountSource,"killsdeathsratio.Deaths" ) ) ) 
            setElementData( source, "Ratio", getElementData( killer, "Kills )/getElementData( source, "Deaths") ) 
        end 
    end 
) 
addEventHandler( "onPlayerLogin",root, 
    function( thePreviousAccount, theCurrentAccount, autoLogin ) 
        local account = getPlayerAccount ( source ) 
        if not getAccountData( account,"killsdeathsratio.Kills" ) and not getAccountData( account,"killsdeathsratio.Deaths" ) then 
            setAccountData( account,"killsdeathsratio.Kills",0 ) 
            setAccountData( account,"killsdeathsratio.Deaths",0 ) 
        end 
        setElementData( source,"Deaths",tonumber( getAccountData( account,"killsdeathsratio.Deaths" ) or 0 ) ) 
        setElementData( source,"Kills,tonumber( getAccountData( account,"killsdeathsratio.Kills" ) or 0 ) ) 
        setElementData( source, "Ratio", getElementData( source, "Kills" )/getElementData( source, "Deaths) ) 
    end 
 ) 
  
  
  
  
 

Link to comment
  • MTA Team

No that will not work.

Try this, and if you get any errors post them:

  
addEventHandler ( "onPlayerWasted", root, 
    function( totalAmmo, killer, killerWeapon, bodypart, stealth ) 
        if killer then 
            local account = getPlayerAccount ( killer ) 
            if killer ~= source then 
                setAccountData( account,"killsdeathsratio.Kills",tonumber( getAccountData( account,"killdeathsratio.Kills" ) or 0 ) +1 ) 
                setElementData( killer, "Kills", tonumber( getAccountData( account,"killsdeathsratio.Kills" ) ) ) 
                setElementData( killer, "Ratio", tonumber(getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) ) 
           end 
       else 
           local accountSource = getPlayerAccount ( source ) 
           setAccountData( accountSource,"killsdeathsratio.Deaths",tonumber( getAccountData(accountSource,"killsdeathsratio.Deaths") or 0 ) +1 ) 
           setElementData( source, "Deaths", tonumber( getAccountData( accountSource,"killsdeathsratio.Deaths" ) ) ) 
            setElementData( source, "Ratio", getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) 
       end 
   end 
) 
  
addEventHandler( "onPlayerLogin",root, 
   function( thePreviousAccount, theCurrentAccount, autoLogin ) 
       local account = getPlayerAccount ( source ) 
       if not getAccountData( account,"killsdeathsratio.Kills" ) and not getAccountData( account,"killsdeathsratio.Deaths" ) then 
           setAccountData( account,"killsdeathsratio.Kills",0 ) 
           setAccountData( account,"killsdeathsratio.Deaths",0 ) 
       end 
       setElementData( source,"Deaths",tonumber( getAccountData( account,"killsdeathsratio.Deaths" ) or 0 ) ) 
       setElementData( source,"Kills",tonumber( getAccountData( account,"killsdeathsratio.Kills" ) or 0 ) ) 
        setElementData( source, "Ratio", getElementData( source, "Kills" )/getElementData( source, "Deaths") ) 
   end 
) 

Link to comment

All is working nice :) but in the scoreboard frist is Deaths after Ratio and Kills. should be Kills,Deaths,Ratio

here the full script :

  
addEventHandler ( "onPlayerWasted", root, 
    function( totalAmmo, killer, killerWeapon, bodypart, stealth ) 
        if killer then 
            local account = getPlayerAccount ( killer ) 
            if killer ~= source then 
                setAccountData( account,"killsdeathsratio.Kills",tonumber( getAccountData( account,"killdeathsratio.Kills" ) or 0 ) +1 ) 
                setElementData( killer, "Kills", tonumber( getAccountData( account,"killsdeathsratio.Kills" ) ) ) 
                setElementData( killer, "Ratio", tonumber(getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) ) 
           end 
       else 
           local accountSource = getPlayerAccount ( source ) 
           setAccountData( accountSource,"killsdeathsratio.Deaths",tonumber( getAccountData(accountSource,"killsdeathsratio.Deaths") or 0 ) +1 ) 
           setElementData( source, "Deaths", tonumber( getAccountData( accountSource,"killsdeathsratio.Deaths" ) ) ) 
            setElementData( source, "Ratio", getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) 
       end 
   end 
) 
  
addEventHandler( "onPlayerLogin",root, 
   function( thePreviousAccount, theCurrentAccount, autoLogin ) 
       local account = getPlayerAccount ( source ) 
       if not getAccountData( account,"killsdeathsratio.Kills" ) and not getAccountData( account,"killsdeathsratio.Deaths" ) then 
           setAccountData( account,"killsdeathsratio.Kills",0 ) 
           setAccountData( account,"killsdeathsratio.Deaths",0 ) 
       end 
       setElementData( source,"Deaths",tonumber( getAccountData( account,"killsdeathsratio.Deaths" ) or 0 ) ) 
       setElementData( source,"Kills",tonumber( getAccountData( account,"killsdeathsratio.Kills" ) or 0 ) ) 
        setElementData( source, "Ratio", getElementData( source, "Kills" )/getElementData( source, "Deaths") ) 
   end 
) 
addEventHandler( "onResourceStart",resourceRoot, 
    function( ) 
        outputDebugString( "add Total Kills to scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Kills",root,5, 0.070 ) 
        ) ) 
         
        outputDebugString( "add Total Kills to scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Deaths",root,5, 0.070 ) 
        ) ) 
         
        outputDebugString( "add Ratio to scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Ratio",root,5, 0.070 ) 
        ) ) 
    end 
) 

an picture : t8vb.png

Picture with my Favorite scoreboard whitch i use :D

f6pz.png

Link to comment
addEventHandler ( "onPlayerWasted", root, 
    function ( totalAmmo, killer, killerWeapon, bodypart, stealth ) 
        if ( killer ) then 
            local account = getPlayerAccount ( killer ) 
            if ( killer ~= source ) then 
                setAccountData ( account, "killsdeathsratio.Kills", tonumber ( getAccountData ( account,"killdeathsratio.Kills" ) or 0 ) + 1 ) 
                setElementData ( killer, "Kills", tonumber ( getAccountData ( account,"killsdeathsratio.Kills" ) ) ) 
                setElementData ( killer, "Ratio", tonumber ( ( getElementData ( killer, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) ) 
           end 
       else 
           local accountSource = getPlayerAccount ( source ) 
           setAccountData ( accountSource, "killsdeathsratio.Deaths", tonumber ( getAccountData ( accountSource, "killsdeathsratio.Deaths" ) or 0 ) + 1 ) 
           setElementData ( source, "Deaths", tonumber ( getAccountData ( accountSource, "killsdeathsratio.Deaths" ) ) ) 
           setElementData ( source, "Ratio", ( getElementData ( source, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) 
       end 
   end 
) 
  
addEventHandler ( "onPlayerLogin", root, 
   function ( thePreviousAccount, theCurrentAccount, autoLogin ) 
        local account = getPlayerAccount ( source ) 
        if ( not getAccountData ( account, "killsdeathsratio.Kills" ) and not getAccountData ( account, "killsdeathsratio.Deaths" ) ) then 
           setAccountData ( account,"killsdeathsratio.Kills", 0 ) 
           setAccountData ( account,"killsdeathsratio.Deaths", 0 ) 
       end 
       setElementData ( source, "Deaths",tonumber ( getAccountData ( account, "killsdeathsratio.Deaths" ) or 0 ) ) 
       setElementData ( source, "Kills",tonumber ( getAccountData ( account, "killsdeathsratio.Kills" ) or 0 ) ) 
       setElementData ( source, "Ratio", ( getElementData ( source, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) 
   end 
) 
addEventHandler( "onResourceStart",resourceRoot, 
    function( ) 
        outputDebugString( "add Total Kills to scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Kills",root,5, 0.070 ) 
        ) ) 
        
        outputDebugString( "add Total Kills to scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Deaths",root,5, 0.070 ) 
        ) ) 
        
        outputDebugString( "add Ratio to scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Ratio",root,5, 0.070 ) 
        ) ) 
    end 
) 

Link to comment
  • MTA Team

As for the order check the export variables:

bool scoreboardAddColumn ( string name, [ element forElement = getRootElement(), int width = 70, string friendlyName = name, int priority = slot after "name" column ] ) 

Priority is were you should set the order for the column

Link to comment
  • 3 months later...
addEventHandler ( "onPlayerWasted", root, 
    function ( totalAmmo, killer, killerWeapon, bodypart, stealth ) 
        if ( killer ) then 
            local account = getPlayerAccount ( killer ) 
            if ( killer ~= source ) then 
                setAccountData ( account, "killsdeathsratio.Kills", tonumber ( getAccountData ( account,"killdeathsratio.Kills" ) or 0 ) + 1 ) 
                setElementData ( killer, "Kills", tonumber ( getAccountData ( account,"killsdeathsratio.Kills" ) ) ) 
                setElementData ( killer, "Ratio", tonumber ( ( getElementData ( killer, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) ) 
           end 
       else 
           local accountSource = getPlayerAccount ( source ) 
           setAccountData ( accountSource, "killsdeathsratio.Deaths", tonumber ( getAccountData ( accountSource, "killsdeathsratio.Deaths" ) or 0 ) + 1 ) 
           setElementData ( source, "Deaths", tonumber ( getAccountData ( accountSource, "killsdeathsratio.Deaths" ) ) ) 
           setElementData ( source, "Ratio", ( getElementData ( source, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) 
       end 
   end 
) 
  
addEventHandler ( "onPlayerLogin", root, 
   function ( thePreviousAccount, theCurrentAccount, autoLogin ) 
        local account = getPlayerAccount ( source ) 
        if ( not getAccountData ( account, "killsdeathsratio.Kills" ) and not getAccountData ( account, "killsdeathsratio.Deaths" ) ) then 
           setAccountData ( account,"killsdeathsratio.Kills", 0 ) 
           setAccountData ( account,"killsdeathsratio.Deaths", 0 ) 
       end 
       setElementData ( source, "Deaths",tonumber ( getAccountData ( account, "killsdeathsratio.Deaths" ) or 0 ) ) 
       setElementData ( source, "Kills",tonumber ( getAccountData ( account, "killsdeathsratio.Kills" ) or 0 ) ) 
       setElementData ( source, "Ratio", ( getElementData ( source, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) 
   end 
) 
addEventHandler( "onResourceStart",resourceRoot, 
    function( ) 
        outputDebugString( "add Total Kills to scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Kills",root,5, 0.070 ) 
        ) ) 
        
        outputDebugString( "add Total Kills to scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Deaths",root,5, 0.070 ) 
        ) ) 
        
        outputDebugString( "add Ratio to scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Ratio",root,5, 0.070 ) 
        ) ) 
    end 
) 

    "EufraT" name="Event" version="2.0.0" type="script" description="Bases"/> 
    

As think i no changed nothing , i only use the script on a other server , it saves deaths but no kills

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...