Advertisement

Author Topic: "Place unit/object in random building and at random buildingPos" BETA  (Read 2382 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
This is a simple script that allows you to place an object/unit anywhere in a city/town/village in a random building at a random buildingPos. Perfect for "hide and seek" missions where you look for an object or a unit and when you want some replay value through randomness. The script literally enables the object/unit to appear in thousands of different places and the location varies every time you run the script.

someBuildingPos.sqf
Code: [Select]
private ["_obj","_radius","_minBuildingPos","_randomPos","_houseArray","_houseNumber","_x","_house","_y"];

_obj = _this select 0;
_radius = _this select 1;
_minBuildingPos = _this select 2;
_randomPos = [(getpos _obj select 0) + _radius*0.5 - (random _radius), (getpos _obj select 1) + _radius*0.5 - (random _radius), 0];
_houseArray = nearestObjects [_randomPos, ["House"], _radius];

sleep 1;

_houseNumber = count _houseArray;

_x = 0;

while {_x <= _houseNumber} do
{
_house = _houseArray select _x;
waitUntil {! isNil "_house"};
if (format ["%1", _house buildingPos _minBuildingPos] != "[0,0,0]") exitWith {_y = 0; while { format ["%1", _house buildingPos _y] != "[0,0,0]" } do {_y = _y + 1}; _y = _y - 1; _obj setPos (_house buildingpos (ceil random _y));};
_x = _x +1;
sleep 0.1;
};

Implementation:

- Place the object/unit in an area with buildings that are enterable.
- call {[unit,radius,minPositions] execVM "someBuildingPos.sqf"};

Example: call {[mySoldier,500,5] execVM "someBuildingPos.sqf"};
- This will place mySoldier in a random building within a 500m radius and the building will have at least 5 positions in it.

Third parameter is obviously the minimum required number of buildingPos's for a building to be chosen by the script. The reason for a minimum is that some buildings only have one and you sometimes can't get there as a player, which may cause problems. In my example mission I chose 5 as minimum, which really makes sure that the building chosen by the script is enterable. Please note that there might be a couple of seconds delay before the script has chosen a house/position.

I might develop this further, so there is an option to repeat the script, making it random patrolling in a city.

Grateful for feedback or any spotting of flaws,

Laggy

contact: tolaggy@hotmail.com
« Last Edit: 04 Feb 2010, 20:23:27 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline fleepee

  • Members
  • *
  • Enter the Matrix!
Tested it, not a bad script, but:

- problem of height: sometimes, you fall to your position, no prob when it's half a meter, but when it's higher, the unit dies...
- in chernagorsk, i've often been on the railroad bridge and in the electric transformers, perhaps you should remove these "buildings" from the available ones. (hard to land on a crane too!)

Will this be the new "random house patrol" script? ;)

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Quote
Will this be the new "random house patrol" script? Wink

Well, I was inspired by the random house patrol ArmA script by Tophe, but that only used one building.
If this script gets released I will of course mention his contribution, if he doesn't oppose for some reason.
This script also only places an object/unit at a random position (so far) and I made it for my mission "Red Mercury".
The falling problem which I never encountered, could easily be solved with a short allowDamage false command.
Don't know how to remove the buildings you mentioned from the _houseArray.
Any ideas?

Laggy
« Last Edit: 04 Feb 2010, 20:20:33 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.