Jump to content
Sign in to follow this  
Ghostwolf

How to spawn ai in buildings

Recommended Posts

Ok so I have a trigger that activates when helicopters are destroyed, what I'd like to happen next is to have enemies seek and destroy at that location once the trigger activates. My problem is that I'm using the commonly known way to place AI in interiors(give them all waypoints and positions within the building) but the problem is, I can only sync 1 AI waypoint to the trigger because all the "enter building waypoints" are stacked on top of each other, allowing me to only click on the top-most one. Ideally I'd like to have the enemy AI move from the building to the trigger, for dramatic effect.

Is there a way to have the AI spawn already inside the building when the mission starts up, opposed to giving them waypoints?

Share this post


Link to post
Share on other sites

Hi mate!

Take a look to my script (Fully tested and working like silk!)

(FILE NAME: Unit_x1_Spawn_x3.sqf)

//Null = [This,"MIDDLE","AUTO",ViewingAngle,[Loc_X_1,Loc_Y_1,Loc_Z_1,Angle_1],[Loc_X_2,Loc_Y_2,Loc_Z_2,Angle_2],[Loc_X_3,Loc_Y_3,Loc_Z_3,Angle_3]] ExecVM "Unit_x1_Spawn_x3.sqf";

// POS_1 POS_2 LOCATION_1 + ANGLE_1 LOCATION_2 + ANGLE_2 LOCATION_3 + ANGLE_3

// POS_1 = Body position when there is NO enemy. Values="DOWN","MIDDLE","UP","AUTO"

// POS_2 = Body position when there is an enemy. Values="DOWN","MIDDLE","UP","AUTO"

If (IsServer) Then

{

Private ["_Angle_Ini","_Pos_Val","_Switch","_Timer","_Angle"];

_Angle_Ini = 0;

_Pos_Val = ([0,1,2] Select Floor Random(3));

_Switch = 0;

Switch (_Pos_Val) Do

{

Case 0:

{

(_This Select 0) SetPos [((_This Select 4) Select 0),((_This Select 4) Select 1),((_This Select 4) Select 2)];

(_This Select 0) SetDir ((_This Select 4) Select 3);

_Angle_Ini = ((_This Select 4) Select 3);

};

Case 1:

{

(_This Select 0) SetPos [((_This Select 5) Select 0),((_This Select 5) Select 1),((_This Select 5) Select 2)];

(_This Select 0) SetDir ((_This Select 5) Select 3);

_Angle_Ini = ((_This Select 5) Select 3);

};

Case 2:

{

(_This Select 0) SetPos [((_This Select 6) Select 0),((_This Select 6) Select 1),((_This Select 6) Select 2)];

(_This Select 0) SetDir ((_This Select 6) Select 3);

_Angle_Ini = ((_This Select 6) Select 3);

};

};

_Timer = 0;

_Angle = Getdir (_This Select 0);

(_This Select 0) SetUnitPos (_This Select 1);

While {Alive(_This Select 0)} Do

{

If (IsNull (AssignedTarGet (_This Select 0))) Then

{

If (_Timer < Time) then

{

_Angle = _Angle_Ini + (Log ([0.1,10] Select Floor Random(2)))*( (((_This Select 3)/2)*0.5)+Random (((_This Select 3)/2)*0.5) );

(_This Select 0) DoWatch [(GetPos (_This Select 0) Select 0) + (80*Sin _Angle),(GetPos (_This Select 0) Select 1) + (80*Cos _Angle),0];

_Timer = Time + (1 + Random 5);

};

}

Else

{

If (_Switch == 0) Then {(_This Select 0) SetUnitPos (_This Select 2); _Switch = -1;};

};

Sleep 1;

};

};

This baby will make spawn the unit randomly at one of three locations. It will set the right direction and stance too.

This script not only a random location and direction... it also manage the unit stance. Unit stance is important to lock units stance to allow them to shot trough windows!

Locations are 3D coordinates so you can place a unit anywhere!

How to gather locations and angles?

You will need 4 triggers.

(CODE FOR TRIGGERS)

1. ALPHA-> Pos1 = (GetPosATL Player); Pos1 = Pos1 + [GetDir Player];

2. BRAVO-> Pos2 = (GetPosATL Player); Pos2 = Pos2 + [GetDir Player];

3. CHARLIE-> Pos3 = (GetPosATL Player); Pos3 = Pos3 + [GetDir Player];

4. DELTA-> CopyToClipboard (Str(Pos1)+","+Str(Pos2)+","+Str(Pos3));

1. Now you only need to run the mission on the editor and move your unit to the desired position. Then look to the desired location and finally press ALPHA.

2. Move the unit to the next location.

3. Now you only need to run the mission on the editor and move your unit to the desired position. Then look to the desired location and finally press BRAVO.

4. Move the unit to the next location.

5. Now you only need to run the mission on the editor and move your unit to the desired position. Then look to the desired location and finally press CHARLIE.

6. Press DELTA to copy the information.

7. Stop the mission and return back to the editor.

8. Create a unit.

9. Inside the init field for the unit add the code to run the script and select the bold text and press CRTL+V (Paste) to introduce the new data:

Null = [This,"AUTO","AUTO",100,[2855.6,5880.88,0.00164986,341.394],[2857.62,5886.96,0.00111771,251.519],[2856.75,5883.51,0.0946131,124.048]] ExecVM "Unit_x1_Spawn_x3.sqf";

(You can manage the unit stance to avoid glitches)

Units using this script are more... effective so you will need less units to make missions more challenging.

If you have any doubt using it please let me know.

If you want an simple mission example with the code contact me (mgllgm@hotmail.com)

I hope you like it!

Murcielago

Share this post


Link to post
Share on other sites

Thanks froggyluv!

I know it works and it works without creating performance issues. By the way I manage to create this using this script!

That was my Silent Rescue mission. Maybe the most difficult COOP mission ever created.

Thanks for your time.

Share this post


Link to post
Share on other sites

I reinstalled ARma2 just to check that out ^^^^.

Wow. Man that is seriously impressive -thats a mission! The detail and care put into this is something I've never seen and you should be designing missions + AI for BI like yesterday.

Hats off to you.

PS: If you ever wanted to release your patrol script.....:627:

Edited by froggyluv

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
Sign in to follow this  

×