Jump to content
egbert

Add WP to randomly spawned unit.

Recommended Posts

Hi there !

 

I'm trying to add some WP to a unit spawned in an array of three positions randomly picked.

 

So basically, what I would like to do is to add a set of waypoints to each of the 3 positions where my unit can spawn. When the unit spawn to one of these 3 pos, a set of waypoints spawns with my unit, so if a shot is fired near my unit, it triggers the activation of the WP's.

 

I use this code for the random position :

if (isServer) then { 
 
 _positions = [
        [10915.8,7847.88,0.279678],
        [11270.8,7876.25,0.573982],
        [10946,9523,0.581001]
    ];

    _pos = selectRandom _positions;

    jose setPosATL _pos;
};

Anyone got a clue to make it work ?

 

Thanks in advance !

Share this post


Link to post
Share on other sites

Thanks MKD3-FHI, this code is indeed interesting for a patrol. But I don't want my spawned unit to patrol, I would like him to follow a specified path to vehicule if there is a threat aroud him, and if not, he stays where he is (I plan to add a FiredNear eventhandler to this unit to trigger the activation of these waypoints I desperatly try to add).

 

The thing is, and this is where I'm stuck, this path won't be the same if my unit spawns in position 1, or position 2, or 3. I guess I have to name the 3 possible positions my unit can spawn, and then use a kind of case condition to link these spawn positions with the sets of waypoints.

Something like :

 

case my unit spawn to "pos_1" then your waypoints are : marker_1.1, marker_1.2 etc...

case my unit spawn to "pos_2" then your waypoints are : marker_2.1, marker_2.2 etc...

 

And finally, if you hear shot fire, then you flee using these waypoints.

 

Something like that.

 

But thanks anyway mate, it's nice of you, any help is most welcome !

Share this post


Link to post
Share on other sites

There are many ways to achieve this behaviour, you could work with a `switch` statement (see the biki if not familiar). Here's one method assuming that these are predefined waypoint positions: you just need an array of waypoint position arrays which corresponds with the spawn position array. Like so:
 

if (isServer) then { 
 
    _positions = [
        [10915.8,7847.88,0.279678],
        [11270.8,7876.25,0.573982],
        [10946,9523,0.581001]
    ];

    _waypoints = [
        [[x,y,z], [x,y,z], [x,y,z], [x,y,z], [x,y,z]],
        [[x,y,z], [x,y,z], [x,y,z], [x,y,z], [x,y,z]],
        [[x,y,z], [x,y,z], [x,y,z], [x,y,z], [x,y,z]]
    ];
 
    _i = floor(random(count _positions));
 
    jose setPosATL (positions select _i);

    {(group jose) addWaypoint [_x,0] } forEach (_waypoints select _i);
};

You'll still need to set up the trigger logic to keep the unit in place until you want them to follow the waypoints.

An alternative would be to just use a single array of nested arrays that contain all of the data associated with each spawn (so rather than two separate arrays it'd be structured like: [[spawn1,waypoints1], [spawn2,waypoints2], ...]

Share this post


Link to post
Share on other sites

Nice ! Thanks a lot Silent !

 

So, with your piece of code, I wonder if the waypoints will be chosen randomly too ? In that case, maybe the alternative way that you mention, keeping the waypoints in a nested array with the positions will fits me better !

 

Thank you verymuch anyway, I'll test it asap !

Share this post


Link to post
Share on other sites

With the exact code above you'll notice I'm selecting an index and saving it to a variable `_i`, this is so that the corresponding value is taken from both arrays. However a nested array will produce the same results  :)

Share this post


Link to post
Share on other sites

So nice, it works perfectly !

 

For the record, I used this code :

 

if (isServer) then { 
 
    _positions = [
        [10915.8,7847.88,0.279678],
        [11270.8,7876.25,0.573982],
        [10946,9523,0.581001]
    ];

    _waypoints = [
        [[10929.9,7867.38,0], [10961.2,7857.93,0], [11008.4,7857.93,0]],
        [[11247.2,7871.59,0], [11202.3,7881.77,0], [11162.2,7888.05,0]],
        [[10921.4,9554.32,0], [10915.6,9572.28,0], [10891.4,9570.19,0]]
    ];
 
    _i = floor(random(count _positions));
 
    jose setPosATL (_positions select _i);

    {(group jose) addWaypoint [_x,0] } forEach (_waypoints select _i);
};
Thank you very much Silent for your help ! And thank you also for your part in the development of ACE 3, we use it almost every day with my team, we could not play without it now !

Share this post


Link to post
Share on other sites

Place three groups with already set waypoints on the map and delete 2 randomly picked groups on mission start:

_mygroups = [group1,group2,group3];
_pick = selectRandom _mygroups;
_mygroups = _mygroups - [_pick];
{{deletevehicle _x} foreach units _x} foreach _mygroups;

4 simple lines.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Wow, that seem really interesting too !

I'm a big noob in scripting, so I don't know which method is the less demanding in ressources. I intend to play this mission on a dedicated server, with max 15 players.

Thanks a lot Grumpy for this new approach, it more looks like what I did before whining here, but instead of delete two of the 3 units, I was hiding them. Problem was they could still open fire on players...

I will definitely give it a try too, and see which has better performances.

Thanks again !

  • Like 1

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

×