forked from Simnation/Main
Update client.lua
This commit is contained in:
parent
4d17fa40c2
commit
d11df2a252
1 changed files with 32 additions and 262 deletions
|
@ -1,272 +1,42 @@
|
||||||
local hasHostage = false
|
-- nordi_hostage/client.lua
|
||||||
local currentHostage = nil
|
|
||||||
local isAimingAtPed = false
|
|
||||||
local lastAimedPed = nil
|
|
||||||
|
|
||||||
-- Check if player has cable ties
|
|
||||||
local function HasCableTies()
|
|
||||||
local hasTies = QBCore.Functions.HasItem('cabletie')
|
|
||||||
return hasTies
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Check if player is aiming at an NPC
|
|
||||||
Citizen.CreateThread(function()
|
Citizen.CreateThread(function()
|
||||||
while true do
|
-- Warte auf QBCore
|
||||||
Citizen.Wait(500)
|
while not QBCore do
|
||||||
local playerPed = PlayerPedId()
|
TriggerEvent('QBCore:GetObject', function(obj) QBCore = obj end)
|
||||||
local _, entity = GetEntityPlayerIsFreeAimingAt(PlayerId())
|
Citizen.Wait(200)
|
||||||
|
|
||||||
if entity and IsEntityAPed(entity) and not IsPedAPlayer(entity) then
|
|
||||||
isAimingAtPed = true
|
|
||||||
lastAimedPed = entity
|
|
||||||
else
|
|
||||||
isAimingAtPed = false
|
|
||||||
lastAimedPed = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Add targeting option when aiming at NPC with weapon
|
|
||||||
Citizen.CreateThread(function()
|
|
||||||
while true do
|
|
||||||
Citizen.Wait(0)
|
|
||||||
if isAimingAtPed and lastAimedPed and not hasHostage then
|
|
||||||
exports['qb-target']:AddTargetEntity(lastAimedPed, {
|
|
||||||
options = {
|
|
||||||
{
|
|
||||||
type = "client",
|
|
||||||
action = function()
|
|
||||||
if HasCableTies() then
|
|
||||||
TriggerEvent('qb-hostage:client:takeHostageMenu', lastAimedPed)
|
|
||||||
else
|
|
||||||
QBCore.Functions.Notify("You need cable ties to take a hostage", "error")
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
icon = "fas fa-user-ninja",
|
|
||||||
label = "Take Hostage",
|
|
||||||
canInteract = function()
|
|
||||||
return not hasHostage and HasCableTies()
|
|
||||||
end
|
|
||||||
}
|
|
||||||
},
|
|
||||||
distance = 2.0
|
|
||||||
})
|
|
||||||
elseif not isAimingAtPed and lastAimedPed and not hasHostage then
|
|
||||||
exports['qb-target']:RemoveTargetEntity(lastAimedPed, 'Take Hostage')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Take hostage menu
|
|
||||||
RegisterNetEvent('qb-hostage:client:takeHostageMenu', function(ped)
|
|
||||||
local options = {}
|
|
||||||
|
|
||||||
if not hasHostage then
|
|
||||||
options[#options+1] = {
|
|
||||||
title = "Take Hostage",
|
|
||||||
description = "Take this person as your hostage",
|
|
||||||
event = "qb-hostage:client:takeHostage",
|
|
||||||
args = { ped = ped }
|
|
||||||
}
|
|
||||||
else
|
|
||||||
options[#options+1] = {
|
|
||||||
title = "Release Hostage",
|
|
||||||
description = "Let your current hostage go",
|
|
||||||
event = "qb-hostage:client:releaseHostage"
|
|
||||||
}
|
|
||||||
|
|
||||||
options[#options+1] = {
|
|
||||||
title = "Put in Vehicle",
|
|
||||||
description = "Put hostage in nearby vehicle",
|
|
||||||
event = "qb-hostage:client:putInVehicleMenu"
|
|
||||||
}
|
|
||||||
|
|
||||||
options[#options+1] = {
|
|
||||||
title = "Remove from Vehicle",
|
|
||||||
description = "Take hostage out of vehicle",
|
|
||||||
event = "qb-hostage:client:removeFromVehicle"
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
lib.registerContext({
|
-- Funktion: Überprüft, ob der Spieler Kabelbinder hat
|
||||||
id = 'hostage_menu',
|
function HasCableTies()
|
||||||
title = 'Hostage Options',
|
local player = QBCore.Functions.GetPlayerData()
|
||||||
options = options
|
local hasTies = false
|
||||||
})
|
|
||||||
|
|
||||||
lib.showContext('hostage_menu')
|
if player and player.items then
|
||||||
end)
|
for _, item in pairs(player.items) do
|
||||||
|
if item.name == 'cableties' and item.amount >= 1 then
|
||||||
-- Take hostage function
|
hasTies = true
|
||||||
RegisterNetEvent('qb-hostage:client:takeHostage', function(data)
|
break
|
||||||
local ped = data.ped
|
|
||||||
if hasHostage then return end
|
|
||||||
|
|
||||||
local playerPed = PlayerPedId()
|
|
||||||
|
|
||||||
-- Play animation and notify
|
|
||||||
RequestAnimDict("anim@gangops@hostage@")
|
|
||||||
while not HasAnimDictLoaded("anim@gangops@hostage@") do
|
|
||||||
Citizen.Wait(100)
|
|
||||||
end
|
|
||||||
|
|
||||||
TaskPlayAnim(playerPed, "anim@gangops@hostage@", "perp_idle", 8.0, 1.0, -1, 49, 0, false, false, false)
|
|
||||||
TaskPlayAnim(ped, "anim@gangops@hostage@", "victim_idle", 8.0, 1.0, -1, 9, 0, false, false, false)
|
|
||||||
|
|
||||||
AttachEntityToEntity(ped, playerPed, GetPedBoneIndex(playerPed, 57005), 0.15, 0.0, -0.05, 340.0, 0.0, 80.0, false, false, false, false, 2, true)
|
|
||||||
|
|
||||||
SetBlockingOfNonTemporaryEvents(ped, true)
|
|
||||||
SetEntityInvincible(ped, true)
|
|
||||||
SetPedFleeAttributes(ped, 0, false)
|
|
||||||
SetPedCombatAttributes(ped, 17, true)
|
|
||||||
SetPedSeeingRange(ped, 0.0)
|
|
||||||
SetPedHearingRange(ped, 0.0)
|
|
||||||
SetPedAlertness(ped, 0)
|
|
||||||
SetPedKeepTask(ped, true)
|
|
||||||
|
|
||||||
currentHostage = ped
|
|
||||||
hasHostage = true
|
|
||||||
|
|
||||||
QBCore.Functions.Notify("You've taken a hostage", "success")
|
|
||||||
|
|
||||||
-- Control loop for hostage
|
|
||||||
Citizen.CreateThread(function()
|
|
||||||
while hasHostage do
|
|
||||||
Citizen.Wait(0)
|
|
||||||
if not IsEntityPlayingAnim(playerPed, "anim@gangops@hostage@", "perp_idle", 3) then
|
|
||||||
TaskPlayAnim(playerPed, "anim@gangops@hostage@", "perp_idle", 8.0, 1.0, -1, 49, 0, false, false, false)
|
|
||||||
end
|
|
||||||
|
|
||||||
if IsPedDeadOrDying(currentHostage, true) then
|
|
||||||
TriggerEvent('qb-hostage:client:releaseHostage')
|
|
||||||
QBCore.Functions.Notify("Hostage died", "error")
|
|
||||||
end
|
|
||||||
|
|
||||||
if IsControlJustReleased(0, 73) then -- X button to release
|
|
||||||
TriggerEvent('qb-hostage:client:releaseHostage')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Release hostage
|
|
||||||
RegisterNetEvent('qb-hostage:client:releaseHostage', function()
|
|
||||||
if not hasHostage then return end
|
|
||||||
|
|
||||||
DetachEntity(currentHostage, true, false)
|
|
||||||
ClearPedTasks(currentHostage)
|
|
||||||
ClearPedTasks(PlayerPedId())
|
|
||||||
|
|
||||||
SetBlockingOfNonTemporaryEvents(currentHostage, false)
|
|
||||||
SetEntityInvincible(currentHostage, false)
|
|
||||||
TaskReactAndFleePed(currentHostage, PlayerPedId())
|
|
||||||
|
|
||||||
RemoveAnimDict("anim@gangops@hostage@")
|
|
||||||
|
|
||||||
currentHostage = nil
|
|
||||||
hasHostage = false
|
|
||||||
|
|
||||||
QBCore.Functions.Notify("You released the hostage", "success")
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Put hostage in vehicle menu
|
|
||||||
RegisterNetEvent('qb-hostage:client:putInVehicleMenu', function()
|
|
||||||
local playerPed = PlayerPedId()
|
|
||||||
local coords = GetEntityCoords(playerPed)
|
|
||||||
local vehicles = QBCore.Functions.GetVehicles()
|
|
||||||
local options = {}
|
|
||||||
|
|
||||||
for _, vehicle in ipairs(vehicles) do
|
|
||||||
local vehCoords = GetEntityCoords(vehicle)
|
|
||||||
local distance = #(coords - vehCoords)
|
|
||||||
|
|
||||||
if distance < 10.0 then
|
|
||||||
local plate = QBCore.Functions.GetPlate(vehicle)
|
|
||||||
local seats = GetVehicleMaxNumberOfPassengers(vehicle)
|
|
||||||
|
|
||||||
for i = -1, seats - 1 do
|
|
||||||
if IsVehicleSeatFree(vehicle, i) then
|
|
||||||
local seatName = i == -1 and "Driver" or ("Passenger " .. (i + 1))
|
|
||||||
options[#options+1] = {
|
|
||||||
title = ("%s (%s)"):format(plate, seatName),
|
|
||||||
description = "Put hostage in this seat",
|
|
||||||
event = "qb-hostage:client:putInVehicle",
|
|
||||||
args = { vehicle = vehicle, seat = i }
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return hasTies
|
||||||
end
|
end
|
||||||
|
|
||||||
if #options == 0 then
|
-- qb-target Integration
|
||||||
QBCore.Functions.Notify("No suitable vehicles nearby", "error")
|
exports['qb-target']:AddTargetModel('prop_paper_bag_small', {
|
||||||
return
|
options = {
|
||||||
end
|
{
|
||||||
|
type = "client",
|
||||||
lib.registerContext({
|
action = function()
|
||||||
id = 'hostage_vehicle_menu',
|
-- Hier kommt deine Geiselnehmer-Logik
|
||||||
title = 'Select Vehicle Seat',
|
end,
|
||||||
options = options
|
icon = "fas fa-hands-bound",
|
||||||
|
label = "Person fesseln",
|
||||||
|
canInteract = function()
|
||||||
|
return HasCableTies()
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
distance = 2.5
|
||||||
})
|
})
|
||||||
|
|
||||||
lib.showContext('hostage_vehicle_menu')
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Put hostage in vehicle
|
|
||||||
RegisterNetEvent('qb-hostage:client:putInVehicle', function(data)
|
|
||||||
if not hasHostage then return end
|
|
||||||
|
|
||||||
local vehicle = data.vehicle
|
|
||||||
local seat = data.seat
|
|
||||||
|
|
||||||
DetachEntity(currentHostage, true, false)
|
|
||||||
ClearPedTasks(currentHostage)
|
|
||||||
ClearPedTasks(PlayerPedId())
|
|
||||||
|
|
||||||
TaskWarpPedIntoVehicle(currentHostage, vehicle, seat)
|
|
||||||
|
|
||||||
SetBlockingOfNonTemporaryEvents(currentHostage, true)
|
|
||||||
SetPedFleeAttributes(currentHostage, 0, false)
|
|
||||||
|
|
||||||
hasHostage = false
|
|
||||||
|
|
||||||
QBCore.Functions.Notify("You put the hostage in the vehicle", "success")
|
|
||||||
RemoveAnimDict("anim@gangops@hostage@")
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Remove hostage from vehicle
|
|
||||||
RegisterNetEvent('qb-hostage:client:removeFromVehicle', function()
|
|
||||||
if IsPedInAnyVehicle(currentHostage, false) then
|
|
||||||
TaskLeaveVehicle(currentHostage, GetVehiclePedIsIn(currentHostage, false), 16)
|
|
||||||
|
|
||||||
Citizen.Wait(1000)
|
|
||||||
|
|
||||||
-- Take hostage again after removing from vehicle
|
|
||||||
local playerPed = PlayerPedId()
|
|
||||||
AttachEntityToEntity(currentHostage, playerPed, GetPedBoneIndex(playerPed, 57005), 0.15, 0.0, -0.05, 340.0, 0.0, 80.0, false, false, false, false, 2, true)
|
|
||||||
|
|
||||||
TaskPlayAnim(playerPed, "anim@gangops@hostage@", "perp_idle", 8.0, 1.0, -1, 49, 0, false, false, false)
|
|
||||||
TaskPlayAnim(currentHostage, "anim@gangops@hostage@", "victim_idle", 8.0, 1.0, -1, 9, 0, false, false, false)
|
|
||||||
|
|
||||||
hasHostage = true
|
|
||||||
|
|
||||||
QBCore.Functions.Notify("You took the hostage out of the vehicle", "success")
|
|
||||||
else
|
|
||||||
QBCore.Functions.Notify("Hostage is not in a vehicle", "error")
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Cleanup on resource stop
|
|
||||||
AddEventHandler('onResourceStop', function(resource)
|
|
||||||
if resource == GetCurrentResourceName() then
|
|
||||||
if hasHostage and currentHostage then
|
|
||||||
DetachEntity(currentHostage, true, false)
|
|
||||||
ClearPedTasks(currentHostage)
|
|
||||||
SetBlockingOfNonTemporaryEvents(currentHostage, false)
|
|
||||||
SetEntityInvincible(currentHostage, false)
|
|
||||||
TaskReactAndFleePed(currentHostage, PlayerPedId())
|
|
||||||
end
|
|
||||||
ClearPedTasks(PlayerPedId())
|
|
||||||
RemoveAnimDict("anim@gangops@hostage@")
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue