private async static void Loop() { if (eventSpawned) { int playerPedId = API.PlayerPedId(); if (!eventDespawned && API.GetEntityHealth(playerPedId) == 0) { eventDespawned = true; await BaseScript.Delay(2000); Deregister(); } Vector3 playerPos = GetPedCoords(playerPedId); if (!eventOnScene) { foreach (int ped in peds) { Vector3 pedPos = GetPedCoords(ped); float distance = API.GetDistanceBetweenCoords(pedPos.X, pedPos.Y, pedPos.Z, playerPos.X, playerPos.Y, playerPos.Z, true); if (distance < 20F) { eventOnScene = true; foreach (int spawnedPed in peds) { API.TaskCombatPed(spawnedPed, playerPedId, 0, 16); } } } } } }