Jump to content
Luft08

Crate is spawning under floor

Recommended Posts

I want to spawn a weapons cache in a random position of a random building in a random city/town.

The problem is that the weapons cache is being spawned under the floor of the building.

 

PlaceWeaponsCache:

if(!isServer) exitWith {};

// Pick random city
private _cityRecord = selectRandom eastCityAreaArray; // [cityName:string, center:pos, radius:number]
private _cityCenter = _cityRecord # 1;
private _cityRadius = _cityRecord # 2;
private _cacheRadius = _cityRadius * 0.5; // Place cache no more than half way to edge of city.
private _bldgList = [_cityCenter, _cacheRadius] call getBuildingList;
private _bldg = selectRandom _bldgList;
waitUntil{!(isNil "_bldg")};

private _housePositions = [_bldg] call BIS_fnc_buildingPositions;
private _cachePos = selectRandom _housePositions;
weaponsCache = createVehicle ["O_supplyCrate_F", _cachePos, [], 0, "CAN_COLLIDE"];

clearItemCargoGlobal weaponsCache;
clearWeaponCargoGlobal weaponsCache;
clearMagazineCargoGlobal weaponsCache;
weaponsCache addMagazineCargoGlobal ["SatchelCharge_Remote_Mag",10];

weaponsCache addEventHandler["Killed", {
    params ["_unit", "_killer", "_instigator", "_useEffects"];
    for "_c" from 1 to 10 do {
        private _bomb = "Bo_GBU12_LGB" createVehicle (getPos _unit);
        _bomb setDamage 1;
    };
}]; 

getBuildingList :

if(!isServer) exitWith {};
params["_center", "_radius"];

if(!isServer) exitWith {};
private _rawBuildingArray = [];
_rawBuildingArray = nearestObjects [_center , ["house"], _radius ];

// process raw date to extract actual houses.
private _bldgList = [];
{
    private _index = (str _x) find "house";
    if(_index != -1) then {
        _bldgList pushBack _x;
    };
} forEach _rawBuildingArray;

_bldgList 

I'm running the code in a mission on the Global Mobilization map. (gm_weferlingen_summer)

Share this post


Link to post
Share on other sites

Never mind... I had an extra if(!isServer) exitWith {}; statement and once removed everything is fine.

I don't understand why that would matter however.  Oh well...

Share this post


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

Never mind... I had an extra if(!isServer) exitWith {}; statement and once removed everything is fine.

I don't understand why that would matter however.  Oh well...

You should keep the spawning code on server only. If not, you multiply crates by number of players (depending on where you run the code).

There is no reason for any interaction between the line od code referring to server, and the fact the crate spawns on or below ground. (Perhaps, you are spawning 2 crates if MP test with hosted and 1 client)

 

If you want to correct the issue (probably depending om map you are using), just add a little offset:

weaponsCache = createVehicle ["O_supplyCrate_F", _cachePos vectorAdd [0,0,0.5], [], 0, "CAN_COLLIDE"];

 

  • Like 2

Share this post


Link to post
Share on other sites

There are a few building positions that are "problematic" when spawning statics in them - the little closet/nook in the back of the "Land_i_Shop_xx" statics and the front steps of a small house come to mind.

5 hours ago, pierremgi said:

If you want to correct the issue (probably depending om map you are using), just add a little offset:

 

A good solution, though sometimes physics can do weird things (supply crate tips over or explodes...). I like to "anchor" statics like this when I spawn them using BIS_fnc_attachToRelative, as a final action after setPos/setVectorUp/et al. I generally add a game logic named "anchor" at [0,0,0] to all of my missions for this reason.

  • Like 3

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

×