Jump to content
Sign in to follow this  
fernandolvferreira

Following Enemy's Spawn Point

Recommended Posts

Hello, everybody.

I'm new to A2 scripting so I've ended up pretty much above my head in this one. I'm trying to develop a mission for my squad where once the group is inside a determined area, takistani militia (basic AK-74 militia) starts to spawn some 250 meters away around the BLUFOR group and go for it... Here are my problems:

First: Determine the "WHILE LOOP" parameter for when the BLUFOR GROUP actively enters a predefined area (trigger or marker)

Second: Define the center area of the group (Three fireteams)

Third: Find the fire-team's group names

Fourth: define de enemy's spawn point randomic pattern around a 250 meter perimeter of the Group's center

After realizing I wouldn't be able to figure it out all by myself, I gave up of this elaborate idea and satisfied myself with a simpler thing, A timed spawn point that would spawn 1 enemy per minute until the UnitCount reaches 500 and then would assign them a waypoint straight to the Player position, but I still couldn't make it work.

Here is what I've done so far... Shamefully:

_unitCount = 0;

while {_unitCount < 500} do {

_unitCount = _unitCount + 1;

_PlayerPosSpawn = [getPos "lucchesi" select 0),(getPos "_Alpha" select 0)];

hint format ["%1 %2", _unitCount, _PlayerPosSpawn];

_groupRAND = CreateGroup EAST;

_REFRAND = _groupRAND createUnit ["TK_INS_Soldier_EP1", [(getMarkerPos "_PlayerPosSpawn" select 0),(getMarkerPos "_PlayerPosSpawn" select 1),0], [], 250, "CANCOLLIDE"];

_mgrand = _groupRAND addwaypoint [getMarkerPos "_PlayerPosSpawn",0 ];

_mgrand setWaypointType "MOVE" ;

_mgrand setWaypointCombatMode "RED";

_mgrand setWaypointBehaviour "AWARE";

_mgrand setWaypointSpeed "FULL";

sleep 60;

}

It itsn't working at all...

"lucchesi" is the player name.

I would be very grateful if you guys could help me with my first design , but I would still be happy if you could help me with my second option.

Thank you for the help!

Edited by fernandolvferreira

Share this post


Link to post
Share on other sites
_PlayerPosSpawn = [getPos lucchesi select 0,getPos lucchesi select 1];
_groupRAND = CreateGroup EAST;
_unitCount = 0;
while {_unitCount < 500} do {
_unitCount = _unitCount + 1;
hint format ["%1 %2", _unitCount, _PlayerPosSpawn];
_groupRAND createUnit ["TK_INS_Soldier_EP1", [_PlayerPosSpawn select 0,_PlayerPosSpawn select 1,0], [], 250, "CANCOLLIDE"];

sleep 60;
};
_mgrand = _groupRAND addwaypoint [_PlayerPosSpawn,0];
_mgrand setWaypointType "MOVE";
_mgrand setWaypointCombatMode "RED";
_mgrand setWaypointBehaviour "AWARE";
_mgrand setWaypointSpeed "FULL";

Share this post


Link to post
Share on other sites

Thank you very much, Schatten

I tried using your code and it finally got me the hint working, but strangely enough, I couldn't find any spawning enemies. I tried reducing the spawning radius as I thought they were spawning without any waypoints. Unfortunately it seems they're not being spawning. The hint is apparently working, giving me the spawn position, but no enemies though.

I took a look in the RPT file and this is what it says:

Array mat in bin\config.bin/CfgHeads/DefaultHead/Wounds/ not multiply of 3
[2.30758e+006,80626,0,"XEH: PreInit Started. v1.0.1.196. MISSINIT: missionName=TESTE_SPAWN, worldName=fallujah, isMultiplayer=false, isServer=true, isDedicated=false"]
[2.30758e+006,80626.7,0,"XEH: PreInit Finished. CACHE DISABLED? (Disable caching with cba_cache_disable.pbo): SLX_XEH_RECOMPILE=false, CBA_COMPILE_RECOMPILE=false, CBA_FUNC_RECOMPILE=false"]
Array mat in bin\config.bin/CfgHeads/DefaultHead/Wounds/ not multiply of 3
Error in expression <
};
_args = _args + _str;

};
_return = _JERR_ERR_U;
_call = _functionName + ",">
 Error position: <_JERR_ERR_U;
_call = _functionName + ",">
 Error Undefined variable in expression: _jerr_err_u
File x\jayarma2lib\addons\common\XEH_preinit.sqf, line 24
"JayArmA2Lib: ACTIVE"
[2.3076e+006,80627.3,0,"XEH: PostInit Started"]
[2.3076e+006,80627.4,0,"CBA_VERSIONING: cba=1.0.1.196, cba_a2=1.0.0.8, cba_oa=1.0.0.6, ace=1.14.0.597, acex=1.14.0.373, acex_ru=1.14.0.77, acex_usnavy=1.14.0.79, "]
[2.3076e+006,80627.6,0,"XEH: PostInit Finished. State: _isClient=true, _isJip=false, _isDedClient=false, _isServer=true, _isDedServer=false, _playerCheckDone=true, _sp=true, _startInitDone=true, _postInitDone=true, _mpRespawn=false, _machineType=1, _sessionId=41, _level=0, _timeOut=false, _game=1, BIS_functions=L 1-1-A:1, group=L 1-1-A, player=lucchesi, _playerType="ACE_USMC_Soldier_D", _playerGroup=B 1-1-A"]

Any idea of what may be causing it?

Thank you very much for the help!

P.S.: I've altered the code so the AddWaypoint would be inside the loop and the spawned units would be directed towards the player, this is how it is looking right now (is it right?):

_PlayerPosSpawn = [getPos lucchesi select 0,getPos lucchesi select 1];
_groupRAND = CreateGroup EAST;
_unitCount = 0;
while {_unitCount < 500} do {
_unitCount = _unitCount + 1;
hint format ["%1 %2", _unitCount, _PlayerPosSpawn];
_groupRAND createUnit ["TK_INS_Soldier_EP1", [_PlayerPosSpawn select 0,_PlayerPosSpawn select 1,0], [], 30, "CANCOLLIDE"];
_mgrand = _groupRAND addwaypoint [_PlayerPosSpawn,0];
_mgrand setWaypointType "MOVE";
_mgrand setWaypointCombatMode "RED";
_mgrand setWaypointBehaviour "AWARE";
_mgrand setWaypointSpeed "FULL";

sleep 60;
};

Share this post


Link to post
Share on other sites
The hint is apparently working, giving me the spawn position

What is position? [0,0,0]?

I took a look in the RPT file and this is what it says:

Array mat in bin\config.bin/CfgHeads/DefaultHead/Wounds/ not multiply of 3
[2.30758e+006,80626,0,"XEH: PreInit Started. v1.0.1.196. MISSINIT: missionName=TESTE_SPAWN, worldName=fallujah, isMultiplayer=false, isServer=true, isDedicated=false"]
[2.30758e+006,80626.7,0,"XEH: PreInit Finished. CACHE DISABLED? (Disable caching with cba_cache_disable.pbo): SLX_XEH_RECOMPILE=false, CBA_COMPILE_RECOMPILE=false, CBA_FUNC_RECOMPILE=false"]
Array mat in bin\config.bin/CfgHeads/DefaultHead/Wounds/ not multiply of 3
Error in expression <
};
_args = _args + _str;

};
_return = _JERR_ERR_U;
_call = _functionName + ",">
 Error position: <_JERR_ERR_U;
_call = _functionName + ",">
 Error Undefined variable in expression: _jerr_err_u
File x\jayarma2lib\addons\common\XEH_preinit.sqf, line 24
"JayArmA2Lib: ACTIVE"
[2.3076e+006,80627.3,0,"XEH: PostInit Started"]
[2.3076e+006,80627.4,0,"CBA_VERSIONING: cba=1.0.1.196, cba_a2=1.0.0.8, cba_oa=1.0.0.6, ace=1.14.0.597, acex=1.14.0.373, acex_ru=1.14.0.77, acex_usnavy=1.14.0.79, "]
[2.3076e+006,80627.6,0,"XEH: PostInit Finished. State: _isClient=true, _isJip=false, _isDedClient=false, _isServer=true, _isDedServer=false, _playerCheckDone=true, _sp=true, _startInitDone=true, _postInitDone=true, _mpRespawn=false, _machineType=1, _sessionId=41, _level=0, _timeOut=false, _game=1, BIS_functions=L 1-1-A:1, group=L 1-1-A, player=lucchesi, _playerType="ACE_USMC_Soldier_D", _playerGroup=B 1-1-A"]

Any idea of what may be causing it?

No idea. These errors are related to CBA not to your script.

I've altered the code so the AddWaypoint would be inside the loop and the spawned units would be directed towards the player, this is how it is looking right now (is it right?):

No. Waypoint should be added one time to group of units.

Before while-loop script creates group. Inside while-loop it creates units and adds them to group. And after while-loop script adds waypoint to group.

Share this post


Link to post
Share on other sites
What is position? [0,0,0]?

The position varies as the player moves, last pos was [3820.72,8168.51]

No idea. These errors are related to CBA not to your script.

Ok then...

No. Waypoint should be added one time to group of units.

Before while-loop script creates group. Inside while-loop it creates units and adds them to group. And after while-loop script adds waypoint to group.

The basic idea for this is script is to spawn enemy units that will pursue the player. If the player moves, the old and new enemy spawned enemy should be assigned the player's current location, basically I want to spawn little waves of enemies and direct them EXACTLY towards the player every time they spawn. I understood what you said about units, groups and waypoints, the problem is: if the _unitCount must come to 500 in order for the while-loop to stop and the addWaypoint is outside of the while-loop, it would create 500 units and ONLY THEN would assign them the waypoint, or am I tripping balls here?

After trying and error, I could get something to work, I came up with this code:

_PlayerPosSpawn = [getPos lucchesi select 0,getPos lucchesi select 1];
_GPREF1 = CreateGroup EAST;
_unitCount = 0;
_marker = createMarker ["Marker1",[_PlayerPosSpawn select 0,_PlayerPosSpawn select 1]];
_marker setMarkerType "DOT";


while {_unitCount < 500} do {
_unitCount = _unitCount + 1;
hint format ["%1 %2", _unitCount, _PlayerPosSpawn];
_marker setMarkerPos getpos lucchesi;
_GPREF1 createUnit ["TK_INS_Soldier_EP1", [(getMarkerPos "Marker1" select 0),(getMarkerPos "Marker1" select 1),0], [], 25, "CANCOLLIDE"];
sleep 60;
};

You'll notice about the createMarker. It is working perfectly, every 60 seconds it updates de markerPos accordingly to the player's position. I did this because two nights ago I came up with a script for a Quick Reaction Force that would spawn on a editor placed marker and run towards another one, so I figured "I know how to spawn units out of markers, so I gave it a try, but once again I failed miserably since the Enemies won't spawn, some minutes ago I noticed it could be occuring because I'm not assigning any names to the enemies as I did in my last script:

_GPREF1 = CreateGroup EAST;     
[b]_REF1_1[/b] = _GPREF1 createUnit ["TK_INS_Soldier_EP1", [(getMarkerPos "WPS1" select 0),(getMarkerPos "WPS1" select 1),0], [], 0, "CANCOLLIDE"];
[b]_REF1_2[/b] = _GPREF1 createUnit ["TK_INS_Soldier_AR_EP1", [(getMarkerPos "WPS1" select 0),(getMarkerPos "WPS1" select 1),0], [], 20, "CANCOLLIDE"];
[b]_REF1_3[/b] = _GPREF1 createUnit ["TK_INS_Soldier_EP1", [(getMarkerPos "WPS1" select 0),(getMarkerPos "WPS1" select 1),0], [], 20, "CANCOLLIDE"];
[b]_REF1_4[/b] = _GPREF1 createUnit ["TK_INS_Soldier_EP1", [(getMarkerPos "WPS1" select 0),(getMarkerPos "WPS1" select 1),0], [], 20, "CANCOLLIDE"];
_mg1 = _GPREF1 addWaypoint [getMarkerPos "WPE1",0 ]; 
_mg1 setWaypointType "MOVE" ;  
_mg1 setWaypointCombatMode "RED";
_mg1 setWaypointBehaviour "AWARE";
_mg1 setWaypointSpeed "FULL";

My first reaction upon this observation was to imegine/hope the engine would name the spawned units automatically, but as they failed to spawn, I began to think I would have to name them, the problem is: If I name them as I did in the earlier script, the second spawned unit would have the same name as the first name and a shit storm would ensue.

I was thinking, maybe if I could name them in a variable form as {SPAWNEDENEMY + _unitcount} so the first one would be "SPAWNEDENEMY1", then "SPAWNEDENEMY2" and so on, but I don't have the knowledge to develop such command, such knowledge would be very appreciated for I would use it in the group's name as well, mainly because I don't want this spawned unit to act as a group, I'd rather them to act as lone units.

The mission I'm working on is a rescue operation inside enemy territory in Fallujah, as soon as the BLUFOR reached the objective it would activate this script and it would swarm them with enemies as if they were hunting BLUFOR down, I don't want a whole group to attack them, I only need them to give some "encouragement" for BLUFOR to keep moving and GTFO ASAP.

Thank you very much for your time and your helpful ideas!

Share this post


Link to post
Share on other sites

Thank you very much for your help, Schatten. I was able to make it work.

This is how I did it in case anyone need it in the future:

_PlayerPosSpawn = [getPos lucchesi select 0,getPos lucchesi select 1];

_GPREF1 = CreateGroup EAST;
_GPREF1 createUnit ["TK_INS_Soldier_EP1", [(getMarkerPos _marker select 0),(getMarkerPos _marker select 1),0], [], 200, "CANCOLLIDE"];

_unitCount = 0;

_marker = createMarker ["Marker1",[_PlayerPosSpawn select 0,_PlayerPosSpawn select 1]];
_marker setMarkerType "DOT";

_SideHQ = createCenter east;

_mg1 = _GPREF1 addWaypoint [getMarkerPos _marker,0 ]; 
_mg1 setWaypointType "MOVE" ;  
_mg1 setWaypointCombatMode "RED";
_mg1 setWaypointBehaviour "AWARE";
_mg1 setWaypointSpeed "FULL";
_mg1 setWaypointPosition [getMarkerPos _marker,0 ];


while {_unitCount < 500} do {

_mg1 setWaypointPosition [getMarkerPos _marker,0 ];

_unitCount = _unitCount + 1;
hint format ["%1 %2", _unitCount, _PlayerPosSpawn];
_marker setMarkerPos getpos lucchesi;
_GPREF1 createUnit ["TK_INS_Soldier_EP1", [(getMarkerPos _marker select 0),(getMarkerPos _marker select 1),0], [], 200, "CANCOLLIDE"];




sleep 60;
};

Notes: One thing I realized was that I ABSOLUTELY NEEDED the waypoint's position to be updated whenever a new enemy spawned, but the already spawned ones also needed to get this information, so I spawned an enemy BEFORE the loop, so the group could be considered "ACTIVE". I also created the waypoint for it before the loop, so the only thing I needed to do about it in the loop was to reset it's position. I basically did the same thing with the _marker.

One thing I read about in the forum was that the enemies wouldn't spawn if there wasn't a OPFOR CENTER created, I tried to create it in the script, but it apparently didn't work, and even if it did, apparently the spawned enemies won't engage you if you don't create at least one OPFOR via the editor, so I kept the OPFOR CENTER creation via script, but also placed an opfor way isolated in the map with a 0% probability.

The waypoint was fully configurated before the loop, since I didn't want have to delete and recreate it in the loop every time, also because it would also interfere with FPS problems.

The while-loop was kept pretty clean:

If _enemycount is < than 500:

UPDATE THE WAYPOINT POSITION (PLAYER POSITION)

ADD 1 to the _playercount

UPDATE THE MARKER POSITION (PLAYER POSITION)

SPAWN ENEMY (200 meters radius)

WAIT 60 seconds and go again.

Thank you!

---------- Post added at 22:56 ---------- Previous post was at 22:08 ----------

Schatten, after I finnished what I thought to be the hardest part of my mission, I came face to face with your version of function to detect whether is object within marker and now I realized how much of a brain dead I am...

(http://forums.bistudio.com/showthread.php?185780-Detects-whether-is-position-within-marker-area&p=2871652&viewfull=1#post2871652)

Could you please enlight me of how could I apply it in my mission, lets say I have a marker called MRK_HEAT. I want my script to be activated whenever a BLUFOR entered within MRK_HEAT's area, but I also wanted it to be disabled once the area was cleared of BLUFOR, how would I do it?

Share this post


Link to post
Share on other sites
Could you please enlight me of how could I apply it in my mission, lets say I have a marker called MRK_HEAT. I want my script to be activated whenever a BLUFOR entered within MRK_HEAT's area, but I also wanted it to be disabled once the area was cleared of BLUFOR, how would I do it?

I think that it is better to use trigger:

_trigger = createTrigger ["EmptyDetector", _markerPosition];

_trigger setTriggerArea [_markerSizeA, _markerSizeB, 0, false];
_trigger setTriggerActivation ["WEST", "PRESENT", true];
_trigger setTriggerStatements [
"this",
"scriptHandler = execVM 'scipt.sqf'",
"terminate scriptHandler"
];

Share this post


Link to post
Share on other sites
I think that it is better to use trigger:

_trigger = createTrigger ["EmptyDetector", _markerPosition];

_trigger setTriggerArea [_markerSizeA, _markerSizeB, 0, false];
_trigger setTriggerActivation ["WEST", "PRESENT", true];
_trigger setTriggerStatements [
"this",
"scriptHandler = execVM 'scipt.sqf'",
"terminate scriptHandler"
];

Would that be it?

_triggerScript = createTrigger ["EmptyDetector", GetMarkerPos MRK_HEAT];

_triggerScript setTriggerArea [450, 450, 0, false];
_triggerScript setTriggerActivation ["WEST", "PRESENT", true];
_triggerScript setTriggerStatements [
"this",
"scriptHandler = execVM 'reinforcements.sqf'",
"terminate scriptHandler"
];

Thanks!

Share this post


Link to post
Share on other sites
Would that be it?

Yes. Seems, it should work.

Share this post


Link to post
Share on other sites

Also for the future you should use -showerrors parameter in Arma startup so you can catch the error as soon as it happens. Most at least. Also, hints are your friend when testing. Return your variables often. They may not be what you think they should be. Good luck with the mission.

Share this post


Link to post
Share on other sites
Also for the future you should use -showerrors parameter in Arma startup ...

As far as I know, it's -ShowScriptErrors - just small correction. :) However, good luck with the mission!

Share this post


Link to post
Share on other sites
Yes. Seems, it should work.

Unfortunately I ran into a series of problems, first one being the failure for the script to create the trigger, it simply didn't create it, so I tried creating two triggers manually through the editor, one for activation and the other for deactivation, both being "ONCE" activation type, since everytime EACH unit walks into the trigger it generates new enemies, so if 8 players walked into it, it would turn the mission into a blood bath. I coudn't link the trigger to the group, because I have three different groups in this mission and any of them must be able to activate the trigger.

---------- Post added at 20:00 ---------- Previous post was at 19:56 ----------

Also for the future you should use -showerrors parameter in Arma startup so you can catch the error as soon as it happens. Most at least. Also, hints are your friend when testing. Return your variables often. They may not be what you think they should be. Good luck with the mission.

Thanks, I was using everything I could to "debug" errors, you can see in the final script I set the marker to DOT:

_marker = createMarker ["Marker1",[_PlayerPosSpawn select 0,_PlayerPosSpawn select 1]];
[b]_marker setMarkerType "DOT";[/b]

I did it because I needed to know if it was actually marking the group's leader position and if it was being updated. The hints about leader's pos and _unitcount helped me alot too, I tried setting everything visible since I'm not very familiar with .RPT files and scripting. I'll keep it in mind for the future. Thanks for the tips!

---------- Post added at 20:01 ---------- Previous post was at 20:00 ----------

LUKI;2969192']As far as I know' date=' it's -ShowScriptErrors - just small correction. :) However, good luck with the mission!

Thanks! I'll try it out. How would it present me the errors?

Share this post


Link to post
Share on other sites
Thanks! I'll try it out. How would it present me the errors?

If you'll have somewhere in the script mistake, black rectangle inform you on you screen - like this. :)

Cheers!

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  

×