Jump to content

Need help here...


GTX

Recommended Posts

Here seems to be wrong this: if getElementData(source, "state") == "dead" then...

I can't get it... It's working fine if I delete that code

Code:

function earnMoney() 
    local position = getAliveRacePlayers() 
    local acc = getPlayerAccount(source) 
    if getElementData(source, "state") == "dead" then 
    else 
  
    if not (position <= 0) then 
        if getPlayerCount() >= count then 
            local pAlive = getAliveRacePlayers() 
            local pDead = getDeadRacePlayers() 
  
            local maxCash = 21*(pAlive+pDead)   -- Total cash available to earn. 
            local portion = 0 
            local finalCash = 0 
  
            if not (position == 1) then 
                portion = math.ceil(maxCash/(pAlive+pDead-1))       -- The amount to multiply by the number of dead players to later return the money value. 
                finalCash = math.ceil(portion*(pDead))      -- Calculate the final money value. 
            else 
                finalCash = maxCash 
            end 
            local playerCash = getAccountData(acc,"Cash") or 0 
            outputChatBox("#FFFFFF>> #ff8600You have recieved $" .. finalCash .. "!",source,255,255,255,true) 
            setAccountData(acc,"Cash", tostring(playerCash) + finalCash) 
            outputDebugString("Final cash for player "..getPlayerName(source)..": "..finalCash) 
        else 
            outputChatBox("#FFFFFF>> #ff0000Need atleast " .. count .. " players to affect the stats!", source, 255, 255, 255, true) 
            return 
        end 
        scoreboardRefresh(source) 
    end 
end 
end 
addEventHandler("onPlayerWasted", getRootElement(), earnMoney) 

Link to comment
  
function earnMoney(old, new) 
    if old == "alive" and new == "dead" then 
    local position = getAliveRacePlayers() 
    local acc = getPlayerAccount(source) 
   -- Missing part? 
    else 
    if not (position <= 0) then 
        if getPlayerCount() >= count then 
            local pAlive = getAliveRacePlayers() 
            local pDead = getDeadRacePlayers() 
  
            local maxCash = 21*(pAlive+pDead)   -- Total cash available to earn. 
            local portion = 0 
            local finalCash = 0 
  
            if not (position == 1) then 
                portion = math.ceil(maxCash/(pAlive+pDead-1))       -- The amount to multiply by the number of dead players to later return the money value. 
                finalCash = math.ceil(portion*(pDead))      -- Calculate the final money value. 
            else 
                finalCash = maxCash 
            end 
            local playerCash = getAccountData(acc,"Cash") or 0 
            outputChatBox("#FFFFFF>> #ff8600You have recieved $" .. finalCash .. "!",source,255,255,255,true) 
            setAccountData(acc,"Cash", tostring(playerCash) + finalCash) 
            outputDebugString("Final cash for player "..getPlayerName(source)..": "..finalCash) 
        else 
            outputChatBox("#FFFFFF>> #ff0000Need atleast " .. count .. " players to affect the stats!", source, 255, 255, 255, true) 
            return 
        end 
        scoreboardRefresh(source) 
    end 
end 
end 
addEventHandler("onPlayerWasted", getRootElement(), earnMoney) 

Try it :)

Btw , your ingame nick is : GTX ?

Link to comment
function earnMoney( ) 
    local position = getAliveRacePlayers( ) 
    local acc = getPlayerAccount( source ) 
    if not getElementData( source, "state" ) == "dead" then 
        if not isGuestAccount( acc ) then 
            if type( count ) == 'number' then 
                if not position <= 0 then 
                    if getPlayerCount( ) >= count then 
                        local pAlive = getAliveRacePlayers( ) 
                        local pDead = getDeadRacePlayers( ) 
          
                        local maxCash = 21*( pAlive + pDead )   -- Total cash available to earn. 
                        local portion = 0 
                        local finalCash = 0 
          
                        if not position == 1 then 
                            portion = math.ceil( maxCash/( pAlive+pDead-1 ) )       -- The amount to multiply by the number of dead players to later return the money value. 
                            finalCash = math.ceil( portion*( pDead ) )      -- Calculate the final money value. 
                        else 
                            finalCash = maxCash 
                        end 
                        local playerCash = getAccountData( acc,"Cash" ) or 0 
                        outputChatBox("#FFFFFF>> #ff8600You have recieved $" .. tostring( finalCash ) .. "!",source,255,255,255,true) 
                        setAccountData( acc,"Cash", tostring( playerCash ) + finalCash ) 
                        outputDebugString( "Final cash for player "..getPlayerName( source )..": "..tostring( finalCash ) ) 
                    else 
                        outputChatBox( "#FFFFFF>> #ff0000Need atleast " .. tostring( count ).. " players to affect the stats!", source, 255, 255, 255, true) 
                        return 
                    end 
                    scoreboardRefresh( source ) 
                end 
            else 
                outputChatBox( 'count variable is not number' ) 
            end  
        end  
    end 
end 
addEventHandler( "onPlayerWasted", root, earnMoney ) 

/debugscript 3 use pls.

Link to comment

Test it and say what output.

function earnMoney( ) 
    local position = getAliveRacePlayers( ) 
    outputChatBox( 'var:position '..tostring( position ) ) 
    local acc = getPlayerAccount( source ) 
    outputChatBox( 'var:acc '..tostring( acc ) ) 
    outputChatBox( 'var:count '..tostring( count ) ) 
    if not getElementData( source, "state" ) == "dead" then 
        outputChatBox( 'state == dead ' ) 
        if not isGuestAccount( acc ) then 
            outputChatBox( ' not guest account ' ) 
            if type( count ) == 'number' then 
                outputChatBox( 'var:count == number' ) 
                if not position <= 0 then 
                    outputChatBox( 'not positon <= 0' ) 
                    if getPlayerCount( ) >= count then 
                        outputChatBox( 'getPlayerCount( ) >= count' ) 
                        local pAlive = getAliveRacePlayers( ) 
                        local pDead = getDeadRacePlayers( ) 
                        outputChatBox( 'var:pAlive '..tostring( pAlive ) ) 
                        outputChatBox( 'var:pDead '..tostring( pDead ) ) 
                         
                        local maxCash = 21*( pAlive + pDead )   -- Total cash available to earn. 
                        local portion = 0 
                        local finalCash = 0 
          
                        if not position == 1 then 
                            portion = math.ceil( maxCash/( pAlive+pDead-1 ) )       -- The amount to multiply by the number of dead players to later return the money value. 
                            finalCash = math.ceil( portion*( pDead ) )      -- Calculate the final money value. 
                        else 
                            finalCash = maxCash 
                        end 
                        local playerCash = getAccountData( acc,"Cash" ) or 0 
                        outputChatBox( 'var:playerCash '..tostring( playerCash ) ) 
                        outputChatBox("#FFFFFF>> #ff8600You have recieved $" .. tostring( finalCash ) .. "!",source,255,255,255,true) 
                        setAccountData( acc,"Cash", tostring( playerCash ) + finalCash ) 
                        outputDebugString( "Final cash for player "..getPlayerName( source )..": "..tostring( finalCash ) ) 
                    else 
                        outputChatBox( "#FFFFFF>> #ff0000Need atleast " .. tostring( count ).. " players to affect the stats!", source, 255, 255, 255, true) 
                        return 
                    end 
                    scoreboardRefresh( source ) 
                end 
            else 
                outputChatBox( 'count variable is not number' ) 
            end  
        else 
            outputChatBox( 'guest account ' ) 
        end  
    end 
end 
addEventHandler( "onPlayerWasted", root, earnMoney ) 

Link to comment
I got 'state' from race resource, so if player's state is 'dead' then...

You want check if player not dead but dead? :D

function earnMoney( ) 
    local position = getAliveRacePlayers( ) 
    outputChatBox( 'var:position '..tostring( position ) ) 
    local acc = getPlayerAccount( source ) 
    outputChatBox( 'var:acc '..tostring( acc ) ) 
    outputChatBox( 'var:count '..tostring( count ) ) 
    --if getElementData( source, "state" ) == "dead" then 
        outputChatBox( 'state == dead ' ) 
        if not isGuestAccount( acc ) then 
            outputChatBox( ' not guest account ' ) 
            if type( count ) == 'number' then 
                outputChatBox( 'var:count == number' ) 
                if not position <= 0 then 
                    outputChatBox( 'not positon <= 0' ) 
                    if getPlayerCount( ) >= count then 
                        outputChatBox( 'getPlayerCount( ) >= count' ) 
                        local pAlive = getAliveRacePlayers( ) 
                        local pDead = getDeadRacePlayers( ) 
                        outputChatBox( 'var:pAlive '..tostring( pAlive ) ) 
                        outputChatBox( 'var:pDead '..tostring( pDead ) ) 
                         
                        local maxCash = 21*( pAlive + pDead )   -- Total cash available to earn. 
                        local portion = 0 
                        local finalCash = 0 
          
                        if not position == 1 then 
                            portion = math.ceil( maxCash/( pAlive+pDead-1 ) )       -- The amount to multiply by the number of dead players to later return the money value. 
                            finalCash = math.ceil( portion*( pDead ) )      -- Calculate the final money value. 
                        else 
                            finalCash = maxCash 
                        end 
                        local playerCash = getAccountData( acc,"Cash" ) or 0 
                        outputChatBox( 'var:playerCash '..tostring( playerCash ) ) 
                        outputChatBox("#FFFFFF>> #ff8600You have recieved $" .. tostring( finalCash ) .. "!",source,255,255,255,true) 
                        setAccountData( acc,"Cash", tostring( playerCash ) + finalCash ) 
                        outputDebugString( "Final cash for player "..getPlayerName( source )..": "..tostring( finalCash ) ) 
                    else 
                        outputChatBox( "#FFFFFF>> #ff0000Need atleast " .. tostring( count ).. " players to affect the stats!", source, 255, 255, 255, true) 
                        return 
                    end 
                    scoreboardRefresh( source ) 
                end 
            else 
                outputChatBox( 'count variable is not number' ) 
            end  
        else 
            outputChatBox( 'guest account ' ) 
        end  
    --end 
end 
addEventHandler( "onPlayerWasted", root, earnMoney ) 

You not need check it :lol:

Code updated.

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