Git Product home page Git Product logo

Comments (1)

gandie avatar gandie commented on September 24, 2024

What exactly do u need? Advice on esx_xp integration?
Maybe the following helps ( pretty clumsy, thats what i did ). Will hopefully apply similar stuff to more esx mods in the next days. Im curious to hear the authors opinion ( good job, nice mod btw 👍 ).

esx_weaponshop integration

  • Add rank column

alter table sesx.weashops add column rank int default 0;

Maybe change your database scheme from sesx to whatever yours is.

Storing ranks in db feels better than in config files, but other mods will require adding config values for rank checking.

Balancing the weapon ranks in db will be tested, can not recommend anything yet.

  • Alter weaponshops code to respect and show new rank column

Server side, add rank column to database reading functions and check when buying:

diff --git a/resources/[esx]/esx_weaponshop/server/main.lua b/resources/[esx]/esx_weaponshop/server/main.lua
index c2b0b65..5583ff2 100644
--- a/resources/[esx]/esx_weaponshop/server/main.lua
+++ b/resources/[esx]/esx_weaponshop/server/main.lua
@@ -14,7 +14,8 @@ MySQL.ready(function()
                        table.insert(shopItems[result[i].zone], {
                                item  = result[i].item,
                                price = result[i].price,
-                               label = ESX.GetWeaponLabel(result[i].item)
+                               label = ESX.GetWeaponLabel(result[i].item),
+                               rank  = result[i].rank
                        })
                end
 
@@ -45,6 +46,15 @@ end)
 ESX.RegisterServerCallback('esx_weaponshop:buyWeapon', function(source, cb, weaponName, zone)
        local xPlayer = ESX.GetPlayerFromId(source)
        local price = GetPrice(weaponName, zone)
+       local rank_needed = GetRank(weaponName, zone)
+
+       local playerRank = xPlayer.get("rank")
+
+       if playerRank < rank_needed then
+               xPlayer.showNotification("Rank too low!")
+               cb(false)
+               return
+       end
 
        if price == 0 then
                print(('esx_weaponshop: %s attempted to buy a unknown weapon!'):format(xPlayer.identifier))
@@ -79,6 +89,19 @@ ESX.RegisterServerCallback('esx_weaponshop:buyWeapon', function(source, cb, weap
        end
 end)
 
+function GetRank(weaponName, zone)
+       local rank = MySQL.Sync.fetchScalar('SELECT rank FROM weashops WHERE zone = @zone AND item = @item', {
+               ['@zone'] = zone,
+               ['@item'] = weaponName
+       })
+
+       if rank then
+               return rank
+       else
+               return 0
+       end
+end
+
 function GetPrice(weaponName, zone)
        local price = MySQL.Sync.fetchScalar('SELECT price FROM weashops WHERE zone = @zone AND item = @item', {
                ['@zone'] = zone,

Client side, show rank in shop:

--- a/resources/[esx]/esx_weaponshop/client/main.lua
+++ b/resources/[esx]/esx_weaponshop/client/main.lua
@@ -56,9 +56,10 @@ function OpenShopMenu(zone)
 
        for i=1, #Config.Zones[zone].Items, 1 do
                local item = Config.Zones[zone].Items[i]
+               local rank = item.rank
 
                table.insert(elements, {
-                       label = ('%s - <span style="color: green;">%s</span>'):format(item.label, _U('shop_menu_item', ESX.Math.GroupDigits(item.price))),
+                       label = ('%s - <span style="color: green;">%s</span> (%s)'):format(item.label, _U('shop_menu_item', ESX.Math.GroupDigits(item.price)), ESX.Math.GroupDigits(rank)),
                        price = item.price,
                        weaponName = item.item
                })

from esx_xp.

Related Issues (20)

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.