Jump to content

[HELP] Get race rank


Recommended Posts

You need some MTA scripting knowledge not just Lua itself. This is your highest priority. Then you can make it yourself with a 10 lines script: https://wiki.multitheftauto.com/wiki/Resource:Race

What do you need money for on a race server? Where do you spend it?

For example, the nitro or repair.

I can also bit MTA LUA, but I may know not what event I should use.

iik saw on the forum have a small script but I do not know if that works.

function check()
local alive = getAlivePlayers()
if (#alive == 1) then
local player = alive[1]
givePlayerMoney(player,1200)
outputChatBox(getPlayerName(player).." has earned $1200 for being the last player alive",getRootElement(),0,255,0)
else
outputChatBox("helaas",getRootElement(),0,255,0)
end
end
addEventHandler("onPlayerWasted",getRootElement(),check)

Link to comment
Why don't you try? Besides, you never said what kind of race.

ok i have make a script but there is a bug

look:

function checkWinAndIfWinGiveWinCash (totalAmmo,killer,killerWeapon,bodypart,stealth)
local rank = getAliveCount()
if (rank == 1) then
local allAlivePlayers = getAlivePlayers()
local player = allAlivePlayers[1]
local playerCount = getPlayerCount()
local pointsToWin = playerCount *13
local cashToWin = playerCount *53
   	savePlayerData (player,"points",loadPlayerData(player,"points") + pointsToWin)
   	savePlayerData (player,"cash",loadPlayerData(player,"cash") +cashToWin)
outputChatBox (getPlayerName(player) .." #FF0000is first! He wins " .. tostring(pointsToWin) .." points and " .. tostring(cashToWin) .."$!",getRootElement(),255,0,0,true)      
end
if(rank == 2) then
outputChatBox (getPlayerName(player) .." #FF0000is 2nd!",getRootElement(),255,0,0,true)
end
end
addEventHandler ("onPlayerWasted",getRootElement(),checkWinAndIfWinGiveWinCash)
addEventHandler ("onPlayerQuit",getRootElement(),checkWinAndIfWinGiveWinCash)

i don't see if i seccond the message, and elseif don't work :(

Maarten123 :D

Link to comment
Output the rank and see, if it is 2, when you're second ranked.

If not, then most likely the getAliveCount function has a mistake in it.

Also, you should make use of elseif at this point:

if(rank == 2) then

function checkWinAndIfWinGiveWinCash (totalAmmo,killer,killerWeapon,bodypart,stealth)
local rank = getAliveCount()
if (rank == 1) then
local allAlivePlayers = getAlivePlayers()
local player = allAlivePlayers[1]
local playerCount = getPlayerCount()
local pointsToWin = playerCount *13
local cashToWin = playerCount *53
   	savePlayerData (player,"points",loadPlayerData(player,"points") + pointsToWin)
   	savePlayerData (player,"cash",loadPlayerData(player,"cash") +cashToWin)
outputChatBox (getPlayerName(player) .." #FF0000is first! He wins " .. tostring(pointsToWin) .." points and " .. tostring(cashToWin) .."$!",getRootElement(),255,0,0,true)      
end
if(rank == 2) then
local allAlivePlayers = getAlivePlayers()
local player = allAlivePlayers[2]
local playerCount = getPlayerCount()
local pointsToWin = playerCount *13
local cashToWin = playerCount *53
outputChatBox (getPlayerName(player) .." #FF0000is 2nd!",getRootElement(),255,0,0,true)
end
end

like this?

but now is it bugged i wnat if all players dead then he say your 2dn or first :D

Link to comment
function check()
local alive = getAlivePlayers()
if (#alive == 1) then
local player = alive[1]
givePlayerMoney(player,1200)
outputChatBox(getPlayerName(player).." is first!",getRootElement(),0,255,0)
end
if(#alive == 2) then
local player2 = alive[2]
outputChatBox(getPlayerName(player2).." is second!",getRootElement(),0,255,0)
end
end
addEventHandler("onPlayerWasted",getRootElement(),check)

this is a simpel version of that nut that is too bugged :D

Link to comment
function check()
local alive = getAlivePlayers()
if (#alive == 1) then
local player = alive[1]
givePlayerMoney(player,1200)
outputChatBox(getPlayerName(player).." is first!",getRootElement(),0,255,0)
end
if(#alive == 2) then
local player2 = alive[2]
outputChatBox(getPlayerName(player2).." is second!",getRootElement(),0,255,0)
end
end
addEventHandler("onPlayerWasted",getRootElement(),check)

this is a simpel version of that nut that is too bugged :D

i see the problem :D

if you winning there are no 2 alive humans/cars

so now i need the dead players and then i get the rank of him :D

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