From 1db215c4f4e80a4fff6170e7dab64519f56857e5 Mon Sep 17 00:00:00 2001 From: Apollyon <37031311+JusCampin@users.noreply.github.com> Date: Fri, 28 Jun 2024 23:22:14 -0700 Subject: [PATCH] Update horse looting (#115) * Update version - version bump * Update package.json - version bump * Update fxmanifest.lua - version bump * Update main.lua - add setting to disable horse kick * Update main.lua - removed functions for taming and looting state data - housekeeping * Update main.lua - updated looting functionality - added ped flag to disable horse kick - housekeeping --- client/main.lua | 198 ++++++++++++++++++++++++++++-------------------- config/main.lua | 3 + fxmanifest.lua | 2 +- server/main.lua | 76 ++++++++----------- ui/package.json | 2 +- version | 4 +- 6 files changed, 152 insertions(+), 133 deletions(-) diff --git a/client/main.lua b/client/main.lua index 5b34481..19751f2 100644 --- a/client/main.lua +++ b/client/main.lua @@ -508,6 +508,7 @@ function SpawnHorse(data) end local currentLevel = Citizen.InvokeNative(0x147149F2E909323C, MyHorse, 7, Citizen.ResultAsInteger()) -- GetAttributeBaseRank + -- SetPedConfigFlag if currentLevel >= 2 then Citizen.InvokeNative(0x1913FE4CBF41C463, MyHorse, 113, true) -- DisableShockingEvents @@ -516,6 +517,7 @@ function SpawnHorse(data) Citizen.InvokeNative(0x1913FE4CBF41C463, MyHorse, 312, true) -- DisableHorseGunshotFleeResponse end Citizen.InvokeNative(0x1913FE4CBF41C463, MyHorse, 297, true) -- ForceInteractionLockonOnTargetPed / Allow to Lead Horse + Citizen.InvokeNative(0x1913FE4CBF41C463, MyHorse, 471, Config.disableKick) -- DisableHorseKick Citizen.InvokeNative(0xE2487779957FE897, MyHorse, 528) -- SetTransportUsageFlags @@ -534,8 +536,7 @@ function SpawnHorse(data) TriggerServerEvent('bcc-stables:RegisterInventory', MyHorseId, horseModel) if Config.shareInventory then - local myHorseNetId = NetworkGetNetworkIdFromEntity(MyHorse) - TriggerServerEvent('bcc-stables:SetLootHorseData', myHorseNetId, MyHorseId) + Entity(MyHorse).state:set('myHorseId', MyHorseId, true) end if Config.horseTag then @@ -559,23 +560,24 @@ end CreateThread(function() if Config.shareInventory then while true do - local pedId, horseId, isLeading, ownerOfMount = nil, nil, nil, nil + local horse, horseId, isLeading, owner = nil, nil, nil, nil local playerPed = PlayerPedId() local sleep = 1000 - pedId = Citizen.InvokeNative(0x0501D52D24EA8934, 1, Citizen.ResultAsInteger()) -- Get HorsePedId in Range + if (IsEntityDead(playerPed)) or (not IsPedOnFoot(playerPed)) then goto END end - if (IsEntityDead(playerPed)) or (pedId == 0) or (pedId == MyHorse) then goto END end + horse = Citizen.InvokeNative(0x0501D52D24EA8934, 1, Citizen.ResultAsInteger()) -- Get HorsePedId in Range + if (horse == 0) or (horse == MyHorse) then goto END end - ownerOfMount = Citizen.InvokeNative(0xAD03B03737CE6810, pedId) -- GetPlayerOwnerOfMount + owner = Citizen.InvokeNative(0xAD03B03737CE6810, horse) -- GetPlayerOwnerOfMount isLeading = Citizen.InvokeNative(0xEFC4303DDC6E60D3, playerPed) -- IsPedLeadingHorse - if (ownerOfMount == 255) or isLeading then goto END end + if (owner == 255) or isLeading then goto END end sleep = 0 PromptSetActiveGroupThisFrame(LootGroup, CreateVarString(10, 'LITERAL_STRING', _U('lootInventory')), 1, 0, 0, 0) if Citizen.InvokeNative(0xC92AC953F0A982AE, LootHorse) then -- PromptHasStandardModeCompleted - horseId = Entity(pedId).state.myHorseId - OpenInventory(pedId, horseId, true) + horseId = Entity(horse).state.myHorseId + OpenInventory(horse, horseId, true) end ::END:: Wait(sleep) @@ -791,8 +793,9 @@ CreateThread(function() local data = Citizen.InvokeNative(0x57EC5FA4D4D6AFCA, 0, i, eventDataStruct:Buffer(), eventDataSize) -- GetEventData if data then if eventDataStruct:GetInt32(16) == 2 then -- Horse Taming Successful - local tamedNetId = NetworkGetNetworkIdFromEntity(eventDataStruct:GetInt32(8)) - TriggerServerEvent('bcc-stables:SetTamedData', tamedNetId) + local tamedPedId = eventDataStruct:GetInt32(8) + local tamedNetId = NetworkGetNetworkIdFromEntity(tamedPedId) + Entity(tamedPedId).state:set('netId', tamedNetId, true) end end elseif event == 402722103 then -- EVENT_ENTITY_DAMAGED @@ -1092,7 +1095,7 @@ function OpenInventory(horsePedId, horseId, isLooting) end if hasBags then - Citizen.InvokeNative(0xCD181A959CFDD7F4, PlayerPedId(), MyHorse, joaat('Interaction_LootSaddleBags'), 0, 1) -- TaskAnimalInteraction + Citizen.InvokeNative(0xCD181A959CFDD7F4, PlayerPedId(), horsePedId, joaat('Interaction_LootSaddleBags'), 0, true) -- TaskAnimalInteraction end TriggerServerEvent('bcc-stables:OpenInventory', horseId) @@ -1100,12 +1103,47 @@ end function FleeHorse() Citizen.InvokeNative(0x22B0D0E37CCB840D, MyHorse, PlayerPedId(), 150.0, 10000, 6, 3.0) -- TaskSmartFleePed + SaveHorseStats(false) + + GetControlOfHorse() + Wait(10000) DeleteEntity(MyHorse) MyHorse = nil end +function ReturnHorse() + local playerPed = PlayerPedId() + + if not MyHorse then + VORPcore.NotifyRightTip(_U('noHorse'), 4000) + return + end + + if Citizen.InvokeNative(0x460BC76A0E10655E, playerPed) then -- IsPedOnMount + Citizen.InvokeNative(0x48E92D3DDE23C23A, playerPed, 0, 0, 0, 0, MyHorse) -- TaskDismountAnimal + while not Citizen.InvokeNative(0x01FEE67DB37F59B2, playerPed) do -- IsPedOnFoot + Wait(10) + end + end + + SaveHorseStats(false) + + GetControlOfHorse() + + DeleteEntity(MyHorse) + MyHorse = nil + VORPcore.NotifyRightTip(_U('horseReturned'), 4000) +end + +function GetControlOfHorse() + while not NetworkHasControlOfEntity(MyHorse) do + NetworkRequestControlOfEntity(MyHorse) + Wait(100) + end +end + AddEventHandler('bcc-stables:HorseBonding', function() while not MaxBonding do Wait(5000) @@ -1310,91 +1348,106 @@ function HorseInfoMenu() end RegisterNetEvent('bcc-stables:BrushHorse', function() + if not MyHorse then + return VORPcore.NotifyRightTip(_U('noHorse'), 4000) + end + local playerPed = PlayerPedId() local dist = #(GetEntityCoords(playerPed) - GetEntityCoords(MyHorse)) if dist > 3.5 then - VORPcore.NotifyRightTip(_U('tooFar'), 4000) - return + return VORPcore.NotifyRightTip(_U('tooFar'), 4000) end - ClearPedTasksImmediately(playerPed) - Citizen.InvokeNative(0xCD181A959CFDD7F4, playerPed, MyHorse, joaat('Interaction_Brush'), joaat('p_brushHorse02x'), 1) -- TaskAnimalInteraction + + ClearPedTasks(playerPed) + Citizen.InvokeNative(0xCD181A959CFDD7F4, playerPed, MyHorse, joaat('Interaction_Brush'), joaat('p_brushHorse02x'), true) -- TaskAnimalInteraction Wait(5000) Citizen.InvokeNative(0x6585D955A68452A5, MyHorse) -- ClearPedEnvDirt Citizen.InvokeNative(0x523C79AEEFCC4A2A, MyHorse, 10, 'ALL') -- ClearPedDamageDecalByZone Citizen.InvokeNative(0x8FE22675A5A45817, MyHorse) -- ClearPedBloodDamage + local health = Citizen.InvokeNative(0x36731AC041289BB1, MyHorse, 0, Citizen.ResultAsInteger()) -- GetAttributeCoreValue local stamina = Citizen.InvokeNative(0x36731AC041289BB1, MyHorse, 1, Citizen.ResultAsInteger()) -- GetAttributeCoreValue - if health < 100 or stamina < 100 then - local healthBoost = Config.boost.brushHealth - local staminaBoost = Config.boost.brushStamina - if healthBoost > 0 then - local newHealth = health + healthBoost - if newHealth > 100 then - newHealth = 100 - end - Citizen.InvokeNative(0xC6258F41D86676E0, MyHorse, 0, newHealth) -- SetAttributeCoreValue + local healthBoost = Config.boost.brushHealth + local staminaBoost = Config.boost.brushStamina + + if healthBoost > 0 then + local newHealth = health + healthBoost + if newHealth > 100 then + newHealth = 100 end - if staminaBoost > 0 then - local newStamina = stamina + staminaBoost - if newStamina > 100 then - newStamina = 100 - end - Citizen.InvokeNative(0xC6258F41D86676E0, MyHorse, 1, newStamina) -- SetAttributeCoreValue + Citizen.InvokeNative(0xC6258F41D86676E0, MyHorse, 0, newHealth) -- SetAttributeCoreValue + end + + if staminaBoost > 0 then + local newStamina = stamina + staminaBoost + if newStamina > 100 then + newStamina = 100 end - if (Config.horseXpPerBrush > 0) and (not MaxBonding) then - if Config.trainerOnly then - if IsTrainer then - SaveXp('brush') - end - else + Citizen.InvokeNative(0xC6258F41D86676E0, MyHorse, 1, newStamina) -- SetAttributeCoreValue + end + + if (Config.horseXpPerBrush > 0) and (not MaxBonding) then + if Config.trainerOnly then + if IsTrainer then SaveXp('brush') end + else + SaveXp('brush') end - Citizen.InvokeNative(0x67C540AA08E4A6F5, 'Core_Fill_Up', 'Consumption_Sounds', true, 0) -- PlaySoundFrontend end + + Citizen.InvokeNative(0x67C540AA08E4A6F5, 'Core_Fill_Up', 'Consumption_Sounds', true, 0) -- PlaySoundFrontend end) RegisterNetEvent('bcc-stables:FeedHorse', function(item) + if not MyHorse then + return VORPcore.NotifyRightTip(_U('noHorse'), 4000) + end + local playerPed = PlayerPedId() local dist = #(GetEntityCoords(playerPed) - GetEntityCoords(MyHorse)) if dist > 3.5 then VORPcore.NotifyRightTip(_U('tooFar'), 4000) return end - ClearPedTasksImmediately(playerPed) - Citizen.InvokeNative(0xCD181A959CFDD7F4, playerPed, MyHorse, joaat('Interaction_Food'), joaat('s_horsnack_haycube01x'), 1) -- TaskAnimalInteraction + + ClearPedTasks(playerPed) + Citizen.InvokeNative(0xCD181A959CFDD7F4, playerPed, MyHorse, joaat('Interaction_Food'), joaat('s_horsnack_haycube01x'), true) -- TaskAnimalInteraction TriggerServerEvent('bcc-stables:RemoveItem', item) Wait(5000) + local health = Citizen.InvokeNative(0x36731AC041289BB1, MyHorse, 0, Citizen.ResultAsInteger()) -- GetAttributeCoreValue local stamina = Citizen.InvokeNative(0x36731AC041289BB1, MyHorse, 1, Citizen.ResultAsInteger()) -- GetAttributeCoreValue - if health < 100 or stamina < 100 then - local healthBoost = Config.boost.feedHealth - local staminaBoost = Config.boost.feedStamina - if healthBoost > 0 then - local newHealth = health + healthBoost - if newHealth > 100 then - newHealth = 100 - end - Citizen.InvokeNative(0xC6258F41D86676E0, MyHorse, 0, newHealth) -- SetAttributeCoreValue + local healthBoost = Config.boost.feedHealth + local staminaBoost = Config.boost.feedStamina + + if healthBoost > 0 then + local newHealth = health + healthBoost + if newHealth > 100 then + newHealth = 100 end - if staminaBoost > 0 then - local newStamina = stamina + staminaBoost - if newStamina > 100 then - newStamina = 100 - end - Citizen.InvokeNative(0xC6258F41D86676E0, MyHorse, 1, newStamina) -- SetAttributeCoreValue + Citizen.InvokeNative(0xC6258F41D86676E0, MyHorse, 0, newHealth) -- SetAttributeCoreValue + end + + if staminaBoost > 0 then + local newStamina = stamina + staminaBoost + if newStamina > 100 then + newStamina = 100 end - if (Config.horseXpPerFeed > 0) and (not MaxBonding) then - if Config.trainerOnly then - if IsTrainer then - SaveXp('feed') - end - else + Citizen.InvokeNative(0xC6258F41D86676E0, MyHorse, 1, newStamina) -- SetAttributeCoreValue + end + + if (Config.horseXpPerFeed > 0) and (not MaxBonding) then + if Config.trainerOnly then + if IsTrainer then SaveXp('feed') end + else + SaveXp('feed') end - Citizen.InvokeNative(0x67C540AA08E4A6F5, 'Core_Fill_Up', 'Consumption_Sounds', true, 0) -- PlaySoundFrontend end + + Citizen.InvokeNative(0x67C540AA08E4A6F5, 'Core_Fill_Up', 'Consumption_Sounds', true, 0) -- PlaySoundFrontend end) RegisterNetEvent('bcc-stables:UseLantern', function() @@ -1656,27 +1709,6 @@ RegisterNUICallback('sellHorse', function(data, cb) end end) -function ReturnHorse() - local playerPed = PlayerPedId() - - if not MyHorse then - VORPcore.NotifyRightTip(_U('noHorse'), 4000) - return - end - - if Citizen.InvokeNative(0x460BC76A0E10655E, playerPed) then -- IsPedOnMount - Citizen.InvokeNative(0x48E92D3DDE23C23A, playerPed, 0, 0, 0, 0, MyHorse) -- TaskDismountAnimal - while not Citizen.InvokeNative(0x01FEE67DB37F59B2, playerPed) do -- IsPedOnFoot - Wait(10) - end - end - - SaveHorseStats(false) - DeleteEntity(MyHorse) - MyHorse = nil - VORPcore.NotifyRightTip(_U('horseReturned'), 4000) -end - function SaveHorseStats(dead) local data = {} local healthCore, staminaCore diff --git a/config/main.lua b/config/main.lua index 1c08572..20b7147 100644 --- a/config/main.lua +++ b/config/main.lua @@ -127,6 +127,9 @@ Config.cooldown = { } ----------------------------------------------------- +Config.disableKick = false -- Default: false / Disable Kick from Horse +----------------------------------------------------- + -- Sell Price for Horse Purchased in Stable is 60% of Horse cashPrice Config.sellPrice = 0.70 -- Default: 0.70 ----------------------------------------------------- diff --git a/fxmanifest.lua b/fxmanifest.lua index 68478e1..23f3c78 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -34,5 +34,5 @@ files { "ui/img/*.*" } -version '1.4.10' +version '1.4.11' diff --git a/server/main.lua b/server/main.lua index b0d813e..e3e7a29 100644 --- a/server/main.lua +++ b/server/main.lua @@ -202,22 +202,6 @@ VORPcore.Callback.Register('bcc-stables:SellMyHorse', function(source, cb, data) end end) -RegisterServerEvent('bcc-stables:SetTamedData', function(netId) - if not netId then - return print('Invalid netId sent to SetTamedData') - end - local tamed = NetworkGetEntityFromNetworkId(netId) - Entity(tamed).state:set('netId', netId, true) -end) - -RegisterServerEvent('bcc-stables:SetLootHorseData', function(netId, myHorseId) - if not netId or not myHorseId then - return print('Invalid params sent to SetMyHorseData') - end - local myHorse = NetworkGetEntityFromNetworkId(netId) - Entity(myHorse).state:set('myHorseId', myHorseId, true) -end) - RegisterServerEvent('bcc-stables:SellTamedHorse', function(horseModel) local src = source local Character = VORPcore.getUser(src).getUsedCharacter @@ -326,25 +310,25 @@ exports.vorp_inventory:registerUsableItem(Config.horsebrush, function(data) local item = exports.vorp_inventory:getItem(src, Config.horsebrush) exports.vorp_inventory:closeInventory(src) TriggerClientEvent('bcc-stables:BrushHorse', src) - if Config.horsebrushDurability == true then - if not next(item.metadata) then + if not Config.horsebrushDurability then return end + + if not next(item.metadata) then + local newData = { + description = _U('horsebrushDesc') .. '
' .. _U('durability') .. 100 - 1 .. '%', + durability = 100 - 1, + id = item.id + } + exports.vorp_inventory:setItemMetadata(src, item.id, newData, 1) + else + if item.metadata.durability < 1 then + exports.vorp_inventory:subItemID(src, item.id) + else local newData = { - description = _U('horsebrushDesc') .. '
' .. _U('durability') .. 100 - 1 .. '%', - durability = 100 - 1, + description = _U('horsebrushDesc') .. '
' .. _U('durability') .. item.metadata.durability - 1 .. '%', + durability = item.metadata.durability - 1, id = item.id } exports.vorp_inventory:setItemMetadata(src, item.id, newData, 1) - else - if item.metadata.durability < 1 then - exports.vorp_inventory:subItemID(src, item.id) - else - local newData = { - description = _U('horsebrushDesc') .. '
' .. _U('durability') .. item.metadata.durability - 1 .. '%', - durability = item.metadata.durability - 1, - id = item.id - } - exports.vorp_inventory:setItemMetadata(src, item.id, newData, 1) - end end end end) @@ -354,25 +338,25 @@ exports.vorp_inventory:registerUsableItem(Config.lantern, function(data) local item = exports.vorp_inventory:getItem(src, Config.lantern) exports.vorp_inventory:closeInventory(src) TriggerClientEvent('bcc-stables:UseLantern', src) - if Config.lanternDurability == true then - if not next(item.metadata) then + if not Config.lanternDurability then return end + + if not next(item.metadata) then + local newData = { + description = _U('durability') .. 100 - 1 .. '%', + durability = 100 - 1, + id = item.id + } + exports.vorp_inventory:setItemMetadata(src, item.id, newData, 1) + else + if item.metadata.durability < 1 then + exports.vorp_inventory:subItemID(src, item.id) + else local newData = { - description = _U('durability') .. 100 - 1 .. '%', - durability = 100 - 1, + description = _U('durability') .. item.metadata.durability - 1 .. '%', + durability = item.metadata.durability - 1, id = item.id } exports.vorp_inventory:setItemMetadata(src, item.id, newData, 1) - else - if item.metadata.durability < 1 then - exports.vorp_inventory:subItemID(src, item.id) - else - local newData = { - description = _U('durability') .. item.metadata.durability - 1 .. '%', - durability = item.metadata.durability - 1, - id = item.id - } - exports.vorp_inventory:setItemMetadata(src, item.id, newData, 1) - end end end end) diff --git a/ui/package.json b/ui/package.json index 085d6a5..4f457bc 100644 --- a/ui/package.json +++ b/ui/package.json @@ -1,7 +1,7 @@ { "name": "bcc-stables", - "version": "1.4.10", + "version": "1.4.11", "private": true, "scripts": { diff --git a/version b/version index a1bd97a..aa482bf 100644 --- a/version +++ b/version @@ -1,2 +1,2 @@ -<1.4.10> -See GitHub for details! +<1.4.11> +Update horse looting.