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. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

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

      1. Recruitment
    2. Events

    1. GTA Online

      1. DLC
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
      7. The Diamond Casino Heist
    2. Grand Theft Auto Series

    3. GTA 6

    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 IV 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 SA Mods
    10. GTA Vice City

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

      1. Guides & Strategies
      2. Help & Support
      3. GTA III 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

Sign in to follow this  
bilago

Vehicle spawning woes.. dotnet / C#

Recommended Posts

bilago

So I'm working on spawning vehicles, and I have the script working to a degree, but have some issues.

Source Code is here: http://pastebin.com/t3W3Gf5a


Issue 1: Cars spawn right in front of the player even when driving at slow speeds.

 

See Line: 198

v = World.CreateVehicle(Vehicle, Game.Player.Character.Position.Around((float)GetRandomNumber(200, 500)));

I have a random generator that will grab a int between 200-500, which should be plenty far away from the player, yet they some times spawn right up front.

Did I use the above code correctly or is the issue with line 205:

v.PlaceOnNextStreet();

The goal is to spawn vehicles on the streets, not in the middle of nowhere.

 

 

 

Issue 2: Spawning a passenger pedestrian doesn't spawn them in the car.

See line: 215

 

  1. //Passengers are spawning ouside of the car... commenting out for now
  2. ////lets spawn a driver and a passenger for police/marines
  3. //for (int i = 0; i <= 1; i++)
  4. //{
  5. // if (i == 0)
  6. // d = v.CreatePedOnSeat(VehicleSeat.Passenger, drivers[GetRandomNumber(drivers.Count)]);
  7. // else
  8. // d = v.CreatePedOnSeat(VehicleSeat.Driver, drivers[GetRandomNumber(drivers.Count)]);
  9. // //The only drivers we are directly specifying are police or marines, give them two random weapons each
  10. // d.Weapons.Give(weapons[GetRandomNumber(weapons.Count)], 1000, true, true);
  11. // d.Weapons.Give(weapons[GetRandomNumber(weapons.Count)], 1000, true, true);
  12. // d.MarkAsNoLongerNeeded();
  13. //}
The goal here is to spawn a random pedestrian type based on a list, which works... but when this is executed:
 d = v.CreatePedOnSeat(VehicleSeat.Passenger, drivers[GetRandomNumber(drivers.Count)]); 

The pedestrian is just standing next to the passenger door and walks away. I've tried spawning this pedestrian before the driver and after the driver and both have the same effect.

 

Any suggestions?

Edited by bilago

Share this post


Link to post
Share on other sites
Prof_Farnsworth

Hey Bilago, I don't have my code in front of me, but here are some tricks I use.

 

For the spawning in front of you:

v = World.CreateVehicle(Vehicle, Game.Player.Character.Position.Around((float)GetRandomNumber(200, 500)));if(v.IsOnScreen){   v.MarkAsNoLongerNeeded();   v.Delete();}else continue as normal

CreatePedOnSeat should work, as I use it to spawn the assassination targets. One thing to try would be calling IsSeatFree() before you create them. If that doesn't work, you can try WarpIntoVehicle() immediately after spawning and checking if they exist.

 

If you still have issues I can post a snippet tonight, or just ILSpy my assassination mod and look under the function "spawnguards". There you will find how I get them into vehicles.

 

Hope it helps!

 

Prof

  • Like 1

Share this post


Link to post
Share on other sites
bilago

Hey Bilago, I don't have my code in front of me, but here are some tricks I use.

 

CreatePedOnSeat should work, as I use it to spawn the assassination targets. One thing to try would be calling IsSeatFree() before you create them. If that doesn't work, you can try WarpIntoVehicle() immediately after spawning and checking if they exist.

 

If you still have issues I can post a snippet tonight, or just ILSpy my assassination mod and look under the function "spawnguards". There you will find how I get them into vehicles.

 

Hope it helps!

 

Prof

 

 

Thanks for the suggestions, I wrote this based on your tips:

                VehicleSeat seat;                if(i==0)                    seat = VehicleSeat.RightFront;                else                     seat = VehicleSeat.Driver;                if (v.IsSeatFree(seat))                    d = v.CreatePedOnSeat(seat, drivers[GetRandomNumber(drivers.Count)]);    

Regarding the solution for the vehicle pop in, doing what you suggested will delete 99% of the vehicles, since it seems that almost every single one spawns in viewing distance other than a few that spawn behind the player :-S

 

 

Edit: I cannot seem to find WarpIntoVehicle() or anything remotely close to that under the Vehicle or Ped class, am I looking in the wrong location?

 

Edit 2: Doing above with pedestrian puts them in the car, but they immediately get out and walk away... lol

Edited by bilago

Share this post


Link to post
Share on other sites
Prof_Farnsworth

It is under "Task".

 

You could also check "IsOccluded" for the vehicles. This would still spawn them if they are blocked from view by an object. Or use the player heading or "ForwardVector" to get a position in front of the character. Another option is to make the vehicle spawn, then make it invisible until it is offscreen, then switch it to visible.

 

Not being sure what you are trying to accomplish makes it difficult to give you a specific solution.

Share this post


Link to post
Share on other sites
bilago

It is under "Task".

 

You could also check "IsOccluded" for the vehicles. This would still spawn them if they are blocked from view by an object. Or use the player heading or "ForwardVector" to get a position in front of the character. Another option is to make the vehicle spawn, then make it invisible until it is offscreen, then switch it to visible.

 

Not being sure what you are trying to accomplish makes it difficult to give you a specific solution.

 

I located it thanks, didn't make a difference though, peds are just getting out of the vehicle and walking away, not sure why.

 

The goal of this mod is to populate dirt roads with vehicles and have the vehicle type match the location (ie only marines with military-esque vehicles spawn near the military base). So having them pop in near a player is more jarring than useful. I want to have cops/marines spawn in pairs as its more realistic to expect a cop to have a partner or more than one marine in a gunner insurgent etc.

Share this post


Link to post
Share on other sites
Prof_Farnsworth

 

It is under "Task".

 

You could also check "IsOccluded" for the vehicles. This would still spawn them if they are blocked from view by an object. Or use the player heading or "ForwardVector" to get a position in front of the character. Another option is to make the vehicle spawn, then make it invisible until it is offscreen, then switch it to visible.

 

Not being sure what you are trying to accomplish makes it difficult to give you a specific solution.

 

I located it thanks, didn't make a difference though, peds are just getting out of the vehicle and walking away, not sure why.

 

The goal of this mod is to populate dirt roads with vehicles and have the vehicle type match the location (ie only marines with military-esque vehicles spawn near the military base). So having them pop in near a player is more jarring than useful. I want to have cops/marines spawn in pairs as its more realistic to expect a cop to have a partner or more than one marine in a gunner insurgent etc.

 

 

Are you clearing the ped tasks at all?

Share this post


Link to post
Share on other sites
bilago

 

 

It is under "Task".

 

You could also check "IsOccluded" for the vehicles. This would still spawn them if they are blocked from view by an object. Or use the player heading or "ForwardVector" to get a position in front of the character. Another option is to make the vehicle spawn, then make it invisible until it is offscreen, then switch it to visible.

 

Not being sure what you are trying to accomplish makes it difficult to give you a specific solution.

 

I located it thanks, didn't make a difference though, peds are just getting out of the vehicle and walking away, not sure why.

 

The goal of this mod is to populate dirt roads with vehicles and have the vehicle type match the location (ie only marines with military-esque vehicles spawn near the military base). So having them pop in near a player is more jarring than useful. I want to have cops/marines spawn in pairs as its more realistic to expect a cop to have a partner or more than one marine in a gunner insurgent etc.

 

 

Are you clearing the ped tasks at all?

 

 

 

I posted the entire source code to the mod in the first post, I do not clear the ped tasks. I just spawn them in the vehicle and give them weapons (when marines)

Share this post


Link to post
Share on other sites
Prof_Farnsworth

 

 

I posted the entire source code to the mod in the first post, I do not clear the ped tasks. I just spawn them in the vehicle and give them weapons (when marines)

 

I didn't see the source before. You are marking them as no longer needed, if you comment this line out, they should stay in the car. I found it's best to only mark them when they are actually not going to be used again in the script or before deleting them.

Share this post


Link to post
Share on other sites
bilago

 

 

 

I posted the entire source code to the mod in the first post, I do not clear the ped tasks. I just spawn them in the vehicle and give them weapons (when marines)

 

I didn't see the source before. You are marking them as no longer needed, if you comment this line out, they should stay in the car. I found it's best to only mark them when they are actually not going to be used again in the script or before deleting them.

 

 

Am I misunderstanding the usage of no longer needed? I assume it tells the game not to hold onto that resource if the game needs it? is it good practice to not mark them that way if they are just serving as general traffic with no tasks other than just driving in the car ?

Share this post


Link to post
Share on other sites
Prof_Farnsworth

 

 

 

 

I posted the entire source code to the mod in the first post, I do not clear the ped tasks. I just spawn them in the vehicle and give them weapons (when marines)

 

I didn't see the source before. You are marking them as no longer needed, if you comment this line out, they should stay in the car. I found it's best to only mark them when they are actually not going to be used again in the script or before deleting them.

 

 

Am I misunderstanding the usage of no longer needed? I assume it tells the game not to hold onto that resource if the game needs it? is it good practice to not mark them that way if they are just serving as general traffic with no tasks other than just driving in the car ?

 

 

From what I've seen it is not like IV's. In V it seems to clear their task as well. Thus, I only use it in the aforementioned circumstances. In your case, maybe mark them when they are a certain distance away and offscreen. Then you don't have to delete them, unless you want to.

Edited by Prof_Farnsworth

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.

Sign in to follow this  

  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

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