Jump to content

Money when finishing a map not working


Mossy

Recommended Posts

function raceWin(rank) 
    if rank ~= 1 then 
    return  
    end 
    local playername = getPlayerName(source) 
    givePlayerMoney(source,1000)---money what player get if he finish.(Default=1000) 
    outputChatBox("* "..playername.." took $1000 for being the last survivor!",root,51,153,255) 
end 
addEventHandler("onPlayerFinish", root, raceWin ) 

Made this for DD. Doesn't seem to be working. No errors in debug. Any ideas?

Link to comment
Are you sure that the script is set to server side on meta.xml?

I found that mistake and made it serverside, but it's still not working. Here's the code again:

  
addEvent ( "onPlayerFinish", true ) 
  
function raceWin(rank) 
    if rank ~= 1 then 
    return  
    end 
    local playername = getPlayerName(source) 
    givePlayerMoney(source,1000)---money what player get if he finish.(Default=1000) 
    outputChatBox("* "..playername.." took $1000 for being the last survivor!",root,51,153,255) 
end 
addEventHandler("onPlayerFinish", root, raceWin ) 

Link to comment

Check this:

addEvent ( "onPlayerFinish", true ) 
  
function raceWin ( rank ) 
    if rank then 
        if rank ~= 1 then 
            return outputChatBox ( "* Your Rank [ "..rank.." ]", source, 255, 255, 0, true ) 
        end 
        local playername = getPlayerName ( source ) 
        givePlayerMoney ( source, 1000 ) -- money what player get if he finish.(Default=1000) 
        outputChatBox ( "* "..playername.." took $1000 for being the last survivor!", root, 51, 153, 255 ) 
    else 
        outputChatBox ( "* You Don't have any Rank.", source, 255, 0, 0, true ) 
    end 
end 
addEventHandler ( "onPlayerFinish", root, raceWin ) 

If he didn't say anything at ChatBox.

The Event isn't added at any resource !!

Link to comment

3NAD, read this quote:

"onPlayerFinish" is only for Race, so doesn't work in DD/DM.

He's obviously using DD/DM and not race with checkpoints, so that event won't work.

@Mossy: Go to "race/modes/destructionderby.lua" and replace the function: "handleFinishActivePlayer" with this one:

function DestructionDerby:handleFinishActivePlayer(player) 
    -- Update ranking board for player being removed 
    if not self.rankingBoard then 
        self.rankingBoard = RankingBoard:create() 
        self.rankingBoard:setDirection( 'up', getActivePlayerCount() ) 
    end 
    local timePassed = self:getTimePassed() 
    self.rankingBoard:add(player, timePassed) 
    -- Do remove 
    local rank = self:getPlayerRank(player) 
    finishActivePlayer(player) 
    if rank and rank > 1 then 
        triggerEvent( "onPlayerFinishDD",player,tonumber( rank ) ) 
    end 
    -- Update ranking board if one player left 
    local activePlayers = getActivePlayers() 
    if #activePlayers == 1 then 
        self.rankingBoard:add(activePlayers[1], timePassed) 
        showMessage(getPlayerName(activePlayers[1]) .. ' is the final survivor!', 0, 255, 0) 
        triggerEvent( "onPlayerWinDD",activePlayers[1] ) 
    end 
end 

Link to comment

No, use this:

function raceWin ( ) 
    local playername = getPlayerName ( source ) 
    givePlayerMoney ( source, 1000 ) 
    outputChatBox ( "* ".. playername .." took $1000 for being the last survivor!", root, 51, 153, 255 ) 
end 
addEvent ( "onPlayerWinDD", true ) 
addEventHandler ( "onPlayerWinDD", root, raceWin ) 

Link to comment

Worked. Thanks!

But now I decided to add more positions but of course it doesn't work.

    function raceWin ( ) 
        local playername = getPlayerName ( source ) 
        givePlayerMoney ( source, 500 ) 
        outputChatBox ( "* " .. playername .. " #ABCDEFreceived $500 for being the last survivor!", root, 255, 255, 255, true ) 
    end 
    addEvent ( "onPlayerWinDD", true ) 
    addEventHandler ( "onPlayerWinDD", root, raceWin ) 
     
addEventHandler("onPlayerRaceWasted",root,function() 
 local rank = exports.race:getPlayerRank(source) 
 if rank == 2 then 
  givePlayerMoney ( source, 250 ) 
  outputChatBox ( "#ABCDEFYou died in 2nd place and received $250.", source, 255, 255, 255, true) 
  elseif rank == 3 then 
  givePlayerMoney ( source, 100 ) 
  outputChatBox ( "#ABCDEFYou died in 3rd place and received $100.", source, 255, 255, 255, true) 
    elseif rank == 4 then 
  givePlayerMoney ( source, 50 ) 
  outputChatBox ( "#ABCDEFYou died in 4th place and received $50.", source, 255, 255, 255, true) 
    elseif rank == 5 then 
      givePlayerMoney ( source, 25 ) 
  outputChatBox ( "#ABCDEFYou died in 5th place and received $25.", source, 255, 255, 255, true) 
      elseif rank == 6 then 
  outputChatBox ( "#ABCDEFYou died in 6th place and received nothing.", source, 255, 255, 255, true) 
 end 
end) 

Link to comment

Got a bit confused. Is this correct?

    function raceWin ( ) 
        local playername = getPlayerName ( source ) 
        givePlayerMoney ( source, 500 ) 
        outputChatBox ( "* " .. playername .. " #ABCDEFreceived $500 for being the last survivor!", root, 255, 255, 255, true ) 
    end 
    addEvent ( "onPlayerWinDD", true ) 
    addEventHandler ( "onPlayerWinDD", root, raceWin ) 
     
 local rank = exports.race:getPlayerRank(source) 
 if rank == 2 then 
  givePlayerMoney ( source, 250 ) 
  outputChatBox ( "#ABCDEFYou died in 2nd place and received $250.", source, 255, 255, 255, true) 
  elseif rank == 3 then 
  givePlayerMoney ( source, 100 ) 
  outputChatBox ( "#ABCDEFYou died in 3rd place and received $100.", source, 255, 255, 255, true) 
    elseif rank == 4 then 
  givePlayerMoney ( source, 50 ) 
  outputChatBox ( "#ABCDEFYou died in 4th place and received $50.", source, 255, 255, 255, true) 
    elseif rank == 5 then 
      givePlayerMoney ( source, 25 ) 
  outputChatBox ( "#ABCDEFYou died in 5th place and received $25.", source, 255, 255, 255, true) 
      elseif rank == 6 then 
  outputChatBox ( "#ABCDEFYou died in 6th place and received nothing.", source, 255, 255, 255, true) 
 end 
end) 
    addEvent ( "onPlayerWinDD", true ) 
    addEventHandler ( "onPlayerWinDD", rank, raceWin ) 

Link to comment

I kind of understand what you're saying. I'm sure this is incorrect. I want just the 1st place to be shown to everyone and I want 2nd-6th to be shown to only the player that died in that position.

        function raceWin ( ) 
            local playername = getPlayerName ( source ) 
            givePlayerMoney ( source, 500 ) 
            outputChatBox ( "* " .. playername .. " #ABCDEFreceived $500 for being the last survivor!", root, 255, 255, 255, true ) 
        end 
        addEvent ( "onPlayerWinDD", true ) 
        addEventHandler ( "onPlayerWinDD", root, raceWin ) 
        
    function raceWin ( ) 
     local rank = exports.race:getPlayerRank(source) 
     if rank == 2 then 
      givePlayerMoney ( source, 250 ) 
      outputChatBox ( "#ABCDEFYou died in 2nd place and received $250.", source, 255, 255, 255, true) 
      elseif rank == 3 then 
      givePlayerMoney ( source, 100 ) 
      outputChatBox ( "#ABCDEFYou died in 3rd place and received $100.", source, 255, 255, 255, true) 
        elseif rank == 4 then 
      givePlayerMoney ( source, 50 ) 
      outputChatBox ( "#ABCDEFYou died in 4th place and received $50.", source, 255, 255, 255, true) 
        elseif rank == 5 then 
          givePlayerMoney ( source, 25 ) 
      outputChatBox ( "#ABCDEFYou died in 5th place and received $25.", source, 255, 255, 255, true) 
          elseif rank == 6 then 
      outputChatBox ( "#ABCDEFYou died in 6th place and received nothing.", source, 255, 255, 255, true) 
     end 
    end) 
    addEvent ( "onPlayerWinDD", true ) 
    addEventHandler ( "onPlayerWinDD", rank, raceWin ) 

Link to comment
function raceWin ( ) 
    local playername = getPlayerName ( source ) 
    givePlayerMoney ( source, 500 ) 
    outputChatBox ( "* " .. playername .. " #ABCDEFreceived $500 for being the last survivor!", root, 255, 255, 255, true ) 
end 
addEvent ( "onPlayerWinDD", true ) 
addEventHandler ( "onPlayerWinDD", root, raceWin ) 
  
addEvent ( "onPlayerFinishDD", true ) 
addEventHandler ( "onPlayerFinishDD", root, 
    function ( rank ) 
        if ( rank == 2 ) then 
            givePlayerMoney ( source, 250 ) 
            outputChatBox ( "#ABCDEFYou died in 2nd place and received $250.", source, 255, 255, 255, true) 
        elseif ( rank == 3 ) then 
            givePlayerMoney ( source, 100 ) 
            outputChatBox ( "#ABCDEFYou died in 3rd place and received $100.", source, 255, 255, 255, true) 
        elseif ( rank == 4 ) then 
            givePlayerMoney ( source, 50 ) 
            outputChatBox ( "#ABCDEFYou died in 4th place and received $50.", source, 255, 255, 255, true) 
        elseif ( rank == 5 ) then 
            givePlayerMoney ( source, 25 ) 
            outputChatBox ( "#ABCDEFYou died in 5th place and received $25.", source, 255, 255, 255, true) 
        elseif ( rank == 6 ) then 
            outputChatBox ( "#ABCDEFYou died in 6th place and received nothing.", source, 255, 255, 255, true) 
        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...