Jump to content

[RACE] Ranking Script - HELP PLEASE


Bkrickl

Recommended Posts

function giveMoneyWinDie ( ) 
    local account = getPlayerAccount ( source ); 
    local playersAlive = getAliveGuys ( 2 ); 
    local playersDead = getDeadGuys ( ); 
    local pAll = playersAlive + playersDead; 
    local checkYourPos = pAll - playersDead; 
    local pos = nil; 
    if tonumber ( checkYourPos ) == 1 then pos = 1 else pos = checkYourPos + 1; end 
    if tonumber ( checkYourPos ) == 2 then pos = 2; end 
    if pos == 1 or pos == 21 or pos == 31 then 
        posName = "st"; 
    elseif pos == 2 or pos == 22 or pos == 32 then 
        posName = "nd"; 
    elseif pos == 3 or pos == 23 or pos == 33 then 
        posName = "rd"; 
    else 
        posName = "th"; 
    end 
    if not getElementData ( source, "gotMoney" ) then 
        local mother = getPlayerCount ( ) 
        if mother == 1 then 
        outputChatBox ( "* There are #abcdef2#FFFFFF or more players #abcdefneeded #FFFFFFto earn money!",source, 255, 255, 255, true ); 
        else 
        local money = math.ceil ( getPlayerCount ( ) * 50 / pos ); 
        givePlayerMoney ( source, money ); 
        outputChatBox ( "* You were #abcdef[#ff0000" .. pos .. posName .. "#abcdef]#ffffff and #abcdefearned #ffffff" .. money .. "#00ff00$!", source, 255, 255, 255, true ); 
        local hi = getPlayerName(source) 
        outputChatBox ( "* "..hi.."#ffffff was #abcdef[#ff0000" .. pos .. posName .. "#abcdef]",g_Root, 255, 255, 255, true ); 
        setElementData ( source, "gotMoney", true ); 
        if account then 
            setAccountData ( account, "money", tostring ( getPlayerMoney ( source ) ) ); 
        end 
        end 
    end 
end 
addEventHandler ( "onPlayerWasted", root , giveMoneyWinDie ) 

I tried this for everybody get money when he waste in Dm Racing.

3rd get 50

2nd get xxx and so

but it doesnt work like it should

sometimes everybody ist 1st or everybody ist 4th or s.th. like this

Kann anyboday help me please :)

Link to comment

Sory here is the full code!

function getAliveGuys ( mode ) 
    if not mode then return end 
    if mode == 1 then 
        pAlive = { }; 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            if ( getElementData ( player, "state" ) == "alive" ) then 
                table.insert ( pAlive, player ); 
            end 
        end 
        return pAlive; 
    elseif mode == 2 then 
        return #pAlive; 
    elseif mode == 3 then 
        if pAlive then 
            pAlive = nil; 
        end 
        return false 
    end 
end 
  
function getDeadGuys ( ) 
    local pDead = 0 
    for _, player in ipairs ( getElementsByType ( "player" ) ) do 
        if getElementData ( player, "state" ) == "dead" then 
            pDead = pDead + 1; 
        end 
    end 
    return pDead; 
end 
  
function giveMoneyWinDie ( ) 
    local account = getPlayerAccount ( source ); 
    local playersAlive = getAliveGuys ( 2 ); 
    local playersDead = getDeadGuys ( ); 
    local pAll = playersAlive + playersDead; 
    local checkYourPos = pAll - playersDead; 
    local pos = nil; 
    if tonumber ( checkYourPos ) == 1 then pos = 1 else pos = checkYourPos + 1; end 
    if tonumber ( checkYourPos ) == 2 then pos = 2; end 
    if pos == 1 or pos == 21 or pos == 31 then 
        posName = "st"; 
    elseif pos == 2 or pos == 22 or pos == 32 then 
        posName = "nd"; 
    elseif pos == 3 or pos == 23 or pos == 33 then 
        posName = "rd"; 
    else 
        posName = "th"; 
    end 
    if not getElementData ( source, "gotMoney" ) then 
        local mother = getPlayerCount ( ) 
        if mother == 1 then 
        outputChatBox ( "* There are #abcdef2#FFFFFF or more players #abcdefneeded #FFFFFFto earn money!",source, 255, 255, 255, true ); 
        else 
        local money = math.ceil ( getPlayerCount ( ) * 50 / pos ); 
        givePlayerMoney ( source, money ); 
        outputChatBox ( "* You were #abcdef[#ff0000" .. pos .. posName .. "#abcdef]#ffffff and #abcdefearned #ffffff" .. money .. "#00ff00$!", source, 255, 255, 255, true ); 
        local hi = getPlayerName(source) 
        outputChatBox ( "* "..hi.."#ffffff was #abcdef[#ff0000" .. pos .. posName .. "#abcdef]",g_Root, 255, 255, 255, true ); 
        setElementData ( source, "gotMoney", true ); 
        if account then 
            setAccountData ( account, "money", tostring ( getPlayerMoney ( source ) ) ); 
        end 
        end 
    end 
end 
addEventHandler ( "onPlayerWasted", root , giveMoneyWinDie ) 

Link to comment
function getAliveGuys ( mode )] --you call it with mode 2  
    if not mode then return end 
    if mode == 1 then 
        pAlive = { }; --table created in mode 1 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            if ( getElementData ( player, "state" ) == "alive" ) then 
                table.insert ( pAlive, player ); 
            end--closed if 
        end -- closed for 
        return pAlive; 
    elseif mode == 2 then -- mode 2 
        return #pAlive;-- returning a tabel witch one was not created bk you call mode = 2 and the table is creaded in mode 1 
  
  
  

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