This commit is contained in:
Nordi98 2025-07-29 00:24:49 +02:00
parent f333947ed9
commit 032ec698d8
50 changed files with 27 additions and 5845 deletions

View file

@ -1,166 +0,0 @@
EquippedItem = nil
ItemData = nil
local AttachedProp
local PerformingAction
local ProcessingEffect
function DisableControls(denied)
for i=1, #denied do
DisableControlAction(0, denied[i], true)
end
end
function RemoveAttachedProp()
if AttachedProp and DoesEntityExist(AttachedProp) then
DeleteEntity(AttachedProp)
end
AttachedProp = nil
end
function AttachProp(name)
RemoveAttachedProp()
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local cfg = Config.Items[name]
local prop = cfg.prop
AttachedProp = CreateProp(prop.model, coords.x, coords.y, coords.z, true, true, false)
SetEntityCollision(AttachedProp, false, true)
AttachEntityToEntity(AttachedProp, ped, GetPedBoneIndex(ped, prop.boneId),
prop.offset.x, prop.offset.y, prop.offset.z,
prop.rotation.x, prop.rotation.y, prop.rotation.z, false, false, false, true, 2, true)
end
function ConsumeItem(name)
if PerformingAction then return end
PerformingAction = "consume"
local cfg = Config.Items[name]
local anim = cfg.animation
local ped = PlayerPedId()
CreateThread(function()
local timeLeft = anim.time
SendNUIMessage({
type = "holdInteract",
bool = true
})
while PerformingAction == "consume" and timeLeft > 0 do
if anim.time - timeLeft > 100 and not IsEntityPlayingAnim(ped, anim.dict, anim.anim, 13) then
timeLeft = timeLeft - 100
PlayAnim(ped, anim.dict, anim.anim, anim.params[1] or 1.0, anim.params[2] or -1.0, anim.params[3] or -1, anim.params[4] or 1, anim.params[5] or 1, anim.params[6], anim.params[7], anim.params[8])
Wait(100)
else
timeLeft = timeLeft - 10
Wait(10)
end
end
SendNUIMessage({
type = "holdInteract",
bool = false
})
ClearPedTasks(ped)
if timeLeft > 0 and anim.time - timeLeft <= 100 then
OptionsMenu()
PerformingAction = nil
elseif timeLeft <= 0 then
lib.callback("pickle_consumables:useItem", "", function(result, uses)
if result and Config.Effects[cfg.effect?.name or ""] then
CreateThread(function()
if ProcessingEffect and not Config.Effects[cfg.effect.name].canOverlap then return end
ProcessingEffect = true
Config.Effects[cfg.effect.name].process(cfg.effect)
ProcessingEffect = false
end)
end
ItemData.uses = uses
if uses < 1 then
return RemoveItem()
end
local cfg = Config.Items[name]
SendNUIMessage({
type = "displayApp",
data = { quantity = uses, time = cfg.animation.time }
})
PerformingAction = nil
end)
else
PerformingAction = nil
end
end)
end
function RemoveItem()
local ped = PlayerPedId()
SendNUIMessage({
type = "hideApp",
})
RemoveAttachedProp()
ClearPedTasks(ped)
EquippedItem = nil
ItemData = nil
PerformingAction = nil
end
function ItemThread(name, metadata)
if EquippedItem then return end
EquippedItem = name
ItemData = metadata
AttachProp(name)
local cfg = Config.Items[name]
SendNUIMessage({
type = "displayApp",
data = { quantity = ItemData.uses, time = cfg.animation.time }
})
CreateThread(function()
local pressTime = 0
local holding = false
while EquippedItem == name do
local ped = PlayerPedId()
if IsControlJustPressed(1, 45) then
TriggerServerEvent("pickle_consumables:returnItem")
RemoveItem()
elseif IsControlPressed(1, 191) or IsControlPressed(1, 51) then
if not PerformingAction then
ConsumeItem(name)
end
elseif PerformingAction then
PerformingAction = nil
end
if cfg.idle and not PerformingAction then
local anim = cfg.idle
if not IsEntityPlayingAnim(ped, anim.dict, anim.anim, 13) then
PlayAnim(ped, anim.dict, anim.anim, anim.params[1] or 1.0, anim.params[2] or -1.0, anim.params[3] or -1, anim.params[4] or 1, anim.params[5] or 1, anim.params[6], anim.params[7], anim.params[8])
Wait(100)
end
end
if GetEntityHealth(ped) < 1 then
local coords = GetEntityCoords(AttachedProp)
local _, zCoords = GetGroundZFor_3dCoord(coords.x, coords.y, coords.z)
RemoveItem()
TriggerServerEvent("pickle_consumables:drop:createDrop", vector3(coords.x, coords.y, zCoords + 1.0))
end
if insideMenu then
DisableControls({1, 2, 24, 69, 70, 92, 114, 140, 141, 142, 257, 263, 264})
else
DisableControls({24, 69, 70, 92, 114, 140, 141, 142, 257, 263, 264})
end
Wait(0)
end
local ped = PlayerPedId()
ClearPedTasks(ped)
end)
end
RegisterNetEvent("pickle_consumables:equipItem", function(name, metadata)
if not Config.Items[name] then return print("^1ERROR: This item is not configured.^0") end
if EquippedItem then return ShowNotification(_L("item_active")) end
ItemThread(name, metadata)
end)
RegisterNetEvent("pickle_consumables:removeItem", function()
RemoveItem()
end)
AddEventHandler("onResourceStop", function(name)
if name ~= GetCurrentResourceName() then return end
TransitionFromBlurred(0)
RemoveAttachedProp()
end)

View file

@ -1,81 +0,0 @@
Players = {}
function EquipItem(source, item, refund)
if Players[source] then
if refund then
Inventory.AddItem(source, item.itemKey, 1, {itemKey = item.itemKey, uses = item.uses}, item.slot)
end
return
end
Players[source] = item
TriggerClientEvent("pickle_consumables:equipItem", source, item.itemKey, item)
end
function GiveRewards(source, rewards)
for i=1, #rewards do
local reward = rewards[i]
local amount = (type(reward.amount) == "table" and math.random(reward.amount[1], reward.amount[2]) or reward.amount)
if not reward.type or reward.type == "item" then
Inventory.AddItem(source, reward.name, amount)
elseif reward.type == "money" then
AddMoney(source, amount)
end
end
end
CreateThread(function()
Wait(1000)
for k,v in pairs(Config.Items) do
RegisterUsableItem(k, function(source, metadata, slot)
if Players[source] then return end
local metadata = metadata or {}
if not metadata.itemKey then
metadata.itemKey = k
metadata.uses = v.uses
metadata.slot = slot
end
Inventory.RemoveItem(source, metadata.itemKey, 1, slot)
EquipItem(source, metadata, false)
end)
end
end)
lib.callback.register("pickle_consumables:useItem", function(source)
if not Players[source] then return end
local metadata = Players[source]
local cfg = Config.Items[metadata.itemKey]
if metadata.uses < 1 then
ShowNotification(source, _L("no_uses_left"))
return false, metadata.uses
end
metadata.uses = metadata.uses - 1
if metadata.uses < 1 then
Players[source] = nil
end
if cfg then
if cfg.rewards then
GiveRewards(source, cfg.rewards)
end
if cfg.status then
ExecuteStatus(source, cfg.status)
end
end
return true, metadata.uses
end)
RegisterNetEvent("pickle_consumables:returnItem", function(destroy)
local source = source
if not Players[source] then return end
local item = Players[source]
if not destroy then
Inventory.AddItem(source, item.itemKey, 1, {itemKey = item.itemKey, uses = item.uses}, item.slot)
end
Players[source] = nil
end)
-- CLIENT
-- lib.callback("pickle_consumables:canUseItem", "", function(game_id, games)
-- end)
-- lib.callback("pickle_consumables:useItem", "", function(game_id, games)
-- end)