Code Monkey home page Code Monkey logo

qb-pefcl's Introduction

qb-pefcl

This is a compatibility resource that enables PEFCL to function properly with QBCore. Please ensure that you have the latest version of PEFCL and QBCore installed Note this currently only works on PEFCL develop branch

Installation Steps:

  1. Download this repository and place it in the resources directory

  2. Add ensure qb-pefcl to your server.cfg (Start this resource after QBCore and PEFCL have been started)

  3. Navigate to the config.json in PEFCL and change the following settings:

    • Under frameworkIntegration
      • enabled: true
      • resource: qb-pefcl
    • Under target
      • type: "qb-target"
      • enabled: true
  4. Navigate to qb-core\server\player.lua and replace those functions:

    • self.Functions.AddMoney =>

          function self.Functions.AddMoney(moneytype, amount, reason)
              reason = reason or 'unknown'
              moneytype = moneytype:lower()
              amount = tonumber(amount)
              if amount < 0 then return end
              if moneytype == 'bank' then
                  local data = {}
                  data.amount = amount
                  data.message = reason
                  exports.pefcl:addBankBalance(self.PlayerData.source, data)
              else
                  if not self.PlayerData.money[moneytype] then return false end
                  self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype] + amount
              end
      
              if not self.Offline then
                  self.Functions.UpdatePlayerData()
                  if amount > 100000 then
                      TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'AddMoney', 'lightgreen', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') added, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason, true)
                  else
                      TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'AddMoney', 'lightgreen', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') added, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason)
                  end
                  TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, false)
              end
      
              return true
        end
    • self.Functions.RemoveMoney =>

            function self.Functions.RemoveMoney(moneytype, amount, reason)
              reason = reason or 'unknown'
              moneytype = moneytype:lower()
              amount = tonumber(amount)
              if amount < 0 then return end
              if not self.PlayerData.money[moneytype] then return false end
              for _, mtype in pairs(QBCore.Config.Money.DontAllowMinus) do
                  if mtype == moneytype then
                      if (self.PlayerData.money[moneytype] - amount) < 0 then
                          return false
                      end
                  end
                  if moneytype == 'bank' then
                      if (exports.pefcl:getDefaultAccountBalance(self.PlayerData.source).data - amount) < 0 then
                          return false
                      end
                  end
              end
              if moneytype == 'bank' then
                  local data = {}
                  data.amount = amount
                  data.message = reason
                  exports.pefcl:removeBankBalance(self.PlayerData.source, data)
              else
                  self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype] - amount
              end
              if not self.Offline then
                  self.Functions.UpdatePlayerData()
                  if amount > 100000 then
                      TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'RemoveMoney', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') removed, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason, true)
                  else
                      TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'RemoveMoney', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') removed, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason)
                  end
                  TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, true)
                  if moneytype == 'bank' then
                      TriggerClientEvent('qb-phone:client:RemoveBankMoney', self.PlayerData.source, amount)
                  end
              end
      
              return true
            end
    • self.Functions.SetMoney =>

          function self.Functions.SetMoney(moneytype, amount, reason)
              moneytype = moneytype:lower()
              amount = tonumber(amount)
              if amount < 0 then return false end
              if moneytype == 'bank' then
                  local data = {}
                  data.amount = amount
                  exports.pefcl:setBankBalance(self.PlayerData.source, data)
                  self.PlayerData.money[moneytype] = exports.pefcl:getDefaultAccountBalance(self.PlayerData.source).data or 0
              else
                  if not self.PlayerData.money[moneytype] then return false end
                  self.PlayerData.money[moneytype] = amount
              end
      
              if not self.Offline then
                  self.Functions.UpdatePlayerData()
                  TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'SetMoney', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') set, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype])
              end
      
              return true
          end
    • self.Functions.GetMoney =>

          function self.Functions.GetMoney(moneytype)
              if not moneytype then return false end
              moneytype = moneytype:lower()
              if moneytype == 'bank' then
                  self.PlayerData.money[moneytype] = exports.pefcl:getDefaultAccountBalance(self.PlayerData.source).data or 0
                  return exports.pefcl:getDefaultAccountBalance(self.PlayerData.source).data
              end
              return self.PlayerData.money[moneytype]
          end
  5. Navigate to qb-core\server\player.lua and add the following function:

        function self.Functions.SyncMoney() 
                local money = exports.pefcl:getDefaultAccountBalance(self.PlayerData.source).data
                self.PlayerData.money['bank'] = money
            if not self.Offline then
                self.Functions.UpdatePlayerData()
            end
        end

qb-pefcl's People

Contributors

samshanks1 avatar antonstjernquist avatar mohmando avatar berkiebb avatar roccomytacco avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.