bhavinbhai2707 Posted May 24, 2016 Share Posted May 24, 2016 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 More sharing options...
Jitnaught Posted May 24, 2016 Share Posted May 24, 2016 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;} bhavinbhai2707 1 Link to comment Share on other sites More sharing options...
bhavinbhai2707 Posted May 24, 2016 Author Share Posted May 24, 2016 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 More sharing options...
Jitnaught Posted May 24, 2016 Share Posted May 24, 2016 (edited) 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 May 24, 2016 by Jitnaught bhavinbhai2707 1 Link to comment Share on other sites More sharing options...
bhavinbhai2707 Posted May 24, 2016 Author Share Posted May 24, 2016 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 More sharing options...
Jitnaught Posted May 24, 2016 Share Posted May 24, 2016 Haha, no problem. Link to comment Share on other sites More sharing options...
bhavinbhai2707 Posted May 25, 2016 Author Share Posted May 25, 2016 (edited) 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 June 1, 2016 by bhavinbhai2707 Link to comment Share on other sites More sharing options...
Jitnaught Posted May 25, 2016 Share Posted May 25, 2016 I don't understand, what's the problem you're having? bhavinbhai2707 1 Link to comment Share on other sites More sharing options...
bhavinbhai2707 Posted May 27, 2016 Author Share Posted May 27, 2016 (edited) I don't understand, what's the problem you're having? heyyy jitnaught m back with a question. . .what is drivingtowaypoint over here??? Edited May 27, 2016 by bhavinbhai2707 Link to comment Share on other sites More sharing options...
AHK1221 Posted May 27, 2016 Share Posted May 27, 2016 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..... Jitnaught 1 Link to comment Share on other sites More sharing options...
bhavinbhai2707 Posted June 1, 2016 Author Share Posted June 1, 2016 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 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