Forum Jump :

Author Message

Posts: 25

Level: Member

Country: us
Location: In the dungeon to hell!
Age: 33
In-game name:

#198885 Posted at 2018-03-29 21:48        
I'm trying to write a script to use a map click for initial positioning and once clicked on the map. Then, it should find all towns, cities, and villages within the given radius. It does do that, all that don't work currently is the trigger part of the script in the for loop. I can't seem to find out how, I've done a lot of searching on google and forums. Without any luck at all. Please help. If additional information is needed please, don't hesitate to ask.

EDIT: After the mission loads and is started, kill all of the guys in one town and you'll see what happens that is not supposed to happen. What it does is the very last marker's trigger is set off. Which is not always the right one.

EDIT 2: Nevermind, I figured it out... now it works as intended. Posting new code incase someone would like to use my code.

mapClick.sqf - Fully working now. But, this was the script that didn't work.
// choose a location to spawn enemies
private ["_maxDistance", "_pos", "_locations", "_towns", "_loc", "_markerName"];

_maxDistance = if (count _this > 0) then {_this select 0} else {200000};

// open map and let player select position
mapPosition = [];
openMap true;
clicked = false;
onMapSingleClick { mapPosition = _pos; clicked = true; };
waitUntil {clicked};
_pos = mapPosition;
mapPosition = nil;
openMap false;
onMapSingleClick {};

// get nearest towns
_towns = nearestLocations [_pos, ["NameVillage", "NameCity", "NameCityCapital"], _maxDistance];
for "_i" from 0 to (count _towns)-1 do {
	_loc = getPos (_towns select _i);
	_markerName = format ["town%1", _i+1];
	createMarker [_markerName, _loc];
	_markerName setMarkerBrush "Grid";
	_markerName setMarkerColor "ColorRed";
	_markerName setMarkerShape "Ellipse";
	_markerName setMarkerSize [120, 120];
	_grp = [getMarkerPos _markerName, east] call PRS_fnc_spawnInfantry;
	_patrol = [leader _grp, _markerName, "NOFOLLOW", "SHOWMARKER"] execVM "ups.sqf";
	statements = format ["hint 'Town Cleared'; ""%1"" setMarkerColor 'ColorGreen'; ""%1"" setMarkerBrush 'Solid';", _markerName];
	_trigger = createTrigger ["EmptyDetector", getMarkerPos _markerName];
	_trigger setTriggerArea [120, 120, 0, false];
	_trigger setTriggerActivation ["EAST", "NOT PRESENT", false];
	_trigger setTriggerStatements ["this", statements, ""];

init.sqf - Initialization script.
player globalChat "Initialising BIS Functions";
waituntil {!isnil "bis_fnc_init"};
PRS_fnc_spawnInfantry = compile preprocessFile "spawnInfantry.sqf";
player globalChat "Mission Initialisation Complete";

_spawnOpp = [] execVM "mapClick.sqf";
waitUntil {scriptDone _spawnOpp};
hintSilent "Mission Started";

spawnInfantry.sqf - Spawns groups of infantry from config files. (Used in mapClick.sqf)
private ["_pos", "_side", "_s", "_grpx", "_grps", "_grp", "_spawnGrp", "_y"];
_pos = _this select 0;
_side = _this select 1;
_faction = if (count _this > 2) then {_this select 2} else {"RU"};
_type = if (count _this > 3) then {_this select 3} else {"Infantry"};

_s = switch (_side) do {
	case resistance: { "Guerrila"; };
	case civilian: { "Civilian"; };
	default {str _side;};

_grpx = count(configFile >> "CfgGroups" >> _s >> _faction >> _type);
_grps = [];
for "_y" from 1 to _grpx-1 do {
	_grps = _grps + [(configFile >> "CfgGroups" >> _s >> _faction >> _type) select _y];
hint format ["Number of groups: %1\nSide choosen: %2", count _grps, _s];
_grp = _grps select floor(random count _grps);
_spawnGrp = [_pos, _side, _grp] call BIS_fnc_spawnGroup;

PS: Thanks in advance, for any help in solving this problem.

This post was edited by theplague1988 (2018-03-30 00:12, ago)

Philip "5n4k3" Simonson