From f5563ceb245d27d2b02b020881fed569508885f4 Mon Sep 17 00:00:00 2001 From: Mrlion Date: Tue, 4 Jun 2024 15:38:09 +0000 Subject: [PATCH] added files --- client/client.lua | 71 +++++++++++++++++++++++++++++++++++++++++++++++ config.lua | 29 +++++++++++++++++++ fxmanifest.lua | 26 +++++++++++++++++ server/server.lua | 9 ++++++ 4 files changed, 135 insertions(+) create mode 100644 client/client.lua create mode 100644 config.lua create mode 100644 fxmanifest.lua create mode 100644 server/server.lua diff --git a/client/client.lua b/client/client.lua new file mode 100644 index 0000000..1291ad4 --- /dev/null +++ b/client/client.lua @@ -0,0 +1,71 @@ +local bags = {} +local bagOptions = Config.MedibagTarget +local medibagprop = Config.MedibagProp +local medibagIds = {} + +RegisterNetEvent("lion_medibag:placeMedbag") +AddEventHandler( + "lion_medibag:placeMedbag", + function() + TriggerServerEvent("lion_medibag:placeMedbag") + end +) + +RegisterNetEvent("lion_medibag:pickupMedbag") +AddEventHandler( + "lion_medibag:pickupMedbag", + function() + local playerPed = PlayerPedId() + local pedCoords = GetEntityCoords(playerPed) + lib.playAnim(playerPed, "random@domestic", "pickup_low", 5.0, 1.0, -1, 48, 0, 0, 0, 0) + TriggerServerEvent("lion_medibag:pickupMedbag") + if Config.Notifications then + Notify("Medibag", Config.Locale["pickedupmedbag"], 2000) + end + local medibagId = GetClosestObjectOfType(pedCoords, 2.0, GetHashKey("xm_prop_x17_bag_med_01a"), false, false, false) + if medibagId ~= 0 then + DeleteEntity(medibagId) + table.remove(medibagIds, table.find(medibagIds, medibagId)) + end + end +) + +RegisterNetEvent("lion_medibag:place") +AddEventHandler( + "lion_medibag:place", + function() + lib.RequestModel(medibagprop) + while not HasModelLoaded(medibagprop) do + Citizen.Wait(10) + end + local playerPed = PlayerPedId() + local itemCount = lib.callback.await("ox_inventory:getItemCount", false, Config.MedibagItem, {}) + local pedCoords = GetEntityCoords(playerPed) + if itemCount >= 1 then + lib.playAnim(playerPed, "random@domestic", "pickup_low", 5.0, 1.0, -1, 48, 0, 0, 0, 0) + TriggerEvent("lion_medibag:placeMedbag") + if Config.Notifications then + Notify("Medibag", Config.Locale["placemedbag"], 2000) + end + local newBag = CreateObject(medibagprop, pedCoords.x, pedCoords.y, pedCoords.z - 1, true, false, false) + SetEntityHeading(newBag, GetEntityHeading(playerPed)) + PlaceObjectOnGroundProperly(newBag) + table.insert(bags, newBag) + table.insert(medibagIds, newBag) + end + end +) + +AddEventHandler( + "onResourceStop", + function(resourceName) + if resourceName == GetCurrentResourceName() then + for _, bag in pairs(bags) do + if DoesEntityExist(bag) then + DeleteEntity(bag) + end + end + end + end +) +exports.ox_target:addModel(medibagprop, bagOptions) diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..5248e54 --- /dev/null +++ b/config.lua @@ -0,0 +1,29 @@ +Config = {} +Config.MedibagItem = "medibag" --ox inventory item +Config.MedibagProp = "xm_prop_x17_bag_med_01a" --Medibag prop, customize this if you want +Config.Notifications = false --Enable/Disable notifications on pickup and place +Config.MedibagTarget = { + { + canInteract = function(_, distance, _) + return not IsEntityDead(PlayerPedId()) and distance < 2.0 + end, + event = 'lion_medibag:pickupMedbag', --Dont edit this until you dont know what are you doing + icon = 'fa-solid fa-briefcase-medical', + label = "Pickup Medibag", + distance = 2.0 + }, +} +Config.Locale = { -- Edit if you want + ['pickedupmedbag'] = "Medibag has been picked up", + ['placemedbag'] = "Medibag has been placed", +} + +Notify = function(title, desciption, duration) -- If you want just replace with your own notifications + lib.notify({ + title = title, + description = desciption, + icon = 'fa-solid fa-briefcase-medical', + iconColor = "#ed1b24", + duration = duration + }) +end \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua new file mode 100644 index 0000000..068abd6 --- /dev/null +++ b/fxmanifest.lua @@ -0,0 +1,26 @@ +fx_version "cerulean" +game "gta5" + +author "Mrlion (@lostedmrlion)" +description "Medibag script for better EMS RP" +version "1.0" +lua54 "true" + +shared_scripts { + '@ox_lib/init.lua', + "config.lua" +} + +client_scripts { + "client/client.lua" +} + +server_scripts { + "server/server.lua" +} + +dependencies { + 'ox_target', + 'ox_lib', + "ox_inventory" +} \ No newline at end of file diff --git a/server/server.lua b/server/server.lua new file mode 100644 index 0000000..f6cce37 --- /dev/null +++ b/server/server.lua @@ -0,0 +1,9 @@ +RegisterServerEvent('lion_medibag:placeMedbag') +AddEventHandler('lion_medibag:placeMedbag',function () + exports.ox_inventory:RemoveItem(source, Config.MedibagItem, 1, nil, nil, nil) +end) + +RegisterServerEvent('lion_medibag:pickupMedbag') +AddEventHandler('lion_medibag:pickupMedbag',function () + exports.ox_inventory:AddItem(source, Config.MedibagItem, 1, nil, nil, nil) +end) \ No newline at end of file