Jump to content
Sign in to follow this  
Marin Lorre

Random ennemy placement

Recommended Posts

Hi,

I'm actually creating my first replayable mission and for that I need to place hostages in a predefined random position, I've place different trigger with hostages inside, I want to choose one of those and delete all other.

Here is the script I made but all hostages are delete when I run it :

 

 

private _HostPos = [trig01, trig02, trig03]

_HostPos deleteAt (random (count _HostPos));

_y = count _HostPos;
for "_i" from 0 to _y do {
    {deleteVehicle _x} forEach allUnits inArea (_HostPos select _i);
};

 

Could you help me ?

thanks

Share this post


Link to post
Share on other sites

Sup @Marin Lorre. I've made a script that do the same, but with a different approach. Take this example:

  • I've got a VIP, wich need random placement. 
  • I've got several possible spots for placement (different buildings inside a town).
  • The VIP has bodyguards; these units are different, depending on the selected placement.

The script does this: the VIP is synchronized against multiple empty logics. Each logic position is a possible location (latitude, longitude and height matters). Then, i've got several AIs synchronized to each logic (the bodyguards at each location). When mission starts, the init code from the VIP gets fired and selects a random location (a randon logic), then places the VIP into that position (with an optional random radius). After that, it takes all the non-selected logics and delete the "orphans" bodyguards.
Take a look at this function (fn_randomPlacement.sqf):
 

params [
	["_target", objNull, [objNull]],
	["_randRadius", 0, [0]]
];

// Get only synchronized "Logics"
private _syncLogics = (synchronizedObjects _target) select { typeOf _x == "Logic" };
private _selectedLogic = selectRandom _syncLogics;

// Set target position
_target setVehiclePosition [_selectedLogic, [], _randRadius, "CAN_COLLIDE"];

// Delete all objects associated with the non-selected Logic
{
	// get attached objects (exclude the _target itself)
	private _attachedObjects = (synchronizedObjects _x) - [_target];
	{
		deleteVehicle _x;
	} forEach _attachedObjects;
} forEach (_syncLogics - [_selectedLogic]);

Then, in the VIP init field (this code is fixed for MP missions):
 

if (local this) then {
   [this, 3] call GLMFW_fnc_randomPlacement;
};

In the editor, I've got this:

                         /--BODYGUARD1
     /-------------LOCIG1---BODYGUARD2
    /                    \--BODYGUARD3
   /
  /                      /--BODYGUARD4
VIP----------------LOGIC2
   \                     \--BODYGUARD5
    \
     \
      \------------LOGIC3---BODYGUARD6

If LOGIC1 is selected at random, you keep BG 1, 2 and 3 (4, 5 and 6 are deleted).
If LOGIC2 is selected at random, you keep BG 4 and 5 (1, 2, 3, 6 are deleted).
If LOGIC3 is selected at random, you keep BG 6 (1, 2, 3, 4, 5 are deleted).

In your example, you can place one "main" hostage as vip, place different logics as possible locations, and synch more hostages into each location. 

Good luck and happy coding!

-EDIT-
When using this script, I've synchronize other objects at each "LOGIC" position, such as cars, boxes, intel, etcétera, to make the selected spot more "immersive friendly" (i mean, you are not tied to AI units at each possible location).

Share this post


Link to post
Share on other sites

Or:

_positions = [_pos1,_pos2,_pos3];
_hostage setPos (selectRandom _positions);

Only need one hostage.

  • Like 2

Share this post


Link to post
Share on other sites

@kaleb c0d3

Thank you very much, as it does actually work perfectly I think i'm gonna use it if you don't mind. However my scientific brain doesn't want to give up and I really don't understand why my script is not working at all.

Merci beaucoup anyway

 

PS: I don't understand the way you define those parameters;

36 minutes ago, kaleb c0d3 said:

params [ ["_target", objNull, [objNull]], ["_randRadius", 0, [0]] ];

 

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Marin Lorre said:

@kaleb c0d3

Thank you very much, as it does actually work perfectly I think i'm gonna use it if you don't mind. However my scientific brain doesn't want to give up and I really don't understand why my script is not working at all.

Merci beaucoup anyway

 

PS: I don't understand the way you define those parameters;

 

Please, use and modify it as you see fit! I'm glad to help you 🙂

 

When you define parameters that way, you are declaring with a type and a default value, like this:

params [
  ["_p", "no value", ["", 0]]
];

// _p : parameter name
// "no value" : default value for _p, if not specified at fuction call (an "optional" parameter)
// ["", 0] :  array of data types accepted for _p, in this case, a string ("") or an integer (0)

For more info, take a look at this.
And about your code, take a look at this piece (not tested tho...)
 

private _possibleLocation = [trig01, trig02, trig03]
private _hostagePos = selectRandom _possibleLocation;

{
	private _unitsInArea = allUnits inArea _x;
	{ deleteVehicle _x } forEach _unitsInArea;
} forEach (_possibleLocation - [_hostagePos]);

If you try my fn_randomPlacement function, let me know how it worked, just to have feedback 😄

Share this post


Link to post
Share on other sites

@Marin Lorre,

Instead of putting effort into removing superfluous objects, why not use that effort to randomly place a single hostage?

In the above examples you still only need one editor placed hostage (if one is the goal). Once the location is established you can setPos the unit at that position.

If one hostage is the goal there should only be one hostage. Easy.

Have fun!

  • Like 2

Share this post


Link to post
Share on other sites
40 minutes ago, wogz187 said:

@Marin Lorre,

Instead of putting effort into removing superfluous objects, why not use that effort to randomly place a single hostage?

In the above examples you still only need one editor placed hostage (if one is the goal). Once the location is established you can setPos the unit at that position.

If one hostage is the goal there should only be one hostage. Easy.

Have fun!

 

I think he wants to move a group of them, not just one.

Share this post


Link to post
Share on other sites
1 hour ago, wogz187 said:

@Marin Lorre,

Instead of putting effort into removing superfluous objects, why not use that effort to randomly place a single hostage?

In the above examples you still only need one editor placed hostage (if one is the goal). Once the location is established you can setPos the unit at that position.

If one hostage is the goal there should only be one hostage. Easy.

Have fun!

I don't want to just place on hostage, but also opfors arround in a "realistic" defence position which isn't possible (at least easily possible) with setPos command.

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Marin Lorre said:

isn't possible (at least easily possible) with setPos command.

 

It definitely is, and is incredibly simple. All you need is an array with the units you want to position, and an array of the positions. Either have 1 position per unit for fixed placements, or an excess of positions to give it some randomness with the code I posted for you. And if you don't know how to remove an element from an array, just ask. 

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  

×