I am trying to make a character selector. Therefore I am placing the ped in mid air with an overview of the city. I am using a cam for this, and when I try to move the character to the airport after he selected his character, nothing happens, even though I am using destroycam. Are there any tricky way I need to do this in order to restore back to the player’s normal camera?
Declared variables at the top + constructor
public int selectedChar;
bool hideHud;
int spawnCam;
public Economy()
{
API.RegisterCommand("setMoney", new Action<int, List<object>, string>(SetMoney), false); // Register a new command, and use the method SetMoney to run the code
API.RegisterCommand("Test", new Action<int, List<object>, string>(Test), false);
EventHandlers["SpawnCharacter"] += new Action<int>(SpawnCharacter); // this event spawns the character
EventHandlers["playerSpawned"] += new Action<dynamic>(playerSpawned); // This event listens for when the player has finished loading and is ready to spawn in-game
}
Where I am creating the cam
private async void playerSpawned(object obj)
{
spawnCam = API.CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", 75.34f, -66.33f,
271.71f, -20, 0, 165, 80, false, 0); // Make a camera with coords xyz and rotate it -20 degrees on x, 0 on y, and 165 on z, make the FOV 80
API.SetEntityHasGravity(Game.PlayerPed.Handle, false); // Disable the gravity for the player (so that he doesn't fall whilst standing mid air)
API.SetEntityVisible(Game.PlayerPed.Handle, false, false); // Make the player invisible (since we just want a overview of the city with no visible ped)
API.SetCamActive(spawnCam, true); // Set the created cam as active
API.RenderScriptCams(true, false, 1, true, true); // Render the cam
API.SetEntityInvincible(Game.PlayerPed.Handle, true); // Make the player unable to die
API.SetEntityCoords(Game.PlayerPed.Handle, 75.34f, -66.33f, 271.71f, false, false, false, true); // Move the player up into the air with the camera (so that people talking around spawn wont be heard)
hideHud = true; // Remove the hud containing the map and health bar
while (hideHud) // Do a while loop
{
API.HideHudAndRadarThisFrame(); // Use a native to hide the hud
await Delay(0); // Wait
}
}
Where I wish to destroy the cam and go back to the player
private async void SpawnCharacter(int TempSelectedChar) // This method spawns the character and requires the id of the selected one from the character menu
{
selectedChar = TempSelectedChar;
Debug.WriteLine(selectedChar.ToString());
await Delay(2000);
API.SetCamActive(spawnCam, false);
//API.DestroyCam(spawnCam, true); // Destroy the existing camera named spawnCam
//API.RenderScriptCams(true, false, 1, true, true); // Render the cam
API.SetEntityInvincible(Game.PlayerPed.Handle, false); // Make the player able to die
API.SetEntityHasGravity(Game.PlayerPed.Handle, true); // Make gravity present to the player
API.SetEntityVisible(Game.PlayerPed.Handle, true, false); // Make the player visible again
API.SetEntityCoords(Game.PlayerPed.Handle, -1037.494f, -2737.36f, 19.79907f, false, false, false, true); // Move the player to the airport
hideHud = false; // Get the hud back
}