Feature #32590

Weapons in buildings

Added by Craig_VG over 2 years ago. Updated over 2 years ago.

Status:Closed Start date:06/10/2012
Priority:Normal Due date:
Assignee:Craig_VG % Done:

100%

Category:-
Target version:1.0 Estimated time:4.00 hours
Affected ArmA II version: BIForumURL:

History

Updated by Craig_VG over 2 years ago

See this post:

http://forums.bistudio.com/showthread.php?128781-TvT-FFA-CO-40-Dynamic-Zombie-Sandbox&p=2168856&viewfull=1#post2168856

Here is the script that does the spawning:


private ["_weapon","_mag","_weap","_building","_positions","_posnumber","_rightonthedot"];
CVG_weapons = ["m24","m40a3","m107","m4spr","glock17_EP1","DMR","smaw","smaw","BAF_AS50_scoped","BAF_AS50_TWS","BAF_L110A1_Aim","BAF_L7A2_GPMG","BAF_L85A2_RIS_ACOG","BAF_L85A2_RIS_CWS","BAF_L85A2_RIS_Holo","m1014","m1014","m1014","m1014","BAF_L85A2_RIS_SUSAT","m8_carbine_pmc","m8_carbineGL","m8_SAW","m8_sharpshooter","m8_compact","BAF_L85A2_UGL_ACOG","AA12_PMC","m8_compact_pmc","BAF_L85A2_UGL_Holo","m8_holo_sd","BAF_L85A2_UGL_SUSAT","BAF_L86A2_ACOG","m8_tws_sd","BAF_LRR_scoped","m8_tws","BAF_LRR_scoped_W","colt1911","m9","m9sd","m16a2","m16a2gl","m16a4","m16a4_gl","m16a4_acg","m16a4_acg_gl","m4a1","m4a1_aim","m4A1_AIM_camo","SCAR_H_CQC_CCO_SD","SCAR_H_STD_EGLM_Spect","SCAR_H_STD_TWS_SD","Sa58P_EP1","Sa58V_EP1","Sa58V_RCO_EP1","Sa58V_CCO_EP1","SCAR_H_LNG_Sniper","SCAR_H_LNG_Sniper_SD","SCAR_L_STD_HOLO","SCAR_L_STD_Mk4CQT","SCAR_H_CQC_CCO","M4A1_AIM_SD_camo","SCAR_L_STD_EGLM_TWS","M4A1_HWS_GL","m4a1_hws_gl_camo","m4a1_hws_gl_sd_camo","m4a1_rco_gl","m8_carbine","m8_carbinegl","m8_compact","m8_sharpshooter","m240_scoped_EP1","M249_EP1","M249_m145_EP1","M110_TWS_EP1","m107_TWS_EP1","M249_TWS_EP1","M60A4_EP1","Mk_48_DES_EP1","g36a","g36k","g36c","g36_c_sd_eotech","mp5a5","mp5sd","m1014","MG36_camo","m249","m240","mk_48","mg36","m1014","m8_saw","M14_EP1","M4A3_RCO_GL_EP1","M4A3_CCO_EP1","SCAR_L_CQC_CCO_SD","SCAR_L_CQC","SCAR_L_CQC_Holo","SCAR_L_CQC_EGLM_Holo","SCAR_L_STD_EGLM_RCO"];

buildings = nearestObjects [[0,0], ["house"], 60000];
{
    _building = _x;
    _positions = _building call fn_getBuildingPositions;
    _posnumber = floor (random (count _positions));
    _rightonthedot = _positions select _posnumber;
    ///NOTE, TEST THE NULL!!!!!
    if (_rightonthedot != nul) then {
        _weapon = CVG_Weapons call BIS_fnc_selectRandom;
        _mag=(getArray (configFile/"Cfgweapons"/_weapon/"magazines")) select 0;
        _weap = "weaponHolder" createVehicle [0,0];
        _weap addMagazineCargo [_mag,2];
        _weap addWeaponCargo [_weapon,1];
        _weap setPos _rightonthedot;
    };
} forEach buildings;

Updated by Craig_VG over 2 years ago

I made the script much better, more dynamic. Weapons are not floating.

Also I put it in DZS and tested it out. Works well.

Pictures:

https://www.dropbox.com/gallery/6891307/1/MoreDZSpics?h=944c7f

Code:


    //building is the current building selected in the forEach loop
    _building = _x;
    //Find the positions, function by Rube
    _positions = _building call fn_getBuildingPositions;
    //check if that chosen position is an empty array, with array compare function
    _check1 = [_positions, []] call arrayCompare;
    if (!_check1) then {
        if ((typeOf _building) in militaryWeaponBuildings) then {
            if (count _positions > 1) then {
                _numberOfPositions = 0;
                _randomnumber = (1+(floor (random (count _positions))));
                _totalPositionsAvailable = (_positions);
                while {_numberOfPositions <= _randomnumber} do {
                    _posnumber = floor (random (count _totalPositionsAvailable));
                    _rightonthedot = _totalPositionsAvailable select _posnumber;
                    //spawn the weapons randomly
                    _weapon = CVG_Weapons call BIS_fnc_selectRandom;
                    //find that weapons magazines
                    _mag=(getArray (configFile/"Cfgweapons"/_weapon/"magazines")) select 0;
                    //create the holder
                    _weap = "weaponHolder" createVehicle [0,0];
                    //add the magazine
                    _weap addMagazineCargo [_mag,1+(floor(random 10))];
                    //add the weapon
                    _weap addWeaponCargo [_weapon,1+(round(random .55))];
                    //set the weapon holder to the position (cant create it on the exact spot, setpos is needed
                    _check2 = [_rightonthedot, []] call arrayCompare;
                    if (((typeOf _building) == ("Land_Mil_Barracks_i")) || ((typeOf _building) == ("Land_Mil_Barracks_i_EP1")) && (!_check2)) then {
                        _weap setPos _rightonthedot;
                        _weap setPos [getPos _weap select 0, getPos _weap select 1,(getPos _weap select 2) - .14];
                    }
                    else
                    {
                        _weap setPos _rightonthedot;
                    };
                    //take another position out of the list:    NOTE! OH CRAP! YOU CAN't REMOVE ARRAYS FROM ARRAYS DAMN IT! WORKAROUND TIME!
                    _totalPositionsAvailable set [_posnumber,20];
                    _totalPositionsAvailable = _totalPositionsAvailable - [20];
                    //add one to the number of positions
                    _numberOfPositions = _numberOfPositions + 1;
                };
            }
            else
            {
                //Pick a random position
                _posnumber = floor (random (count _positions));
                //Select that position
                _rightonthedot = _positions select _posnumber;
                //spawn the weapons randomly
                _weapon = CVG_Weapons call BIS_fnc_selectRandom;
                //find that weapons magazines
                _mag=(getArray (configFile/"Cfgweapons"/_weapon/"magazines")) select 0;
                //create the holder
                _weap = "weaponHolder" createVehicle [0,0];
                //add the magazine
                _weap addMagazineCargo [_mag,1+(floor(random 10))];
                //add the weapon
                _weap addWeaponCargo [_weapon,1+(round(random .55))];
                //set the weapon holder to the position (cant create it on the exact spot, setpos is needed
                _weap setPos _rightonthedot;
            };
        } 
        else
        {
            _num = (random 100);
            if (_num < chanceNumber) then {
                //Pick a random position
                _posnumber = floor (random (count _positions));
                //Select that position
                _rightonthedot = _positions select _posnumber;
                //spawn the weapons randomly
                _weapon = CVG_Weapons call BIS_fnc_selectRandom;
                //find that weapons magazines
                _mag=(getArray (configFile/"Cfgweapons"/_weapon/"magazines")) select 0;
                //create the holder
                _weap = "weaponHolder" createVehicle [0,0];
                //add the magazine
                _weap addMagazineCargo [_mag,1+(floor(random 5))];
                //add the weapon
                _weap addWeaponCargo [_weapon,1+(round(random .55))];
                //set the weapon holder to the position (cant create it on the exact spot, setpos is needed
                _weap setPos _rightonthedot;
                if (CVG_Debug == 2) then {
                    _marker=createMarker [format ["mar%1",random 100000],_rightonthedot];
                    _marker setMarkerType "Dot";
                    _marker setMarkerColor "ColorBrown";
                    _marker setMarkerSize [2,2];
                };
            };
        };
    };

Updated by Craig_VG over 2 years ago

  • % Done changed from 60 to 80
  • Estimated time changed from 2.00 to 4.00

Updated by Craig_VG over 2 years ago

  • Status changed from In progress to Closed
  • % Done changed from 80 to 100

Issue with the putting of weapon and magazine into weapon holder.

On server it would show up, but not on clients.

I realized that I needed to use addWeaponCargoGlobal. So has been fixed.

Also available in: Atom PDF