AI spawned waves from random direction


Download this demo mission (editor version)I did and check out the selNewDir.sqf. That shows how to spawn groups in random areas based on a trigger. It’s all code, but it’s commented code!

Code:
//////////////////////////////////////////////////////////////////
// Function file for ArmA 2: Operation Arrowhead
// Created by: kylania (Some code from shk)
//////////////////////////////////////////////////////////////////
// This script, called from a trigger, will pick a destination and spawn guys on it.

// Don't allow a new wave if a current wave is active.
if (respawnAble) then {

	// Initialize Functions
	waitUntil{!(isNil "BIS_fnc_init")};
	waitUntil{!(isNil "BIS_MPF_InitDone")};

	// Run from a trigger it will activate on all clients, by making
	// it check for isServer this will only run on the server.  The
	// rHINT function will broadcast the direction to all clients.
	// This way we only get one direction instead of everyone getting
	// a different direction.
	if (isServer) then {
		_rndDir = ["North","East","South","West"] select floor(random 4);
		_rndDirhint = [nil,nil,"per",rHINT,_rndDir] call RE;

	// If you only wanted one of the two markers to get guys use this line.
	//_markerRnd = curDir + "spawn" + str(ceil(random 2));
	_marker1 = _rndDir + "spawn1";
	_marker2 = _rndDir + "spawn2";

	// How many enemies in each group.
	_enemyCount = _this select 0;

	// Warn of the incoming attack.
	hint format["%1 Spawn activated!", _rndDir];

	// Spawn the first group and have them attack.
	grp = [getMarkerPos _marker1, east, _enemyCount] call BIS_fnc_spawnGroup;
	null = [grp,(getMarkerPos "infdestination")] call BIS_fnc_taskAttack; 

	// Spawn the second group and have them attack.
	grp2 = [getMarkerPos _marker2, east, _enemyCount] call BIS_fnc_spawnGroup;
	null = [grp2, (getMarkerPos "infdestination")] call BIS_fnc_taskAttack;
	};

} else {
	// If there's currently an attack underway, remind the player of that instead of spawning new.
	hint "Attack underway!";
};
  1. #1 by Khalashnikovf on September 18, 2010 - 12:40 PM

    Ok, you can delete it. I figured it out finally.
    This is the working version. Now It will be easy to make some array of units which you want to use and it is done.

    // How many enemies in each group.
    _countE = 0;
    _enemy = _this select 0;
    _rndm = _this select 1;
    _countE = _enemy + floor (random _rndm);

    // ————- PART FOR DESIGNATING TYPE AND COUNT OF UNITS ———————
    _eC = [];
    _enemyCount = [];

    sleep 1;

    for [{_n = 0},{_n <= _countE},{_n = _n+1}] do
    {
    _unitType = floor (random 5);
    switch (_unitType) do {
    case 0: {_eC = ["TK_INS_Soldier_3_EP1"];};
    case 1: {_eC = ["TK_INS_Soldier_4_EP1"];};
    case 2: {_eC = ["TK_INS_Soldier_AT_EP1"];};
    case 3: {_eC = ["TK_INS_Soldier_MG_EP1"];};
    case 4: {_eC = ["TK_INS_Soldier_AR_EP1"];};
    case 5: {_eC = ["TK_INS_Soldier_Sniper_EP1"];};
    };
    _enemyCount = _enemyCount+_eC;
    };

    • #2 by kylania on September 18, 2010 - 3:52 PM

      Glad you got it working, nice addition!

    • #3 by Khalashnikovf on September 18, 2010 - 6:49 PM

      Dont know why, but its not working anymore. I call it same way like before. Isnt it possible,that when I add another markers on map it wont work? Im done 🙁
      Or maybe a big count of civilian units making impossible to spawn another units?

      • #4 by Khalashnikovf on September 18, 2010 - 7:56 PM

        Emm, I made download of my mission. If you could pls spend one hour max to find what is going on?!?!? 🙁

        http://www.megaupload.com/?d=KAFGC7QB
        It needs ied_pack from armaholic, but Im sure you got it already.

        Pls,baging,sad eyes… desperate 🙁
        And also it looks like it stopper to work blurring.sqf script. Like all BI functions stopped working 🙁

        • #5 by kylania on September 18, 2010 - 8:02 PM

          Sure can. 🙂

        • #6 by kylania on September 18, 2010 - 9:30 PM

          Ahh it was an easy fix. You don’t start the map with any OPFOR units on it, so none can be spawned via scripts without first creating a center.

          Simply place any Takistani Militia unit on the map, set it’s Probability of presence to 0% so it won’t show up, but then you’ll be able to spawn the TK_INS units you’re trying to.

          • #7 by Khalashnikovf on September 19, 2010 - 4:04 AM

            AAAAAAA DAMM IT !!! 😀
            I KNEW that something WILL happen WRONG when I delete it 😀
            But NO…Im sured my self,it wil be fine,it was useless there,he is stupid so why he is doing this? 😀
            AAAAAAAAAAAA 😀
            THANKS MAN 😀
            Love your work!!!
            Keep it Coming

    • #8 by Khalashnikovf on September 19, 2010 - 4:12 AM

      Well, You probably seen in that mission my civilians,right?
      Do you think it migt be working even for Civilians?
      And somehow put them something like throwing rocks (anim with grenade throwing and then samo probability of hit) and some exceptions would have pistols only (and of course someone will be your “Market Day” 🙂 .
      But I have no idea how to force these civilians to at least run close to the player like in my scenario. And not mention to how add them function to launch your script or add them Pistols 🙁

Comments are closed.