From 6c3650fa30c581417466515c4e1994cad9109a57 Mon Sep 17 00:00:00 2001 From: Nfire Date: Sat, 16 Apr 2022 11:49:41 +0200 Subject: [PATCH] feat(server): add Carcass degradation --- README.md | 9 ++++++++- config.lua | 18 ++++++++++-------- fxmanifest.lua | 2 +- server/main.lua | 19 ++++++++++++++++++- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 253ee50..9573eb1 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Item to add : label = 'Boar Carcass', weight = 20000, stack = false, + degrade = 5*60, client = { add = function() TriggerEvent('nfire_hunting:CarryCarcass') @@ -45,6 +46,7 @@ Item to add : label = 'Hawk Carcass', weight = 3000, stack = false, + degrade = 5*60, client = { add = function() TriggerEvent('nfire_hunting:CarryCarcass') @@ -58,6 +60,7 @@ Item to add : label = 'Cormorant Carcass', weight = 3000, stack = false, + degrade = 5*60, client = { add = function() TriggerEvent('nfire_hunting:CarryCarcass') @@ -71,6 +74,7 @@ Item to add : label = 'Coyote Carcass', weight = 3000, stack = false, + degrade = 5*60, client = { add = function() TriggerEvent('nfire_hunting:CarryCarcass') @@ -84,6 +88,7 @@ Item to add : label = 'Deer Carcass', weight = 18000, stack = false, + degrade = 5*60, client = { add = function() TriggerEvent('nfire_hunting:CarryCarcass') @@ -94,9 +99,10 @@ Item to add : } }, ['carcass_mtlion'] = { - label = 'Montain Lion Carcass', + label = 'Mountain Lion Carcass', weight = 16000, stack = false, + degrade = 5*60, client = { add = function() TriggerEvent('nfire_hunting:CarryCarcass') @@ -110,6 +116,7 @@ Item to add : label = 'Rabbit Carcass', weight = 3000, stack = false, + degrade = 5*60, client = { add = function() TriggerEvent('nfire_hunting:CarryCarcass') diff --git a/config.lua b/config.lua index 7818a9e..8cda661 100644 --- a/config.lua +++ b/config.lua @@ -27,15 +27,17 @@ Config.goodWeapon = { } Config.sellPrice = { - ['carcass_boar'] = 1000, - ['carcass_hawk'] = 1200, - ['carcass_cormorant'] = 600, - ['carcass_coyote'] = 300, - ['carcass_deer'] = 500, - ['carcass_mtlion']= 800, - ['carcass_rabbit'] = 400 + ['carcass_boar'] = {min = 150,max = 1000}, -- min = 0 durability max = 100 durability + ['carcass_hawk'] = {min = 200,max = 1200}, + ['carcass_cormorant'] = {min = 60,max = 600}, + ['carcass_coyote'] = {min = 30,max = 300}, + ['carcass_deer'] = {min = 50,max = 500}, + ['carcass_mtlion'] = {min = 80,max = 800}, + ['carcass_rabbit'] = {min = 40,max = 400} } +Config.degrade = true + Config.gradeMultiplier = { ['★☆☆'] = 0.5, -- not killed by a goodWeapon ['★★☆'] = 1.0, -- killed by a goodWeapon @@ -57,7 +59,7 @@ Config.antiFarm = { } ----------------------------------------------------------------------------------------------------------------------- +-------------------------------------- DO NOT TOUCH -------------------------------------------------------------------------------- Locales = {} function _(str, ...) -- Translate string diff --git a/fxmanifest.lua b/fxmanifest.lua index 1a122f3..7af454b 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -5,7 +5,7 @@ game 'gta5' name "nfire_hunting" description "Hunting Script made for ox_inventory" author "Nfire" -version "1.1.2" +version "1.2.0" dependencies { '/server:5181', diff --git a/server/main.lua b/server/main.lua index 7280485..c8151b7 100644 --- a/server/main.lua +++ b/server/main.lua @@ -50,7 +50,16 @@ RegisterNetEvent('nfire_hunting:SellCarcass') AddEventHandler('nfire_hunting:SellCarcass',function (item) local itemData = exports.ox_inventory:Search(source,'slots', item)[1] if itemData.count >= 1 then - local reward = Config.sellPrice[item] * Config.gradeMultiplier[itemData.metadata.type] + local reward = Config.sellPrice[item].max * Config.gradeMultiplier[itemData.metadata.type] + if Config.degrade and itemData.metadata.durability ~= nil then + local currentTime = os.time() + local maxTime = itemData.metadata.durability + local minTime = maxTime - itemData.metadata.degrade * 60 + if currentTime >= maxTime then + currentTime = maxTime + end + reward =math.floor(map(currentTime, maxTime, minTime, Config.sellPrice[item].min * Config.gradeMultiplier[itemData.metadata.type], Config.sellPrice[item].max * Config.gradeMultiplier[itemData.metadata.type])) + end exports.ox_inventory:RemoveItem(source, item, 1, nil, itemData.slot) exports.ox_inventory:AddItem(source, 'money', reward) end @@ -85,6 +94,10 @@ function Antifarm(source,coords) return true end +function map(x, in_min, in_max, out_min, out_max) + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min +end + -- lib.addCommand('group.admin', 'giveCarcass', function(source, args) -- for key, value in pairs(Config.carcass) do -- exports.ox_inventory:AddItem(source, value, 1, {type = '★☆☆', image = value..1}) @@ -100,4 +113,8 @@ end -- lib.addCommand('group.admin', 'printAntifarm', function(source, args) -- print(json.encode(antifarm,{indent = true})) +-- end) + +-- lib.addCommand('group.admin', 'printInv', function(source, args) +-- print(json.encode(exports.ox_inventory:Inventory(source).items,{indent = true})) -- end) \ No newline at end of file