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

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Arena War
      2. After Hours
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA Next

    4. GTA V

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

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

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

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

    2. Forum Support

    3. Site 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
Posted (edited)

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
Posted (edited)

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
Posted (edited)

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
Posted (edited)

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
Posted (edited)

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
Posted (edited)

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.