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

Happy Holidays from the GTANet team!

How to create random enemies while going to destination


bhavinbhai2707
 Share

Recommended Posts

bhavinbhai2707

hello guys. . .i am creating a mod and want that when i am going to destination enemies are created on random basis through out the route anytime. . . . for example when i am driving to destination the enemies suddenly comes from a street and start attacking on me and sometimes it may happen that there are no enemies at all while going to destination

any ideas on how can i do it plssss suggest me ;)

Link to comment
Share on other sites

You could use the Random class for random number generation, and then use the number to determine if you want to spawn enemies or not.

Random rand = new Random(); //global variables (inside class, outside of any function)bool decidedEnemyCreation = false;if (drivingToWaypoint && !decidedEnemyCreation) //inside function{   int num = rand.Next(0, 1);   if (num == 0)   {      //create enemies   }   decidedEnemyCreation = true;}else{   decidedEnemyCreation = false;}
  • Like 1
Link to comment
Share on other sites

bhavinbhai2707

 

You could use the Random class for random number generation, and then use the number to determine if you want to spawn enemies or not.

Random rand = new Random(); //global variables (inside class, outside of any function)bool decidedEnemyCreation = false;if (drivingToWaypoint && !decidedEnemyCreation) //inside function{   int num = rand.Next(0, 1);   if (num == 0)   {      //create enemies   }   decidedEnemyCreation = true;}else{   decidedEnemyCreation = false;}

so far i understood it but still some questions in my mind it solved half of my problem . . how do i generate them in between of route i mean to say if i am driving from Michael's house to airport and the enemy should be created in between the route it can be anytime anywhere. . .any idea on this ;)

Link to comment
Share on other sites

Remove the "decidedEnemyCreation" variable and all uses of it, put the if statement segment of code in a Tick event function, and on each tick create a random number and set the tick's Interval to that.

 

Keep in mind this would change the interval for all code in all Tick event functions.

Random rand = new Random(); //global variable (inside class, outside of any function)if (drivingToWaypoint) //inside Tick event{   int num = rand.Next(0, 1);   if (num == 0)   {      //create enemies   }   Interval = rand.Next(3, 30) * 1000; //3 seconds to 30 seconds}
Edited by Jitnaught
  • Like 1
Link to comment
Share on other sites

bhavinbhai2707

 

Remove the "decidedEnemyCreation" variable and all uses of it, put the if statement segment of code in a Tick event function, and on each tick create a random number and set the tick's Interval to that.

 

Keep in mind this would change the interval for all code in all Tick event functions.

Random rand = new Random(); //global variable (inside class, outside of any function)if (drivingToWaypoint) //inside Tick event{   int num = rand.Next(0, 1);   if (num == 0)   {      //create enemies   }   Interval = rand.Next(3, 30) * 1000; //3 seconds to 30 seconds}

though its 2:00 am over here i got to try this now lol ;) . . . .and thanq thanq thanq very much :) for the help i really appreciate your help. . .will contact soon if any trouble is there ;)

Link to comment
Share on other sites

bhavinbhai2707

 

 

I don't understand, what's the problem you're having?

heyyy jitnaught m back with a question. . .what is drivingtowaypoint over here???

 

It's just a bool you have to develop to check if you are driving.....

Haha, no problem. :)

ohh yeah it worked man but don't u think changing interval can really created chaos an delay for other code to work in the tick functions plss help me ;) Edited by bhavinbhai2707
Link to comment
Share on other sites

bhavinbhai2707

I don't understand, what's the problem you're having?

heyyy jitnaught m back with a question. . .what is drivingtowaypoint over here???

Edited by bhavinbhai2707
Link to comment
Share on other sites

 

I don't understand, what's the problem you're having?

heyyy jitnaught m back with a question. . .what is drivingtowaypoint over here???

 

It's just a bool you have to develop to check if you are driving.....

Link to comment
Share on other sites

bhavinbhai2707

 

 

I don't understand, what's the problem you're having?

 

heyyy jitnaught m back with a question. . .what is drivingtowaypoint over here???

 

It's just a bool you have to develop to check if you are driving.....

i tried it bro. . .but i doesn't seem to work i kept driving for more

than 20 mins but enemies were not there can u please check the code once again please ;)

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.