Jump to content
wingnutwn

Coding OBJ with Marker that is destructible.

Recommended Posts

I'm trying to create _x barracks, make them destructible and set markers on them.    I can make the barracks and save the positions in an array, I can't seem to make markers on them (only 1 is creating) and they buildings are not destructible.   So any of you real coders want to write up some code I would sure appreciate it so I can learn how to do it, if its even possible.   Maybe I'm trying to do too much in one "for "_i" from  1 to _numwnbarracks do {"?   Thanks in advance.

Share this post


Link to post
Share on other sites

Usually, it's better to provide your code. This way, people can help you on error or bad scripting. Here, we can't guess how do you create your barracks, on which position, which map, which mod, when...  Help for being helped.

  • Like 1

Share this post


Link to post
Share on other sites

I was afraid you would want to see it haha

 

 hint 'Creating Barracks';
	"wn_barracks_marker" setMarkerShape "ICON";"wn_barracks_marker" setMarkerType "mil_warning";"wn_barracks_marker" setMarkerBrush "SOLID";"wn_barracks_marker" setMarkerDir 0;"wn_barracks_marker" setMarkerColor "ColorRed";"wn_barracks_marker" setMarkerText "Enemy Barracks";
	missionNamespace setVariable ["wn_barracks_pos",[]];
	wn_barracks = _numwnbarracks;
	
	for "_i" from 1 to _numwnbarracks do {
			_loc = [_ESSAreaMkr, 50] call ESS_fnc_findSafePos;
			wn_barracks_pos append _loc;
			_wn_barracks = createVehicle [selectRandom _temparraywnbarracks,_loc];
//			_wn_barracks_marker = createMarker ["wn_barracks_marker",_loc];
			_wngrpb = createGroup [east, true];
			_wngrpb1 = _wngrpb createUnit [selectRandom _temparrayUn, _loc, [], 0, "FORM"];
			_wngrpb1 moveingunner _wn_barracks;
				switch (_i) do { 
					case "1" : {_wn_barracks_marker1 = createMarker ["wn_barracks_marker",_loc]};
					case "2" : {_wn_barracks_marker2 = createMarker ["wn_barracks_marker",_loc]};
					case "3" : {_wn_barracks_marker3 = createMarker ["wn_barracks_marker",_loc]};
					case "4" : {_wn_barracks_marker4 = createMarker ["wn_barracks_marker",_loc]};
					case "5" : {_wn_barracks_marker5 = createMarker ["wn_barracks_marker",_loc]};
					case "6" : {_wn_barracks_marker6 = createMarker ["wn_barracks_marker",_loc]};
				};
		};

 

Share this post


Link to post
Share on other sites

Your script should start with the marker creation... I can't see createMarker. You probably added it in editor (empty one) then work it with this script..;

If your marker exists in editor, it's useless to change the type, brush, dir, color....

You just have to play with alpha (transparency) . set it to 0 in editor and >0 when you want to see it on map.

missionNamespace setVariable ["wn_barracks_pos",[]];    is same as:    wn_barracks_pos = [];

wn_barracks = _numwnbarracks; ???? you just set it [] so from where come _numwnbarracks ???  If not defined (here) it's subject to error.

 

That's for starting. So your code, as is,  is inconsistent.

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks Pierre, and I love you addons!

 

So I got the code to work and do what I want it to do.

 

	wn_barracks = _numwnbarracks;
	
	for "_i" from 1 to _numwnbarracks do {
			_wn_b_marker = format ['Bunker_%1',_i];
			_loc = [_ESSAreaMkr, 50] call ESS_fnc_findSafePos;
			_marker = createMarker [_wn_b_marker,_loc];
			_wn_b_marker setMarkerType "mil_objective";_wn_b_marker setMarkerText "Barracks";_wn_b_marker setMarkerAlpha 0.4;_wn_b_marker setMarkerColor "ColorRed";		
			wn_barracks_pos append _loc;
			_wn_barracks = createVehicle [selectRandom _temparraywnbarracks,_loc];
			_wngrpb = createGroup [east, true];
			_wngrpb1 = _wngrpb createUnit [selectRandom _temparrayUn, _loc, [], 0, "FORM"];
			_wngrpb1 moveingunner _wn_barracks;
			
		};

Now I need to figure out how to make the _wn_barracks = createVehicle [selectRandom _temparraywnbarracks,_loc]; which are to bag_bunkers to be destroyable.   Then I can figure out how to do a !alive bag_bunker count thing.   Anyways thanks for looking at it, and if you have any ideas on how to set the attributes in the above scope to make them destroyable please let me know.   I'm thinking I need to give them each a variable just like the markers so I can "check them"?

Share this post


Link to post
Share on other sites

 wn_barracks = _numwnbarracks;  . this line seems to me useless, except if you need wn_barraks inside some other code (sqf, different scope...)

 

Be sure _numwnbaraks is OK, by a hint from debug console : hint str _numwnbaraks should return an array of ....

 

for "_i" from 1 to _numwnbarracks do { _wn_b_marker = format ['Bunker_%1',_i]; _loc = [_ESSAreaMkr, 50] call ESS_fnc_findSafePos; _marker = createMarker [_wn_b_marker,_loc]; _wn_b_marker setMarkerType "mil_objective";_wn_b_marker setMarkerText "Barracks";_wn_b_marker setMarkerAlpha 0.4;_wn_b_marker setMarkerColor "ColorRed"; wn_barracks_pos append _loc; _wn_barracks = createVehicle [selectRandom _temparraywnbarracks,_loc]; _wngrpb = createGroup [east, true]; _wngrpb1 = _wngrpb createUnit [selectRandom _temparrayUn, _loc, [], 0, "FORM"]; _wngrpb1 moveingunner _wn_barracks; }

 

For From To code starts at 0 and ends at total -1 elements, as any array is indexed from 0 to last element (count array -1)

 

There are too many things to note in your bit of code. So, let's say your are spawning some bag bunker... (which class? we don't know anything about _temparraywnbarracks). Why are you scripting : _wngrpb1 moveingunner _wn_barracks; ???? _wn_barraks is an array, not a vehicle!

 

Well, I think this code is not yours and you don't have any clue of what you're doing. I'm not sure of what you want with your bag bunkers but some objects don't have a destroyed (ruin/wreck) model. So, make them destructible just means hiding them... if you know how to decide they are destroyed. Your project is far too much imprecise.

 

Share this post


Link to post
Share on other sites

Harsh, I like it.   Yeah I'm old and teaching myself at least I just learned that I can setpos of _wngrpb1 to _loc rather then moveingunner from this and I should hint my variables.   I'll get there maybe someday - maybe.

 

And I'm playing with ESS (enemy spawning system) and trying to manipulate the spawning of things to my liking.

 

Here is the script that I chose to play with.

 

/*
	Enemy Spawning System (ESS) - by Enigx

	ESS_Launch.sqf

*/

params ["_fazioneESS","_sideInd","_ESSAreaMkr","_UNpatrol","_UNhouse","_sttc","_lghtarray","_hvyarray","_wnbarracksarray","_wnXYsize","_distance"];
_numFT = _UNpatrol select 0; _unitsXteamMax = _Unpatrol select 1;
_groupInBuild = _UNhouse select 0; _numUnitInBuild = _UNhouse select 1;
_NumStatic = _sttc select 0; _NumLghVeh = _lghtarray select 0;_patlght = _lghtarray select 1;_lghtProb = _lghtarray select 2; _NumHvyVeh = _hvyarray select 0;_pathvy = _hvyarray select 1;_numwnbarracks = _wnbarracksarray select 0;
_mkrX = _wnXYsize select 0; _mkrY = _wnXYsize select 1;

private ["_temparrayUn","_temparrayStc","_temparrayLghVeh","_temparrayHvyVeh","_temparraywnbarracks","_grpB","_grpC","_grpD","_grpE","_newpos","_UnInVeh"];
systemchat format ['%1',_fazioneESS];
_mPos = getMarkerPos _ESSAreaMkr;
_mkrAgl = markerDir _ESSAreaMkr;


// Initiate the ESS zone and activation trigger
//_ESSAreaMkr setMarkerAlpha 1;

//_essActivated = createTrigger ["EmptyDetector",_mPos]; 
//_essActivated setTriggerArea [2000,2000,0,FALSE,150]; 
//_essActivated setTriggerActivation ["ANYPLAYER","PRESENT",false];
//_essActivated setTriggerTimeout [1, 1, 1, true];
//_essActivated setTriggerStatements ["this","",""];


//waituntil {triggeractivated _essActivated};	// wait until players in area



// Impose sleep time to avoid overlapping spawn calling 
_TempSpawn = 0.1;

// definition of the faction to be used
_temparrayUn = ([_fazioneESS] call ESS_fnc_getunit) select 0;

_temparrayStc = ([_fazioneESS] call ESS_fnc_getunit) select 1;

_temparrayLghVeh = ([_fazioneESS] call ESS_fnc_getunit) select 2;

_temparrayHvyVeh = ([_fazioneESS] call ESS_fnc_getunit) select 3;

_temparraywnbarracks = ([_fazioneESS] call ESS_fnc_getunit) select 4;

	
// Spawn of patrolling units
for "_i" from 1 to _numFT do {
	sleep _TempSpawn;
	_p1 = [_ESSAreaMkr] call SHK_pos;
		
	sleep _TempSpawn;
	_p2 = [_ESSAreaMkr] call SHK_pos;
		
	sleep _TempSpawn;
	_p3 = [_ESSAreaMkr] call SHK_pos;
		
	sleep _TempSpawn;
	_p4 = [_ESSAreaMkr] call SHK_pos;
		
	sleep _TempSpawn;
	_p5 = [_ESSAreaMkr] call SHK_pos;
		
	sleep _TempSpawn;
	_nFT = floor(random _unitsXteamMax);
	private _EnemyFireTeam = [];
	for "_k" from 0 to _nFT do {
		_EnemyFireTeam pushBack (selectRandom _temparrayUn);
	};
	null = ["O_G_Offroad_01_F",0, _EnemyFireTeam, [_p1,_p2,_p3,_p4,_p5],_sideInd] execVM "ESS_system\functions\ESS_Enemy_patrol_V2.sqf";
		
	sleep _TempSpawn;
};


// Spawn of units in buildings
for "_i" from 1 to  _groupInBuild do {
	sleep _TempSpawn;
	_pB = [_ESSAreaMkr] call SHK_pos;
	_grpB = createGroup [_sideInd, true];
	for "_j" from 0 to floor(random(_numUnitInBuild)) do {
		_UnB = _grpB createUnit [selectRandom _temparrayUn, _pB, [], 0, "FORM"];
		[_UnB] join _grpB;
	};
	0 = [_pB, units _grpB, 50,false,false,true,false] execVM "ESS_system\functions\Zen_OccupyHouse.sqf";
};


// Spawn of static turrets
for "_i" from 1 to  _NumStatic do {
	sleep _TempSpawn;
	_pC=[_ESSAreaMkr,50] call ESS_fnc_findSafePos;
	_staticOBJ = createVehicle [selectRandom _temparrayStc, _pC,[], 0,"FORM"];
	wn_enemy_static append [_staticOBJ];
	_grpC = createGroup [_sideInd, true];
	_UnC = _grpC createUnit [selectRandom _temparrayUn, _pC, [], 0, "FORM"];
	[_UnC] join _grpC;
	_UnC moveingunner _staticOBJ;
};


// Spawn of light vehicles
if (_patlght == 0) then {
	for "_i" from 1 to _NumLghVeh do {
		sleep _TempSpawn;	
		_pD = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;
		sleep _TempSpawn;
		_VehLghClass = selectRandom _temparrayLghVeh;		
		_VehLgh = createVehicle [_VehLghClass, _pD, [], 0, "NONE"];
		wn_enemy_light append [_VehLgh];
		_grpD = createGroup [_sideInd, true];	
		_dvrD = _grpD createUnit [selectRandom _temparrayUn, _pD, [], 0, "FORM"];
		_gnrD = _grpD createUnit [selectRandom _temparrayUn, _pD, [], 0, "FORM"];
		[_dvrD,_gnrD] join _grpD;
		_dvrD moveInDriver _VehLgh;	
		if ((!isNull gunner _VehLgh) || (_VehLgh emptyPositions "gunner">0)) then {_gnrD moveInGunner _VehLgh;} else {_gnrD moveincargo _VehLgh;};
		_chance = random 100;		
		if (_chance < _lghtProb) then {		
			_numCrewTot = ([_VehLghClass, true] call BIS_fnc_crewCount);
			_numCrew = ([_VehLghClass, false] call BIS_fnc_crewCount);
			_numCargo = _numCrewTot - _numCrew -1;
			for "_k" from 1 to _numCargo do {
			_crewD = _grpD createUnit [selectRandom _temparrayUn, _pD, [], 0, "FORM"];
			[_crewD] join _grpD;
			_crewD moveInAny _VehLgh;
			};
		};		
	};
} else {	
	for "_i" from 1 to _NumLghVeh do {
		sleep _TempSpawn;
		_pp1 = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;		
		sleep _TempSpawn;
		_pp2 = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;	
		sleep _TempSpawn;
		_pp3 = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;		
		sleep _TempSpawn;
		_pp4 = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;		
		sleep _TempSpawn;
		_pp5 = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;
		_VehLghClass = selectRandom _temparrayLghVeh;			
		_chance = random 100;		
		if (_chance < _lghtProb) then {
			_numCrewTot = ([_VehLghClass, true] call BIS_fnc_crewCount);
			_numCrew = ([_VehLghClass, false] call BIS_fnc_crewCount);
			_numCargo = _numCrewTot - _numCrew -1;
			_VehLgh = createVehicle [_VehLghClass, _pp1, [], 0, "NONE"];
			wn_enemy_light append [_VehLgh];
			_grpF = createGroup [_sideInd, true];	
			_dvrF = _grpF createUnit [selectRandom _temparrayUn, _pp1, [], 0, "FORM"];
			_gnrF = _grpF createUnit [selectRandom _temparrayUn, _pp1, [], 0, "FORM"];
			[_dvrF,_gnrf] join _grpF;
			_dvrF moveInDriver _VehLgh;	
			if ((!isNull gunner _VehLgh) || (_VehLgh emptyPositions "gunner">0)) then {_gnrF moveInGunner _VehLgh;} else {_gnrF moveincargo _VehLgh;};
			for "_k" from 1 to _numCargo do {
				_crewF = _grpF createUnit [selectRandom _temparrayUn, _pp1, [], 0, "FORM"];
				[_crewF] join _grpF;
				_crewF moveInAny _VehLgh;
			};
			_VehLgh limitSpeed 30;
			_EnGrp = group _VehLgh;
			_wpts = [_pp1,_pp2,_pp3,_pp4,_pp5];
			for "_k" from 0 to 4 do
			{
			_wp = _EnGrp addWaypoint [_wpts select _k, 0];
			_wp setWaypointType "MOVE";
			_wp setWaypointBehaviour "SAFE";
			_wp setWaypointCombatMode "YELLOW";
			_wp setWaypointSpeed "LIMITED";			
			};
			_wp = _EnGrp addWaypoint [[(_pp5 # 0)+2,(_pp5 # 1)+2,0], 0];
			_wp setWaypointType "CYCLE";			
		} else {
			null = [_VehLghClass,1, [selectRandom _temparrayUn,selectRandom _temparrayUn], [_pp1,_pp2,_pp3,_pp4,_pp5],_sideInd] execVM "ESS_system\functions\ESS_Enemy_patrol_V2.sqf";
		};		
		sleep _TempSpawn;
	};
};

// Spawn of heavy vehicles
if (_pathvy == 0) then {
	for "_i" from 1 to _NumHvyVeh do {
		sleep _TempSpawn;	
		_pE = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;
		sleep _TempSpawn;	
		_VehHvy = createVehicle [selectRandom _temparrayHvyVeh, _pE, [], 0, "NONE"];
		wn_enemy_heavy append [_VehHvy];
		_grpE = createGroup [_sideInd, true];	
		_dvrE = _grpE createUnit [selectRandom _temparrayUn, _pE, [], 0, "FORM"];
		_gnrE = _grpE createUnit [selectRandom _temparrayUn, _pE, [], 0, "FORM"];
		[_dvrE,_gnrE] join _grpE;
		_gnrE moveInDriver _VehHvy;	
		if ((!isNull gunner _VehHvy) || (_VehHvy emptyPositions "gunner">0)) then {_gnrE moveInGunner _VehHvy;} else {_gnrE moveincargo _VehHvy;};
	};
} else {	
	for "_i" from 1 to _NumHvyVeh do {
		sleep _TempSpawn;
		_ppv1 = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;		
		sleep _TempSpawn;
		_ppv2 = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;	
		sleep _TempSpawn;
		_ppv3 = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;		
		sleep _TempSpawn;
		_ppv4 = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;		
		sleep _TempSpawn;
		_ppv5 = [_ESSAreaMkr,50] call ESS_fnc_findSafePos;
		null = [selectRandom _temparrayHvyVeh,1, [selectRandom _temparrayUn,selectRandom _temparrayUn], [_ppv1,_ppv2,_ppv3,_ppv4,_ppv5],_sideInd] execVM "ESS_system\functions\ESS_Enemy_patrol_V2.sqf";
		sleep _TempSpawn;
	};
	};

	sleep _TempSpawn;

// Spawn Barracks
	wn_barracks = _numwnbarracks;
	
	for "_i" from 1 to _numwnbarracks do {
		sleep _TempSpawn;	
			_wn_b_marker = format ['Bunker_%1',_i];
			_loc = [_ESSAreaMkr, 50] call ESS_fnc_findSafePos;
			_marker = createMarker [_wn_b_marker,_loc];
			_wn_b_marker setMarkerType "mil_objective";_wn_b_marker setMarkerText "Barracks";_wn_b_marker setMarkerAlpha 0.4;_wn_b_marker setMarkerColor "ColorBlack";		
			wn_barracks_pos append _loc;
//			_wn_barracks = [_loc, random(360), call (compile (preprocessFileLineNumbers "comp\wn_barracks.sqf"))] call BIS_fnc_ObjectsMapper;
			_wn_barracks = createVehicle [selectRandom _temparraywnbarracks,_loc,[],0,"CAN_COLLIDE"];
			_wngrpb = createGroup [east, true];
			_wngrpb1 = _wngrpb createUnit [selectRandom _temparrayUn, _loc, [], 0, "FORM"];
			_wngrpb1 moveingunner _wn_barracks;
			
		};

I have added things on lines 8,11,12,96,112,150,189 and 216-232.   216-232 was my question.

 

I wanted to make barracks which I'm using   "  _wnbarracks_type = ["Land_BagBunker_01_large_green_F", "Land_BagBunker_Large_F"];"  code pulling from another script to randomly pick one or the other and placing it on a random position.   Ultimately when the barracks is destroyed it would give you points.

 

Good talk and  thanks for the motivation! 

Edited by wingnutwn
Maybe I should have given more information.

Share this post


Link to post
Share on other sites
Spoiler

use spoiler please (the eye in the edit bar)

 

The good news is that you can inflict damage on your bunkers...  even if you'll never see the difference.
I suggest you to apply this code on any bunker (blow it up with charges):

 

<anyBunkerVariable> addEventHandler ["handleDamage", {
  params ["_bunker", "", "_damage","","","","_instigator"];
  if (_damage > 0.86) then {
     format ["%1 has destroyed a %2",name _instigator, getText (configOf _bunker / "displayName")] remoteExec ["hint"];
     _bunker hideObjectGlobal TRUE};
     _damage
}];

 

Run it on server. As test, for any edited bunker, replace <anyBunkerVariable> by this  and write the code in init field of the object.

 

Share this post


Link to post
Share on other sites

Thank you for your expertise, I will give this a whirl and see if I can get it to work.   Again, thanks.

 

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

×