Jump to content

Help with race money when someone wins.


Mario222

Recommended Posts

 

I have this resource that gives money to players based on their rank that I configure and adapt for only 20 players (maximum limit that I put on my server), it is a DD server but also a race and some from FunDD. So, the resource doesn't work, I have maps of both types and I need it to work in terms of rank but with the number of people left as I configure it, but that the winner, when no one is left alive, can take their money but I can't achieve how do it, I'm sorry if I bother but I'm still new to this Lua.

 

    -- # Server Side !
    local Ranks = {
        {1,400},
        {2,200},
        {3,100},
        {4,80},
        {5,50},
        {6,30},
        {7,20},
        {8,20},
        {9,20},
        {10,10}
        {11,10}
        {12,10}  
        {13,10}  
        {14,10}  
        {15,10} 
        {16,5}
        {17,5}
        {18,5}
        {19,5}
        {20,5}        
    }
     
    addEventHandler("onPlayerWasted",root,
        function (  )
            for _,v in ipairs ( Ranks ) do
                if ( exports["race"]:getPlayerRank( source ) == v[1] ) then
                    givePlayerMoney ( source,v[2] )
                end
            end
        end
    )

Edited by Mario222
error
Link to comment
2 hours ago, _SAXI_ said:

You had a problem in the table.

Here's the fix:

  local Ranks = {
        {1,400},
        {2,200},
        {3,100},
        {4,80},
        {5,50},
        {6,30},
        {7,20},
        {8,20},
        {9,20},
        {10,10},
        {11,10},
        {12,10}, 
        {13,10},  
        {14,10},  
        {15,10}, 
        {16,5},
        {17,5},
        {18,5},
        {19,5},
        {20,5}
    }

 

Yes i didn't saw that i fixed the problem. How to make it give money to the player regardless of whether it is a DD map or a race I can use the function of 

???

Link to comment

You can use an array to solve that.

local Ranks = {
    {1,400},
    {2,200},
    {3,100},
    {4,80},
    {5,50},
    {6,30},
    {7,20},
    {8,20},
    {9,20},
    {10,10},
    {11,10},
    {12,10},  
    {13,10},  
    {14,10},  
    {15,10}, 
    {16,5},
    {17,5},
    {18,5},
    {19,5},
    {20,5}        
}

local payToPlayer={};

addEventHandler('onPlayerWasted',root,function()
    for _,v in ipairs(Ranks) do
        if(exports["race"]:getPlayerRank(source) == v[1] )then
            payToPlayer[source] = v[2];
        end
    end
end)

addEventHandler('onPlayerSpawn',root,function()
    if(payToPlayer[source])then
        givePlayerMoney(source,payToPlayer[source]);
        payToPlayer[source] = nil; -- reset the array
    end
end)

 

Link to comment

Hello,

Here the documentation that can help you https://wiki.multitheftauto.com/wiki/Resource:Race.
To distinguish Race from DD you can use info table from onMapStarting race event.

Here an example how we could use it :

local mapmode = nil

addEventHandler("onMapStarting", root, function(info)
	mapmode = info.modename
end
)

function giveRacePrice(rank)
	if (mapmode == 'Sprint') then -- if mode is race
		for _,v in ipairs(Ranks) do
			if(rank == v[1] )then
				payToPlayer[source] = v[2];
			end
		end
	end
end
addEventHandler("onPlayerFinish", root, giveRacePrice) -- event from Race

function giveDDPrice(rank)
	if (mapmode == 'Destruction derby') then -- if mode is DD
		for _,v in ipairs(Ranks) do
			local rank = (#getAlivePlayers() + 1) -- or exports["race"]:getPlayerRank(source) ?
			if(rank == v[1] )then
				payToPlayer[source] = v[2];
			end
		end
	end
end
addEventHandler("onPlayerWasted", root, giveDDPrice)


 

Edited by Mkl
  • Like 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...