I have a problem with pointsystem.
what happens is that when a player enters the server, the player wins. And the player in the first place, not it wins the points and the money.
*this script is not made by me, I just want to help me solve the problem
- server.lua
function checkWinAndIfWinGiveWinCash ()
local rank = getAliveCount()
local allAlivePlayers = getAlivePlayers()
local player = allAlivePlayers[1]
local playeracc = getPlayerAccount(player)
local playerCount = getPlayerCount()
local pointsToWin = playerCount *37
local cashToWin = playerCount *187
local money = getPlayerMoney(player)
local woncash = money + cashToWin
if not isGuestAccount(playeracc) then
if (rank == 1) then
savePlayerData (player,"points",loadPlayerData(player,"points") + pointsToWin)
setPlayerMoney(player, woncash)
outputChatBox ("#ff0000* #ffffff" .. getPlayerName(player) .." #ffffffis wins #ff0000" .. tostring(pointsToWin) .." #ffffffpoints and #ff0000" .. tostring(cashToWin) .. "$",getRootElement(),255,0,0,true)
end
end
if isGuestAccount(playeracc) then
if (rank == 1) then
outputChatBox ("#ffaa00* #ffffff"..getPlayerName(player)..clor.." #ff000should log in to earn money and points",getRootElement(),255,0,0,true)
end
end
end
addEventHandler ("onPlayerWasted",getRootElement(),checkWinAndIfWinGiveWinCash)
addEventHandler ("onPlayerRaceWasted",getRootElement(),
function()
killPed (source)
setElementHealth (source,0)
if (isPedInVehicle(source)) then
blowVehicle (getPedOccupiedVehicle(source))
end
end)
function findPlayerByName (playerPart)
for i,v in ipairs (getElementsByType ("player")) do
if (string.find(getPlayerName(v),playerPart)) then
return v
end
end
end
function getDeadCount ()
deadAmount = 0
for i,v in ipairs (getDeadPlayers()) do
deadAmount = deadAmount +1
end
return deadAmount
end
function getSpawnedCount ()
spawnedAmount = 0
for i,v in ipairs (getAlivePlayers()) do
if (isPedInVehicle (v)) then
spawnedAmount = spawnedAmount +1
end
end
return spawnedAmount
end
function getAliveCount ()
aliveAmount = 0
for i,v in ipairs (getAlivePlayers()) do
aliveAmount = aliveAmount +1
end
return aliveAmount
end