Jump to content
Sign in to follow this  
Concept

Trigger to detect units name?

Recommended Posts

Hi all,

This is my first post here! im new to arma 2 and am diving straight in at the deep end :yay:

I have a marker that has a trigger on it. An opfor group will move towards the marker and then the trigger will set them a new marker (again with a new trigger on it) thus randomising patrols.

I have a script that will randomise the marker that is choosen (i hope) but the main thing im having trouble with is the group name being picked up by the trigger to be executed in the script.

nul = [group this, "mark_waypoint1"] execVM "islandPatrol.sqf";

I have tried numerous things to get the trigger to pick up the activating units name but i am starting to pull out my hair! Can somone please help me!?

The script works fine when i try

nul = [patrol1, "mark_waypoint1"] execVM "islandPatrol.sqf";

(patrol1 being the group name) but i dont want all units that happen to cross the trigger to get a new waypoint!

Thanks for anyone still reading this and sorry for being NUB :(

Share this post


Link to post
Share on other sites

you could try this

nul = [(thislist select 0), "mark_waypoint1"] execVM "islandPatrol.sqf";

that usually gives the name of the unit activating the trigger.

If you place this in a trigger it will display the name of the unit if it has one.

hint format ["who %1",(thislist select 0)]

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Thanks for your reply. Yes that brings back the unit name. Now i need to get the group of that unit, im sure i have seen that command somewhere! :)

Thanks again

Share this post


Link to post
Share on other sites
group :)

nul = [group (thislist select 0), "mark_waypoint1"] execVM "islandPatrol.sqf";

Yea thats what i ended up with! Thanks very much for your help guys. Now to go get the islandPatrol to check if the name of the group contains patrol and im rolling!!! :yay:

---------- Post added at 07:22 PM ---------- Previous post was at 06:51 PM ----------

ok. confused.com!

I name a group patrol1 and patrol2 in the init of the SL of the group. My thinking was to have a if statment that was in the islandPatrol.sqf to check if patrol was in the name of the unit. I want the

nul = [group (thislist select 0), "mark_waypoint1"] execVM "islandPatrol.sqf";

to give me the name of the unit but its giving me 0 1-1-A and 0 1-1-B. Any ideas on a get around for this?

Share this post


Link to post
Share on other sites

try just getting the group leader

nul = [leader (thislist select 0), "mark_waypoint1"] execVM "islandPatrol.sqf";

If you name the SL bob and any of bob's boys enter the trigger it will fire off the script and pass bob's name to the script.

Edited by Jonescrusher

Share this post


Link to post
Share on other sites

I'd be hesitant to try to use the group name itself. Rather treat them as abstract things, i.e. it's a "group object" which when printed out will have a particular name, but don't pretend it's a string of some kind.

If it's only one group you want it to activate on, then group the leader with the trigger, and set it to "any group member present" and be done with it. The game can do that itself.

If you want it to handle multiple groups, I'd suggest:

  • name each group in the editor (i.e. in one of the member's init fields, put mygroupname = group this)
  • in init.sqf, make an array with all the groups you want it to consider, e.g.
    patrol_group_list = [patrol1, patrol2, patrol3];


  • in your activation script, if (groupthatactivatedit in patrol_group_list) ...

Share this post


Link to post
Share on other sites

groupthis = group (thislist select 0); if (groupthis in patrolGroupList) then { nul = [groupthis, "mark_waypoint1"] execVM "islandPatrol.sqf"; };

This is what is working in conjunction with the patrolGroupList.

Thanks very much!

Share this post


Link to post
Share on other sites

Ok, now i have another problem. I have triggers in which other units that are not patroling can be in. If there is more than one group in the trigger then the first group will get a new waypoint as normal but the others will just sit there.

Is there a way to get the trigger to start again after the first unit has moved away? EG. Re-check for the requirements?

If anyone can help xfire me: jlid or post here :)

Thanks

Share this post


Link to post
Share on other sites

You might be better off using setWaypointScript instead of triggers.

Share this post


Link to post
Share on other sites

How would that work?

Would the unit be given waypoints randomly or a mass of them at the start of the mission

Share this post


Link to post
Share on other sites

It would be better to do it that way, I do have a semi random patrol script that someone else started a while back.

to make it work place this in each group leader init

nul=[this] execVM"rndway.sqf"

Place 6 markers around the map wp1 - wp6

_unit = _this select 0;
_group = group leader _unit;
//_posnum = round (random 2);
_posnum = floor (random 3); 

hint format["%1 ",_posnum];

sleep 2;
if (_posnum == 0) then 
{
_wp1 = _group addWaypoint [GetMarkerPos "WP1", 0];
[_group, 1] setWaypointType "MOVE";
//wp1 SetWaypointTimeout[60, 120, 180];

_wp2 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP3",0];
[_group, 3] SetWaypointType"MOVE";

_wp4 = _group AddWaypoint[GetMarkerPos "WP4", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP5", 0];
[_group, 5] SetWaypointType"MOVE";

_wp6 = _group AddWaypoint[GetMarkerPos "WP6", 0];
[_group, 6] SetWaypointType"MOVE";


}
else { 	

if (_posnum == 1) then {

_wp1 = _group addWaypoint [GetMarkerPos "WP3", 0];
[_group, 1] setWaypointType "MOVE";

_wp2 = _group AddWaypoint[GetMarkerPos "WP1", 0];
[_group, 2] SetWaypointType"MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP3",0];
[_group, 3] SetWaypointType"MOVE";

_wp4 = _group AddWaypoint[GetMarkerPos "WP4", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 5] SetWaypointType"MOVE";

_wp6 = _group AddWaypoint[GetMarkerPos "WP5", 0];
[_group, 6] SetWaypointType"MOVE";
}

else {

if (_posnum == 2) then {

    _wp1 = _group AddWaypoint[GetMarkerPos "WP6", 0];
[_group, 1] SetWaypointType"MOVE";

_wp2 = _group addWaypoint [GetMarkerPos "WP1", 0];
[_group, 2] setWaypointType "MOVE";

_wp3 = _group AddWaypoint[GetMarkerPos "WP4",0];
[_group, 3] SetWaypointType"MOVE";

_wp4 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 4] SetWaypointType"MOVE";

_wp5 = _group AddWaypoint[GetMarkerPos "WP5", 0];
[_group, 5] SetWaypointType"MOVE";

_wp6 = _group AddWaypoint[GetMarkerPos "WP2", 0];
[_group, 6] SetWaypointType"MOVE";
}
}
};

You cam easily add more waypoints and markers or new patraols

Edited by F2k Sel

Share this post


Link to post
Share on other sites

_posnum = round (random 2);

It would be better to use floor (random 3) instead, assuming random returns numbers which are overall evenly distributed between 0 and not-quite-2 (which is what a good random number algorithm ought to do).

With round random 2:

  • To get a 0, the number must be less than 0.5 - which means about one quarter of the random numbers will be rounded to 0.
  • To get a 1, the number must be between 0.5 and 1.5 - about half of the numbers returned by random 2.
  • To get a 2, the number must be above 1.5 - again, a quarter of the possible results.

So it will favour patrol path #1 much more than #0 or #2.

If you use floor random 3 instead, then:

  • 0.0000 - 0.9999 will result in 0.
  • 1.0000 - 1.9999 will result in 1.
  • 2.0000 - 2.9999 will result in 2.

That gives every number an equal chance of being selected.

(Note that random 3 returns a number between 0 inclusive and 3 not-inclusive, i.e. it will never return 3).

Share this post


Link to post
Share on other sites

Good spot I was just noticing myself that it wasn't as random as it should have been, Thanks.

Script changed to use floor.

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  

×