Skip to content

Commit

Permalink
New job check and change horse/player relationship (#72)
Browse files Browse the repository at this point in the history
* update release.yml

added bcc_stables.sql

* Housekeeping config.lua

* Housekeeping readme

* update version

update from version 1.1.0 to 1.1.1

* update license file ext

* update laguages

* update server.lua

- Add new job check
- update buy and save function for escaping horse purchase
- Housekeeping

* update client.lua

- moved job check to server callback
- update blip and npc structure
- updated horse name func to support escaping during rename process
- updated distance checks
- housekeeping
  • Loading branch information
JusCampin authored Jul 15, 2023
1 parent 9b84f75 commit cc25954
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 404 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
working-directory: ./ui
- uses: vimtor/action-zip@v1
with:
files: fxmanifest.lua license.md README.md locale.lua version ui/dist client server config img languages
files: fxmanifest.lua LICENSE.md README.md locale.lua version ui/dist client server config img languages bcc_stables.sql
recursive: false
dest: bcc-stables.zip
- name: get-npm-version
Expand Down
File renamed without changes.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# bcc-stables

#### Description

Stables script for RedM servers using the [VORP framework](https://github.com/VORPCORE). Using the 7 original stable locations from the game. More stable locations may be added in the `config.lua` file.

#### Features

- Buy and sell horses through the stables
- Cash and/or gold may be used for payments in the menu
- Individual inventory for each horse
Expand All @@ -23,21 +21,17 @@ Stables script for RedM servers using the [VORP framework](https://github.com/VO
- Use oil lantern from inventory to equip a lantern to your horse

#### Tips

- Whistleing -- A short whistle will call your horse. A long one will set your horse to follow you. A second long whistle or mounting your horse will cancel following.

#### Commands

`/horseRespawn` Respawn your horse while bypassing the distance check

#### Dependencies

- [vorp_core](https://github.com/VORPCORE/vorp-core-lua)
- [vorp_inventory](https://github.com/VORPCORE/vorp_inventory-lua)
- [vorp_utils](https://github.com/VORPCORE/vorp_utils)

#### Installation

- Download the latest release `bcc-stables.zip` at [/releases/latest](https://github.com/BryceCanyonCounty/bcc-stables/releases/latest)
- Add `bcc-stables` folder to your resources folder
- Add `ensure bcc-stables` to your `resources.cfg`
Expand All @@ -47,12 +41,9 @@ Stables script for RedM servers using the [VORP framework](https://github.com/VO
- Restart server

#### Credits

- lrp_stables
- vorp_stores
- [ByteSizd](https://github.com/AndrewR3K) - Vue Boilerplate for RedM
- [SavSin](https://github.com/DavFount) - UI conversion to VueJS

#### GitHub

- https://github.com/BryceCanyonCounty/bcc-stables
254 changes: 84 additions & 170 deletions client/client.lua

Large diffs are not rendered by default.

240 changes: 120 additions & 120 deletions config/config.lua

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ dependencies {
'vorp_utils'
}

version '1.1.0'
version '1.1.1'
4 changes: 3 additions & 1 deletion languages/en_lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Locales["en_lang"] = {
shortGold = "You don't have enough gold",
shortCash = "You don't have enough money",
needJob = "You don't have the required job!",
needJobGrade = "You don't have the required job grade!",
horseLimit = "You can have a maximum of ~o~",
horses = "~q~ horses!",
soldHorse = "You sold a horse for: $~t6~",
Expand All @@ -23,5 +24,6 @@ Locales["en_lang"] = {
noSaddlebags = "You need ~o~saddlebags~q~ to store your items",
noHorses = "You don't own any horses",
purchaseSuccessful = "Purchase Successful!",
tooFar = "You're not close enough to your horse"
tooFar = "You're not close enough to your horse",
nameHorse = "Name your horse:"
}
4 changes: 3 additions & 1 deletion languages/it_lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Locales["it_lang"] = {
shortGold = "Non hai abbastanza oro",
shortCash = "Non hai abbastanza dollari",
needJob = "You don't have the required job!",
needJobGrade = "You don't have the required job grade!",
horseLimit = "Puoi avere un massimo di ~o~",
horses = "~q~ cavalli!",
soldHorse = "Hai venduto un cavallo per: $~t6~",
Expand All @@ -23,5 +24,6 @@ Locales["it_lang"] = {
noSaddlebags = "Hai bisogno delle ~o~bisacce~q~ per riporre i tuoi oggetti",
noHorses = "Non possiedi nessun cavallo",
purchaseSuccessful = "Acquisto completato!",
tooFar = "You're not close enough to your horse"
tooFar = "You're not close enough to your horse",
nameHorse = "Name your horse:"
}
211 changes: 111 additions & 100 deletions server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,8 @@ local VORPInv = {}
TriggerEvent('getCore', function(core)
VORPcore = core
end)

VORPInv = exports.vorp_inventory:vorp_inventoryApi()

RegisterNetEvent('bcc-stables:GetMyHorses', function()
local src = source
local Character = VORPcore.getUser(src).getUsedCharacter
local identifier = Character.identifier
local charid = Character.charIdentifier

MySQL.Async.fetchAll('SELECT * FROM player_horses WHERE identifier = ? AND charid = ?', { identifier, charid },
function(horses)
TriggerClientEvent('bcc-stables:ReceiveHorsesData', src, horses)
end)
end)

RegisterNetEvent('bcc-stables:BuyHorse', function(data)
local src = source
local Character = VORPcore.getUser(src).getUsedCharacter
Expand All @@ -26,35 +13,30 @@ RegisterNetEvent('bcc-stables:BuyHorse', function(data)
local maxHorses = Config.maxHorses

MySQL.Async.fetchAll('SELECT * FROM player_horses WHERE identifier = ? AND charid = ?', { identifier, charid },
function(horses)
if #horses >= maxHorses then
VORPcore.NotifyRightTip(src, _U('horseLimit') .. maxHorses .. _U('horses'), 5000)
function(horses)
if #horses >= maxHorses then
VORPcore.NotifyRightTip(src, _U('horseLimit') .. maxHorses .. _U('horses'), 5000)
TriggerClientEvent('bcc-stables:StableMenu', src)
return
end
if data.IsCash then
if Character.money >= data.Cash then
TriggerClientEvent('bcc-stables:SetHorseName', src, data, false)
else
VORPcore.NotifyRightTip(src, _U('shortCash'), 5000)
TriggerClientEvent('bcc-stables:StableMenu', src)
return
end
Wait(200)

if data.IsCash then
local cashPrice = data.Cash
if Character.money >= cashPrice then
Character.removeCurrency(0, cashPrice)
else
VORPcore.NotifyRightTip(src, _U('shortCash'), 5000)
TriggerClientEvent('bcc-stables:StableMenu', src)
return
end
else
if Character.gold >= data.Gold then
TriggerClientEvent('bcc-stables:SetHorseName', src, data, false)
else
local goldPrice = data.Gold
if Character.gold >= goldPrice then
Character.removeCurrency(1, goldPrice)
else
VORPcore.NotifyRightTip(src, _U('shortGold'), 5000)
TriggerClientEvent('bcc-stables:StableMenu', src)
return
end
VORPcore.NotifyRightTip(src, _U('shortGold'), 5000)
TriggerClientEvent('bcc-stables:StableMenu', src)
return
end
TriggerClientEvent('bcc-stables:SetHorseName', src, data, false)
end)
end
end)
end)

RegisterNetEvent('bcc-stables:BuyTack', function(data)
Expand Down Expand Up @@ -89,17 +71,23 @@ RegisterNetEvent('bcc-stables:SaveNewHorse', function(data, name)
local charid = Character.charIdentifier

MySQL.Async.execute('INSERT INTO player_horses (identifier, charid, name, model, gender) VALUES (?, ?, ?, ?, ?)',
{ identifier, charid, tostring(name), data.ModelH, data.gender },
function(done)
end)
{ identifier, charid, tostring(name), data.ModelH, data.gender },
function(done)
if data.IsCash then
Character.removeCurrency(0, data.Cash)
else
Character.removeCurrency(1, data.Gold)
end
TriggerClientEvent('bcc-stables:StableMenu', src)
end)
end)

RegisterNetEvent('bcc-stables:UpdateHorseName', function(data, name)
local horseId = data.horseId

MySQL.Async.execute('UPDATE player_horses SET name = ? WHERE id = ?', { name, horseId },
function(done)
end)
local src = source
MySQL.Async.execute('UPDATE player_horses SET name = ? WHERE id = ?', { name, data.horseId },
function(done)
TriggerClientEvent('bcc-stables:StableMenu', src)
end)
end)

RegisterNetEvent('bcc-stables:SelectHorse', function(id)
Expand All @@ -109,23 +97,19 @@ RegisterNetEvent('bcc-stables:SelectHorse', function(id)
local charid = Character.charIdentifier

MySQL.Async.fetchAll('SELECT * FROM player_horses WHERE identifier = ? AND charid = ?', { identifier, charid },
function(horse)
for i = 1, #horse do
local horseId = horse[i].id
MySQL.Async.execute(
'UPDATE player_horses SET selected = ? WHERE identifier = ? AND charid = ? AND id = ?',
{ 0, identifier, charid, horseId },
function(horse)
for i = 1, #horse do
local horseId = horse[i].id
MySQL.Async.execute('UPDATE player_horses SET selected = ? WHERE identifier = ? AND charid = ? AND id = ?', { 0, identifier, charid, horseId },
function(done)
if horse[i].id == id then
MySQL.Async.execute('UPDATE player_horses SET selected = ? WHERE identifier = ? AND charid = ? AND id = ?', { 1, identifier, charid, id },
function(done)
if horse[i].id == id then
MySQL.Async.execute(
'UPDATE player_horses SET selected = ? WHERE identifier = ? AND charid = ? AND id = ?',
{ 1, identifier, charid, id },
function(done)
end)
end
end)
end
end)
end
end)
end
end)
end)

RegisterNetEvent('bcc-stables:GetSelectedHorse', function()
Expand All @@ -135,18 +119,29 @@ RegisterNetEvent('bcc-stables:GetSelectedHorse', function()
local charid = Character.charIdentifier

MySQL.Async.fetchAll('SELECT * FROM player_horses WHERE identifier = ? AND charid = ?', { identifier, charid },
function(horses)
if #horses ~= 0 then
for i = 1, #horses do
if horses[i].selected == 1 then
TriggerClientEvent('bcc-stables:SetHorseInfo', src, horses[i].model, horses[i].name,
horses[i].components, horses[i].id, horses[i].gender)
end
function(horses)
if #horses ~= 0 then
for i = 1, #horses do
if horses[i].selected == 1 then
TriggerClientEvent('bcc-stables:SetHorseInfo', src, horses[i].model, horses[i].name, horses[i].components, horses[i].id, horses[i].gender)
end
else
VORPcore.NotifyRightTip(src, _U('noHorses'), 5000)
end
end)
else
VORPcore.NotifyRightTip(src, _U('noHorses'), 5000)
end
end)
end)

RegisterNetEvent('bcc-stables:GetMyHorses', function()
local src = source
local Character = VORPcore.getUser(src).getUsedCharacter
local identifier = Character.identifier
local charid = Character.charIdentifier

MySQL.Async.fetchAll('SELECT * FROM player_horses WHERE identifier = ? AND charid = ?', { identifier, charid },
function(horses)
TriggerClientEvent('bcc-stables:ReceiveHorsesData', src, horses)
end)
end)

RegisterNetEvent('bcc-stables:UpdateComponents', function(components, horseId, MyHorse_entity)
Expand All @@ -157,10 +152,10 @@ RegisterNetEvent('bcc-stables:UpdateComponents', function(components, horseId, M
local encodedComponents = json.encode(components)

MySQL.Async.execute('UPDATE player_horses SET components = ? WHERE identifier = ? AND charid = ? AND id = ?',
{ encodedComponents, identifier, charid, horseId },
function(done)
TriggerClientEvent('bcc-stables:SetComponents', src, MyHorse_entity, components)
end)
{ encodedComponents, identifier, charid, horseId },
function(done)
TriggerClientEvent('bcc-stables:SetComponents', src, MyHorse_entity, components)
end)
end)

RegisterNetEvent('bcc-stables:SellHorse', function(id)
Expand All @@ -171,26 +166,26 @@ RegisterNetEvent('bcc-stables:SellHorse', function(id)
local modelHorse = nil

MySQL.Async.fetchAll('SELECT * FROM player_horses WHERE identifier = ? AND charid = ?', { identifier, charid },
function(horses)
for i = 1, #horses do
if tonumber(horses[i].id) == tonumber(id) then
modelHorse = horses[i].model
MySQL.Async.execute('DELETE FROM player_horses WHERE identifier = ? AND charid = ? AND id = ?',
{ identifier, charid, id },
function(done)
for _, horseConfig in pairs(Config.Horses) do
for models, values in pairs(horseConfig.colors) do
if models == modelHorse then
local sellPrice = (Config.sellPrice * values.cashPrice)
Character.addCurrency(0, sellPrice)
VORPcore.NotifyRightTip(src, _U('soldHorse') .. sellPrice, 5000)
end
end
function(horses)
for i = 1, #horses do
if tonumber(horses[i].id) == tonumber(id) then
modelHorse = horses[i].model
MySQL.Async.execute('DELETE FROM player_horses WHERE identifier = ? AND charid = ? AND id = ?', { identifier, charid, id },
function(done)
for _, horseConfig in pairs(Config.Horses) do
for models, values in pairs(horseConfig.colors) do
if models == modelHorse then
local sellPrice = (Config.sellPrice * values.cashPrice)
Character.addCurrency(0, sellPrice)
VORPcore.NotifyRightTip(src, _U('soldHorse') .. sellPrice, 5000)
end
end)
end
end
end
end)
end
end)
end
TriggerClientEvent('bcc-stables:StableMenu', src)
end)
end)

-- Inventory
Expand Down Expand Up @@ -228,14 +223,31 @@ VORPInv.RegisterUsableItem('oil_lantern', function(data)
TriggerClientEvent('bcc-stables:UseLantern', src, data)
end)

-- Job Check
RegisterNetEvent('bcc-stables:GetPlayerJob', function()
-- Check if Player has Required Job
VORPcore.addRpcCallback('CheckPlayerJob', function(source, cb, shop)
local src = source
local Character = VORPcore.getUser(src).getUsedCharacter
local CharacterJob = Character.job
local CharacterGrade = Character.jobGrade
local playerJob = Character.job
local jobGrade = Character.jobGrade

TriggerClientEvent('bcc-stables:SendPlayerJob', src, CharacterJob, CharacterGrade)
if playerJob then
for _, job in pairs(Config.shops[shop].allowedJobs) do
if playerJob == job then
if tonumber(jobGrade) >= tonumber(Config.shops[shop].jobGrade) then
cb(true)
else
VORPcore.NotifyRightTip(src, _U('needJobGrade'), 4000)
cb(false)
end
else
VORPcore.NotifyRightTip(src, _U('needJob'), 4000)
cb(false)
end
end
else
VORPcore.NotifyRightTip(src, _U('needJob'), 4000)
cb(false)
end
end)

--- Check if properly downloaded
Expand All @@ -245,7 +257,6 @@ function file_exists(name)
end

if not file_exists('./ui/index.html') then
print("^1 INCORRECT DOWNLOAD! ^0")
print(
'^4 Please Download: ^2(bcc-stables.zip) ^4from ^3<https://github.com/BryceCanyonCounty/bcc-stables/releases/latest>^0')
print('^1 INCORRECT DOWNLOAD! ^0')
print('^4 Please Download: ^2(bcc-stables.zip) ^4from ^3<https://github.com/BryceCanyonCounty/bcc-stables/releases/latest>^0')
end
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bcc-stables",
"version": "1.1.0",
"version": "1.1.1",
"private": true,
"scripts": {
"shim": "node build/fxupdate.js",
Expand Down

0 comments on commit cc25954

Please sign in to comment.