Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Diamond Casino Heist
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Red Dead Online

      1. Frontier Pursuits
      2. Find Lobbies & Outlaws
      3. Help & Support
    3. Crews

      1. Events
    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

    2. GTA 6

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    3. Gangs

    1. Announcements

    2. Support

    3. Suggestions

diogoscf

[C#] CreateVehicle doesn"t spawn Helicopters properly

Recommended Posts

diogoscf

So I have this bit of my code that is supposed to spawn a Valkyrie:

 

Model mod = new Model(VehicleHash.Valkyrie);
mod.Request();
while (!mod.IsLoaded)
{
  stop_scripts();
  Script.Wait(0);
}
escape_veh3 = World.CreateVehicle(mod, new Vector3(-1179.25f, -2845.386f, 14.333f));
escape_veh3.Heading = 325.6199f;
escape_veh3.IsPersistent = true;
mod.MarkAsNoLongerNeeded();

But it doesn't seem to spawn it. It gives no errors though, and if I replace the Valkyrie with another Helicopter, it doesn't work, but if I replace it with a ground vehicle, it works properly. Anyone know what's going on?

Share this post


Link to post
Share on other sites
Guest

What happens if you just try it like this?

escape_veh3 = World.CreateVehicle(VehicleHash.Valkyrie, new Vector3(-1179.25f, -2845.386f, 14.333f));
escape_veh3.Heading = 325.6199f;
escape_veh3.IsPersistent = true;

Edit: Just tried this and it spawned a Valkyrie near the Airport Security building. What is your stop_scripts() function doing?

 

vsl9KQs.jpg

Edited by Guest

Share this post


Link to post
Share on other sites
diogoscf

Still doesn't work, but the stop_script() is used on other moments of  the script. Also it seems, that the Valkyrie spawns in, but invisible and underground, as when I tried to spawn in on the Vespucci pier, it was under the pier and invisible

The stop_script() does this:

public void stop_scripts()
        {
            Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, new InputArgument[] { "respawn_controller" });
            Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, new InputArgument[] { "re_prison" });
            Function.Call(Hash.STOP_ALARM, new InputArgument[] { "PRISON_ALARMS", 0 });
            Function.Call(Hash.CLEAR_AMBIENT_ZONE_STATE, new InputArgument[] { "AZ_COUNTRYSIDE_PRISON_01_ANNOUNCER_GENERAL", 0 });
            Function.Call(Hash.CLEAR_AMBIENT_ZONE_STATE, new InputArgument[] { "AZ_COUNTRYSIDE_PRISON_01_ANNOUNCER_WARNING", 0 });
        }

 

Share this post


Link to post
Share on other sites
Guest
1 minute ago, diogoscf said:

Update: If I blip the Valkyrie, this happens:

 

[img=https://imgur.com/a/Mx73K9K]

 

 

That looks like a completely different position. The image I posted is where the coordinates you are using should spawn it.

 

Might be worth adding this in your onTick, just to check the location:

World.DrawMarker(MarkerType.DebugSphere, new Vector3(-1179.25f, -2845.386f, 14.333f), Vector3.Zero, Vector3.Zero, new Vector3(1f, 1f, 1f), Color.Yellow);

This is what I see when I add that marker code and blip the vehicle, it's in a completely different place to yours.

rPTS8k1.jpg

Share this post


Link to post
Share on other sites
diogoscf

When I use a ground vehicle it spawns perfectly there, but the helicopetr doesn't

Share this post


Link to post
Share on other sites
Guest

I would be tempted to output the actual coordinates to screen after you spawn the Valkyrie and then check to see if you have any other code that is telling something to happen at that location. I would also comment out that stop_scripts() function, just to make sure that isn't affecting anything.

 

Also make sure to test your script with no other scripts running, just to make sure another script isn't causing the problem. I always test scripts in a version of the game where I only have my scripts present, so you know exactly what is running in the game. As that's at the airport and you are having problems with an aircraft/helicopter, maybe you have a script that is controlling what happens at that location, that only affects that type of vehicle.

Edited by Guest

Share this post


Link to post
Share on other sites
diogoscf

After some testing, it seems that the Valkyrie spawns slightly above the ground (at the right place), and falls down, but doesn't stop falling at the ground and, for some obscure reason, changes position slightly later on.

Share this post


Link to post
Share on other sites
Guest

That's pretty bizarre... falling through the ground sounds like it is having the collision turned off.

 

If you want to try something, here's a link to the test mod I created for the pictures i posted. It's a cs file, so you can check it before you use it, to make sure it's safe (if you're concerned). https://drive.google.com/file/d/1g0sJMTymhcNW0OgFaqECHJrlebqnVAU0/view?usp=sharing

 

Try that and see if the same thing happens. Just use NumPad9 to spawn the Valkyrie.

 

If you want to host your code somewhere and then PM me a link, I am happy to check it out, see if I can spot anything.

Edited by Guest

Share this post


Link to post
Share on other sites
diogoscf

The code is not mine originally, but I've made some changes. ver, the original version had the same problem. The original source code is at https://github.com/marhex/Marhex_Prison-Mod/ The bit that spawns the Valkyrie is on Main.cs

Share this post


Link to post
Share on other sites
Guest

Hmmm, that mod is pretty much broken. I put a UI.Notify on the code that spawns the Valkyrie and it never gets shown, which means the Valkyrie never gets spawned. So it tells you to steal a vehicle that never exists.

 

The Valkyrie only ever spawns when the 'E' key is pressed and you've been arrested and you just happen to be near 1625.474f, 2491.485f, 45.62026f and you're not escaping, so that whole spawn code section is just broken.

 

Edit: Actually, the weird thing is the other vehicles do spawn... so maybe I am not reading that sectoin properly. Stress levels are high today, so it's making concentrating difficult... I will have another look later, when I can clear my head a bit.

 

It would also spawn it into the map where no collision had been loaded if you were near that location, which means it would fall through the floor. If you are ever going to spawn a vehicle a long distance away from the player, then you have to use this:

Function.Call(Hash.SET_ENTITY_LOAD_COLLISION_FLAG, spawnVehicle, true);

That will tell the game to force the collision to load around the entity. spawnVehicle is whatever the name of your vehicle is. But you would typically only spawn the vehicle when you were within range of it, less than 150f to 200f away for instance.

Edited by Guest

Share this post


Link to post
Share on other sites
diogoscf

That explains it. It is supposed only to spawn if you're at the prison, because it's supposed to be part of a prison escape. I tried your bit of code and it worked. Thank you so much!!!

Share this post


Link to post
Share on other sites
Guest

I am just going to quickly check it again because I am honeslty not sure how much of my last post is true. I'll post back later with some more info, sorry for causing any confusion. :(

 

Edit: It seems I was wrong. It is getting spawned, it was the UI.notify that wasn't getting displayed for some reason. It just seems to be several thousand meters under the map. I am going to try freezing the position when it spawns, see if that holds it in place.

Edited by Guest

Share this post


Link to post
Share on other sites
Guest

Okay, freezing the position worked, so change the spawn code to this:

    escape_veh3 = World.CreateVehicle(mod, new Vector3(-1179.25f, -2845.386f, 14.333f);
    escape_veh3.Heading = 325.6199f;
    escape_veh3.IsPersistent = true;
    escape_veh3.FreezePosition = true;
    mod.MarkAsNoLongerNeeded();

And then in prison_escape.cs, at line 125, make the code match this:

    if (steps == 3)
    {
            if (Game.Player.Character.IsInVehicle(escape_veh3))
            {
                vehb.Remove();
                escape_veh3.FreezePosition = false;
                escape_ped2.Task.EnterVehicle(escape_veh3, VehicleSeat.RightRear, 5000);
                steps = 4;
            }
    }

That will freeze its position when it spawns and unfreeze it when you get in... assuming your spawn position is correct that is. The original Z position was 13.5665f

Edited by Guest

Share this post


Link to post
Share on other sites
diogoscf

Your simple SET_ENTITY_LOAD_COLLISION_FLAG worked. I don't see I would use that. Thanks anyway.

 

Also, the original Z position was slightly underground

Share this post


Link to post
Share on other sites
Guest
1 hour ago, diogoscf said:

Also, the original Z position was slightly underground

Yeah, that happens with helicopters that have skids/runners instead of wheels. It's because they compress when you're on the ground, like suspension, so the Z position is lower than it shoould be. There's a native SET_VEHICLE_ON_GROUND_PROPERLY that I think can help with that, can't remember for sure though.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.