Home   Help Search Login Register  

Author Topic: need help spawning in certain conditions  (Read 2336 times)

0 Members and 1 Guest are viewing this topic.

Offline Supergrunt

  • Members
  • *
need help spawning in certain conditions
« on: 14 Oct 2009, 23:53:59 »
hi there,

i need some help in spawning VTE NVA troops unlimitly until the player destroyes a certain object or kills the enemy general.

the idea is to have a endless battle go on between a set number of US troops and wave after wave of enemy troops

to make the enemy have bigger numbers i also need the enemy to spawn 2 groups at the same time move them to the battle area (LZXray)  from there spawn point (base) endlessly until the object or general is destroyed.

i tried looking and searched the forums and all the spawn posts around but nothing fits my idea
and because i am a scripting idiot i cant get this to work on my own so please help me...

greetz

Supergrunt
« Last Edit: 14 Oct 2009, 23:55:32 by Supergrunt »

Offline tcp

  • Members
  • *
    • Violator Gaming
Re: need help spawning in certain conditions
« Reply #1 on: 15 Oct 2009, 01:08:58 »
I adapted Norrin's AI respawn script to have enemy alive conditions instead of lives.

http://www.filefront.com/14723635/Operation_Stormbreaker_v3b.Chernarus.pbo

The misssion needs some tweaking since too much enemy helis spawn and the assault team can't destroy the objectives fast enough, so the defending team took on about 200 waves of enemies. It could probably use a dead body cleanup script.

Offline Supergrunt

  • Members
  • *
Re: need help spawning in certain conditions
« Reply #2 on: 15 Oct 2009, 12:47:42 »
first things first   i asked a ARMA question not ARMA 2  :P

and second but most important part  I AM A SCRIPTING IDIOT and i need lots of help getting it done

i found several scripts by searching but none realy worked (arma 1.14)

script 1
Code: [Select]
_marker1 = _this select 0
_marker2 = _this select 1
_group = _this select 2
_units = _this select 3

_countunits = _units
_group = creategroup east

#Update1

"soldierEB" createUnit [getMarkerPos _marker1, _group]

_countunits = _countunits -1

? _countunits > 0 : goto "Update1"

_group move getMarkerPos _marker2
{_x allowFleeing 0} foreach units _group

_countunits = _units

#Update2

{alive _x} count units _group < 1: goto "Update1"

sleep 15

goto "Update2"

exit


script number 2

Code: [Select]
// Description: Continuously respawn all selected AI infantry and vehicle groups at nominated
// marker after each entire group is killed.
// Group will then resume their original (guard) waypoint, if any.
// I.C.E. module
// Ver 1.0
//-----------------------------------------------------------------------------
// Notes: ICE_RespawnAIGroups is a global variable and is self initializing.
// Notes: Loop will detect late changes to ICE_RespawnAIGroups.
//-----------------------------------------------------------------------------
/* Usage:
  Call this for each AI group or AI vehicle.
  nul=[this] execVM 'AIGroupRespawn.sqf';

  Then call this once (from init.sqf) to begin loop.
  nul=[] execVM 'AIGroupRespawn.sqf'; // no parameter means start infinite loop
*/
//-----------------------------------------------------------------------------
if (!isServer) exitWith {};

if (isNil "ICE_RespawnAIGroups") then
{
  ICE_RespawnAIGroups = [];
};

if (count _this > 0) exitWith
{
  private ["_group"];
  _group = _this select 0;
  if (typeName _group != "GROUP") then {_group = group _group};
  if !(_group in ICE_RespawnAIGroups) then
  {
    ICE_RespawnAIGroups = ICE_RespawnAIGroups+[_group];
  };
  // exit script.
};
//-----------------------------------------------------------------------------

#define AIGroupRespawn_infantryDelay (60*4) //(60*10) - respawn wait period (in seconds)
#define AIGroupRespawn_vehicleDelay (60*15) //(60*25) - respawn wait period (in seconds)
#define AIGroupRespawn_monitor (60*2) //(60*2) - monitoring period for checking group status (in seconds)

#define enum_groupDefs_group 0
#define enum_groupDefs_status 1
#define enum_groupDefs_unitDefs 2

#define enum_groupDefs_statusAlive 1
#define enum_groupDefs_statusRespawn 2

#define ICE_RespawnAIGroups_Markers ['AIGroupRespawnEast1', 'AIGroupRespawnEast2', 'AIGroupRespawnEast3', 'AIGroupRespawnEast4']
//-----------------------------------------------------------------------------
private ["_groupDefs", "_groupDefsCount"];
_groupDefs = [];
_groupDefsCount = count _groupDefs;
//-----------------------------------------------------------------------------
/*
// this is a temp substitute for a debug output console
fn_DebugAppend =
{
  player groupChat format['%1', _this]; // debug
};
*/
//-----------------------------------------------------------------------------
fn_isVehicle_v2 =
{
  private ["_objOrType", "_result"];
  _objOrType = _this select 0;
  _result = ((_objOrType isKindOf "LandVehicle") || (_objOrType isKindOf "Air") || (_objOrType isKindOf "Ship"));
  _result;
};
//-----------------------------------------------------------------------------
// creates an array containing all relevant groups and their original unit structure
/*
[
  [group1, 'aliveStatus',
    [
      [unitType1, crewType1, rank1, skill1],
      [unitType2, crewType1, rank2, skill2],
      ...
    ]
  ],
  [group2, 'aliveStatus',
    ...
  ],
  ...
]
*/
_fn_CreateGroupDefs =
{
  private ["_group", "_unitDefs", "_unit", "_vehicle", "_record"];
  {
    _group = _x;
   
    _found = false;
    {
      if (_x select enum_groupDefs_group == _group) exitWith
      { _found = true };
    } forEach _groupDefs;
   
    if (!_found) then
    {
      _unitDefs = [];
      {
        _unit = _x;
       
        // it seems that sometimes during initialization, units will not actually be in their vehicle (this could be mod dependent)
        _vehicle = objNull;
        if ([vehicle _unit] call fn_isVehicle_v2) then
        {
          _vehicle = vehicle _unit;
        }
        else
        {
          if ([assignedVehicle _unit] call fn_isVehicle_v2) then
          {
            _vehicle = assignedVehicle _unit;
          };
        };

        _record = if ([_vehicle] call fn_isVehicle_v2) then
        {
          if ((driver _vehicle == _unit) || ('Driver' in assignedVehicleRole _unit)) then // only add 1 vehicle per crew
          {
            //[typeOf _vehicle, typeOf driver _vehicle, rank _unit, skill _unit];
            [typeOf _vehicle, typeOf _unit, rank _unit, skill _unit];
          }
          else
          {
            [];
          };
        }
        else
        {
          [typeOf _unit, 'n/a', rank _unit, skill _unit];
        };
       
        if (count _record > 0) then
        {
          _unitDefs set[count _unitDefs, _record];
        };
      } forEach units _group;

      _groupDefs set[count _groupDefs, [_group, enum_groupDefs_statusAlive, _unitDefs]];
    };
  } forEach ICE_RespawnAIGroups;
 
  _groupDefsCount = count _groupDefs;
  //['AIGroupRespawn.sqf', _groupDefs] call fn_DebugAppend;
};
//-----------------------------------------------------------------------------
_fn_RespawnGroup =
{
  private["_groupDef", "_group", "_unitDefs", "_hasVehicles", "_pos", "_dest", "_delay"];
  // passes _groupDef by reference for modification
  _groupDef = _this select 0;
 
  _group = _groupDef select enum_groupDefs_group;
  _unitDefs = _groupDef select enum_groupDefs_unitDefs;

  _hasVehicles = false;
  {
    if ([_x select 0] call fn_isVehicle_v2) exitWith
    { _hasVehicles = true };
  } forEach _unitDefs;
 
  _delay = if (_hasVehicles)
  then {AIGroupRespawn_vehicleDelay}
  else {AIGroupRespawn_infantryDelay};
  if (f_var_debugMode > 0) then {_delay = 20};
  sleep _delay;
 
  //player globalChat format['%1: Spawning group', _group]; // debug
  _pos = [];
  {
    private["_type", "_crew_type", "_rank", "_skill", "_AI", "_vehicle"];
    _type = _x select 0;
    _crew_type = _x select 1;
    _rank = _x select 2;
    _skill = _x select 3;

    if ([_type] call fn_isVehicle_v2) then
    {
      //player globalChat format['%1: Spawning vehicle: %2', _group, _type]; // debug
     
      _vehicle = createVehicle [_type,
        getMarkerPos (ICE_RespawnAIGroups_Markers select 0),
        ICE_RespawnAIGroups_Markers,
        getMarkerSize (ICE_RespawnAIGroups_Markers select 0) select 0,
        "FORM"];
     
      // call your own vehicle init script here. Eg: "killed" event handler.
      nul=[_vehicle] execVM "Mission\DestroyObject\InitDestroyEnemyVehicle.sqf";
     
      if (count _pos == 0) then
      {
        _pos = position _vehicle;
      }
      else
      {
        _vehicle setPos _pos;
      };

      {
        //player globalChat format['%1: checking seat: %2', _group, _x]; // debug
       
        _seats = _vehicle emptyPositions _x;
        if (_seats > 0) then
        {
          //player globalChat format['%1: adding seat: %2', _group, _x]; // debug
          _AI = _group createUnit[_crew_type, _pos, [], 20, "FORM"];
          sleep 1;
          switch(_x)do
          {
            case "Commander": {_AI moveInCommander _vehicle};
            case "Driver":
            {
              _AI moveInDriver _vehicle;
             
              [_AI] execVM "Scripts\Debug\TrackingMarker.sqf";
             
              // reactivate old WP
              _WPs = waypoints _AI;
              if (count _WPs > 1) then
              {
                _dest = WaypointPosition (_WPs select 1);
                _AI move _dest;
                (group _AI) setCurrentWaypoint (_WPs select 1);

                [[WEST, 'HQ'], format['Detected unit: %1', [_type] call fn_getDisplayName]] call fn_sideChat; // debug
                ['AIGroupRespawn.sqf', format['Detected unit: %1', [_type] call fn_getDisplayName]] call fn_DebugAppend;
              }
              else
              {
                [[WEST, 'HQ'], format['Detected unit: %1 -- no WP!', [_type] call fn_getDisplayName]] call fn_sideChat; // debug
                ['AIGroupRespawn.sqf', format['Detected unit: %1 -- no WP!', [_type] call fn_getDisplayName]] call fn_DebugAppend;
              };
            };
            case "Gunner": {_AI moveInGunner _vehicle};
          };
        };
      } forEach ["Commander", "Driver", "Gunner"];
    }
    else
    {
      //player globalChat format['%1: Spawning unit: %2', _group, _type]; // debug
     
      _AI = _group createUnit[_type, getMarkerPos (ICE_RespawnAIGroups_Markers select 0), ICE_RespawnAIGroups_Markers, getMarkerSize (ICE_RespawnAIGroups_Markers select 0) select 0, "FORM"];
     
      if (count _pos == 0) then
      {
        _pos = position _AI;
       
        // reactivate old WP
        _WPs = waypoints _AI;
        if (count _WPs > 1) then
        {
          _dest = WaypointPosition (_WPs select 1);
          _AI move _dest;
          (group _AI) setCurrentWaypoint (_WPs select 1);
        };
       
        [leader _AI] execVM "Scripts\Debug\TrackingMarker.sqf";
       
        [[WEST, 'HQ'], format['Detected unit: %1', [_type] call fn_getDisplayName]] call fn_sideChat; // debug
        ['AIGroupRespawn.sqf', format['Detected unit: %1', [_type] call fn_getDisplayName]] call fn_DebugAppend;
      }
      else
      {
        _AI setPos _pos;
      };
     
      _AI setRank _rank;
      _AI setSkill _skill;
    };
    sleep 1;
  } forEach _unitDefs;
  //player setPos _pos; // debug
 
  // original (guard) waypoints will still exist and will become active again
  //player sideChat format['%1: Waypoints: %2 %3', _group, count waypoints _group, waypoints _group]; // debug
  //if (f_var_debugMode > 0) then {GLexec globalChat format["AI group respawned at %1", [_pos] call fn_GridRefCoords]};

  // update status (of original array)
  _groupDef set[enum_groupDefs_status, enum_groupDefs_statusAlive];
};
//-----------------------------------------------------------------------------
// Continuously respawn all selected AI groups after each entire group is killed.
private["_group"];

while {true} do
{
  if (_groupDefsCount != count ICE_RespawnAIGroups) then
  {
    call _fn_CreateGroupDefs;
  };

  sleep AIGroupRespawn_monitor;

  {
    _group = _x select enum_groupDefs_group;
   
    /*
    player groupChat format['%1 %7 status=%5, count=(%2, %3) - %4 %6',
      time,
      count units _group,
      {alive _x} count units _group,
      player distance leader _group,
      _x select enum_groupDefs_status,
      units _group,
      _group]; // debug
    */

    if ({alive _x} count units _group == 0) then
    {
      if (_x select enum_groupDefs_status == enum_groupDefs_statusAlive) then
      {
        //player sideChat format['%1: All group members are dead', _group]; // debug

        // update status outside of spawn - to prevent spawn being called more than once
        _x set[enum_groupDefs_status, enum_groupDefs_statusRespawn];
       
        // spawn this block but don't wait for it to finish due to it's sleep delay and to allow processing of other groups
        // passes _x by reference for modification
        [_x] spawn _fn_RespawnGroup;
      };
    };
  } forEach _groupDefs;
};
//-----------------------------------------------------------------------------

Both scripts are to get what i want but i cant seem to figure it out

Offline tcp

  • Members
  • *
    • Violator Gaming
Re: need help spawning in certain conditions
« Reply #3 on: 16 Oct 2009, 02:00:53 »
My mistake. If you extract that pbo, the AI respawn scripts are compatible with both versions of ArmA. It takes the information from the units you place in the editor. Instructions are included.

Here's the rundown for the part that checks whether a unit/building is alive as a condition for respawn.

_dead=true; //reset
{if (alive _x) then {_dead=false}} forEach _fob; //_fob is array of units/buildings that have to be alive
if(_dead) exitWith{}; //if none are alive exit current scope (loop or script)

continue with creation

Offline Supergrunt

  • Members
  • *
Re: need help spawning in certain conditions
« Reply #4 on: 18 Oct 2009, 20:11:20 »
tnx will try to sort it out  :)

 
« Last Edit: 08 Nov 2009, 12:40:15 by Supergrunt »

Offline Supergrunt

  • Members
  • *
Re: need help spawning in certain conditions
« Reply #5 on: 08 Nov 2009, 12:40:58 »
1001 tries later and still no luck  so any help is very very very welcome by now


Offline Supergrunt

  • Members
  • *
Re: need help spawning in certain conditions
« Reply #6 on: 24 Nov 2009, 19:41:18 »
118 views and no reply's ?  it sure looks like the ARMA community has shifted to ARMA 2 leaving us poor ARMA players out to dry  :P