Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
feat(server): add Carcass degradation
Browse files Browse the repository at this point in the history
  • Loading branch information
N-fire committed Apr 16, 2022
1 parent eccb2e8 commit 6c3650f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Item to add :
label = 'Boar Carcass',
weight = 20000,
stack = false,
degrade = 5*60,
client = {
add = function()
TriggerEvent('nfire_hunting:CarryCarcass')
Expand All @@ -45,6 +46,7 @@ Item to add :
label = 'Hawk Carcass',
weight = 3000,
stack = false,
degrade = 5*60,
client = {
add = function()
TriggerEvent('nfire_hunting:CarryCarcass')
Expand All @@ -58,6 +60,7 @@ Item to add :
label = 'Cormorant Carcass',
weight = 3000,
stack = false,
degrade = 5*60,
client = {
add = function()
TriggerEvent('nfire_hunting:CarryCarcass')
Expand All @@ -71,6 +74,7 @@ Item to add :
label = 'Coyote Carcass',
weight = 3000,
stack = false,
degrade = 5*60,
client = {
add = function()
TriggerEvent('nfire_hunting:CarryCarcass')
Expand All @@ -84,6 +88,7 @@ Item to add :
label = 'Deer Carcass',
weight = 18000,
stack = false,
degrade = 5*60,
client = {
add = function()
TriggerEvent('nfire_hunting:CarryCarcass')
Expand All @@ -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')
Expand All @@ -110,6 +116,7 @@ Item to add :
label = 'Rabbit Carcass',
weight = 3000,
stack = false,
degrade = 5*60,
client = {
add = function()
TriggerEvent('nfire_hunting:CarryCarcass')
Expand Down
18 changes: 10 additions & 8 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,7 +59,7 @@ Config.antiFarm = {
}


----------------------------------------------------------------------------------------------------------------------
-------------------------------------- DO NOT TOUCH --------------------------------------------------------------------------------
Locales = {}

function _(str, ...) -- Translate string
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
19 changes: 18 additions & 1 deletion server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand All @@ -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)

0 comments on commit 6c3650f

Please sign in to comment.