Jump to content

[HELP] Rank System


MrXz

Recommended Posts

Hi all ,

good going through my trunk of old scripts and I found this

---------- server.lua

addEventHandler ("onPlayerRaceWasted",getRootElement(), 
function() 
  killPed (source) 
  setElementHealth (source,0) 
  if (isPedInVehicle(source)) then 
    blowVehicle (getPedOccupiedVehicle(source)) 
  end 
end) 
  
addEventHandler ("onPlayerJoin",getRootElement(), 
function() 
  setElementHealth (source,0) 
  setTimer (setElementHealth,1500,1,0) 
  savePlayerData (source,"lastPlayerName",getPlayerName(source)) 
end) 
  
addEventHandler ("onPlayerChangeNick",getRootElement(), 
function(olnick,newnick) 
  savePlayerData (source,"lastPlayerName",newnick) 
end) 
  
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) .." #FF0000 Win! " .. tostring(pointsToWin) .." points and " .. tostring(cashToWin) .."$!",getRootElement(),255,0,0,true)       
  end 
end 
addEventHandler ("onPlayerWasted",getRootElement(),checkWinAndIfWinGiveWinCash) 
addEventHandler ("onPlayerQuit",getRootElement(),checkWinAndIfWinGiveWinCash) 
  
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 
  
-- The load-and-save part. 
function loadPlayerData (player,datatype) 
  local playerIP = getPlayerSerial (player) 
  if (playerIP) then 
    local root = xmlLoadFile ("users.xml") 
    if (root) then 
      local usersNode = xmlFindChild (root,"user",0) 
      if (usersNode) then 
        local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. getPlayerSerial(player),0) 
        if not (playerRootNode == false) then 
          local playerData = xmlNodeGetAttribute (playerRootNode,datatype) 
          if (playerData) then 
            xmlUnloadFile (root) 
            return playerData 
          else 
            xmlNodeSetAttribute (playerRootNode,datatype,0) 
            xmlSaveFile (root) 
            xmlUnloadFile (root) 
            return 0 
          end 
        else 
          local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. getPlayerSerial(player)) 
          xmlNodeSetAttribute (playerRootNode,datatype,0) 
          xmlSaveFile (root) 
          xmlUnloadFile (root) 
          return 0 
        end 
      end 
    end 
  end 
end 
  
function savePlayerData (player,datatype,newvalue) 
  local playerIP = getPlayerSerial (player) 
  if (playerIP) then 
    local root = xmlLoadFile ("users.xml") 
    if (root) then 
      local usersNode = xmlFindChild (root,"user",0) 
      if (usersNode) then 
        local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. getPlayerSerial(player),0) 
        if not (playerRootNode == false) then 
          local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue) 
          xmlSaveFile (root) 
          xmlUnloadFile (root) 
          return newNodeValue 
        else 
          local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. getPlayerSerial(player)) 
          local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue) 
          xmlSaveFile (root) 
          xmlUnloadFile (root) 
          return newNodeValue 
        end 
      end 
    end 
  end 
end 
  

and well thought of making a system of rank with exp, and may do so using this script and adding to the scoreboard.

or else how to do aid, thanks :)

Sorry for bad english?

Edited by Guest
Link to comment

you mean that?

function ANANZAA() 
    local playerCash = tonumber( loadPlayerData ( source, "cash" ) ) 
    setElementData ( source, "cash", playerCash ) 
    local playerPoint = tonumber( loadPlayerData ( source, "points" ) ) 
    setElementData ( source, "points", playerPoint ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), ANANZAA) 
addEventHandler ( "onPlayerWasted", getRootElement(), ANANZAA) 
  
call(getResourceFromName("scoreboard"), "addScoreboardColumn", "cash") 
call(getResourceFromName("scoreboard"), "addScoreboardColumn", "points") 

Link to comment

well, I have ready about the scoreboard but what I look for is how to do ranking system, .... bone as this example

Player 1 - Rank 1

Player 2 - Rank 3

Player 5 - Rank 7

if I explain?

I just want a help, not an entire script

Link to comment
well, I have ready about the scoreboard but what I look for is how to do ranking system, .... bone as this example

Player 1 - Rank 1

Player 2 - Rank 3

Player 5 - Rank 7

if I explain?

I just want a help, not an entire script

you can use table.sort for the list.

Link to comment
example?

http://www.lua.org/manual/5.1/manual.ht ... table.sort

also 50p's post:

You can easily sort values within SQL queries. That's only if you use SQL tables to store points. You can also sort numbers in tables.
points = { 4, 6, 7, 8, 5, 9 } 
table.sort( points ); 
for k, v in ipairs( points ) do 
    print( k .. ".  " .. v ); 
end 
--[[ 
1. 4 
2. 6 
3. 7 
4. 8 
5. 5 
6. 9 
]] 

If you want the highest to be on top and the lowest on bottom then you have to make a function which will compare 2 numbers and return the higher one. And use this function in table.sort function. Like so:

table.sort( points, function( a, b ) return a > b end ); 
--[[ 
output: 
1. 9 
2. 8 
3. 7 
4. 6 
5. 5 
6. 4  
]] 

If you want to know more about table.sort function or sorting in Lua go here:

http://www.lua.org/manual/5.1/manual.ht ... table.sort

http://www.lua.org/pil/19.3.html

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