Jump to content
Sign in to follow this  
craptakular

spawning a group with a trigger

Recommended Posts

I have been watching this video series to teach me how to spawn units and groups based on a trigger.

This works in the editor but in his videos he says this won't work for multiplayer? :confused:

I have the following script that I call via the trigger andf it works, but will it work in MP? IF not, where do I read to make it work?

//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: : Craptakular
//////////////////////////////////////////////////////////////////

//Groups can be found here: http://community.bistudio.com/wiki/Ambient_Combat_Manager_-_Group_types
//The script below spawns a single group and tells them to follow a single waypoint.

_TakGroup1 = [(getMarkerPos "spawnpoint1"), EAST, (ConfigFIle >> "CfgGroups" >> "EAST" >>"BIS_TK" >> "Infantry" >> "TK_InfantrySquad")] call BIS_fnc_spawnGroup;

_wp1 = _TakGroup1 addWaypoint [(getmarkerpos "wp1a"), 0];
_wp1 setwaypointtype "MOVE";
_wp1 setwaypointstatements ["True", ""];

_wp2 = _TakGroup1 addWaypoint [(getmarkerpos "wp1b"), 0];
_wp2 setwaypointtype "MOVE";
_wp2 setwaypointstatements ["True", ""];

_wp3 = _TakGroup1 addWaypoint [(getmarkerpos "wp1c"), 0];
_wp3 setwaypointtype "SAD";
_wp3 setwaypointstatements ["True", ""];

Secondly, is it possible to minimise the amount of code and have multiple groups use the same waypoints without duplicating 9 lines of code each time?

I have search the forum, I apologies if this question is so stupid but we all started somewhere :D

Share this post


Link to post
Share on other sites

Well at least your second question is easy to answer: yes, it is possible.

Using a finite array consisting of markernames will allow you to cycle through it with a forEach.

// Example
_markers = ["wp1a", "wp1b", "wp1c"]; // etc...
_waypoints = [];
_currWp = objNull;
_TakGroup1 = [(getMarkerPos "spawnpoint1"), EAST, (ConfigFIle >> "CfgGroups" >> "EAST" >>"BIS_TK" >> "Infantry" >> "TK_InfantrySquad")] call BIS_fnc_spawnGroup; 

{
   _currWp = _TakGroup1 addWaypoint [(getmarkerpos _x), 0];
   _currWp setwaypointtype "MOVE";
   _currWp setwaypointstatements ["True", ""]; 

   _waypoints set [count _waypoints, _currWp];
} forEach _markers;

After the loop is done, all your waypoints references are stored in the _waypoints-array (_wp1 = _waypoints select 0, _wp2 = _waypoints select 1, etc).

Okay the only problem I see here concerning MP is this script would be executed on all clients once the trigger gets activated, spawning several groups.

So you would want to limit this i.e. using a

if (isServer) then {execVM "spawnGroup.sqf";}

in the activation field of your trigger. But it should suffice to wrap the if-statement around the content of the act.-field you already have.

I didn't try it so I don't know if my hunches are correct, so you should test it with a MP mission :D

Share this post


Link to post
Share on other sites

After reading up a bit more I think this should be the right code for it to work in multiplayer:

//Groups can be found here: http://community.bistudio.com/wiki/Ambient_Combat_Manager_-_Group_types
//The script below spawns a single group and tells them to follow a single waypoint.

if (!isServer) exitwith {};

_TakGroup1 = [(getMarkerPos "spawnpoint1"), EAST, (ConfigFIle >> "CfgGroups" >> "EAST" >>"BIS_TK" >> "Infantry" >> "TK_InfantrySquad")] call BIS_fnc_spawnGroup;

_wp1 = _TakGroup1 addWaypoint [(getmarkerpos "wp1a"), 0];
_wp1 setwaypointtype "MOVE";
_wp1 setwaypointstatements ["True", ""];

_wp2 = _TakGroup1 addWaypoint [(getmarkerpos "wp1b"), 0];
_wp2 setwaypointtype "MOVE";
_wp2 setwaypointstatements ["True", ""];

_wp3 = _TakGroup1 addWaypoint [(getmarkerpos "wp1c"), 0];
_wp3 setwaypointtype "SAD";
_wp3 setwaypointstatements ["True", ""];

Could someone confirm this is now correct?

Share this post


Link to post
Share on other sites

Look at the lower end of my post, as we are concordant with using the if-statement, it should be alright in MP :)

Share this post


Link to post
Share on other sites
Look at the lower end of my post, as we are concordant with using the if-statement, it should be alright in MP :)

Thanks matey, I didn't see you post before! doh. I will test it, forgot about Foreach and loops :p

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  

×