Jump to content

Recommended Posts

Hello,

I'm using this level system. I would like someone to help me with a script. As soon as the player climbs the level. He would win some items. And a message would appear stating that he has Went up the level.

Can someone help me ?

File Cliente:                                    

local sW, sH = guiGetScreenSize()
local windowRank = guiCreateWindow ( (sW-500)/2, (sH-400)/2, 500, 400, "Manage Players Level System", false )
guiWindowSetSizable ( windowRank, false )
guiSetVisible ( windowRank, false)
local windowRankGridList = guiCreateGridList ( 10, 28, 360, 360, false, windowRank )
local windowRankColumn = guiGridListAddColumn( windowRankGridList, "Name", 0.90 )
local windowRankEdit = guiCreateEdit( 383, 150, 100, 30, "", false, windowRank)
local windowRankEdit2 = guiCreateEdit( 383, 250, 100, 30, "", false, windowRank)
local windowRankButton = guiCreateButton( 383, 358, 100, 30, "Change", false, windowRank)
local windowRankLabelLevel = guiCreateLabel(383, 120, 100, 20,"Level: None", false, windowRank)
guiLabelSetHorizontalAlign (windowRankLabelLevel, "center")
local windowRankLabelExp = guiCreateLabel(383, 220, 100, 20,"Experiencia: None", false, windowRank)
guiLabelSetHorizontalAlign (windowRankLabelExp, "center")

local ranksTable =
{
  {"1","Treinamento","1000"},
  {"2","Cadete Júnior","2000"},
  {"3","Cadete","3000"},
  {"4","Cadete Sênior","4000"},
  {"5","Cadete de 1ª Classe","5000"},
  {"6","Recruta","5800"},
  {"7","Soldado","8100"},
  {"8","Soldado Raso de 2ª Classe","11000"},
  {"9","Soldado Raso","14600"},
  {"10","Soldado Raso de 1ª Classe","18800"},
  {"11","Especialista","23800"},
  {"12","Especialista de Artilharia","29600"},
  {"13","Especialista Técnico","36300"},
  {"14","Especialista de 1ª Classe","44100"},
  {"15","Patrulheiro","53000"},
  {"16","Soldado EP","63000"},
  {"17","Cabo","74500"},
  {"18","Líder de Tiro","87400"},
  {"19","Sargento de 3ª Classe","102000"},
  {"20","Sargento de 2ª Classe","118400"},
  {"21","Sargento","136700"},
  {"22","Sargento de 1ª Classe","157200"},
  {"23","Sargento de Apoio","180000"},
  {"24","Sargento de Artilharia","205200"},
  {"25","Sargento Mestre","233300"},
  {"26","Primeiro Sargento","264400"},
  {"27","Sargento Comandante","298700"},
  {"28","Sargento de Artilharia Mestre","336500"},
  {"29","Sargento Maior","378000"},
  {"30","Sargento de Companhia","423700"},
  {"31","Candidato a Sargento Oficial","473700"},
  {"32","Sargento Oficial","528400"},
  {"33","Sargento Oficial Chefe","588100"},
  {"34","Sargento Oficial Chefe de 1ª Classe","653400"},
  {"35","Sargento Oficial Mestre","724400"},
  {"36","Intendente","801600"},
  {"37","Cadete-Oficial Júnior","885500"},
  {"38","Cadete-Oficial Sênior","976400"},
  {"39","Aspirante","1074800"},
  {"40","Segundo Tenente","1181100"},
  {"41","Primeiro Tenente","1296000"},
  {"42","Subtenente","1419700"},
  {"43","Tenente","1552900"},
  {"44","Tenente-Coronel","1696200"},
  {"45","Tenente-Capitão","1849900"},
  {"46","Capitão","2014800"},
  {"47","Capitão 1","2191200"},
  {"48","Capitão 2","2380000"},
  {"49","Capitão 3","2581500"},
  {"50","Coronel ","2796400"},
  {"51","Brigadeiro","3025300"},
  {"52","Marechal de Campo","3268800"},
  {"53","Comandante","3527500"},
  {"54","Alto-Comandante","3801900"},
  {"55","Supremo Comandante","4092800"},
  {"56","Major-General","4400600"},
  {"57","Tenente-General","4726000"},
  {"58","General-Marechal de Campo","5069500"},
  {"59","Segundo Tenente SF","5431800"},
  {"60","Primeiro Tenente SF'","6000000"},
  {"61","Subtenente SF'","6568200"},
  {"62","Tenente SF","7136400"},
  {"63","Tenente-Coronel SF'","7704600"},
  {"64","Tenente-Capitão SF","8272800"},
  {"65","Capitão SF","8841000"},
  {"66","Capitão 1 SF","9409200"},
  {"67","Capitão 2 SF","9977400"},
  {"68","Capitão 3 SF","10545600"},
  {"69","Coronel SF","11113800"},
  {"70","General de Exército","11692000"}
}


function getPlayerRankName()
  for i=1,70 do
    if getElementData(localPlayer, "level") == tonumber(ranksTable[1]) then
      return ranksTable[2]
    end
  end
end

function getPlayerRankExperience()
  for i=1,70 do
    if getElementData(localPlayer, "level") == tonumber(ranksTable[1]) then
      return tonumber(ranksTable[3])
    end
  end
end

function mainRanks()
  if getElementData(localPlayer, "logedin") == true then
    if getElementData(localPlayer, "experience") > getPlayerRankExperience() then
      if getElementData(localPlayer, "level") < 70 then
        setElementData(localPlayer, "level", getElementData(localPlayer, "level") + 1)
      end
    end
    dxDrawImage ( sW/22, sH/2.8, sW/60, sH/60, "images/level/rank"..getElementData(localPlayer, "level")..".jpg" )  
    dxDrawText ( getPlayerRankName().." ("..getElementData(localPlayer, "level")..")",sW/65, sH/3.6, sW/0, sH/0, tocolor ( 240, 230, 140, 255 ), 1.02, "default-bold" ) 
    dxDrawText ( "Experiência atual: "..getElementData(localPlayer, "experience"), sW/65, sH/3.27, sW/0, sH/0, tocolor ( 70, 130, 180, 255 ), 1.02, "default-bold" )
    if getElementData(localPlayer, "level") < 70 then
      dxDrawText ( "Experiencia necessario: "..getPlayerRankExperience(),sW/65, sH/3, sW/0, sH/0, tocolor ( 70, 130, 180, 255 ), 1.02, "default-bold" )
    else
      dxDrawText ( "O máximo foi alcançado",sW/65, sH/3, sW/0, sH/0, tocolor ( 70, 130, 180, 255 ), 1.02, "default-bold" )
    end   
  end
end
addEventHandler ( "onClientRender", root, mainRanks )

function toggleWindowRanks()
  if getElementData(localPlayer, "adminRanks") == true then 
    if guiGetVisible(windowRank) == false then
      guiSetVisible(windowRank, true)
      showCursor(true)
      for k, v in ipairs (getElementsByType("player")) do
        if getElementData (v, "logedin") == true then
          local row = guiGridListAddRow ( windowRankGridList )
          guiGridListSetItemText ( windowRankGridList, row, windowRankColumn, getPlayerName ( v ), false, false )
        end
      end
    else
      guiSetVisible(windowRank, false)
      showCursor(false)
      guiGridListClear(windowRankGridList)
    end
  end
end
bindKey("F7", "down", toggleWindowRanks)

function windowRankClick()
local playerName = guiGridListGetItemText ( windowRankGridList, guiGridListGetSelectedItem ( windowRankGridList ), 1 )
  if source == windowRankGridList then
    if guiGridListGetSelectedCount(windowRankGridList) == 1 then
      guiSetText(windowRankLabelLevel, "Level: "..getElementData(getPlayerFromName(playerName), "level"))
      guiSetText(windowRankLabelExp, "Experiencia: "..getElementData(getPlayerFromName(playerName), "experience"))
    else
      guiSetText(windowRankLabelLevel, "Level: None")
      guiSetText(windowRankLabelExp, "Experiencia: None")
    end
  end 
  if source == windowRankButton then
    if guiGridListGetSelectedCount(windowRankGridList) == 1 then
    local playerName = guiGridListGetItemText ( windowRankGridList, guiGridListGetSelectedItem ( windowRankGridList ), 1 )
      if guiGetText(windowRankEdit) ~= "" then
        setElementData(getPlayerFromName(playerName), "level", tonumber(guiGetText(windowRankEdit)))
        guiSetText(windowRankLabelLevel, "Level: "..getElementData(getPlayerFromName(playerName), "level"))
      end
      if guiGetText(windowRankEdit2) ~= "" then
        setElementData(getPlayerFromName(playerName), "experience", tonumber(guiGetText(windowRankEdit2)))
        guiSetText(windowRankLabelExp, "Experiencia: "..getElementData(getPlayerFromName(playerName), "experience"))
      end   
    else
      outputChatBox("#FF0000[LEVEL SYSTEM]: #FFFFFFSelecione o Player!", thePlayer, 171, 205, 239, true)
    end
  end
end
addEventHandler ("onClientGUIClick", windowRank, windowRankClick) 

 

Link to comment
  • Moderators

Just replace the lines 106 to 123 by this:

function onLevelUp(newLevel)
  outputChatBox("You just leveled up to level "..tostring(newLevel).." !")
  -- Add code to give items here
end

function mainRanks()
  if getElementData(localPlayer, "logedin") == true then
    if getElementData(localPlayer, "experience") > getPlayerRankExperience() then
      if getElementData(localPlayer, "level") < 70 then
        local newLevel = getElementData(localPlayer, "level") + 1
        setElementData(localPlayer, "level", newLevel)
        onLevelUp(newLevel)
      end
    end
    dxDrawImage ( sW/22, sH/2.8, sW/60, sH/60, "images/level/rank"..getElementData(localPlayer, "level")..".jpg" )  
    dxDrawText ( getPlayerRankName().." ("..getElementData(localPlayer, "level")..")",sW/65, sH/3.6, sW/0, sH/0, tocolor ( 240, 230, 140, 255 ), 1.02, "default-bold" ) 
    dxDrawText ( "Experiência atual: "..getElementData(localPlayer, "experience"), sW/65, sH/3.27, sW/0, sH/0, tocolor ( 70, 130, 180, 255 ), 1.02, "default-bold" )
    if getElementData(localPlayer, "level") < 70 then
      dxDrawText ( "Experiencia necessario: "..getPlayerRankExperience(),sW/65, sH/3, sW/0, sH/0, tocolor ( 70, 130, 180, 255 ), 1.02, "default-bold" )
    else
      dxDrawText ( "O máximo foi alcançado",sW/65, sH/3, sW/0, sH/0, tocolor ( 70, 130, 180, 255 ), 1.02, "default-bold" )
    end   
  end
end
addEventHandler ( "onClientRender", root, mainRanks )

And modify the onLevelUp function to your needs.

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