Home   Help Search Login Register  

Author Topic: Random positions inside a bulding  (Read 2208 times)

0 Members and 1 Guest are viewing this topic.

Offline sharkattack

  • Former Staff
  • ****
Random positions inside a bulding
« on: 31 Mar 2008, 19:19:02 »
guys
how could i start a hostage unit  in one of several positions inside a building
ive previously been grouping with markers but this isnt very accurate  when using indoors

is there a better way ?

many thanks in advance  :)
"HOLY SARDINE" - see Shark-Attack meet his match

Offline Loyalguard

  • Former Staff
  • ****
Re: Random positions inside a bulding
« Reply #1 on: 31 Mar 2008, 22:42:06 »
I haven't tried it but you could try this perhaps.  If the building had five positions (indices 0-4)...

Code: [Select]
_p = floor(random 5); // Return either 0, 1, 2, 3, 4 randomly.
unitname setPos (nearestBuilding unitname buildingPos _p); // Place the unit at a random position determined by _p in the nearest building.

...change unitname to the name of the unit or pointer variable as applicable.  You also have to determine how many building positions there are in the building in order to seed the random command.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Random positions inside a bulding
« Reply #2 on: 31 Mar 2008, 22:51:06 »
Baddo wrote a function, buildingPosCount, to count how many building positions were available in a given building, but it was for OFP. No idea whether it is still valid in ArmA, but it is likely that you can get some joy from it, especially since it is very simple.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline i0n0s

  • Former Staff
  • ****
Re: Random positions inside a bulding
« Reply #3 on: 01 Apr 2008, 15:17:13 »
There is a script on armaholic which does the requested job:
Link

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: Random positions inside a bulding
« Reply #4 on: 01 Apr 2008, 16:53:37 »
Baddo wrote a function, buildingPosCount, to count how many building positions were available in a given building, but it was for OFP. No idea whether it is still valid in ArmA, but it is likely that you can get some joy from it, especially since it is very simple.

It should work in ArmA too. I think I tested some time last year that it works.

Another note from the top of my head is that the nearestBuilding function only returns buildings which have indexed positions in them.

As a sidenote, I've actually just recently been playing with indexed building positions in ArmA... and faced an annoying problem with some guard towers: if you order a unit to go into it, the unit often falls to the ground when on top of the ladders. Argh! I can fall from it too. So a setPos into the guard tower is required if you want to avoid that. Just one of the many stupid annoyances we have when creating missions  :scratch:

Edit: I will post here an unfinished function which creates and inserts units into indexed building positions. I don't have possibility now to finish it, but I will post it here, maybe someone can use it as is or modify it like they wish:

Code: [Select]
private ["_group", "_buildingType", "_unitType", "_middlePosOfRange"];
private ["_range", "_posIndices", "_houseList", "_houseCount"];

_buildingType = _this select 0;
_range = _this select 1;
_middlePosOfRange = _this select 2;
_posIndices = _this select 3;
_unitType = _this select 4;
_group = _this select 5;

_houseList = nearestObjects [_middlePosOfRange, [_buildingType], _range];

_houseCount = count _houseList;

private ["_retval", "_posIndicesCount"];
_retval = false;
_posIndicesCount = count _posIndices;
if ( ( _houseCount > 0 ) && ( _posIndicesCount > 0 ) ) then { 
    private ["_k", "_building", "_pos", "_i"];
    _k = 0;
    while { _k < _houseCount } do {
        _building = _houseList select _k;
        _i = 0;   
        while { _i < _posIndicesCount } do {
            _pos = _building buildingPos (_posIndices select _i);
            _unitType createUnit [_middlePosOfRange, _group, "BDO_guard = this; this setUnitPos ""up""", 0.8];
            BDO_guard setPos _pos;       
            BDO_guard disableAI "move";
            sleep 0.2;
            _i = _i + 1;
        };
        sleep 0.2;
        _k = _k + 1;
    };
    BDO_guard = nil;
    _retval = true;
};
_retval

I'm calling it like this:

Code: [Select]
["Land_posed", 200, (getMarkerPos "BDO_UPS01"), [1], "SoldierWB", BDO_watchTowerGrp] execVM "BDO_insertIntoBuildingPositions.sqf";
The "Land_posed" is the building type which is to be used.

The 200 is the range from which searchs the buildings.

(getMarkerPos "BDO_UPS01") is the centre of the range.

[1] is an array of indexed building positions into which to insert the created units. In this case I only insert one unit per building. The index numbers start from zero (0). You can extend this to use the buildingPosCount and randomize the positions fed to this function in your calling script/function. But always remember, the first index is 0 and not 1 like it is shown in-game. In the case of the "Land_posed" watch tower, if I wanted to fill the 0 position too, I'd have [0,1] passed to the function, and a unit would appear at the ground close to the tower, and another unit would be in the tower.

"SoldierWB" is the unit type to be created and inserted into the building positions.

BDO_watchTowerGrp is the group into which the units are created. I'm just having one unit pre-placed into the map which has "BDO_watchTowerGrp = group this" in its initialization field.

In my case I have all the created units in the same group, placed into watch towers. And their movement needs to be disabled, otherwise they run to their leader. This is advantageous: the units share information about enemies when they are in the same group, which fits perfectly for watch tower guards. You can imagine that all watch towers have radios. Fill all watch towers like this in a larger base at North Sahrani and try to invade it with enemy skill set to high... I got quite nice fireworks as a result.



As I said, this is unfinished work but maybe it helps someone.
« Last Edit: 01 Apr 2008, 17:16:46 by Baddo »

Offline sharkattack

  • Former Staff
  • ****
Re: Random positions inside a bulding
« Reply #5 on: 01 Apr 2008, 17:25:08 »
thanks mate
will check it out

ive been  playing with building pos to position some static guards
used the example from the comref but i get an error returned

this setPos ((object 172902) buildingPos 1)

 ???
"HOLY SARDINE" - see Shark-Attack meet his match

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: Random positions inside a bulding
« Reply #6 on: 01 Apr 2008, 17:27:45 »
I think the objectID way doesn't work in ArmA.

See my example. I get a list of buildings with nearestObjects. So I needed to know the type of building and from which area to look for them. When I have the list I can iterate over it and insert units into the indexed positions in the buildings.

nearestBuilding also works, and it only finds buildings which have indexed positions in them.

I recommend you try the function I posted above and adjust it to your needs if required. Mainly the bits in createUnit could need modification:

_unitType createUnit [_middlePosOfRange, _group, "BDO_guard = this; this setUnitPos ""up""", 0.8];

...in bold what you might have to edit for your needs.

For my watch tower units I am planning to have a function which makes it possible for them to kneel if they detect enemies. Otherwise they will just stand straight in the middle of a firefight. But for some building/position types you would want that, it depends if the units can shoot at their targets while kneeled or not.
« Last Edit: 01 Apr 2008, 17:39:26 by Baddo »

Offline Cheetah

  • Former Staff
  • ****
Re: Random positions inside a bulding
« Reply #7 on: 01 Apr 2008, 17:38:18 »
Bardosy started working on a dynamic defend script.

It uses the positions defined for each building. Could help?
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline sharkattack

  • Former Staff
  • ****
Re: Random positions inside a bulding
« Reply #8 on: 01 Apr 2008, 19:05:27 »
thanks all
im gonna with go the script that iOnOs suggests
nice and simple and seems to work a treat ..

thanks again  :)
"HOLY SARDINE" - see Shark-Attack meet his match

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: Random positions inside a bulding
« Reply #9 on: 01 Apr 2008, 21:59:44 »
It's nice that it's working...


EDIT: Removed the unnecessary quote of entire previous post    h-
« Last Edit: 02 Apr 2008, 22:05:49 by h- »