Search the Community
Showing results for tags 'foreach'.
Found 10 results
-
optimization [SOLVED] 5 lines only. Can you do it with less?
thy_ posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
Hello, folks. Is there any chance you share a faster or more elegant way to write the same result below? Code goal: at the mission starts, search once all named markers and remove all found markers that aren't area markers (rectangles and ellipses), saving the result in a list for further purposes. Pretty sure even the first code line below could be smarter/complete. // Search through all markers on the map with the prefix "mark_" and append them in a list: _areaMarkersOnly = allMapMarkers select {_x find "mark_" isEqualTo 0}; // result example: ["mark_1", "mark_garbage", "mark_2"] but unfortunately including markers with unwanted shapes. { // forEach in _areaMarkersOnly: // It will be needed to identify what will be deleted later: _index = _areaMarkersOnly find _x; // If the marker (_x) is NOT rectangle and is NOT ellipse, so... if ( (markerShape _x != "RECTANGLE") AND (markerShape _x != "ELLIPSE") ) then { // delete this marker from my list: _areaMarkersOnly deleteAt _index; }; } forEach _areaMarkersOnly; SOLVED! Below, you see the code that works for me after the community advice: _acceptableShapes = ["RECTANGLE", "ELLIPSE"]; _prefix = "mark_"; if ( !_debug ) then { // Selecting only relevant markers: _areaMarkersOnly = allMapMarkers select { (_x find _prefix == 0) AND {(markerShape _x) in _acceptableShapes} }; } else { // For debugging purporses, the way to select the relevant markers here it is slightly different. Now selecting all markers shapes: _areaMarkersOnly = allMapMarkers select { _x find _prefix == 0 }; { // forEach _areaMarkersOnly: // _x index in the list, need it to delete _x from the list: _markerIndex = _areaMarkersOnly find _x; // if the marker has no the shapes acceptables, do it: if ( !((markerShape _x) in _acceptableShapes) ) then { // delete the marker from the list: _possibleMinefields deleteAt _markerIndex; // delete the marker from the map: deleteMarker _x; // and print this messages: systemChat format ["DEBUG > Marker '%1' has NO a rectangle or ellipse shape to be considered a area marker.", _x]; }; } forEach _areaMarkersOnly; }; -
Pretty sure I'm stepping through a basic question but, really, I've TRIED hard all this afternoon to find out on my own how to make the forEach understand the array content are trigger variable names already dropped in place via Eden Editor. myTriggersVarNames = [ "myTrg1", "myTrg2", "myTrg3" ]; while {true} do { // Doesn't work: { if (player inArea _x) then { systemChat "Player inside the trigger"; }; } forEach myTriggersVarNames; // Working fine: /* if (player inArea myTrg1) then { systemChat "Player inside the trigger" }; */ sleep 3; }
- 4 replies
-
- triggervarname
- foreach
-
(and 4 more)
Tagged with:
-
.sqf Scripting with Array + forEach + forEach into a forEach
thy_ posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
I need some help: my code is stuck in my own (low) understanding around array and forEach when they need/should work together. Below, may you kindly point out the mistakes and show the fixes? I already read a lot of BIS wiki looking for how to code forEach inside forEach, even it doesn't look so clever, feeling... private _drivers = [driver01, driver02, driver03]; private _cars = [car01, car02, car03]; While {true} do { // DRIVERS { // forEach _drivers start... if (alive _x) then // if the driver is alive, so... { if ((_x distance _targetMarker) <= 30) then // DONT KNOW BUT IM NOT SURE THIS IS RIGHT. ISN't IT? { if (lifeState _x == "HEALTHY") then // if the driver is healthy, so... { _x directSay _sound1; // the driver screams. if (!isNull objectParent _x) then // if the driver is onboard a vehicle, so... { hint "driver has a veh"; // show text on screen. }; }; }; }; } forEach _drivers; // repeat that for each driver. // CARS { // forEach _cars start... if (alive _x) then // if the cars alive, then... { if ((_targetMarker distance _x) <= 30) then // DONT KNOW BUT IM NOT SURE THIS IS RIGHT. ISN't IT? { <HERE EACH DRIVER> directSay _sound2; // I DONT KNOW HOW TO CALL ANOTHER ARRAY+FOREACH HERE. sleep 0.3; _something createVehicle getPos _x; // DONT KNOW BUT IM NOT SURE THIS IS RIGHT. ISN't IT? }; if ((damage _x) >= 0.1) then // if the car get damage, then... { hint "car got damage!"; // show the text on screen. }; }; } forEach _cars; // repeat that for each car. sleep 1; // a looping breath. }; // while next looping. -
well, i'm trying to create a ww2 scenery with parachute jump. And for that I'm using the IFA3_LIB mod. The C-47s from there have the normal sitting position and also the standing up position which is when you are about to jump. I wanted to make the player not have to worry about clicking anything when jumping, so I got this script so that the jump could be done alone: Now an important detail, this script works perfectly when the plane's crew is seated (in game they appear as: crew) But before the jump takes place/the above script runs, I put in another script that makes the entire crew that was seated to stand up, and therefore be in the standing up position. In this case, when the plane reaches the trigger with the jump script, everyone standing inside the plane is still inside the plane... :l I believe maybe that's why: since when they are standing they are apparently no longer considered "crew". But I don't know, I don't know much about scripts, I was wondering if there is another variety to use in forEach other than "crew" that works for this case... An example of all units jumping out of the plane except the pilot would work but I don't know how to do it. Challenge launched! xD Thanks in advance guys!
- 1 reply
-
- eden editor
- ifa3_liberation
-
(and 4 more)
Tagged with:
-
Race Circuit Script (aka learning to count)
wogz187 posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
This topic is solved. Clear courses by reaching the next marker. If you're looking for the module it's available here: Drive Link This is the test rig in the demo. Adding new marks and whole new courses is easy. From here on is the original topic, I need to learn how to count. I posted this the other day, with a plea to understand why it works when, in my estimation, it shouldn't really. Regardless. I set about to simplify ring counting. I don't like having one .sqf file for each ring course. I feel like 1 or 2 scripts should be able to do this. One file if somebody helps me to learn how to count. Two if this works: Determine which course and define ring marks with generic titles, ringCOURSE.sqf-- this example shows 2 courses with 3 rings each if (ringCHALL==1) then { ring1=ringMARK1_1; ring2=ringMARK1_2; //first course second mark ring3=ringMARK1_3; rings= []execVM "ringCLEAR.sqf"; }; if (ringCHALL==2) then { ring1=ringMARK2_1; ring2=ringMARK2_2; //second course second mark ring3=ringMARK2_3; rings= []execVM "ringCLEAR.sqf"; }; and then build a switchdo case for each ring, or a waitUntil loop, or... I don't know and that's the question. Keep in mind there is only one ring with one trigger attached to drive the ring clearing script(s). This is what it needs to do, ["task1",[currentRING,true]] call BIS_fnc_taskSetDestination; ringGOAL_1 setpos (getpos currentRING); The real trick in this is how to go from: ring1, ring2, ring3, to set the variable "currentRING" in sequence. Oh, boy! I hope that makes sense! -
I have recently encountered some odd behavior in one of my scripts. I thought I had a pretty good grasp of this command but it has stopped behaving in the usual way. consider the following: {_x setUnitPos "UP"}forEach units group squad1; In the past and indeed up until a few minutes ago in my script, this yielded the expected behaviour of each member of squad 1 standing up. Then I got a typerror . Type group, expected object. So then I removed the word group from the command: {_x setUnitPos"UP"}forEach units squad1; And NOW it works again. Does anyone know what is going on with this? Thanks for the help.
-
I am making a scenario where I need to have all the groups on the EAST side to change their behaviour. I tried to use foreach on multiple different ways but nothing seems to work. This is what I tried: { if (side _x == EAST) then { _x allowFleeing 0; _x setCombatMode "RED"; }; } forEach allgroups; { if (side _x == EAST) then { group _x allowFleeing 0; group _x setCombatMode "RED"; }; } forEach allUnits; Can someone help me? Thanks
-
Spawn protection for players and vehicles alike (dedicated server)
Asmodeuz posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
Hello, I'd like to have a protection zone (spawn protection) for both human players and vehicles (empty or not) inside a trigger area. This should work in dedicated server environment. I've tried two slightly different approaches and neither of them work well enough. The most current I'm trying to get to work is one where I placed a trigger for Independent side with the following attributes: Type: None Activation: Independent Activation Type: Present Repetable [Yes] Server Only [No] Condition this On Activation {(player) allowDamage false} forEach playableUnits; hint "Spawn protection enabled"; On Deactiavation {(player) allowDamage true} forEach playableUnits; hint "Spawn protection disabled"; While testing this works quite nicely. Leaving the trigger area on foot makes the player vulnerable to everything that can actually kill the player. But as long as the player stays inside the trigger area he/she will be invulnerable. Pretty basic stuff I guess. But there's a catch: if the player spawns a vehicle inside the trigger area, jumps in the vehicle for a short moment, then jumps out and leaves the trigger area on foot and as long as the vehicle stays inside the trigger area the player will be invulnerable. Why is this happening and how would I go on to fix it? Earlier I was trying to use another approach to this: Type: None Activation: Independent Activation Type: Present Repetable [Yes] Server Only [No] Condition ((vehicle player) in thisList) On Activation {(vehicle player) allowDamage false} Foreach thislist; hint "Spawn protection enabled"; On Deactiavation {(vehicle player) allowDamage true} forEach [allUnits, vehicles]; hint "Spawn protection disabled"; This worked as well as the first one: when the player moves out of the trigger area on foot he/she will become vulnerable. But as with the another approach spawning a vehicle and getting in produces awkward result: now even if the player drives out of the trigger area he will be invulnerable indefinitely. So all in all neither of the two approaches work well enough. Also both of the alternatives don't make vehicles invulnerable at all when situated inside the trigger area. Any pointers how to achieve player and vehicle invulnerability at the same time using a trigger?- 4 replies
-
- spawn protection
- vehicle
-
(and 3 more)
Tagged with:
-
apply or forEach (or maybe count)?
sarogahtyp posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
Hey guys, I just crawled the wiki for usefull commands and found apply in it. Correct me if Im wrong but I think its doing nearly the same as forEach if u not need that _forEachIndex variable. Is there another difference which i ve not seen and did anybody measure which command is faster? -
Hello, Hope all are well. I have run into a problem in a script. In the script the there is a piece that I am working to create some AI defenders for a random task.... For some reason this only runs for the first "_manType". I have not been able to see my mistake. I am sure I am missing something silly. Ideas? Thanks, dubl /***************************************************************** Create defenders ***************************************************************/ { _manType = _x select 0; _manName = _x select 1; _man = _manType createVehicle getMarkerPos "defend1"; if (_manName != "") then { (_man select 0) setVehicleVarName _manName; missionNamespace setVariable [_manName, (_man select 0)]; }; }Foreach[ ["B_soldier_LAT_F", "man1"], ["B_soldier_AR_F", "man2"], ["B_soldier_exp_F", "man3"], ["B_medic_F", "man4"] ];