Skip to content

Commit

Permalink
added files
Browse files Browse the repository at this point in the history
  • Loading branch information
L0stedMrlion committed Jun 4, 2024
1 parent 2a3a27f commit f5563ce
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
71 changes: 71 additions & 0 deletions client/client.lua
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 29 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -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"
}
9 changes: 9 additions & 0 deletions server/server.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit f5563ce

Please sign in to comment.