Forum Jump :

Author Message


Posts: 23
Rank:


Level: Member

Country: us
Location:
Occupation: MECH. ENGR. STUDENT
Age:
In-game name: grimbah

 
#1 Posted at 2014-08-27 22:06        
     
id like to put a trigger at each city location on the map, but have no idea where to get started. I was thinking of using a loop that would create a trigger at each element of like a _locations array. Something like this:

_nearbyLocations = nearestLocations [ (position gamelogic0), ["nameCity"], 10000];
private ["_loopcount"];

_loopcount = 0;
{
	_nearbyLocationsPos = getPos (_nearbyLocations select _loopcount);
	_trgrname = format ["_trgr%1", _loopcount];
	//_trgr = _trgrname select _loopcount;
	_trgrname = createTrigger ["EmptyDetector", _nearbyLocationsPos];
	_trgrname setTriggerArea [300,300,0,false];
	_trgrname setTriggerActivation ["WEST","PRESENT",false];
	_trgrname setTriggerStatements ["this","hint 'trigger activated'","nul = execVM 'scripts\fillHouse.sqf'"];
	_loopcount = _loopcount + 1;

} forEach _nearbyLocations;

but its not working. the triggers dont spawn *SCRATCH*

Added 1 hour 34 minutes later:

alright. i have no idea. whats wrong here?
_nearbyLocations = nearestLocations [ (position gamelogic0), ["nameCity"], 10000];
private ["_loopcount"];

_loopcount = 0;
while {_loopcount < 9} do {
	_nearbyLocationsPos = getPos (_nearbyLocations select _loopcount);
	call compile format ["_trgrname%1 = createTrigger ['EmptyDetector', _nearbyLocationsPos];", _loopcount];
	_this setTriggerArea [300,300,0,false];
	_this setTriggerActivation ['WEST','PRESENT',false];
	_this setTriggerStatements ["this","hint 'trigger activated'","nul = execVM 'scripts\fillHouse.sqf'"];
	_loopcount = _loopcount + 1;

};
_loopcount = 0;
while {_loopcount < 9} do {
	call compile format ["_debugmarker%1 = createMarker [(format ['marker%1', _loopcount]), getPos _trgrname%1];", _loopcount];
	//= createMarker [(format ["marker%1", _loopcount]), position _trgrname];
	call compile format ["_debugmarker%1 setMarkerShape 'ICON';", _loopcount];
	call compile format ["_debugmarker%1 setMarkerType 'DOT';", _loopcount];
	call compile format ["_debugmarker%1 setMarkerColor 'ColorRed';", _loopcount];
	_loopcount = _loopcount + 1;
};

Added 6 hours 5 minutes later:

okay so i have it to the point where i spawn triggers on each of the locations in a city on any map with Capital Cities/Cities/Towns, but when the trigger runs the script it runs it on the last element of the townlist array. any insight? how do i extract the trigger element out of the array that was activated?

This post was edited by baconator (2014-08-28 06:42, ago)


Author Message

Crix  



Posts: 122
Rank:


Level: Member

Country: de
Location:
Occupation:
Age:
In-game name:

 
#2 Posted at 2014-08-28 11:42        
     
Hey,
do you actually want to run your script (fillHouse.sqf) on deactivation? Because right now it does.

See if this works for you:
private ["_arr"]; 
_arr = nearestLocations [(getPos gamelogic0), ["nameCity"], 10000]; 
{
	private ["_trg", "_mrk"]; 
	_trg = createTrigger ["EmptyDetector", getPos _x]; 
	_trg setTriggerArea [300, 300, 0, false]; 
	_trg setTriggerActivation ["WEST","PRESENT",false];
	_trg setTriggerStatements ["this",(format ["locMrk_%1 setMarkerColor 'colorWest';", _forEachIndex]),"0 = execVM 'scripts\fillHouse.sqf';"];
	
	missionNamespace setVariable [format ["locMrk_%1", _forEachIndex], (createMarker [(format ["mrk_%1", random 10000]), getPos _trg])]; 
	_mrk = missionNamespace getVariable format ["locMrk_%1", _forEachIndex]; 
	_mrk setMarkerShape "ICON"; 
	_mrk setMarkerType "mil_DOT"; 
	_mrk setMarkerColor "colorRed"; 
}
forEach _arr; 

This post was edited by Crix (2014-08-28 11:49, ago)


Advertisement


Author Message


Posts: 317
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name: BrotherhoodOfHam

 
#3 Posted at 2014-08-28 13:09        
     
Alternatively you could use this as a starting point.

if (!isServer) exitWith {};
#define DEBUG
#define OFFSET 0

_locations = (nearestLocations [[0,0,0], ["NameCity", "NameVillage", "NameCityCapital"], 40000]);

{
	_xy = size _x;
	
	_trig = createTrigger ["EmptyDetector", position _x];
	_trig setTriggerArea 
	[
		(_xy select 0) + OFFSET,
		(_xy select 1) + OFFSET,
		direction _x,
		false
	];
	
	_trig setTriggerActivation
	[
		"WEST",
		"PRESENT",
		true
	];
	
	_trig setTriggerStatements
	[
		"this",
		"hint 'in area';",
		"hint 'not in area';"
	];
	
	#ifdef DEBUG
	_mkr = createMarker [format ["dmkr_%1", _forEachIndex], position _x];
	_mkr setMarkerShape "ELLIPSE";
	_mkr setMarkerSize 
	[
		(_xy select 0) + OFFSET,
		(_xy select 1) + OFFSET
	];
	#endif
} forEach _locations;

You could then change the trigger statements to whatever you want,
it seems to work for me.

Some delicious stuff:
3D marker script
Some WIP delicious stuff:
Modular Customization Interface

Author Message


Posts: 23
Rank:


Level: Member

Country: us
Location:
Occupation: MECH. ENGR. STUDENT
Age:
In-game name: grimbah

 
#4 Posted at 2014-08-28 22:43        
     
Crix:
Hey,
do you actually want to run your script (fillHouse.sqf) on deactivation? Because right now it does.

No lol wow.. big mistake. Thankyou.

# BrotherhoodOfHam : Alternatively you could use this as a starting point.

That code is really clean but its kind of hard to follow. What value is _x representing? Is it the index of the loop or is it the object that is initiating the script?

never mind lol i figured it out. now to add gamelogics and call the fillHouse.sqf script once the triggers activate.. oh boy =-O

im stoopid.. i dont need game logics to call the script. the trigger activation can call it *WALL*

Added 1 hour 33 minutes later:

okay so here is the error thats occuring when the trigger is activated:
Error in expression <'Logic' createUnit [getPos _this, group gamelogi>
  Error position: <createUnit [getPos _this, group gamelogi>
  Error 0 elements provided, 3 expected

and this is what is running from my missionStart.sqf script:
_trig setTriggerStatements
	[
		"this",
		"'Logic' createUnit [getPos _this, group gamelogic,'nul = this execVM ""LV\fillHouse.sqf""'];",
		""
	];

thanks to larrow fromt the BI forums i got it working!!! wooo!! when calling "this" from a trigger it will return false. you have to use thisTrigger. Where was that on the wiki?? I guess i have alot more to learn!! :-D

Added 3 hours 30 minutes later:

as an update, here is my script so far (ty BrotherhoodofHam @}->-- ):

if (!isServer or bcReady) exitWith {};

//#define DEBUG
#define OFFSET 0

player globalchat "Mission Setup Starting..";

gamelogic setPos [0,0,0];

_locations = (nearestLocations [[0,0,0], ["NameCity", "NameVillage", "NameCityCapital"], 40000]);

{
	_xy = size _x;

	_trig = createTrigger ["EmptyDetector", position _x];
	_trig setTriggerArea
	[
		(_xy select 0) + OFFSET,
		(_xy select 1) + OFFSET,
		direction _x,
		false
	];

	_trig setTriggerActivation
	[
		"WEST",
		"PRESENT",
		false
	];

	_trig setTriggerStatements
	[
		"this",
		"bcTriggerPos = getPos thisTrigger; 'Logic' createUnit [bcTriggerPos, group gamelogic, 'nul = [this] execVM ""scripts\bcMilitarize.sqf""']",
		""
	];

	#ifdef DEBUG
	_mkr = createMarker [format ["dmkr_%1", _forEachIndex], position _x];
	_mkr setMarkerShape "ELLIPSE";
	_mkr setMarkerSize
	[
		(_xy select 0) + OFFSET,
		(_xy select 1) + OFFSET
	];
	#endif

} forEach _locations;

bcReady = true;

This post was edited by baconator (2014-08-29 10:09, ago)


Author Message


Posts: 317
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name: BrotherhoodOfHam

 
#5 Posted at 2014-08-29 10:14        
     
Awesome glad to know it works now :-D

Some delicious stuff:
3D marker script
Some WIP delicious stuff:
Modular Customization Interface

Author Message


Posts: 23
Rank:


Level: Member

Country: us
Location:
Occupation: MECH. ENGR. STUDENT
Age:
In-game name: grimbah

 
#6 Posted at 2014-09-01 06:13        
     
another update to the setupTrigger.sqf :-D

// Called by init.sqf

// Gets a list of the towns from the map config and creates triggers at their location.

// Made by baconator with LOTS of thanks to BrotherhoodofHam

if (!isServer) exitWith {};

private ["_location", "_locations", "_locationPos", "_locationName", "_trig", "_trig2", "_xy", "_mkr", "_rndNum", "_rndNum2", "_cacheRadius", "_closeBuildings","_closeBuilding", "_closeBuildingPos", "_a", "_i", "_newCachePos", "_ammoCache", "_numOfCaches", "_badPos", "_badPos2","_ammoCacheArray","_presenceMkr"];

_locations = (nearestLocations [[0,0,0], ["StrongpointArea", "NameCity","NameVillage","NameCityCapital"], 40000]);

// the x value of the Strongpoint location you dont want a trigger.
_badPos = [8664.08,8345.58,8431.82,9072.83];

// name of city/capital/village you dont want a trigger.
_badPos2 = ["LoyManara","Jaza"];


_ammoCacheArray = [];
_presenceMkr = objNull;

{
	_location = _locations select _forEachIndex;
	_locationPos = position _location;
	_locationName = name _location;

	if (DEBUG == 1) then {hintSilent str _locationPos;};

	/* scratch
	position[] = {8664.08,2395.72}; AStrongpoint_LoyManara_01
	position[] = {8345.58,2434.09}; ""_02
	position[] = {8431.82,2980.07}; ""_03
	position[] = {9072.83,2696.97}; ""_04
	*/

	if (!((_locationPos select 0) in _badPos)) then {
		if (!(_locationName in _badPos2)) then {

			// create an enemy location at random town
			_rndNum = floor((floor random (count _locations)) / 3);
			_rndNum2 = floor random (count _locations);

			if (_rndNum > _rndNum2) then {

				_xy = size _x;

				// creates game object that executes a script
				_trig = createTrigger ["EmptyDetector", position _x];
				_trig setTriggerArea
				[
					(_xy select 0) + (paramsArray select 2) + OFFSET,
					(_xy select 1) + (paramsArray select 2) + OFFSET,
					direction _x,
					false
				];

				_trig setTriggerActivation
				[
					"WEST",
					"PRESENT",
					false
				];

				_trig setTriggerStatements
				[
					"this",
					"if (MISSION_READY) then {
						_bcTriggerPos = getPos thisTrigger;
						'Logic' createUnit
						[
							_bcTriggerPos, group gamelogic, 'nul = [this] execVM ""LV\militarize.sqf"";'
						]
					}",
					""
				];

				// creates a mkr when activated and changes that marker when its deactivated
				_trig2 = createTrigger ["EmptyDetector", position _x];
				_trig2 setTriggerArea
				[
					(_xy select 0) + (paramsArray select 2) + OFFSET,
					(_xy select 1) + (paramsArray select 2) + OFFSET,
					direction _x,
					false
				];

				_trig2 setTriggerActivation
				[
					"EAST",
					"PRESENT",
					true
				];

				_trig2 setTriggerStatements
				[
					"this",
					"
						if (isServer) then {
							if (_presenceMkr != objNull) then {deleteMarker '_presenceMkr';};
							_presenceMkr = createMarker ['_presenceMkr', position thisTrigger];
							_presenceMkr setMarkerShape 'ELLIPSE';
							_presenceMkr setMarkerSize [((paramsArray select 2) + OFFSET), ((paramsArray select 2) + OFFSET)];
							_presenceMkr setMarkerColor 'Color1_FD_F';
						};
					",
					"if (isServer) then {_presenceMkr setMarkerColor 'ColorIndependent';};"
				];

				// 33% chance there is a cache at this location
				if (floor(random 3) == 1) then {
					_cacheRadius = (_xy select 0) + (paramsArray select 2) + OFFSET;
					_closeBuildings = nearestObjects [position _x, ["building","house"], _cacheRadius];
					_closeBuilding = _closeBuildings select (floor random (count _closeBuildings));
					_closeBuildingPos = [];
					_a = 0;
					while { _a < (count _closeBuildings) } do {
						_closeBuilding = (_closeBuildings select _a);
						_i = 0;
						while { ((_closeBuilding buildingPos _i) select 0) != 0 } do {
							_closeBuildingPos set [count (_closeBuildingPos), (_closeBuilding buildingPos _i)];
							_i = _i + 1;
						};
						_a = _a + 1;
					};
					_newCachePos = _closeBuildingPos select floor(random count _closeBuildingPos);
					if (typeName _newCachePos == "ARRAY") then {

						_ammoCache = createVehicle ["Box_FIA_Ammo_F", _newCachePos, [], 0, "NONE"];
						_ammoCache setPosASL [(getPosASL _ammoCache select 0), (getPosASL _ammoCache select 1), ((getPosAsL _ammoCache select 2) + 1.4)];
						AMMO_CACHE_ARRAY = _ammoCacheArray + [_ammoCache];
						NUM_OF_CACHES = count _ammoCacheArray;

						if (DEBUG == 1) then {
							_mkr = createMarker [format ["cache%1", _forEachIndex], getPos _ammocache];
							_mkr setMarkerShape "ICON";
							_mkr setMarkerType "mil_dot";
							_mkr setMarkerColor "colorRed";
							hintSilent format["There are %1 caches", NUM_OF_CACHES];
						};
					};
				};

				// sets marker parameters based on location
				switch (toLower(type _location)) do {
					case "namevillage": {
						_mkr = createMarker [format ["village%1", _forEachIndex], getPos _x];
						_mkr setMarkerShape "ICON";
						_mkr setMarkerType "mil_unknown";
						_mkr setMarkerColor "ColorOPFOR";
						_mkr setMarkerText "Possible Enemy Camp";
					};
					case "namecity": {
						_mkr = createMarker [format ["city%1", _forEachIndex], getPos _x];
						_mkr setMarkerShape "ICON";
						_mkr setMarkerType "mil_unknown";
						_mkr setMarkerColor "ColorOPFOR";
						_mkr setMarkerText "Possible Enemy Town";
					};
					case "namecitycapital": {
						_mkr = createMarker [format ["capital%1", _forEachIndex], getPos _x];
						_mkr setMarkerShape "ICON";
						_mkr setMarkerType "mil_warning";
						_mkr setMarkerColor "ColorOPFOR";
						_mkr setMarkerText "Confirmed Enemy Activity";
					};
					case default {
						if (floor(random 10) < 6) then { // 60% strongpoint will be marked
							_mkr = createMarker [format ["strpt%1", _forEachIndex], getPos _x];
							_mkr setMarkerShape "ICON";
							_mkr setMarkerType "mil_triangle";
							_mkr setMarkerColor "ColorOPFOR";
						};
					};
				};

				// for debugging
				if (DEBUG == 0) then {
					_mkr = createMarker [format ["dmkr_%1", _forEachIndex], position _x];
					_mkr setMarkerShape "ELLIPSE";
					_mkr setMarkerSize
					[
						(_xy select 0) + (paramsArray select 2) + OFFSET,
						(_xy select 1) + (paramsArray select 2) + OFFSET
					];
					_mkr setMarkerDir direction _x;
					_mkr = createMarker [format ["dmkr2_%1", _forEachIndex], position _x];
					_mkr setMarkerShape "ICON";
					_mkr setMarkerType "mil_dot";
					_mkr setMarkerColor "colorRed";
					_mkr setMarkerText str _x;
				};
			};
		};
	};
} forEach _locations;

sleep 3;

MISSION_READY = true;


Author Message


Posts: 317
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name: BrotherhoodOfHam

 
#7 Posted at 2014-09-01 13:53        
     
wow this looks fantastic :-)

Some delicious stuff:
3D marker script
Some WIP delicious stuff:
Modular Customization Interface

Author Message


Posts: 105
Rank:


Level: Member

Country: us
Location:
Occupation: Marine
Age:
In-game name: shadowmarine578

 
#8 Posted at 2014-09-02 16:40        
     
oh cool does this work in MP as well, like on a dedicated server???

and what does this line do?
if (!isServer or bcReady) exitWith {};
i know the first half is checking if its on a server but the bcReady is where i am lost.
it looks awesome tho cant wait to try it out.


Author Message


Posts: 317
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name: BrotherhoodOfHam

 
#9 Posted at 2014-09-02 17:30        
     
You could just use the code I originally pasted, since I assume Baconator is using this as part of some other script.

Some delicious stuff:
3D marker script
Some WIP delicious stuff:
Modular Customization Interface

Author Message


Posts: 23
Rank:


Level: Member

Country: us
Location:
Occupation: MECH. ENGR. STUDENT
Age:
In-game name: grimbah

 
#10 Posted at 2014-09-06 03:19        
     
The "bcReady" is a boolean variable that turns off the loading screen after everything is setup. I added this because i would like to eventually make it dedicated server compatible but im no networking genius so we'll see where that road takes me lol this is actually more of an init script to call other scripts. Basically the framework for a larger "patrol ops-esque" type mission. It will get you all of the locations and create triggers there, while simultaneously creating caches but you would really need a main loop to keep an eye on the number of caches still alive. there are some major tweeks that im implementing (civvies and randomness) now but ill post the updates to git hub or something (with a link here)