server/main.lua

πŸ‡«πŸ‡· Initialiser le job2 pour le joueur qui se connecte.

πŸ‡ΊπŸ‡Έ Initialize job2 for the player who connects.

  • Query

    • πŸ‡«πŸ‡· Au dΓ©but de votre fichier, vous avez cette variable:

    • πŸ‡ΊπŸ‡Έ At the beginning of your file, you have this variable:

    local loadPlayer = "SELECT `accounts`, `job`, `job_grade`, `group`, `position`, `inventory`, `skin`, `loadout`, `metadata`"
    • πŸ‡«πŸ‡· Remplacez lΓ , par ceci:

    • πŸ‡ΊπŸ‡Έ Replace it with this:

    local loadPlayer = "SELECT `accounts`, `job`, `job_grade`, `job2`, `job2_grade`, `group`, `position`, `inventory`, `skin`, `loadout`, `metadata`"
  • πŸ‡«πŸ‡· Les boucles

  • πŸ‡ΊπŸ‡Έ The loops

    • πŸ‡«πŸ‡· Cherchez dans le fichier toutes les boucles ci-dessous:

    • πŸ‡ΊπŸ‡Έ Find all the loops below in the file:

    while not next(ESX.Jobs) do
    • πŸ‡«πŸ‡· Et remplacez, par ceci:

    • πŸ‡ΊπŸ‡Έ Replace it with this:

    while not next(ESX.Jobs) and not next(ESX.Jobs2) do
  • πŸ‡«πŸ‡· Cherchez la fonction loadESXPlayer(identifier, playerId, isNew)

  • πŸ‡ΊπŸ‡Έ Find the function loadESXPlayer(identifier, playerId, isNew)

    • πŸ‡«πŸ‡· Puis, remplacez la fonction entiΓ¨re par celle-ci:

    • πŸ‡ΊπŸ‡Έ Then, replace the entire function with this one:

      function loadESXPlayer(identifier, playerId, isNew)
          local userData = {
              accounts = {},
              inventory = {},
              loadout = {},
              weight = 0,
              name = GetPlayerName(playerId),
              identifier = identifier,
              firstName = "John",
              lastName = "Doe",
              dateofbirth = "01/01/2000",
              height = 120,
              dead = false,
          }
      
          local result = MySQL.prepare.await(loadPlayer, { identifier })
      
          -- Accounts
          local accounts = result.accounts
          accounts = (accounts and accounts ~= "") and json.decode(accounts) or {}
      
          for account, data in pairs(Config.Accounts) do
              data.round = data.round or data.round == nil
      
              local index = #userData.accounts + 1
              userData.accounts[index] = {
                  name = account,
                  money = accounts[account] or Config.StartingAccountMoney[account] or 0,
                  label = data.label,
                  round = data.round,
                  index = index,
              }
          end
      
          -- Job
          local job, grade = result.job, tostring(result.job_grade)
      
          if not ESX.DoesJobExist(job, grade) then
              print(("[^3WARNING^7] Ignoring invalid job for ^5%s^7 [job: ^5%s^7, grade: ^5%s^7]"):format(identifier, job, grade))
              job, grade = "unemployed", "0"
          end
      
          local jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade]
      
          userData.job = {
              id = jobObject.id,
              name = jobObject.name,
              label = jobObject.label,
      
              grade = tonumber(grade),
              grade_name = gradeObject.name,
              grade_label = gradeObject.label,
              grade_salary = gradeObject.salary,
      
              skin_male = gradeObject.skin_male and json.decode(gradeObject.skin_male) or {},
              skin_female = gradeObject.skin_female and json.decode(gradeObject.skin_female) or {},
          }
      
          local job2, grade2 = result.job2, tostring(result.job2_grade)
      
          if not ESX.DoesJob2Exist(job2, grade2) then
              print(("[^3WARNING^7] Ignoring invalid job2 for ^5%s^7 [job2: ^5%s^7, grade2: ^5%s^7]"):format(identifier, job2, grade2))
              job2, grade2 = "nogang", "0"
          end
      
          local job2Object, grade2Object = ESX.Jobs2[job2], ESX.Jobs2[job2].grades[grade2]
      
          userData.job2 = {
              id = job2Object.id,
              name = job2Object.name,
              label = job2Object.label,
      
              grade = tonumber(grade2),
              grade_name = grade2Object.name,
              grade_label = grade2Object.label,
              grade_salary = grade2Object.salary,
      
              skin_male = grade2Object.skin_male and json.decode(grade2Object.skin_male) or {},
              skin_female = grade2Object.skin_female and json.decode(grade2Object.skin_female) or {},
          }
      
          -- Inventory
          if not Config.CustomInventory then
              local inventory = (result.inventory and result.inventory ~= "") and json.decode(result.inventory) or {}
      
              for name, item in pairs(ESX.Items) do
                  local count = inventory[name] or 0
                  userData.weight += (count * item.weight)
      
                  userData.inventory[#userData.inventory + 1] = {
                      name = name,
                      count = count,
                      label = item.label,
                      weight = item.weight,
                      usable = Core.UsableItemsCallbacks[name] ~= nil,
                      rare = item.rare,
                      canRemove = item.canRemove,
                  }
              end
              table.sort(userData.inventory, function(a, b)
                  return a.label < b.label
              end)
          elseif result.inventory and result.inventory ~= "" then
              userData.inventory = json.decode(result.inventory)
          end
      
          -- Group
          if result.group then
              if result.group == "superadmin" then
                  userData.group = "admin"
                  print("[^3WARNING^7] ^5Superadmin^7 detected, setting group to ^5admin^7")
              else
                  userData.group = result.group
              end
          else
              userData.group = "user"
          end
      
          -- Loadout
          if not Config.CustomInventory then
              if result.loadout and result.loadout ~= "" then
      
                  local loadout = json.decode(result.loadout)
                  for name, weapon in pairs(loadout) do
                      local label = ESX.GetWeaponLabel(name)
      
                      if label then
                          userData.loadout[#userData.loadout + 1] = {
                              name = name,
                              ammo = weapon.ammo,
                              label = label,
                              components = weapon.components or {},
                              tintIndex = weapon.tintIndex or 0,
                          }
                      end
                  end
              end
          end
      
          -- Position
          userData.coords = json.decode(result.position) or Config.DefaultSpawns[ESX.Math.Random(1,#Config.DefaultSpawns)]
      
          -- Skin
          userData.skin = (result.skin and result.skin ~= "") and json.decode(result.skin) or { sex = userData.sex == "f" and 1 or 0 }
      
          -- Metadata
          userData.metadata = (result.metadata and result.metadata ~= "") and json.decode(result.metadata) or {}
      
          -- xPlayer Creation
          local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job, userData.job2, userData.loadout, GetPlayerName(playerId), userData.coords, userData.metadata)
      
          GlobalState["playerCount"] = GlobalState["playerCount"] + 1
          ESX.Players[playerId] = xPlayer
          Core.playersByIdentifier[identifier] = xPlayer
      
          -- Identity
          if result.firstname and result.firstname ~= "" then
              userData.firstName = result.firstname
              userData.lastName = result.lastname
      
              local name = ("%s %s"):format(result.firstname, result.lastname)
              userData.name = name
      
              xPlayer.set("firstName", result.firstname)
              xPlayer.set("lastName", result.lastname)
              xPlayer.setName(name)
      
              if result.dateofbirth then
                  userData.dateofbirth = result.dateofbirth
                  xPlayer.set("dateofbirth", result.dateofbirth)
              end
              if result.sex then
                  userData.sex = result.sex
                  xPlayer.set("sex", result.sex)
              end
              if result.height then
                  userData.height = result.height
                  xPlayer.set("height", result.height)
              end
          end
      
          TriggerEvent("esx:playerLoaded", playerId, xPlayer, isNew)
          userData.money = xPlayer.getMoney()
          userData.maxWeight = xPlayer.getMaxWeight()
          xPlayer.triggerEvent("esx:playerLoaded", userData, isNew, userData.skin)
      
          if not Config.CustomInventory then
              xPlayer.triggerEvent("esx:createMissingPickups", Core.Pickups)
          elseif setPlayerInventory then
              setPlayerInventory(playerId, xPlayer, userData.inventory, isNew)
          end
      
          xPlayer.triggerEvent("esx:registerSuggestions", Core.RegisteredCommands)
          print(('[^2INFO^0] Player ^5"%s"^0 has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId))
      end
  • πŸ‡«πŸ‡· Cherchez le callbackesx:getPlayerData

  • πŸ‡ΊπŸ‡Έ Find the callback esx:getPlayerData

    • πŸ‡«πŸ‡· Puis, remplacez la fonction entiΓ¨re par celle-ci:

    • πŸ‡ΊπŸ‡Έ Then, replace the entire function with this one:

    ESX.RegisterServerCallback("esx:getPlayerData", function(source, cb)
        local xPlayer = ESX.GetPlayerFromId(source)
    
        cb({
            identifier = xPlayer.identifier,
            accounts = xPlayer.getAccounts(),
            inventory = xPlayer.getInventory(),
            job = xPlayer.getJob(),
            job2 = xPlayer.getJob2(),
            loadout = xPlayer.getLoadout(),
            money = xPlayer.getMoney(),
            position = xPlayer.getCoords(true),
            metadata = xPlayer.getMeta(),
        })
    end)
  • πŸ‡«πŸ‡· Cherchez le callback esx:getOtherPlayerData

  • πŸ‡ΊπŸ‡Έ Find the callback esx:getOtherPlayerData

    • πŸ‡«πŸ‡· Puis, remplacez la fonction entiΓ¨re par celle-ci:

    • πŸ‡ΊπŸ‡Έ Then, replace the entire function with this one:

    ESX.RegisterServerCallback("esx:getOtherPlayerData", function(_, cb, target)
        local xPlayer = ESX.GetPlayerFromId(target)
    
        cb({
            identifier = xPlayer.identifier,
            accounts = xPlayer.getAccounts(),
            inventory = xPlayer.getInventory(),
            job = xPlayer.getJob(),
            job2 = xPlayer.getJob2(),
            loadout = xPlayer.getLoadout(),
            money = xPlayer.getMoney(),
            position = xPlayer.getCoords(true),
            metadata = xPlayer.getMeta(),
        })
    end)

Last updated