i was trying to make a simple dogfight System, with both the P-45 nokata (only machine guns no missiles) and P-996 lazer (lock on missiles) and i made the basic stuff work, but they never attacked the player in any way, how can i do so?
Clean version
– server:
RegisterCommand("airraid", function(source, args, raw)
TriggerClientEvent("airraid:spawnPlane", -1)
end, true)
– client:
local spawnedPlanes = {}
RegisterNetEvent("airraid:spawnPlane")
AddEventHandler("airraid:spawnPlane", function()
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local model = `lazer`
local pilotModel = `s_m_m_pilot_02`
RequestModel(model)
RequestModel(pilotModel)
while not HasModelLoaded(model) or not HasModelLoaded(pilotModel) do
Wait(10)
end
local spawnRadius = 600.0
local angle = math.random() * math.pi * 2
local spawnX = playerCoords.x + math.cos(angle) * spawnRadius
local spawnY = playerCoords.y + math.sin(angle) * spawnRadius
local spawnZ = playerCoords.z + 150.0
local plane = CreateVehicle(model, spawnX, spawnY, spawnZ, math.random(0, 360), true, true)
SetVehicleEngineOn(plane, true, true, false)
SetEntityInvincible(plane, false)
SetVehicleLivery(plane, math.random(0, 2))
SetVehicleForwardSpeed(plane, 120.0)
SetEntityAsMissionEntity(plane, true, false)
SetPlaneTurbulenceMultiplier(plane, 0.5)
SetVehicleCanBreak(plane, true)
SetVehicleDirtLevel(plane, 5.0)
SetVehicleLandingGear(plane, 3)
local pilot = CreatePedInsideVehicle(plane, 1, pilotModel, -1, true, false)
SetPedKeepTask(pilot, true)
SetPedAsEnemy(pilot, false)
SetEntityInvincible(pilot, false)
SetBlockingOfNonTemporaryEvents(pilot, true)
local destRadius = 3000.0
local destAngle = math.random() * math.pi * 2
local destX = spawnX + math.cos(destAngle) * destRadius
local destY = spawnY + math.sin(destAngle) * destRadius
local destZ = spawnZ + math.random(-40, 40)
TaskPlaneMission(
pilot, plane, 0, 0,
destX, destY, destZ,
4, -- mission type: fly to
400.0, -- cruise speed
0, -- targetVehicle
GetEntityHeading(plane),
10.0, 10.0, 50.0
)
local blip = AddBlipForEntity(plane)
SetBlipSprite(blip, 16)
SetBlipColour(blip, 1)
SetBlipScale(blip, 1.0)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Aereo Ostile")
EndTextCommandSetBlipName(blip)
table.insert(spawnedPlanes, {plane = plane, pilot = pilot, blip = blip})
CreateThread(function()
while DoesEntityExist(plane) do
Wait(2000)
-- Se l'aereo o il pilota muoiono, rimuoviamo solo il blip, lasciando i detriti
if IsEntityDead(pilot) or IsEntityDead(plane) then
RemoveBlip(blip)
break
end
end
end)
end)