Jump to content

Question


xeon17

Recommended Posts

i wanna crate a script , when player enter server when he login that his name get changed to his account name.

i added a login/register system when someone join server , extample his name was : XeonsDK

when he login to his account ''EufraT'' his name get changed to ''EufraT'' not more XeonsDK.

What functions i need to use for this?

And how to crate save player score , extample when player quit his kills,deaths and kdr get saved in his account.

Link to comment

Thank you , but is there any way to disable that players can change name. This script is great , but players can change their name after. :/:(

I use this scores system :

local root = getRootElement() 
local scoresRoot = getResourceRootElement(getThisResource()) 
  
local scoreColumns = {"kills", "deaths", "self", "ratio", "status"} 
local isColumnActive = {} 
  
local KDR_DECIMAL_PLACES = 2 
  
--http://lua-users.org/wiki/SimpleRound 
local function round(num, idp) 
    local mult = 10^(idp or 0) 
    return math.floor(num * mult + 0.5) / mult 
end 
  
local function setScoreData (element, column, data) 
    if isColumnActive[column] then 
        setElementData(element, column, data) 
    end 
end 
  
local function resetScores (element) 
    setScoreData(element, "kills", 0) 
    setScoreData(element, "deaths", 0) 
    setScoreData(element, "self", 0) 
    setScoreData(element, "ratio", "-") 
    local status = "" 
    if isPedDead(element) then 
        status = "Dead" 
    end 
    setScoreData(element, "status", status) 
end 
  
local function updateRatio (element) 
    local deaths = getElementData(element, "deaths") 
    if deaths == 0 then 
        setScoreData(element, "ratio", "-") 
    else 
        local kdr = round(getElementData(element, "kills") / deaths, KDR_DECIMAL_PLACES) 
        setScoreData(element, "ratio", tostring(kdr)) 
    end 
end 
  
function updateActiveColumns () 
    for i, column in ipairs(scoreColumns) do 
        if get(column) then 
            isColumnActive[column] = true 
            exports.scoreboard:addScoreboardColumn(column) 
        elseif isColumnActive[column] then 
            isColumnActive[column] = false 
            exports.scoreboard:removeScoreboardColumn(column) 
        end 
    end 
end 
  
addEventHandler("onResourceStart", scoresRoot, 
    function () 
        updateActiveColumns() 
        for i, player in ipairs(getElementsByType("player")) do 
            resetScores(player) 
        end 
    end 
) 
  
addEventHandler("onResourceStop", scoresRoot, 
    function () 
        for i, column in ipairs(scoreColumns) do 
            if isColumnActive[column] then 
                exports.scoreboard:removeScoreboardColumn(column) 
            end 
        end 
    end 
) 
  
addEventHandler("onPlayerJoin", root, 
    function () 
        resetScores(source) 
    end 
) 
  
addEventHandler("onPlayerWasted", root, 
    function (ammo, killer, weapon) 
        if killer then 
            if killer ~= source then 
                -- killer killed victim 
                setScoreData(killer, "kills", getElementData(killer, "kills") + 1) 
                setScoreData(source, "deaths", getElementData(source, "deaths") + 1) 
                if isColumnActive["ratio"] then 
                    updateRatio(killer) 
                    updateRatio(source) 
                end 
            else 
                -- victim killed himself 
                setScoreData(source, "self", getElementData(source, "self") + 1) 
            end 
        else 
            -- victim died 
            setScoreData(source, "deaths", getElementData(source, "deaths") + 1) 
            if isColumnActive["ratio"] then 
                updateRatio(source) 
            end 
        end 
         
        setScoreData(source, "status", "Dead") 
    end 
) 
  
addEventHandler("onPlayerSpawn", root, 
    function () 
        setScoreData(source, "status", "") 
    end 
) 
  
addCommandHandler("score", 
    function (player) 
        if player then 
            for i, column in ipairs(scoreColumns) do 
                if column == "status" then 
                    break 
                end 
                if isColumnActive[column] then 
                    exports.scoreboard:addScoreboardColumn(column) 
                    outputConsole(column .. ": " .. getElementData(player, column), player) 
                end 
            end 
        end 
    end 
) 

There is another Scores system who save score of players in their accounts when they logout , but is full of bugs.

addEventHandler ( "onPlayerWasted", root, 
    function( totalAmmo, killer, killerWeapon, bodypart, stealth ) 
        if killer then 
            local account = getPlayerAccount ( killer ) 
            if killer ~= source then 
                setAccountData( account,"totalkillsdeaths.Kills",tonumber( getAccountData( account,"totalkillsdeaths.Kills" ) or 0 ) +1 ) 
                setElementData( killer, "Kills", tonumber( getAccountData( account,"totalkillsdeaths.Kills" ) ) ) 
                setElementData( killer, "ratio", tonumber(getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) ) 
            end  
        else 
            local accountSource = getPlayerAccount ( source ) 
            setAccountData( accountSource,"totalkillsdeaths.Deaths",tonumber( getAccountData(accountSource,"totalkillsdeaths.Deaths") or 0 ) +1 ) 
            setElementData( source, "Deaths", tonumber( getAccountData( accountSource,"totalkillsdeaths.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,"totalkillsdeaths.Kills" ) and not getAccountData( account,"totalkillsdeaths.Deaths" ) then 
            setAccountData( account,"totalkillsdeaths.Kills",0 ) 
            setAccountData( account,"totalkillsdeaths.Deaths",0 ) 
        end 
        setElementData( source,"Deaths",tonumber( getAccountData( account,"totalkillsdeaths.Deaths" ) or 0 ) ) 
        setElementData( source,"Kills",tonumber( getAccountData( account,"totalkillsdeaths.Kills" ) or 0 ) ) 
        setElementData( source, "ratio", getElementData( source, "Kills" )/getElementData( source, "T/D") ) 
    end 
 ) 
  
addEventHandler( "onResourceStart",resourceRoot, 
    function( ) 
        outputDebugString( "add Total Kills to scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Kills",root,2, 0.032 ) 
        ) ) 
         
        outputDebugString( "add ratioto scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "ratio",root,4, 0.047 ) 
        ) ) 
         
        outputDebugString( "add Total Deaths to scoreboard Return: "..tostring( 
            call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Deaths",root,3, 0.032 ) 
        ) ) 
    end 
) 
  

is there any way to save the scores of the frist scores system in accounts , when play logout

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