1
0
Fork 0
forked from Simnation/Main
Main/resources/[Developer]/[Mark]/plugin_npchealbyAnna/plugin_npcheal_client.lua

160 lines
5.5 KiB
Lua
Raw Normal View History

2025-06-07 08:51:21 +02:00
local pluginData = {
name = "test_plugin",
description = "NPC Heal",
author = "test",
version = "1.2"
}
RegisterClientPlugin(pluginData, function(print)
print("plugin_npcheal_client.lua loaded")
end)
local QBCore = exports['qb-core']:GetCoreObject()
local NPCPosition = {x = 349.18676, y = -577.2429, z = 28.822866, rot = 250.00}
local isNearPed = false
local isAtPed = false
local isPedLoaded = false
local pedModel = GetHashKey("s_m_m_doctor_01")
local npc
local reviveTime = 15000
local doctor = 0
local price = 5000
local isBusy = false
local isBeingTreated = false
Citizen.CreateThread(function()
while true do
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local distance = Vdist(playerCoords, NPCPosition.x, NPCPosition.y, NPCPosition.z)
isNearPed = distance < 20.0
isAtPed = distance < 2.0
if isNearPed and not isPedLoaded then
RequestModel(pedModel)
while not HasModelLoaded(pedModel) do
Wait(10)
end
npc = CreatePed(4, pedModel, NPCPosition.x, NPCPosition.y, NPCPosition.z - 1.0, NPCPosition.rot, false, false)
FreezeEntityPosition(npc, true)
SetEntityHeading(npc, NPCPosition.rot)
SetEntityInvincible(npc, true)
SetBlockingOfNonTemporaryEvents(npc, true)
isPedLoaded = true
elseif not isNearPed and isPedLoaded then
DeleteEntity(npc)
isPedLoaded = false
end
Citizen.Wait(500)
end
end)
Citizen.CreateThread(function()
while true do
if isNearPed and isAtPed then
showInfobar('Drücke ~g~E~s~, um für ' .. price ..' $ eine Behandlung zu erhalten')
if IsControlJustReleased(0, 38) then
if not isBusy then
isBusy = true
isBeingTreated = true
TriggerEvent("disableMovementControls", true)
local playerHealth = GetEntityHealth(PlayerPedId())
if playerHealth < 200 then
QBCore.Functions.TriggerCallback('visn_are:docOnline', function(medicOn, hasEnoughMoney)
if medicOn <= doctor and hasEnoughMoney then
QBCore.Functions.Progressbar("Notarzt", "Der Notarzt behandelt dich", reviveTime, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = true,
disableCombat = true,
}, {}, {}, {}, function() -- Progress Callback
TriggerServerEvent('visn_are:charge')
TriggerEvent("visn_are:resetHealthBuffer")
SetEntityHealth(PlayerPedId(), 200)
ShowNotification('Du bezahlst ' .. price ..' $ für die Behandlung')
ShowNotification("Du bist gesund")
isBusy = false
isBeingTreated = false
TriggerEvent("disableMovementControls", false)
end, function() -- Cancel Callback
ShowNotification("Behandlung abgebrochen")
isBusy = false
isBeingTreated = false
TriggerEvent("disableMovementControls", false)
end)
elseif medicOn > doctor then
ShowNotification("Zuviele Medics im Dienst, rufe einen!")
isBusy = false
isBeingTreated = false
TriggerEvent("disableMovementControls", false)
elseif not hasEnoughMoney then
ShowNotification("Du hast nicht genug Geld für die Behandlung")
isBusy = false
isBeingTreated = false
TriggerEvent("disableMovementControls", false)
end
end)
else
ShowNotification("Du bist bereits gesund")
isBusy = false
isBeingTreated = false
TriggerEvent("disableMovementControls", false)
end
else
ShowNotification("Du wirst schon behandelt")
end
end
end
Citizen.Wait(1)
end
end)
function ShowNotification(text)
SetNotificationTextEntry('STRING')
AddTextComponentString(text)
DrawNotification(false, true)
end
function showInfobar(msg)
SetTextComponentFormat('STRING')
AddTextComponentString(msg)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
end
RegisterNetEvent("disableMovementControls")
AddEventHandler("disableMovementControls", function(disable)
local playerPed = PlayerPedId()
if disable then
SetPedCurrentWeaponVisible(playerPed, false, true, true, true)
SetPlayerControl(playerPed, false, 0)
else
SetPedCurrentWeaponVisible(playerPed, true, true, true, true)
SetPlayerControl(playerPed, true, 0)
end
end)