Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

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

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

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

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

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    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. Design Your Own Mission
      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
    1. Announcements

    2. Support

    3. Suggestions

Setting Spawned Vehicle Direction


motorsport71
 Share

Recommended Posts

motorsport71

thanks for reading. I'm having trouble getting a vehicle to spawn in a direction not facing a preset world direction depending on my placement on the map. I want to be able to have the vehicle spawn relative to Niko's position / heading, in other words, the direction he is facing no matter where he is. I cannot seem to make that work. Since "toheading = single" sets a coordinate and "ped.direction" is read only i'm having a difficult time. I tried using some of the native functions such as "Get_Char_Heading" and "Create_Car" using the x,y,z coordinates but my programming is sub par at best and i cannot get the script to store variables as the coordinates, and i'm not even sure that would work. The vector3 spawning setup for .net Scripthook is great but i don't see anyway to modify directional heading. Is this an easy thing i'm missing? If someone could lend a hand or give an example i would be greatly appreciative. Thanks again. A newb.

 

BTW, i'm using .vb, but a c# example would be great as well... thanks again smile.gif

Link to comment
Share on other sites

motorsport71

@thaCURSEDpie

 

Thanks for the info, converted to .vb this is what i get:

 

Private Function spawnVehExample(vehName As String, offsetPos As Vector3, headingOffset As Single) As Integer' Get the player heading.Dim vehHeading As Single = Player.Character.Heading' Offset the heading.vehHeading += headingOffset' Get the spawn position.Dim vehPos As Vector3 = Player.Character.GetOffsetPosition(offsetPos)' Spawn the vehicle.   Vehicle name would be "FAGGIO" as needed to be spelled exact in place of 'vehName'.  Gta.vehicle needs               only to be Vehicle in .vbDim veh As Vehicle = World.CreateVehicle(vehName, vehPos)' Check if vehicle is spawned correctly.If veh Is Nothing OrElse Not veh.Exists() Then  Error code 1: failed to spawn vehicle! Return 1End If'Set heading.veh.Heading = vehHeading'SuccessReturn 0End Function

 

 

I tried to replace "vehName" in the with the vehicle's name 'as string', but in .vb using .net Scripthook i have to use " " around the vehicle's name, thus changing it from useable code to a bunch of "this needs corrected" errors.

Link to comment
Share on other sites

thaCURSEDpie

I don't understand your problem (I'm also not that familiar with VB)... You can just call the function I wrote, you don't need to customize the function at all. notify.gif

Link to comment
Share on other sites

motorsport71

Okay, here is the original code:

 

Dim vehicle As vehicle = world.createvehicle("Faggio", player.character.position)                   If exists(vehicle) Then                   vehicle.visible = False                   Vehicle.MakeProofTo(True, True, True, True, True)                   Dim ped As ped = player.character                   If exists(ped) Then                       Ped.WarpIntoVehicle(vehicle, vehicleseat.driver)

 

 

If, and i think i'm understanding how to use the "call" function properly

 

Call spawnVehExample()  'UNMODIFIED FROM thaCURSEDpie Function               If exists(vehicle) Then                   vehicle.visible = False                   Vehicle.MakeProofTo(True, True, True, True, True)                   Dim ped As ped = player.character                   If exists(ped) Then                       Ped.WarpIntoVehicle(vehicle, vehicleseat.driver)                   End If               End If

 

If i use it this way i get the errors "Argument not specified for the parameter "headingOffset' of 'Private Function spawnVehExample(vehName As String, offsetPos As Vector3, headingOffset As Single) as Integer" and the same for "offsetPos" and "vehName".

 

that is why i though i should have changed the "vehName" in the Function to the vehicle i was to spawn to solve the error problem, as i had mentioned in my last post. I tried spawning the vehicle, etc, but the error is still there and i just cannot seem to reference the vehicle to be spawned?

Link to comment
Share on other sites

 

Private Function spawnVehExample(vehName As String, offsetPos As Vector3, headingOffset As Single) As Vehicle' Get the player heading.Dim vehHeading As Single = Player.Character.Heading' Offset the heading.vehHeading += headingOffset' Get the spawn position.Dim vehPos As Vector3 = Player.Character.GetOffsetPosition(offsetPos)' Spawn the vehicle.   Vehicle name would be "FAGGIO" as needed to be spelled exact in place of 'vehName'.  Gta.vehicle needs              only to be Vehicle in .vbDim veh As Vehicle = World.CreateVehicle(vehName, vehPos)' Check if vehicle is spawned correctly.If veh Is Nothing OrElse Not veh.Exists() Then Error code 1: failed to spawn vehicle!Return NothingEnd If'Set heading.veh.Heading = vehHeading'SuccessReturn veh End Function

 

 

I don't know VB so the "Nothing" return could be incorrect, the method returns a Vehicle type return now instead of an integer.

 

Usage:

 

 

Vehicle v = SpawnVehicleExample...... If Exists(v) Then...........

 

 

Btw you are using your cases incorrectly, your Ped, ped, Vehicle, vehicle are mostly all wrong dude, maybe just a typo in your example but I thought I'd point it out.

 

Link to comment
Share on other sites

motorsport71

okay, tried calling updated function by Donny78 using

 

Vehicle v = SpawnVehicleExample...... If Exists(v) Then...........

 

still nowhere.

 

If i type in Vehicle v = SpawnVehicleExample, for instance, .vb modifies it by default to Vehicle(v = SpawnVehicleExample) to make it correct .vb format. So i tried replacing "Vehicle" with Faggio, "Faggio"(which it won't accept in quotations). I replaced the v the same way. No go.

 

I understand how to spawn a vehicle. very easy stuff. There i am at Point A.

 

I can see how the function thaCURSEDpie wrote / Donny78 modified is working to get the player's direction / heading, and tell the spawning vehicle to face that direction. And here is Point C.

 

But how do i tell the Sub to use the Function to spawn a vehicle by vehicle name? I cannot figure out point b. As i mentioned before, sub par programming skill. kindergardners laugh. not as hard as you though confused.gif

 

EDIT biggrin.gifbiggrin.gifbiggrin.gif

 

I found a way to fix my problem. I did this:

 

Dim vehicle As vehicle = world.createvehicle("Faggio", player.character.position)               If exists(vehicle) Then                   Native.Function.Call("Set_Car_Heading", vehicle, player.character.heading)                   vehicle.visible = False                   Vehicle.MakeProofTo(True, True, True, True, True)

 

I never expected in a million years that when i would insert the native function AND use player.character.heading as it's rotation that it would work. Wonders never cease. Thanks to all who read this thread. Many appreciations. smile.gif

Edited by motorsport71
Link to comment
Share on other sites

I have just created my own custom in C#:

 

 

private Vehicle SpawnVehicle(string modelName, Vector3 offsetPos, float offsetRot){   Vehicle vehicle = World.CreateVehicle(Model.FromString(modelName), Player.Character.GetOffsetPosition(offsetPos));   if (Exists(vehicle))   {       vehicle.Heading = (Player.Character.Heading + offsetRot);       return vehicle;   }   return null;}

 

 

Then in my scripts spawning bit:

 

 

SpawnVehicle("FAGGIO", new Vector3(0f, 10f, 0f), 0f);

 

 

No issues.

 

Maybe I posted something incorrectly when trying that VB version.

 

Also when you say "still nowhere" what does that mean dude ? Did you get errors or ?

Link to comment
Share on other sites

thaCURSEDpie

@motorsport71

So in the end you just did what I did, only a little bit differently? notify.gif

 

From your posts it's pretty clear you lack some important programming knowledge, such as: how to call a function. I strongly advice you to look up some tutorials on Visual Basic.

 

@Donny78

I believe that's correct, IIRC 'Nothing' is VB's version of 'Null'.

Link to comment
Share on other sites

motorsport71

@thaCURSEDpie

 

i don't disagree at all. i have a "learning" problem suicidal.gif so i have to "disect" and "reconfigure" to learn how something works, in other words, take it apart and put it back together again. That's why i chose .vb, it may be different from what everyone else uses, but in .net scripthook it's easy to use. I now can now take a look at, for instance, c++ source code, and 'see' what the person is doing... i just don't know how to impliment them through proper programming knowledge. The script i'm finishing is i've rewritten/added Nixolas Superman into a .vb source for .net Scripthook(the script has a lot of other options). It works great now that the heading issue is solved, which you guys will get creds for helping. Nixolas also has stated in the README anyone can use his source code for a mod as long as he gets credit, which he will of course.

 

i'm just a dumb auto body technician from Pittsburgh tounge2.gif but i try.

 

I thank you guys once again, sincerely.

Link to comment
Share on other sites

thaCURSEDpie

Everybody's got to start somewhere smile.gif. Looking at someone else's code can be very helpful.

 

I've had a look around and this: http://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P2.htm seems to be a decent tutorial on Visual Basic. Honestly, you can't learn everything from other people's code, sometimes you just need to learn it from the experts smile.gif (for free! haha).

 

Good luck!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 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.