motorsport71 Posted August 17, 2011 Share Posted August 17, 2011 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 Link to comment Share on other sites More sharing options...
thaCURSEDpie Posted August 17, 2011 Share Posted August 17, 2011 http://pastebin.com/bFyeQMqa Should work, haven't tested it though. Link to comment Share on other sites More sharing options...
motorsport71 Posted August 18, 2011 Author Share Posted August 18, 2011 @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 More sharing options...
lindsayslorach Posted August 18, 2011 Share Posted August 18, 2011 What kind of errors do you get? Link to comment Share on other sites More sharing options...
thaCURSEDpie Posted August 18, 2011 Share Posted August 18, 2011 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. Link to comment Share on other sites More sharing options...
motorsport71 Posted August 19, 2011 Author Share Posted August 19, 2011 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 More sharing options...
Donny78 Posted August 19, 2011 Share Posted August 19, 2011 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 More sharing options...
motorsport71 Posted August 20, 2011 Author Share Posted August 20, 2011 (edited) 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 EDIT 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. Edited August 20, 2011 by motorsport71 Link to comment Share on other sites More sharing options...
Donny78 Posted August 20, 2011 Share Posted August 20, 2011 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 More sharing options...
thaCURSEDpie Posted August 20, 2011 Share Posted August 20, 2011 @motorsport71 So in the end you just did what I did, only a little bit differently? 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 More sharing options...
motorsport71 Posted August 20, 2011 Author Share Posted August 20, 2011 @thaCURSEDpie i don't disagree at all. i have a "learning" problem 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 but i try. I thank you guys once again, sincerely. Link to comment Share on other sites More sharing options...
thaCURSEDpie Posted August 21, 2011 Share Posted August 21, 2011 Everybody's got to start somewhere . 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 (for free! haha). Good luck! Link to comment Share on other sites More sharing options...
motorsport71 Posted August 21, 2011 Author Share Posted August 21, 2011 @thaCURSEDpie thank you Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now