Jump to content
Sign in to follow this  
icfhoop

If shot down...

Recommended Posts

Hello all,

Before going into my question , i searched the forums but found nothing about this topic to the best of my knowledge.

Anyways, I was wondering, is it possible to have an enemy group spawned say 200 meters away from a player if their helicopter is shot down anywhere. To get an understanding, the choppers are all player controlled, but if one gets shot down, could wherever it touches down at have enemies spawned near it and attack? And I mean anywhere on the map.

Thanks for the help.

Share this post


Link to post
Share on other sites

Well the algorithm for solving this could be something like this:

Wait until: the helicopter is below certain height on map and it is damaged (there is probably some way to check if the rotors are destroyed).

Keep picking a random dir, and using math calculate a point a certain distance (200 for example) away from the "crash". Check this point and a couple of points near to check if the surface is water. If it is then try again. Else you have a position

Spawn a group here and give them MOVE waypoint towards crash site.

Share this post


Link to post
Share on other sites

Thanks for the speedy reply, but I am a noob when it comes to actually putting scripts together so if I could get some help as to that area, I would be grateful. :) But again thanks for the fast reply.

Share this post


Link to post
Share on other sites

I've been unable to find out how you check if the rotor is damaged. Another way would be to artificially damage it when the chopper is hit. For now something like this would do in a trigger:

//Chopper must be damaged more than 20% (1-0.2=0.8) and must lower than 3m in the terrain. (Might not work on steep slopes :S).

Condition: damage the_chopper < 0.8 && getPosATL the_chopper select 2 < 3

On act: 0 = [] execVM "hunterGroup.sqf";

Then hunterGroup.sqf is something like this (saved in mission folder (not the one with the pbo's)):

if (!isServer) exitWith {} //Server only

_foundPosition = false; //Have not found position yet
_retries = 10; //Max attempts
_crashPos = getPosATL the_chopper; //Where the chopper crashed
_spawnPos = []; //Not set yet

while {!_foundPosition && _retries > 0} do {
 //Pick random direction
 _dir = random 360;
 _dist = 300;

  //Find position _dist way in _dir from crash site.
 _newPos = +_crashPos;
 _newPos set [0, (_newPos select 0) + (sin _dir) * _dist];
 _newPos set [1, (_newPos select 0) + (cos _dir) * _dist];
  //Must not be water
  if (!surfaceIsWater _newPos) then {
     _foundPosition = true;
     _spawnPos = +_newPos;
  } else {
     _retries = _retries - 1
  };
};

if (_foundPosition) then {
 _newGroup = [something, Something, Something, Something] call BIS_fnc_spawnGroup;
 _wp = _newGroup addWaypoint [_spawnPos, 0];
 _wp setWaypointType = "MOVE";
 _newGroup setBehaviour "YELLOW";
};

This is completely written from memory and some places might be incomplete, eg. the spawnGroup call from above which is a function I haven't really used so someone else might help you with that.

Share this post


Link to post
Share on other sites

Nice work MuzzelFlash, I started doing it myself but you beat me to it.

There were a couple of minor typos.

name a chopper heli

To call the script I place this code it in a triggers conditon

!canmove heli and (getposATL heli select 2) <=5

and in the on act

nul=[heli] execvm "Hunters.sqf";

code with errors don't use..

Original code but had errors don't use.

//nul=[heli] execvm "Hunters.sqf";

if (!isServer) exitWith {}; //Server only
_air = _this select 0;
_foundPosition = false; //Have not found position yet
_retries = 10; //Max attempts
_crashPos = getPosATL _air; //Where the chopper crashed
_spawnPos = []; //Not set yet

while {!_foundPosition && _retries > 0} do {
 //Pick random direction
 _dir = random 360;
 _dist = 300;

  //Find position _dist way in _dir from crash site.
 _newPos = +_crashPos;
 _newPos set [0, (_newPos select 0) + (sin _dir) * _dist];
 _newPos set [1, (_newPos select 0) + (cos _dir) * _dist];
  //Must not be water
  if (!surfaceIsWater _newPos) then {
     _foundPosition = true;
     _spawnPos = +_newPos;
  } else {
     _retries = _retries - 1;
  };
};

if (_foundPosition) then {
 _newGroup = [_spawnPos, west, ["CDF_Soldier_TL", "CDF_Soldier", "CDF_Soldier_Medic", "CDF_Soldier_GL", "CDF_Soldier_AR"],[], ["SERGEANT", "PRIVATE", "PRIVATE", "PRIVATE", "PRIVATE"],[0.3,0.1,0.1,0.1,0.1],[],[],round (random 360)] call BIS_fnc_spawnGroup; 
//player setpos _spawnpos;// testing use only
 _wp = _newgroup1 addWaypoint [_spawnPos, 0];
 _wp setWaypointType   "MOVE";
 _newGroup setBehaviour "YELLOW";
};

The newgroup don't move to the chopper they just stand around, any ideas?

Corrected code and should work..

Working code this is the corrected version and can also be seen in post 10

//nul=[heli] execvm "Hunters.sqf";

private ["_foundPosition","_spawnPos","_retries","_dir","_dist","_newPos","_newGroup","_wp","_air","_crashPos"];

if (!isServer) exitWith {}; //Server only
_air = _this select 0;
_foundPosition = false; //Have not found position yet
_retries = 10; //Max attempts
_crashPos = getPosATL _air; //Where the chopper crashed
_spawnPos = []; //Not set yet

while {!_foundPosition && _retries > 0} do {
 //Pick random direction
 _dir = random 360;
 _dist = 300;

  //Find position _dist way in _dir from crash site.
 _newPos = +_crashPos;
 _newPos set [0, (_newPos select 0) + (sin _dir) * _dist];
 _newPos set [1, (_newPos select 0) + (cos _dir) * _dist];
  //Must not be water
  if (!surfaceIsWater _newPos) then {
     _foundPosition = true;
     _spawnPos = +_newPos;
  } else {
     _retries = _retries - 1;
  };
};

if (_foundPosition) then {
 _newGroup = [_spawnPos, west, ["CDF_Soldier_TL", "CDF_Soldier", "CDF_Soldier_Medic", "CDF_Soldier_GL", "CDF_Soldier_AR"],[], ["SERGEANT", "PRIVATE", "PRIVATE", "PRIVATE", "PRIVATE"],[0.3,0.1,0.1,0.1,0.1],[],[],round (random 360)] call BIS_fnc_spawnGroup; 
 _wp = _newGroup addWaypoint [getPos _air, 0];
 _wp setWaypointType   "MOVE";
 _newGroup setBehaviour "AWARE";
};

.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

You give the waypoint to some group in a local variable _newgroup1 not _newGroup.

Edit: Just check setBehaviour it is not the one with the color names. Set it to "AWARE" instead or something.

Fixed version of fixed version ( :) ). Here:

//nul=[heli] execvm "Hunters.sqf";

private ["_foundPosition","_spawnPos","_retries","_dir","_dist","_newPos","_newGroup","_wp","_air","_crashPos"];

if (!isServer) exitWith {}; //Server only
_air = _this select 0;
_foundPosition = false; //Have not found position yet
_retries = 10; //Max attempts
_crashPos = getPosATL _air; //Where the chopper crashed
_spawnPos = []; //Not set yet

while {!_foundPosition && _retries > 0} do {
 //Pick random direction
 _dir = random 360;
 _dist = 300;

  //Find position _dist way in _dir from crash site.
 _newPos = +_crashPos;
 _newPos set [0, (_newPos select 0) + (sin _dir) * _dist];
 _newPos set [1, (_newPos select 0) + (cos _dir) * _dist];
  //Must not be water
  if (!surfaceIsWater _newPos) then {
     _foundPosition = true;
     _spawnPos = +_newPos;
  } else {
     _retries = _retries - 1;
  };
};

if (_foundPosition) then {
 _newGroup = [_spawnPos, west, ["CDF_Soldier_TL", "CDF_Soldier", "CDF_Soldier_Medic", "CDF_Soldier_GL", "CDF_Soldier_AR"],[], ["SERGEANT", "PRIVATE", "PRIVATE", "PRIVATE", "PRIVATE"],[0.3,0.1,0.1,0.1,0.1],[],[],round (random 360)] call BIS_fnc_spawnGroup; 
//player setpos _spawnpos; testing use only
 _wp = _newGroup addWaypoint [_spawnPos, 0];
 _wp setWaypointType   "MOVE";
 _newGroup setBehaviour "AWARE";
};

Edited by Muzzleflash

Share this post


Link to post
Share on other sites

Sorry that came about as I was trying other things it's now back to the original but they still don't move.

if (_foundPosition) then {
 _newGroup = [_spawnPos, west, ["CDF_Soldier_TL", "CDF_Soldier", "CDF_Soldier_Medic", "CDF_Soldier_GL", "CDF_Soldier_AR"],[], ["SERGEANT", "PRIVATE", "PRIVATE", "PRIVATE", "PRIVATE"],[0.3,0.1,0.1,0.1,0.1],[],[],round (random 360)] call BIS_fnc_spawnGroup; 
// player setpos _spawnpos;// testing use only
 _wp = _newGroup addWaypoint [_spawnPos, 0];
 _wp setWaypointType   "MOVE";
 _newGroup setBehaviour "AWARE";
};

Share this post


Link to post
Share on other sites

I'm currently unable to test myself. What is does the following give:

hint str(_spawnPos); Is it valid?

hint str(_newGroup);

hint str(_wp);

Perhaps some syntax is incorrect after the spawning that result in the move waypoint not being added correctly. Can you try a delay 2s after the spawning?

Regarding the skill range (the decimal numbers), think that the function only uses the first two. Min and max.

Share this post


Link to post
Share on other sites
I'm currently unable to test myself. What is does the following give:

hint str(_spawnPos); Is it valid?

hint str(_newGroup);

hint str(_wp);

Perhaps some syntax is incorrect after the spawning that result in the move waypoint not being added correctly. Can you try a delay 2s after the spawning?

Regarding the skill range (the decimal numbers), think that the function only uses the first two. Min and max.

I removed the if statement incase that was causing a locality issue but still makes no difference.

_spawnPos works and give the x,y,z

_newGroup B 1-1-C

_wp [b 1-1-C,1]

I've also tried naming the group in the same way as spawning a vehicle using

  newGroup =  newGroup select 0;

_newGroup = _newGroup select 0;

but both cause error in addwaypoint.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

(Kicking head in wall)

Omg the solution is so simple and so stupid of me to write it wrong.

We've been telling them to move to their own spawn location!!

They should go to getPos _air instead of _spawnPos

Btw. I got correct hint on all, both the group, the waypoint and the position.

This should work correctly:

//nul=[heli] execvm "Hunters.sqf";

private ["_foundPosition","_spawnPos","_retries","_dir","_dist","_newPos","_newGroup","_wp","_air","_crashPos"];

if (!isServer) exitWith {}; //Server only
_air = _this select 0;
_foundPosition = false; //Have not found position yet
_retries = 10; //Max attempts
_crashPos = getPosATL _air; //Where the chopper crashed
_spawnPos = []; //Not set yet

while {!_foundPosition && _retries > 0} do {
 //Pick random direction
 _dir = random 360;
 _dist = 300;

  //Find position _dist way in _dir from crash site.
 _newPos = +_crashPos;
 _newPos set [0, (_newPos select 0) + (sin _dir) * _dist];
 _newPos set [1, (_newPos select 0) + (cos _dir) * _dist];
  //Must not be water
  if (!surfaceIsWater _newPos) then {
     _foundPosition = true;
     _spawnPos = +_newPos;
  } else {
     _retries = _retries - 1;
  };
};

if (_foundPosition) then {
 _newGroup = [_spawnPos, west, ["CDF_Soldier_TL", "CDF_Soldier", "CDF_Soldier_Medic", "CDF_Soldier_GL", "CDF_Soldier_AR"],[], ["SERGEANT", "PRIVATE", "PRIVATE", "PRIVATE", "PRIVATE"],[0.3,0.1,0.1,0.1,0.1],[],[],round (random 360)] call BIS_fnc_spawnGroup; 
 [b]_wp = _newGroup addWaypoint [getPos _air, 0];[/b]
 _wp setWaypointType   "MOVE";
 _newGroup setBehaviour "AWARE";
};

Edited by Muzzleflash

Share this post


Link to post
Share on other sites

LOL it the obvious stuff that's the hardest to spot.

Cheers working now..

I did get the hints working in the end they failed because I forgot I'd placed them outside the if statement which kept them local.

.

Edited by F2k Sel

Share this post


Link to post
Share on other sites
Just a n. question. How it works ?

I've updated post 5 that should give you the info you need.

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  

×