Jump to content
BlackbirdSD

How to have AI start at the same "Random start position" as another object?

Recommended Posts

The goal of my mission is to get to a tower that has 5 random start positions.  Instead of having a defensive group of enemy at each possible start position, how do I have the enemy start where my tower starts?

Thanks

Share this post


Link to post
Share on other sites

I'm guessing you're using some sort of markers to start the random position of the tower, right? So by each marker, set up a trigger where if an object is present,(youTowerName) he spawns the guards...or by using the "hide/show module" you un-hide them...

Share this post


Link to post
Share on other sites
3 hours ago, zagor64bz said:

I'm guessing you're using some sort of markers to start the random position of the tower, right? So by each marker, set up a trigger where if an object is present,(youTowerName) he spawns the guards...or by using the "hide/show module" you un-hide them...

Thats an idea but i found that simply hiding units doesnt help performance.  I wanted to have less AI on the map. 

Share this post


Link to post
Share on other sites
1 hour ago, wogz187 said:

@BlackbirdSD,
 

This is a module?

Its a marker under "System" called "Empty"  then I right click on the object point to "Connect" then click on "Set Random Start"  then draw a line to that marker.  Im using 3den so not sure if its a default option.  Works great.

 

Share this post


Link to post
Share on other sites

@BlackbirdSD,
So, if you just want to use editor methods, put a player activated trigger on each of your possible spawn positions. When the player is present, trigger your bad guys to setPos on their selected positions. Delete all the triggers once the player is in position.

I'd suggest a simple scripted solution.

Have fun!

Share this post


Link to post
Share on other sites
4 hours ago, wogz187 said:

@BlackbirdSD,
So, if you just want to use editor methods, put a player activated trigger on each of your possible spawn positions. When the player is present, trigger your bad guys to setPos on their selected positions. Delete all the triggers once the player is in position.

I'd suggest a simple scripted solution.

Have fun!

Would you be able to show me an example?  There will be about 50 AI i will need to move to that location.

Share this post


Link to post
Share on other sites

@BlackbirdSD
Moving the units to position is simple. The number of units is completely arbitrary. However, you likely don't want them to all pile on top of each other-- over what kind of area are they to be dispersed? Are there markers in place to show where units should go? Are they to be garrisoned? Where is the position they will go to?

 

  • Like 2

Share this post


Link to post
Share on other sites

Place a small rock on the map. Name it  rock1   Set the rock so it will start at a random place.

 

Place an enemy on the map and name him   red1  In the init of the enemy write   red1 setpos  getpos  rock1

 

The rock starts at a random place and the soldier starts by standing on the rock.

  • Like 1

Share this post


Link to post
Share on other sites
31 minutes ago, wogz187 said:

@BlackbirdSD
Moving the units to position is simple. The number of units is completely arbitrary. However, you likely don't want them to all pile on top of each other-- over what kind of area are they to be dispersed? Are there markers in place to show where units should go? Are they to be garrisoned? Where is the position they will go to?

 

So I currently have about 10 groups anywhere from 3 to 6 per group at each of my 4 possible end points(which is a military tower).  Each group currently has a scripted waypoint with this command [group this, getPos this, 500] call BIS_fnc_taskPatrol; so they patrol the area where the end tower will be.  I will want to have about 10 groups total that will only be around wherever the end point tower is so i can get rid of the rest.  Then they will patrol that area.

Thanks

Share this post


Link to post
Share on other sites

@BlackbirdSD,

Try this,
1) Put your groups into an array,

you_enemy_grp=[group_1, group_2, group_3];

2) Create (player activated) triggers for each of the possible player start positions
in the ON ACTIVATION field of each trigger,

you_randomTower=
{	params ["_grp", "_location"];
    	[_grp, _location] spawn {
			[(_this select 0), getPos (_this select 1), 500] call BIS_fnc_taskPatrol;
            		{
                		_x setPosATL [((getPosATL (_this select 1) select 0) + random 3), ((getPosATL (_this select 1) select 1) + random 3), getPosATL (_this select 1) select 2]  
        }forEach units (_this select 0);
    };
};

{
[_x, _location] call you_randomTower
} forEach you_enemy_group;

It's important to change "_location" in the call (at the bottom) to the adjacent tower for each trigger.

When player activates the trigger all the groups listed in the array will be randomly placed near "_location".

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

It's not like we have a lot of information here, but from what I have understood so far a possible, yet quite crude, solution could look like the following

/*
 * _units: The units in the trigger (those you want to keep)
 * _triggers: The triggers you want to delete (all except the one triggered)
 */
// Get the parameters passed to the script
params["_units", "_triggers"];

// Delete the triggers
{
	deleteVehicle _x;
} forEach _triggers;

// Delete the units that are not in the trigger
{
	deleteVehicle _x;
} forEach (allUnits - _units);

// Get the groups
private _groups = [];
{
	_groups pushBackUnique (group _x);
} forEach _units;

// Create the patrol tasks
{
	[_x, getPos (leader _x), 500] call BIS_fnc_taskPatrol;
} forEach _groups;

And then inside each trigger, you could call the script like

private _triggers = [trig1, trig2, trig3, trig4]; // Make an array with all triggers
[thisList, _triggers - thisTrigger] execVM "theScriptAbove.sqf"; // Call the script

I know this is a very bad scripted solution but I believe that at least points to a certain direction. Hope it helps somehow.

 

Please keep in mind that there must be a whole bunch of better ways to do achieve what you want to do here so do spend some time refining the solution or improvise another better one. Additionally, note that the provided code is untested, so treat with caution.

 

Don't hesitate to ask again if you encounter further issues.

  • Like 1

Share this post


Link to post
Share on other sites

Frankly, I hope you try the 50 rocks method. That sounds awesome!

Have fun!

  • Haha 1

Share this post


Link to post
Share on other sites
2 hours ago, Joe98 said:

Place a small rock on the map. Name it  rock1   Set the rock so it will start at a random place.

 

Place an enemy on the map and name him   red1  In the init of the enemy write   red1 setpos  getpos  rock1

 

The rock starts at a random place and the soldier starts by standing on the rock.

Would this have to be done with each enemy in the group or can it be done in the Init box of the group?

Share this post


Link to post
Share on other sites
1 hour ago, wogz187 said:

@BlackbirdSD,

Try this,
1) Put your groups into an array,


you_enemy_grp=[group_1, group_2, group_3];

2) Create (player activated) triggers for each of the possible player start positions
in the ON ACTIVATION field of each trigger,


you_randomTower=
{	params ["_grp", "_location"];
    	[_grp, _location] spawn {
			[(_this select 0), getPos (_this select 1), 500] call BIS_fnc_taskPatrol;
            		{
                		_x setPosATL [((getPosATL (_this select 1) select 0) + random 3), ((getPosATL (_this select 1) select 1) + random 3), getPosATL (_this select 1) select 2]  
        }forEach units (_this select 0);
    };
};

{
[_x, _location] call you_randomTower
} forEach you_enemy_group;

It's important to change "_location" in the call (at the bottom) to the adjacent tower for each trigger.

When player activates the trigger all the groups listed in the array will be randomly placed near "_location".

Have fun!

I havent done anything with arrays yet so not sure how that works,

Share this post


Link to post
Share on other sites

@BlackbirdSD,
Just like in the example above. Name the groups as you please and then list the names within the array like this,

you_enemy_grp=[group_1, group_2, group_3];

while you're at it do the same thing for the triggers,

you_triggerList=[ trigger_1, trigger_2, trigger_3];

Put the above lists in your init.sqf or the init properties dialog box. You may also paste the "you_randomTower" function into either init. It does not have to be in each trigger.

you_randomTower=
{	params ["_grp", "_location"];
    	[_grp, _location] spawn {
			[(_this select 0), getPos (_this select 1), 500] call BIS_fnc_taskPatrol;
            		{
                		_x setPosATL [((getPosATL (_this select 1) select 0) + random 3), ((getPosATL (_this select 1) select 1) + random 3), getPosATL (_this select 1) select 2]  
        }forEach units (_this select 0);
    };
};

Now your trigger ON ACTIVATION looks like,

{
[_x, _location] call you_randomTower
} forEach you_enemy_group;

{
deleteVehicle _x
}forEach you_triggerList;

All neat and tidy.

*remember to define "_location" in each of the trigger calls (to the adjacent tower)!
example:

{
[_x, RandomTower_1] call you_randomTower
} forEach you_enemy_group;


Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

So all of my units on the map have this command in the Init field of every group leader.  So the entire group starts in a random location within a random 500M radius.

_pos = [[[getPos this,500]]] call BIS_fnc_randomPos; 

 _x setPos _pos; 
} forEach (units (group this)); 
 

I stumbled onto an even simpler method that so far looks great.

 

I made a tower and named it T1.

I made a group of AI and in the Init field I put this 

_pos = [[[getPos T1,500]]] call BIS_fnc_randomPos; 

 _x setPos _pos; 
} forEach (units (group this));

 

All I did was change the "this"  to "T1"

Then I gave the leader a scripted waypoint with this [group this, getPos this, 500] call BIS_fnc_taskPatrol; in the init field.  

Now wherever I move the tower, the entire group spawns within a random 500m radius of the tower then continues with their 500m patrol around the tower.   This will be so helpful for a lot of my missions!

 

Thanks for all your suggestions guys.

 

 

 

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites
9 hours ago, BlackbirdSD said:

Thats an idea but i found that simply hiding units doesnt help performance.  I wanted to have less AI on the map. 

As I mentioned spawning the units will be better....

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Just now, zagor64bz said:

As I mentioned spawning the units will be better....

Why?  Ive tried hiding large numbers of units in the past and it does not improve performance.

Share this post


Link to post
Share on other sites
4 minutes ago, BlackbirdSD said:

Why?  Ive tried hiding large numbers of units in the past and it does not improve performance.

Exactly!!!!

HIDING = "conceal, hide, something from the view of the player"

SPAWNING= "creating a new unit whenever needed."

  • Like 1

Share this post


Link to post
Share on other sites
Just now, zagor64bz said:

Exactly!!!!

HIDING = "conceal,hide, something from the view of the player"

SPAWNING= "creating a new unit whenever needed."

I got ya.  The problem with that is I made my own custom units.  Also when I spawn enemy, can they still follow a scripted waypoint?

  • Sad 1

Share this post


Link to post
Share on other sites
1 minute ago, BlackbirdSD said:

The problem with that is I made my own custom units.

I think is doable.....

 

2 minutes ago, BlackbirdSD said:

Also when I spawn enemy, can they still follow a scripted waypoint?

I think is doable as well...

 

 

  • Like 1

Share this post


Link to post
Share on other sites
1 minute ago, zagor64bz said:

I think is doable.....

 

I think is doable as well...

 

 

I thought of that before but never could figure it out.

Thanks

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×