Jump to content
Sign in to follow this  
Provac

AIM Random Units in Building

Recommended Posts

Hi there, just spent all night yesterday figuring out how to make a custom script for my clans CQB training. I thought id share it with the community if someone needs something like this.

Im not a scripting guru so dont expect anything fancy like the pros make biggrin_o.gif Its partially tested in MP, it works but not perfectly. If the script isnt activated by a trigger the host has to trigger it (as I use addAction in my cqb mission to start and reset the course).

Here is the initial code to place units at random positions in a building.

Quote[/b] ]

//AIM CQB TargetSpawn

//Created By: Provac

//Mission.sqm must contain: One Marker and One Group Leader Unit of the enemy faction.

//Place the Enemy Group Leader away from the action as he is the portal for activating the

//script more than once.

_i = 0;

_types = ["ACE_SoldierE_SR","ACE_SoldierE_MarksmanAK","ACE_SoldierEMedic&q

uot;];

_hotel = [0,0,0] nearestObject 125422;

//Targets in building group leader

"SoldierE" createUnit [getMarkerPos "MarkerTSpawn", LogicSpawn, "TSpawn=this", 0.7, "Corporal"];

//Targets group leader leaves LogicSpawn

[TSpawn] join grpnull;

//Spawn _i ammount of targets + group leader

while {_i < 19} do {

_i = _i+1;

_z = (random (count _types));

     _z = (_z -(_z mod 1));

     _guy = _types select _z;

     _guy createUnit [getMarkerPos "MarkerTSpawn", TSpawn, "",0.7,"Corporal"];

};

//Teleports the enemy group into target building

{_x setpos (_hotel buildingPos 1+random 265)} forEach units group TSpawn;

//Disables the AI's ability to move so that they dont try to rejoin formation

{_x disableAI "MOVE"} forEach units group TSpawn;

//Randomizes their view direction

{_x setDir (random 360)} forEach units group TSpawn;

//Forces units to stay standing up

{_x setUnitPos "UP"} forEach units group TSpawn;

And here is the rar with all the scripts and my CQB mission.

Addons used: ACEmod

Scripts and Mission File: http://www.asylm.se/aim/downloads/AIM_CQB_Training_Hotel.SaraLite.rar

hope it helps if you need something like this, next im gonna try and make it a little more server friendly.

Enjoy!  biggrin_o.gif

Share this post


Link to post
Share on other sites

Great!

However, excuse my ignorance when it comes to scripting and im kinda sorta noobish in mission editing. But how do i activate the enemy AI's? I see you write there has to be a trigger for the AI? I thaught that was done in the example mission or maybe theres something i do wrong.

The "SpawnInBuilding.sqf" was outside the example mission folder. Does it has to go into the folder? And how do i activate the trigger?

EDIT: tested trigger the spawninbuilding.sqf with "this exec" and it did trigger some enemies. However i got an error and it triggered like 2 enemies only. I probably did it wrong though?

Error was some wrong in expression "...while i < 19 do...", but its probably my own fault in triggering it wrong?

Thanks a bunch.

Alex

Share this post


Link to post
Share on other sites

the AI should be active with this script, the only thing that is disabled AI wise is their ability to move. Because they are connected to a squad leader they would try to move back into formation and move away from their building positions.

Each building has a set amount of positions. You have to find out how many positions are in the building you want to place units into.

The SpawnInBuilding.sqf is the original script with some explenation. Its the same as easy, medium and hard.sqf in the mission folder.

To correct the spawn position for your building edit this line.

Quote[/b] ]

//Teleports the enemy group into target building

{_x setpos (_hotel buildingPos 1+random 265)} forEach units group TSpawn;

The number that represents your positions is the one highlighted in bold -1.

For your error in expression make sure everything looks correct, not missing any "," or "[]"

Quote[/b] ]

//Spawn _i ammount of targets + group leader

while {_i < 19} do {

_i = _i+1;

_z = (random (count _types));

_z = (_z -(_z mod 1));

_guy = _types select _z;

_guy createUnit [getMarkerPos "MarkerTSpawn", TSpawn, "",0.7,"Corporal"];

};

It is also important to get the spawn names right, if they arent right the script wont function properly.

I usually make 1 marker called "MarkerTSpawn", then I make a enemy soldier which I usually call "LogicSpawn". Place these two in a location outside of your action areas. If youre LogicSpawn gets killed the script will fail if you want to use LogicSpawn more than once.

If you still have problems post your edited script and il have a quick look.

Share this post


Link to post
Share on other sites

About the error, i didnt do anything inside your scripts, so if there was an error it wasnt me creating it. But maybe it happened as i initialized everything wrong. I just added your script "SpawnInBuilding.sqf" into the mission folder (as it was not in there from start). And then i initialized it with a trigger. Thats all i did.

About the example mission, cant you make it complete? 1 version that we can just start and test instead of us having to add 2 AI units and markers plus initialation etc. Would be nice. Easier for me as a noob to see how its done as well. But ill try add what you explained though. Hopefully i get it right.

Alex

Share this post


Link to post
Share on other sites

Il make a easy setup with just the things thats needed for a good solid understandable preview of getting units randomly into a building. Il post it up later today biggrin_o.gif

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  

×