neues consumables
This commit is contained in:
		
							parent
							
								
									9d9a5c919b
								
							
						
					
					
						commit
						fbaf832f92
					
				
					 49 changed files with 3321 additions and 0 deletions
				
			
		|  | @ -0,0 +1,166 @@ | |||
| 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) | ||||
|  | @ -0,0 +1,81 @@ | |||
| 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) | ||||
|  | @ -0,0 +1,229 @@ | |||
| insideMenu = nil | ||||
| local Throwables = {} | ||||
| local Drops = {} | ||||
| local DropInteracts = {} | ||||
| local PlacingProp | ||||
|  | ||||
| function OptionsMenu() | ||||
|     if insideMenu then return end | ||||
|     insideMenu = true | ||||
|     local options = { | ||||
|         { | ||||
|             title = _L("give_item"), | ||||
|             description = _L("give_item_desc"), | ||||
|             onSelect = function() | ||||
|                 insideMenu = nil | ||||
|                 local players = GetPlayersInArea() | ||||
|                 local players_list = {} | ||||
|                 for i=1, #players do | ||||
|                     local id = GetPlayerServerId(players[i]) | ||||
|                     players_list[#players_list + 1] = {label = _L("give_dialog_player", GetPlayerName(players[i]), id), value = id} | ||||
|                 end | ||||
|                 if #players_list < 1 then return ShowNotification(_L("nobody_near")) end | ||||
|                 local input = lib.inputDialog(_L("give_item"), { | ||||
|                     {type = 'select', label = _L("give_dialog_player_title"), default = players_list[1].value, required = true, options = players_list}, | ||||
|                     {type = 'slider', label = _L("give_dialog_portion"), default = 1, required = true, min = 1, max = ItemData.uses }, | ||||
|                 })  | ||||
|                 if not input then return end | ||||
|                 local target = input[1] | ||||
|                 local amount = input[2] | ||||
|                 TriggerServerEvent("pickle_consumables:giveItem", target, amount) | ||||
|             end | ||||
|         }, | ||||
|         { | ||||
|             title = _L("place_item"), | ||||
|             description = _L("place_item_desc"), | ||||
|             onSelect = function() | ||||
|                 insideMenu = nil | ||||
|                 local item = EquippedItem | ||||
|                 RemoveItem() | ||||
|                 PlaceProp(Config.Items[item].prop.model, function(coords) | ||||
|                     TriggerServerEvent("pickle_consumables:drop:createDrop", vector3(coords.x, coords.y, coords.z + 1.04)) | ||||
|                 end) | ||||
|             end | ||||
|         }, | ||||
|         { | ||||
|             title = _L("throw_item"), | ||||
|             description = _L("throw_item_desc"), | ||||
|             onSelect = function() | ||||
|                 insideMenu = nil | ||||
|                 ThrowItem() | ||||
|             end | ||||
|         }, | ||||
|         { | ||||
|             title = _L("cancel_action"), | ||||
|             description = _L("cancel_action_desc"), | ||||
|             onSelect = function() | ||||
|                 insideMenu = nil | ||||
|             end | ||||
|         }, | ||||
|     }  | ||||
|  | ||||
|     if #options < 1 or not EquippedItem then  | ||||
|         insideMenu = nil | ||||
|         return  | ||||
|     end | ||||
|  | ||||
|     lib.registerContext({ | ||||
|         id = 'pickle_consumables_options', | ||||
|         title = _L("pickle_consumables_options"), | ||||
|         options = options, | ||||
|         onExit = function()  | ||||
|             insideMenu = nil | ||||
|         end | ||||
|     }) | ||||
|     lib.showContext('pickle_consumables_options') | ||||
| end | ||||
|  | ||||
| -- Throwing | ||||
|  | ||||
| function GetDirectionFromRotation(rotation) | ||||
|     local dm = (math.pi / 180) | ||||
|     return vector3(-math.sin(dm * rotation.z) * math.abs(math.cos(dm * rotation.x)), math.cos(dm * rotation.z) * math.abs(math.cos(dm * rotation.x)), math.sin(dm * rotation.x)) | ||||
| end | ||||
|  | ||||
| function PerformPhysics(entity, action) | ||||
|     local power = 1.0 * Config.Options.throwing.power | ||||
|     FreezeEntityPosition(entity, false) | ||||
|     local rot = GetGameplayCamRot(2) | ||||
|     local dir = GetDirectionFromRotation(rot) | ||||
|     SetEntityHeading(entity, rot.z + 90.0) | ||||
|     if not action or action == "throw" then  | ||||
|         SetEntityVelocity(entity, dir.x * power, dir.y * power, dir.z * power) | ||||
|     else | ||||
|         SetEntityVelocity(entity, dir.x * power, dir.y * power, (dir.z * 1.75) * power) | ||||
|     end | ||||
| end | ||||
|  | ||||
| function CreateThrowable(model, attach) | ||||
|     local ped = PlayerPedId() | ||||
|     local heading = GetEntityHeading(ped) | ||||
|     local coords = GetOffsetFromEntityInWorldCoords(ped, 0.0, 1.0, 0.5) | ||||
|     local prop = CreateProp(model, coords.x, coords.y, coords.z, true, true, true) | ||||
|     if not prop then return end | ||||
|     if attach then  | ||||
|         local off, rot = vector3(0.05, 0.0, -0.085), vector3(90.0, 90.0, 0.0) | ||||
|         AttachEntityToEntity(prop, ped, GetPedBoneIndex(ped, 28422), off.x, off.y, off.z, rot.x, rot.y, rot.z, false, false, false, true, 2, true) | ||||
|     else  | ||||
|         local coords = GetOffsetFromEntityInWorldCoords(ped, 0.0, 1.0, -0.9) | ||||
|         SetEntityCoords(prop, coords.x, coords.y, coords.z) | ||||
|     end | ||||
|     return prop | ||||
| end | ||||
|  | ||||
| function ThrowItem() | ||||
|     if not EquippedItem then return end | ||||
|     local item = EquippedItem | ||||
|     local ped = PlayerPedId() | ||||
|     TriggerServerEvent("pickle_consumables:returnItem", true) | ||||
|     RemoveItem() | ||||
|     ClearPedTasksImmediately(ped) | ||||
|     local prop = CreateThrowable(Config.Items[item].prop.model,true) | ||||
|     CreateThread(function() | ||||
|         PlayAnim(ped, "melee@thrown@streamed_core", "plyr_takedown_front", -8.0, 8.0, -1, 49) | ||||
|         Wait(600) | ||||
|         ClearPedTasks(ped) | ||||
|     end) | ||||
|     Wait(550) | ||||
|     DetachEntity(prop, false, true) | ||||
|     SetEntityCollision(prop, true, true) | ||||
|     SetEntityRecordsCollisions(prop, true) | ||||
|     TriggerServerEvent("pickle_consumables:throwing:throwObject", {net_id = ObjToNet(prop)}) | ||||
|     local coords = GetOffsetFromEntityInWorldCoords(ped, 0.0, 0.0, 1.0) | ||||
|     SetEntityCoords(prop, coords.x, coords.y, coords.z) | ||||
|     SetEntityHeading(prop, GetEntityHeading(ped) + 90.0) | ||||
|     PerformPhysics(prop) | ||||
| end | ||||
|  | ||||
| RegisterNetEvent("pickle_consumables:throwing:setObjectData", function(throwID, data) | ||||
|     Throwables[throwID] = data | ||||
| end) | ||||
|  | ||||
| -- Drops | ||||
|  | ||||
| function GetDirectionCoords() | ||||
|     local range = 1000.0 | ||||
| 	local coords = GetGameplayCamCoord() | ||||
|     local rot = GetGameplayCamRot(2) | ||||
|     local dir = GetDirectionFromRotation(rot) | ||||
| 	local ecoords = vector3(coords.x + dir.x * range, coords.y + dir.y * range, coords.z + dir.z * range) | ||||
|     local retval, hit, endCoords, surfaceNormal, entityHit = GetShapeTestResult(StartShapeTestRay(coords.x, coords.y, coords.z, ecoords.x, ecoords.y, ecoords.z, -1, -1, 1)) | ||||
| 	return hit, endCoords, entityHit  | ||||
| end | ||||
|  | ||||
| function PlaceProp(model, cb) | ||||
|     if PlacingProp then return cb(nil, true) end  | ||||
|     if not cb then return end | ||||
|     PlacingProp = true | ||||
|     local coords = GetEntityCoords(PlayerPedId()) | ||||
|     local heading = 0.0 | ||||
|     local prop = CreateObject(model, coords.x, coords.y, coords.z, false, true, false) | ||||
|     FreezeEntityPosition(prop, true) | ||||
|     SetEntityCollision(prop, false, false) | ||||
|     CreateThread(function() | ||||
|         while PlacingProp do | ||||
|             ShowInteractText(_L("interact_place")) | ||||
|             local hit, hitCoords, entity = GetDirectionCoords() | ||||
|             if hit and hitCoords then  | ||||
|                 coords = vector3(hitCoords.x, hitCoords.y, hitCoords.z + 0.04) | ||||
|                 heading = GetGameplayCamRot(2).z | ||||
|                 SetEntityCoords(prop, coords.x, coords.y, coords.z) | ||||
|                 SetEntityRotation(prop, 0, 0, heading, 2) | ||||
|                 if IsControlJustPressed(1, 51) then | ||||
|                     PlacingProp = false | ||||
|                 end | ||||
|             end | ||||
|             Wait(0)  | ||||
|         end | ||||
|         DeleteEntity(prop) | ||||
|         if not cb then return end | ||||
|         cb(coords, heading) | ||||
|     end) | ||||
| end | ||||
|  | ||||
| function RemoveDrop(dropID) | ||||
|     Drops[dropID] = nil | ||||
|     DeleteInteraction(DropInteracts[dropID]) | ||||
|     DropInteracts[dropID] = nil | ||||
| end | ||||
|  | ||||
| RegisterNetEvent("pickle_consumables:drop:addDrop", function(dropID, data) | ||||
|     RemoveDrop(dropID) | ||||
|     Drops[dropID] = data | ||||
|     DropInteracts[dropID] = CreateInteraction({ | ||||
|         label = _L("pickup_drop"), | ||||
|         model = {modelType = "prop", hash = data.model, offset = vector3(0.0, 0.0, 0.0)}, | ||||
|         coords = data.coords, | ||||
|         heading = data.heading | ||||
|     }, function(selected) | ||||
|         local ped = PlayerPedId() | ||||
|         PlayAnim(ped, "random@domestic", "pickup_low", -8.0, 8.0, -1, 1, 1.0) | ||||
|         Wait(1500) | ||||
|         ClearPedTasks(ped) | ||||
|         TriggerServerEvent("pickle_consumables:drop:collectDrop", dropID) | ||||
|     end)  | ||||
| end) | ||||
|  | ||||
| RegisterNetEvent("pickle_consumables:drop:removeDrop", function(dropID) | ||||
|     RemoveDrop(dropID) | ||||
| end) | ||||
|  | ||||
| RegisterNetEvent("pickle_consumables:updateUses", function(uses) | ||||
|     if not ItemData then return end | ||||
|     ItemData.uses = uses | ||||
|     if uses < 1 then | ||||
|         return RemoveItem() | ||||
|     end | ||||
|     local cfg = Config.Items[EquippedItem] | ||||
|     SendNUIMessage({ | ||||
|         type = "displayApp", | ||||
|         data = { quantity = uses, time = cfg.animation.time } | ||||
|     }) | ||||
| end) | ||||
|  | ||||
| AddEventHandler("onResourceStop", function(name)  | ||||
|     if (GetCurrentResourceName() ~= name) then return end | ||||
|     for k,v in pairs(Throwables) do  | ||||
|         DeleteEntity(NetToObj(v.net_id)) | ||||
|     end | ||||
| end) | ||||
|  | @ -0,0 +1,86 @@ | |||
| local Throwables = {} | ||||
| local Drops = {} | ||||
|  | ||||
| -- Throwing | ||||
|  | ||||
| RegisterNetEvent("pickle_consumables:throwing:throwObject", function(data) | ||||
|     local source = source | ||||
|     local throwID = nil | ||||
|     repeat | ||||
|         throwID = os.time() .. "_" .. math.random(1000, 9999) | ||||
|     until not Throwables[throwID]  | ||||
|     Throwables[throwID] = data | ||||
|     TriggerClientEvent("pickle_consumables:throwing:setObjectData", -1, throwID, data) | ||||
|     SetTimeout(1000 * Config.Options.throwing.despawnTime, function() | ||||
|         DeleteEntity(NetworkGetEntityFromNetworkId(Throwables[throwID].net_id)) | ||||
|         Throwables[throwID] = nil | ||||
|         TriggerClientEvent("pickle_consumables:throwing:setObjectData", -1, throwID, nil) | ||||
|     end) | ||||
| end) | ||||
|  | ||||
| -- Drops | ||||
|  | ||||
| function CreateDrop(coords, data) | ||||
|     local dropID = nil | ||||
|     repeat | ||||
|         dropID = os.time() .. "_" .. math.random(1000, 9999) | ||||
|     until not Drops[dropID]  | ||||
|     Drops[dropID] = data | ||||
|     Drops[dropID].coords = coords | ||||
|     Drops[dropID].heading = 0.0 | ||||
|     Drops[dropID].model = Config.Items[data.itemKey].prop.model | ||||
|     TriggerClientEvent("pickle_consumables:drop:addDrop", -1, dropID, data) | ||||
|     if Config.Options.drop.despawnTime and Config.Options.drop.despawnTime > 0 then | ||||
|         SetTimeout(1000 * Config.Options.drop.despawnTime, function() | ||||
|             RemoveDrop(dropID) | ||||
|         end) | ||||
|     end | ||||
| end | ||||
|  | ||||
| function RemoveDrop(dropID) | ||||
|     Drops[dropID] = nil | ||||
|     TriggerClientEvent("pickle_consumables:drop:removeDrop", -1, dropID) | ||||
| end | ||||
|  | ||||
| RegisterNetEvent("pickle_consumables:drop:collectDrop", function(dropID) | ||||
|     local source = source | ||||
|     local drop = Drops[dropID] | ||||
|     if not drop then return end | ||||
|     RemoveDrop(dropID) | ||||
|     EquipItem(source, drop, true) | ||||
| end) | ||||
|  | ||||
| RegisterNetEvent("pickle_consumables:drop:createDrop", function(coords) | ||||
|     local source = source | ||||
|     local item = Players[source] | ||||
|     if not item then return end | ||||
|     if #(GetEntityCoords(GetPlayerPed(source)) - coords) > 100.0 then return end | ||||
|     Players[source] = nil | ||||
|     TriggerClientEvent("pickle_consumables:removeItem", source) | ||||
|     CreateDrop(coords, item) | ||||
| end) | ||||
|  | ||||
| -- Giving | ||||
|  | ||||
| RegisterNetEvent("pickle_consumables:giveItem", function(target, amount) | ||||
|     local source = source | ||||
|     local item = Players[source] | ||||
|     if not item or target < 1 then return end | ||||
|     local amount = amount | ||||
|     local uses = item.uses | ||||
|     if amount >= uses then | ||||
|         amount = uses | ||||
|         Players[source] = nil | ||||
|         TriggerClientEvent("pickle_consumables:removeItem", source) | ||||
|     else | ||||
|         Players[source].uses = Players[source].uses - amount | ||||
|         TriggerClientEvent("pickle_consumables:updateUses", source, Players[source].uses) | ||||
|     end | ||||
|     local targetItem = Players[target] | ||||
|     if targetItem and targetItem.itemKey == item.itemKey then | ||||
|         Players[target].uses = Players[target].uses + amount | ||||
|         TriggerClientEvent("pickle_consumables:updateUses", target, Players[target].uses) | ||||
|     else | ||||
|         EquipItem(target, {itemKey = item.itemKey, uses = amount}, true) | ||||
|     end | ||||
| end) | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nordi98
						Nordi98