Jump to content
Sign in to follow this  
alleycat

cycling buildingpos?

Recommended Posts

I am looking for a way to check how many positions a building has. I searched the forums and many topics covering garrisoning have some form of buildingpos cycle but I do not understand the examples because they are part of a large script and I would also like to figure out the algorithm for myself for learning purposes.

In pseudocode I would like to do this:

test a building for wether it has building positions up to 20 (more precisely, check if buildingpos _number does actually exist)

Not sure how to syntax that shit however. any pointers?

This one seems to appear very often in garrison scripts:

while { format ["%1", _house buildingPos _y] != "[0,0,0]"

I dont get the != "[0,0,0]". Why does it compare against a 3 number array?

Edited by alleycat

Share this post


Link to post
Share on other sites

I would imagine while it's not equal to [0,0,0] that means buildingPos _y is actually valid

This is how I think it should go

_y=0;
while { format ["%1", (_this select 0) buildingPos _y] != "[0,0,0]"} do { 
_y=_y+1;
};

// positions 
hint str _y;

Share this post


Link to post
Share on other sites

I came up with this:

_c = 0;
while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
hintsilent format ["The building has %1 positions", _c];

_spawnlocs = _c;
while {_spawnlocs > 0} do
{
_loot  = createVehicle ["WeaponHolder", (_x buildingpos _spawnlocs), [], 0, "CAN COLLIDE"];
//_loot = "WeaponHolder" createVehicle (_x buildingpos _spawnlocs);
_loot addWeaponCargoGlobal ["MetisLauncher",1];
_loot setpos [getpos _loot select 0,getpos _loot select 1, 1];
_spawnlocs = _spawnlocs - 1
}

It works but it has a weird problem: If I run this on smaller buildings all items are spawned outside. However in a large building like the hangar they spawn correctly. I think something is checking wether there is room for the object in the background.

Share this post


Link to post
Share on other sites

You can't use _loot setpos [getpos _loot select 0,getpos _loot select 1, 1]; to reset their positions it has to be done in the createVehicle.

However you then get the next problem which is height, I never have found a good way to find the exact height of each floor.

buildingPos doesn't seem to return an exact position and if you try setting object heights manually they're not constant so if you get one right another is off. Also some positions are outside a building such as top and bottom of ladders.

Share this post


Link to post
Share on other sites
You can't use _loot setpos [getpos _loot select 0,getpos _loot select 1, 1]; to reset their positions it has to be done in the createVehicle.

What do you mean? Does this line cause the problem with my loot spawning outside?

EDIT: It doesnt apparently. leaving it out spawns loot at the desired height, but still outside.

Edited by alleycat

Share this post


Link to post
Share on other sites

Spawning inside for me, on barracks at Utes airport. Maybe a building issue. Just the height is messed up.

_x = _this select 0;//building
_c = 0;
while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
hintsilent format ["The building has %1 positions", _c];

_spawnlocs = _c;
while {_spawnlocs > 0} do
{

_posx = (_x buildingpos _spawnlocs) select 0;
_posy = (_x buildingpos _spawnlocs) select 1;
_posz = (_x buildingpos _spawnlocs) select 2;


_loot  = createVehicle ["WeaponHolder",[_posx,_posy,_posz] , [], 0, "can_collide"];

_loot addWeaponCargoGlobal ["MetisLauncher",1];

_spawnlocs = _spawnlocs - 1;
}

Share this post


Link to post
Share on other sites

Your code fixed the positioning, thanks. I dont get why. Now for the weird part, my approach placed all items at the perfect height but outside of buildings. Going to attempt to combine both methods and report back.

EDIT: Both codes worked. The problem was the "can_collide". If it is not used the items spawn outside. If it is used, inside. But at a messed up height.

Edited by alleycat

Share this post


Link to post
Share on other sites
Spawning inside for me, on barracks at Utes airport. Maybe a building issue. Just the height is messed up.

_x = _this select 0;//building
_c = 0;
while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
hintsilent format ["The building has %1 positions", _c];

_spawnlocs = _c;
while {_spawnlocs > 0} do
{

_posx = (_x buildingpos _spawnlocs) select 0;
_posy = (_x buildingpos _spawnlocs) select 1;
_posz = (_x buildingpos _spawnlocs) select 2;


_loot  = createVehicle ["WeaponHolder",[_posx,_posy,_posz] , [], 0, "can_collide"];

_loot addWeaponCargoGlobal ["MetisLauncher",1];

_spawnlocs = _spawnlocs - 1;
}

How can i select multiple buildings in a given radius?

Tried many different things but nothing worked at all.

THanks for any help.

Share this post


Link to post
Share on other sites

Call it by using a gamelogic placed in the centre of the area in which you wish to spawn stuff.

In the init put null=[this,1000] execvm "loot.sqf"

save as loot.sqf

_pos = _this select 0;//building
_rad = _this select 1;// radius of all buildings
ary=[];
_bldgs =  nearestobjects [_Pos,["house"],_rad];// position, building, radius

{

_c = 0;
while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
// hintsilent format ["The building has %1 positions", _c];

_spawnlocs = _c;
while {_spawnlocs > 0} do
{
   _posx = (_x buildingpos _spawnlocs) select 0;
   _posy = (_x buildingpos _spawnlocs) select 1;
   _posz = (_x buildingpos _spawnlocs) select 2;

// fake object that falls to correct height    
_drop  = createVehicle ["suitcase",[_posx,_posy,_posz] , [], 0, "can_collide"];
_drop setvelocity [0,0,-1];
_drop hideobject true;
ary = ary + [_drop];// make an array for later deletion

// spawn weaponholder and attacht to object _drop to place at correct height 
_loot  = createVehicle ["WeaponHolder",_x , [], 0, "can_collide"];
_loot attachto [_drop,[0,0,0]];

_loot addWeaponCargoGlobal ["MetisLauncher",1];// add weapon to weapon holder 

_spawnlocs = _spawnlocs - 1;
};  

} foreach _bldgs;

sleep 3;// needs delay or weaponholders will be deleted 

// delete _drop object
{
deletevehicle _x;
} foreach ary;

This only spawns one type of object, it would need to select random weapons and ammo for it to be any use.

Share this post


Link to post
Share on other sites
Call it by using a gamelogic placed in the centre of the area in which you wish to spawn stuff.

In the init put null=[this,1000] execvm "loot.sqf"

save as loot.sqf

_pos = _this select 0;//building
_rad = _this select 1;// radius of all buildings
ary=[];
_bldgs =  nearestobjects [_Pos,["house"],_rad];// position, building, radius

{

_c = 0;
while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
// hintsilent format ["The building has %1 positions", _c];

_spawnlocs = _c;
while {_spawnlocs > 0} do
{
   _posx = (_x buildingpos _spawnlocs) select 0;
   _posy = (_x buildingpos _spawnlocs) select 1;
   _posz = (_x buildingpos _spawnlocs) select 2;

// fake object that falls to correct height    
_drop  = createVehicle ["suitcase",[_posx,_posy,_posz] , [], 0, "can_collide"];
_drop setvelocity [0,0,-1];
_drop hideobject true;
ary = ary + [_drop];// make an array for later deletion

// spawn weaponholder and attacht to object _drop to place at correct height 
_loot  = createVehicle ["WeaponHolder",_x , [], 0, "can_collide"];
_loot attachto [_drop,[0,0,0]];

_loot addWeaponCargoGlobal ["MetisLauncher",1];// add weapon to weapon holder 

_spawnlocs = _spawnlocs - 1;
};  

} foreach _bldgs;

sleep 3;// needs delay or weaponholders will be deleted 

// delete _drop object
{
deletevehicle _x;
} foreach ary;

This only spawns one type of object, it would need to select random weapons and ammo for it to be any use.

Thank you ver y much!(:

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  

×