14 Commits

Author SHA1 Message Date
Jim Shield
d263b1d156 v1.5 2023-02-19 21:47:06 +00:00
Jim Shield
7d8aa1bbc6 Fix version number print 2023-02-19 21:46:48 +00:00
Jim Shield
3330724d4e Fixes and support for RewardItems 2023-02-19 21:40:26 +00:00
Jim Shield
3e2eef8a38 Add options for RewardItem variables 2023-02-19 21:39:16 +00:00
Jim Shield
b1730d24f1 Remove duplicate remove event causing kicks 2023-02-17 09:43:59 +00:00
Jim Shield
632fd1de5b Merge pull request #8 from jimathy/v1.4
v1.4 Update
2023-02-14 15:17:04 +00:00
Jim Shield
d0fa6b750b Update README.md 2023-02-14 15:14:53 +00:00
Jim Shield
52816242fa Revert "v1.4 beta update info"
This reverts commit c25cb643bc.
2023-02-14 15:14:17 +00:00
Jim Shield
4e38c81645 Revert "Fix snippet formatting"
This reverts commit 7996100dad.
2023-02-14 15:14:13 +00:00
Jim Shield
7a6762ee08 Revert "Update item example snippet"
This reverts commit 6ba9febb0a.
2023-02-14 15:14:07 +00:00
Jim Shield
6ba9febb0a Update item example snippet 2023-02-14 15:10:13 +00:00
Jim Shield
7996100dad Fix snippet formatting 2023-02-14 15:08:18 +00:00
Jim Shield
c25cb643bc v1.4 beta update info 2023-02-14 15:07:46 +00:00
Jim Shield
a4901972b9 Update README.md 2023-02-14 14:56:50 +00:00
5 changed files with 92 additions and 73 deletions

View File

@@ -6,15 +6,29 @@ This script is designed as a replacement/override for food and drink consumables
It's main purpose was to make it possible to not stand up while sitting due to lazy events such as ClearPedTasks in most scripts, this one is designed to cancel the animation you have chosen, not all animations. This includes progressbar.
## v1.4 Beta Information
I've added a export system that allows scripts to easily add new foods and drinks to be usable and then sync them between players
This should work but may have issues.
But because of the export system being used, Jim-Consumables **NEEDS** to start before any scripts that use it.
And small example snippet for this imports the item and the emote, then syncs it to players
```lua
local foodTable = {
["shotfries"] = { emote = "bsfries", canRun = false, time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "food", stats = { hunger = math.random(55,65), }},
}
local emoteTable = {
["bsfries"] = {"mp_player_inteat@burger", "mp_player_int_eat_burger_fp", "Fries", AnimationOptions = { Prop = "prop_food_bs_chips", PropBone = 18905, PropPlacement = {0.09, -0.06, 0.05, 300.0, 150.0}, EmoteMoving = true, EmoteLoop = true, }},
}
for k, v in pairs(emoteTable) do exports["jim-consumables"]:importEmote(k, v) end
for k, v in pairs(foodTable) do exports["jim-consumables"]:importConsumable(k, v) end
```
This will grab the `shotfries` item info and add it to the `Config.Consumables` while the servers running and the same with the built-in emote system
# Installation
```
Please stop asking to how add a progressbar...PLEASE
This script was designed to not need one, because of how it cancels all the player animations instantly
You can manage without a progressbar.
```
This script is recommended to be ran last/at the bottom of your server.cfg because this is intended to take control of items, if ran too early the original script may override this one.
It already takes control of default qbcore food and drink, but you would probably want to add more.
@@ -28,6 +42,10 @@ To add an item, you only need to add a new item table in the Config.Consumables
heal = 0, -- Set amount to heal by after consuming
armor = 5, -- Amount of armor to add
type = "food", -- Type: "alcohol" / "drink" / "food"
returnItem = { -- Item that will be given when the item is used
item = "plastic", -- eg. Plastic bottles can give "plastic"
amount = 1,
},
stats = {
screen = "rampage", -- The screen effect to be played when after consuming the item
effect = "heal", -- The status effect given by the item, "heal" / "stamina"
@@ -70,4 +88,4 @@ If this script is enabled it will automatically try to use their system to apply
"strength" -- Strength effect
```
This script supports dpemotes style emotes, so if you have some that you want to be triggered when eating or drinking drop it in the Config.Emotes section.
This script supports dpemotes style emotes, so if you have some that you want to be triggered when eating or drinking drop it in the Config.Emotes section.

View File

@@ -28,13 +28,20 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName)
if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Starting event, locking inventory and grabbing data^7..") end
LocalPlayer.state:set("inv_busy", true, true) TriggerEvent('inventory:client:busy:status', true) TriggerEvent('canUseInventoryAndHotbar:toggle', false)
local Player = PlayerPedId()
local emote = Config.Emotes[Config.Consumables[itemName].emote] or "eat"
local emote = Config.Emotes[Config.Consumables[itemName].emote] or Config.Emotes["crisps"]
local returnItem = Config.Consumables[itemName].returnItem or nil
local animDict = tostring(emote[1])
local anim = tostring(emote[2])
local animDict, anim = tostring(emote[1]), tostring(emote[2])
local model, model2, bone, bone2, drugeffect, stress
local P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12 = table.unpack({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}) -- Default placement coord cariable
if emote.AnimationOptions.Prop then
local RewardItem = Config.Consumables[itemName].rewards or nil
local time = Config.Consumables[itemName].time or math.random(5000, 6000)
local type = Config.Consumables[itemName].type or ""
local stress = Config.Consumables[itemName].stress or 0
local heal = Config.Consumables[itemName].heal or 0
local armor = Config.Consumables[itemName].armor or 0
local string = "Using "
if emote.AnimationOptions.Prop then
model = emote.AnimationOptions.Prop
bone = GetPedBoneIndex(Player, emote.AnimationOptions.PropBone)
P1, P2, P3, P4, P5, P6 = table.unpack(emote.AnimationOptions.PropPlacement)
@@ -44,14 +51,9 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName)
P7, P8, P9, P10, P11, P12 = table.unpack(emote.AnimationOptions.SecondPropPlacement)
end
end
local time = Config.Consumables[itemName].time or math.random(5000, 6000)
local type = Config.Consumables[itemName].type or "food"
local stress = Config.Consumables[itemName].stress or 0
local heal = Config.Consumables[itemName].heal or 0
local armor = Config.Consumables[itemName].armor or 0
if type == "drink" or type == "alcohol" then string = "Drinking " end
if type == "food" then string = "Eating " end
if type == "drug" then string = "Using " end
if type == "drink" or type == "alcohol" then string = "Drinking "
elseif type == "food" then string = "Eating "
else string = "Using " end
if consuming then
cancelled = true
if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Event already started^7, ^1Cancelling^7.") end
@@ -68,12 +70,9 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName)
if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Grabbing Emote Animation Options^7...") end
if emote.AnimationOptions then
if emote.AnimationOptions.EmoteLoop then MovementType = 1
if emote.AnimationOptions.EmoteMoving then MovementType = 51
end
elseif emote.AnimationOptions.EmoteMoving then MovementType = 51
elseif emote.AnimationOptions.EmoteMoving == false then MovementType = 0
elseif emote.AnimationOptions.EmoteStuck then MovementType = 50
end
elseif emote.AnimationOptions.EmoteStuck then MovementType = 50 end
else MovementType = 0 end
if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Checking if player is in a vehicle^7...") end
local InVehicle = IsPedInAnyVehicle(Player, true)
@@ -131,18 +130,34 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName)
if not cancelled then
toggleItem(false, itemName, 1)
if returnItem ~= nil then toggleItem(true, returnItem.item, returnItem.amount) end
if QBCore.Shared.Items[itemName].thirst then TriggerServerEvent("jim-consumables:server:addThirst", QBCore.Functions.GetPlayerData().metadata["thirst"] + QBCore.Shared.Items[itemName].thirst) end
if QBCore.Shared.Items[itemName].hunger then TriggerServerEvent("jim-consumables:server:addHunger", QBCore.Functions.GetPlayerData().metadata["hunger"] + QBCore.Shared.Items[itemName].hunger) end
if not QBCore.Shared.Items[itemName].thirst and not QBCore.Shared.Items[itemName].hunger then
local hunger = 0
local thirst = 0
if Config.Consumables[itemName].stats then
if Config.Consumables[itemName].stats.hunger then hunger = Config.Consumables[itemName].stats.hunger end
TriggerServerEvent("jim-consumables:server:addHunger", QBCore.Functions.GetPlayerData().metadata["hunger"] + hunger)
if Config.Consumables[itemName].stats.thirst then thirst = Config.Consumables[itemName].stats.thirst end
TriggerServerEvent("jim-consumables:server:addThirst", QBCore.Functions.GetPlayerData().metadata["thirst"] + thirst)
-- Reward Item calculations
CreateThread(function()
if RewardItem then
for i = 1, Config.Consumables[itemName].amounttogive do
local rarity = math.random(1, countTable(Config.Rarity)) -- rarity calculation
while true do
local item = math.random(1, countTable(RewardItem)) -- random item in the list to pick
if RewardItem[item].rarity >= rarity then
toggleItem(true, RewardItem[item].item, math.random(1, RewardItem[item].max))
if Config.Debug then print("^5Debug^7: ^2Given reward prize^7: '^6"..RewardItem[item].item.."^7'") end
break
end
Wait(100)
end
Wait(1500)
end
end
end
end)
local hunger = 0
local thirst = 0
if Config.Consumables[itemName].stats then
if Config.Consumables[itemName].stats.hunger then hunger = Config.Consumables[itemName].stats.hunger end
TriggerServerEvent("jim-consumables:server:addHunger", QBCore.Functions.GetPlayerData().metadata["hunger"] + hunger)
if Config.Consumables[itemName].stats.thirst then thirst = Config.Consumables[itemName].stats.thirst end
TriggerServerEvent("jim-consumables:server:addThirst", QBCore.Functions.GetPlayerData().metadata["thirst"] + thirst)
end
if Config.Debug then print("^5Debug^7: ^2Hunger^7: [^6"..hunger.."^7] ^2Thrist^7: [^6"..thirst.."^7]" ) end
if stress and stress ~= 0 then
if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Reliving ^6"..stress.." ^2stress^7.") end
TriggerServerEvent('hud:server:RelieveStress', stress)
@@ -200,7 +215,7 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName)
else CreateThread(function() StaminaEffect({(tonumber(stats.time) or 10000), (stats.amount or 6)}) end) end
end
if GetResourceState("ps-buffs") == "started" then --PS-BUFFS ONLY
if Config.Debug then print("^5Debug^7: ^3Consume^7: ^4PS^7-^4Buffs ^2found^7, ^2hooking in to get buffs and applying ^6"..stats.effect.." Buff ^2for ^6"..(stats.time or "nil").."^7ms") end
--if Config.Debug then if stats.effect then print("^5Debug^7: ^3Consume^7: ^4PS^7-^4Buffs ^2found^7, ^2hooking in to get buffs and applying ^6"..stats.effect.." Buff ^2for ^6"..(stats.time or "nil").."^7ms") end end
if stats.effect == "armor" then exports["ps-buffs"]:AddArmorBuff((tonumber(stats.time) or 10000), (stats.amount or 6)) end
if stats.effect == "stress" then exports["ps-buffs"]:AddStressBuff((tonumber(stats.time) or 10000), (stats.amount or 6)) end
if stats.effect == "swimming" then exports["ps-buffs"]:SwimmingBuffEffect((tonumber(stats.time) or 10000), (stats.amount or 6)) end
@@ -221,18 +236,8 @@ end)
CreateThread(function()
while true do
Wait(10)
if alcoholCount > 0 then
Wait(1000 * 60 * 15)
alcoholCount -= 1
else
Wait(1000)
end
if drugCount > 0 then
Wait(1000 * 60 * 15)
drugCount -= 1
else
Wait(1000)
end
if alcoholCount > 0 then Wait(1000 * 60 * 15) alcoholCount -= 1 else Wait(1000) end
if drugCount > 0 then Wait(1000 * 60 * 15) drugCount -= 1 else Wait(1000) end
end
end)

View File

@@ -1,4 +1,4 @@
print("^2Jim^7-^2Consumables ^7v^41^7.^43^7.^42 ^7- ^2Consumables Script by ^1Jimathy^7")
print("^2Jim^7-^2Consumables ^7v^41^7.^45 ^7- ^2Consumables Script by ^1Jimathy^7")
-- If you need support I now have a discord available, it helps me keep track of issues and give better support.
@@ -45,28 +45,37 @@ Config = {
["meth"] = { emote = "coke", time = math.random(5000, 6000), stress = math.random(12, 24), heal = 0, armor = 10, type = "drug", stats = { effect = "stamina", widepupils = false, canOD = true } },
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--Example item
--[[ ["heartstopper"] = {
--[[Example item
["heartstopper"] = {
emote = "burger", -- Select an emote from below, it has to be in here
time = math.random(5000, 6000), -- Amount of time it takes to consume the item
stress = math.random(1,2), -- Amount of stress relief, can be 0
heal = 0, -- Set amount to heal by after consuming
armor = 5, -- Amount of armor to add
type = "food", -- Type: "alcohol" / "drink" / "food"
returnItem = { -- Item that will be given when the item is used
item = "plastic", -- eg. Plastic bottles can give "plastic"
amount = 1,
},
stats = {
screen = "rampage", -- The screen effect to be played when after consuming the item
screen = "thermal", -- The screen effect to be played when after consuming the item "rampage" "turbo" "focus" "weed" "trevor" "nightvision" "thermal"
effect = "heal", -- The status effect given by the item, "heal" / "stamina"
-- This supports ps-buffs effects "armor" "stress" "swimming" "hacking" "intelligence" "luck" "strength"
time = 10000, -- How long the effect should last (if not added it will default to 10000)
amount = 6, -- How much the value is changed by per second
hunger = math.random(10,20), -- The hunger/thirst stats of the item, if not found in the items.lua
thirst = math.random(10,20), -- The hunger/thirst stats of the item, if not found in the items.lua
hunger = math.random(10, 20), -- The hunger/thirst stats of the item, if not found in the items.lua
thirst = math.random(10, 20), -- The hunger/thirst stats of the item, if not found in the items.lua
},
}, ]]
--Reward Items Variables
-- These can be the only thing in a consumable table and the item will still work
amounttogive = 3, -- Used for "RewardItems", tells the script how many to give
rewards = {
[1] = {
item = "plastic", -- prize item name
max = 10, -- max amount to give (this is put into math.random(1, max) )
rarity = 1, -- the rarity system, 1 being rarest, 4 being most common
},
},
},]]
},
Emotes = {

View File

@@ -1,6 +1,6 @@
name "Jim-Consumables"
author "Jimathy"
version "v1.4"
version "v1.5"
description "Consumable Script By Jimathy"
fx_version "cerulean"
game "gta5"

View File

@@ -6,19 +6,6 @@ for k, v in pairs(Config.Consumables) do
if not Config.Emotes[v.emote] then print("^1Debug^7: ^2Emote check ^7- '^1"..k.."^7' ^2requested emote ^7'^6"..v.emote.."^7' - ^2not found in config^7.^2lua^7") end
end
RegisterNetEvent('jim-consumables:server:toggleItem', function(give, item, amount)
local src = source
if give == 0 or give == false then
if QBCore.Functions.GetPlayer(src).Functions.RemoveItem(item, amount or 1) then
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], "remove", amount or 1)
end
else
if QBCore.Functions.GetPlayer(src).Functions.AddItem(item, amount or 1) then
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], "add", amount or 1)
end
end
end)
RegisterNetEvent("jim-consumables:server:DupeWarn", function(item, newsrc)
local src = newsrc or source
local P = QBCore.Functions.GetPlayer(src)