Hello guys new here, new to lua. I have written this simple script were at a set location a NPC will be, armed and if you get near it will start shooting at you.
Now the NPC spawns and has a weapon, But it doesnt shoot at the player.
So lost if anyone can lead me into the right doc that be great.
-- Define the location of the NPC ped
local npcLocation = vector4(-1650.63, 3161.53, 32.84, 178.02)
-- Create the NPC ped at the specified location
local npcPed = CreatePed(4, 0x9B22DBAF, npcLocation.x, npcLocation.y, npcLocation.z, npcLocation.w, false, true)
GiveWeaponToPed(npcPed, GetHashKey("WEAPON_CARBINERIFLE"), 9999, true, true)
function CheckPlayerDistance()
local player = GetPlayerPed(-1)
local playerLocation = GetEntityCoords(player)
local distance = #(playerLocation - vector3(npcLocation.x, npcLocation.y, npcLocation.z))
-- If the player is within 10 units of the NPC ped, engage the player with a carbine rifle
if distance < 10.0 then
SetPedShootsAtCoord(npcPed, playerLocation.x, playerLocation.y, playerLocation.z, true)
TaskCombatPed(npcPed, player, 0, 2, 500)
SetPedCombatAttributes(npcPed, 46, true)
SetPedCombatAttributes(npcPed, 0, true)
SetPedCombatAttributes(npcPed, 1, true)
SetPedCombatAttributes(npcPed, 3, true)
SetPedCombatAttributes(npcPed, 5, true)
end
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(30)
CheckPlayerDistance()
end
end)