Hi! I made a neat little script that sets a camera at a coord and for each spawn location set, makes peds at that location, however, this script does NOT wait for the player to spawn before moving, so my player just gets spawned at the default location. How can I fix this so the script waits for the player?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
using CitizenFX.Core.Native;
namespace Events
{
public class Events : BaseScript
{
public Events()
{
EventHandlers["LIBCore:client:onSessionStarted"] += new Action(TestEvent);
}
private async void TestEvent()
{
Vector4[] spawnLocations = new Vector4[]
{
new Vector4(-262.3599f, -975.2946f, 31.2196f, 268.0552f),
new Vector4(-258.4986f, -973.2682f, 31.2200f, 147.3466f),
new Vector4(-261.2221f, -972.8484f, 31.2200f, 185.6964f)
};
int camera = API.CreateCam("DEFAULT_SCRIPTED_CAMERA", true);
API.SetCamRot(camera, 0f, 0f, 25f, 2);
API.SetCamCoord(camera, -257.7698f - 0.5f, -979.1187f + 1f, 34.0717f - 2f);
API.RenderScriptCams(true, false, 0, true, true);
for(int i = 0; i < spawnLocations.Length; i++)
{
API.RequestModel((uint)PedHash.Bevhills01AMM);
while (!API.HasModelLoaded((uint)PedHash.Bevhills01AMM))
{
await BaseScript.Delay(100);
}
Vector3 vector3 = new Vector3(spawnLocations[i].X, spawnLocations[i].Y, spawnLocations[i].Z - 1f);
Ped ped = await World.CreatePed(PedHash.Bevhills01AMM, vector3, spawnLocations[i].W);
API.TaskSetBlockingOfNonTemporaryEvents(ped.Handle, true);
API.FreezeEntityPosition(ped.Handle, true);
API.SetEntityInvincible(ped.Handle, true);
}
Vector3 camCoords = API.GetCamCoord(camera);
API.SetEntityCoordsNoOffset(Game.Player.Character.Handle, camCoords.X, camCoords.Y - 1f, camCoords.Z, false, true, true);
}
}
}