mat10193 13 Posted April 27, 2018 Hello, I am having a bit of difficulty writing a script to do what i want it to do, and I have tried to search google, but I have not have much luck. I am trying to write a script that pops up a certain set of targets, that much i have down, but i need it to be able to detect when all enemy targets are down and if any one of the civilian targets gets shot. What I am having difficulty scripting is for the mission to be able to detect when certain targets are hit and when certain ones are not. any help would be greatly appreciated. Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted April 27, 2018 3 minutes ago, mat10193 said: Hello, I am having a bit of difficulty writing a script to do what i want it to do, and I have tried to search google, but I have not have much luck. I am trying to write a script that pops up a certain set of targets, that much i have down, but i need it to be able to detect when all enemy targets are down and if any one of the civilian targets gets shot. What I am having difficulty scripting is for the mission to be able to detect when certain targets are hit and when certain ones are not. any help would be greatly appreciated. Check out addMissionEventHandler and entityKilled. Also addEventHandler and its hit command, which runs every time the unit it's assigned to gets hit. Cheers 1 Share this post Link to post Share on other sites
mat10193 13 Posted April 28, 2018 so here is what i have so far: set1.sqf: Spoiler _set1 = ["tr_1","tr_2","tr_3"]; _hostage1 = ["th_1","th_2","th_3"]; _numberoftargets = 3; _myatttargethit = 0; _hostage1 addEventHandler ["Hit", {player execVM "scripts\shoothouse\hostagehit1.sqf"}]; _set1 addEventHandler ["Hit", {myatt_targethit = myatt_targethit + 1}]; waitUntil {myatt_targethit == _numberoftargets}; sleep 1; "Set complete!See instructor for future orders" remoteExec ["systemchat", 0]; sleep 1; but i keep getting this error message: Spoiler 14:17:50 Error in expression <ts = 3; _myatttargethit = 0; _hostage1 addEventHandler ["Hit", {player execVM "> 14:17:50 Error position: <addEventHandler ["Hit", {player execVM "> 14:17:50 Error addeventhandler: Type Array, expected Object 14:17:50 File C:\Users\MATTHEW\Documents\Arma 3 - Other Profiles\M%2eVespalec\mpmissions\popup_test.VR\scripts\shoothouse\set1.sqf, line 6 Share this post Link to post Share on other sites
7erra 629 Posted April 28, 2018 59 minutes ago, mat10193 said: _hostage1 addEventHandler ["Hit", {player execVM "scripts\shoothouse\hostagehit1.sqf"}]; _set1 addEventHandler ["Hit", {myatt_targethit = myatt_targethit + 1}]; Your syntax for addEventHandler is wrong. You are using an array where you should acutally use an object. What exactly are th_1-3 and tr_1-3? Share this post Link to post Share on other sites
mat10193 13 Posted April 28, 2018 they are groups of pop up targets, i want the script to be able to detect when one of them is hit Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted April 29, 2018 7 hours ago, mat10193 said: they are groups of pop up targets, i want the script to be able to detect when one of them is hit As of now they're strings and not variable names that could hold either an object or a group. You also can use forEach to execute the same command for multiple array elements, using the magic Variable _x: _set1 = [tr_1,tr_2,tr_3];//will only work if you have editor placed objects with the same names _hostage1 = [th_1,th_2,th_3]; _numberoftargets = 3; _myatttargethit = 0; { _x addEventHandler ["Hit", {player execVM "scripts\shoothouse\hostagehit1.sqf"}]; } forEach _hostage1; { _x addEventHandler ["Hit", {myatt_targethit = myatt_targethit + 1}]; } forEach _set1; waitUntil {myatt_targethit == _numberoftargets}; sleep 1; "Set complete!See instructor for future orders" remoteExec ["systemchat", 0]; Cheers Share this post Link to post Share on other sites
mat10193 13 Posted April 29, 2018 Thanks for the response, I will try this as soon as I get home! Share this post Link to post Share on other sites
mat10193 13 Posted May 2, 2018 alright, that part is working, now i am having a problem with the script ending once all of the enemy targets are hit. this is what i have: Spoiler _set1 = [tr_1,tr_2,tr_3]; _hostage1 = [th_1,th_2,th_3]; _numberoftargets = 3; _myatttargethit = 0; { _x addEventHandler [ "HIT", { (_this select 0) removeAllEventHandlers "HIT"; player execVM "scripts\shoothouse\hostagehit1.sqf"; } ]; } forEach _hostage1; { _x addEventHandler ["Hit", {_myatttargethit = _myatttargethit + 1}]; } forEach _set1; waitUntil {_myatttargethit == _numberoftargets}; sleep 1; { _x removeEventHandler ["Hit", 0]; } forEach _set1; sleep 1; [["Set complete! See an instructor for further orders!"],"systemChat",TRUE,FALSE] spawn BIS_fnc_MP; sleep 1; _myatttargethit = 0; Share this post Link to post Share on other sites
mat10193 13 Posted May 2, 2018 19 minutes ago, mat10193 said: alright, that part is working, now i am having a problem with the script ending once all of the enemy targets are hit. this is what i have: Reveal hidden contents _set1 = [tr_1,tr_2,tr_3]; _hostage1 = [th_1,th_2,th_3]; _numberoftargets = 3; _myatttargethit = 0; { _x addEventHandler [ "HIT", { (_this select 0) removeAllEventHandlers "HIT"; player execVM "scripts\shoothouse\hostagehit1.sqf"; } ]; } forEach _hostage1; { _x addEventHandler ["Hit", {_myatttargethit = _myatttargethit + 1}]; } forEach _set1; waitUntil {_myatttargethit == _numberoftargets}; sleep 1; { _x removeEventHandler ["Hit", 0]; } forEach _set1; sleep 1; [["Set complete! See an instructor for further orders!"],"systemChat",TRUE,FALSE] spawn BIS_fnc_MP; sleep 1; _myatttargethit = 0; Nevermind, I got it working, the code i have now is: Spoiler _set1 = [tr_1,tr_2,tr_3]; _hostage1 = [th_1,th_2,th_3]; _numberoftargets = 3; TAG_myatttargethit = 0; { _x addEventHandler [ "HIT", { (_this select 0) removeAllEventHandlers "HIT"; player execVM "scripts\shoothouse\hostagehit1.sqf"; } ]; } forEach _hostage1; { _x addEventHandler ["Hit", {TAG_myatttargethit = TAG_myatttargethit + 1}]; } forEach _set1; waitUntil {TAG_myatttargethit == _numberoftargets}; sleep 1; { _x removeEventHandler ["Hit", 0]; } forEach _set1; sleep 1; [["Set complete! See an instructor for further orders!"],"systemChat",TRUE,FALSE] spawn BIS_fnc_MP; sleep 1; TAG_myatttargethit = 0; Thank you for your help! Share this post Link to post Share on other sites
Harzach 2505 Posted May 2, 2018 Not sure using a global variable there is going to work for you. When you hit one target, the variable will be incremented for every target. Share this post Link to post Share on other sites
mat10193 13 Posted May 2, 2018 i am not going to have the targets pop back up after being shot Share this post Link to post Share on other sites