I had some time to work on this again tonight and I think we got it. Here is the basic scheme.
When the player activates the addAction to start the range session, the script only executes locally on the player's client. But, we need the popup script to only run on the server in order to make sure the animations work correctly. So, the addAction executes a script called startRange.sqf. This script doesn't actually start the popup script, but it alerts the server to start it with a public variable event handler. When a public variable (IRON_rangeStarted) is set to true and is broadcasted from the player's client to all other clients and the server the PVEH fires the popupscript. startRange.sqf also records the name of the player that activated the addAction for later use to make sure only that player sees the hint. So, the PVEH fires and only the server runs popup.sqf (via isServer). This script does whatever you want it to do (i.e. animate the popups, records hits, etc) and records the number of hits in another public variable called IRON_count. Now since IRON_count only changes on the server (where popup.sqf is run) we broadcast it to all other clients (to include the player who activated the addAction) which in turn fires another PVEH that whenever the hit count changes, it will show a hint with the number of hits only to the player who activated the addAction. I have tested this on a dedicated server with two clients connected and verified you only see a hint on whatever client activates the addAction. Here is all the code you need:
Editor: Put this in unit di_1's (or any unit's) init line:
actionId = this addAction ["Start Range", "startRange.sqf", [], 1, true, true, "", ""];
This is the addAction that starts the range as you described you wanted (I think).
Next, init.sqf:
// init.sqf
// Initilaize a global variable that will record who started a new range session. It will be given a real value and broadcasted publicly in startRange.sqf.
IRON_caller = objNull;
// Create a global variable that will determine when a new range session has started.
IRON_rangeStarted = false;
// Add a PVEH so if a new range session has started then execute popup.sqf.
"IRON_rangeStarted" addPublicVariableEventHandler {if (IRON_rangeStarted) then {_iron=[] execVM "popup.sqf"}};
// Create a global variable that will record the number of hits on target. The server and clients will start with 0.
IRON_count = 0;
// Add a PVEH to show the hint only to the player when the hit count changes.
"IRON_count" addPublicVariableEventHandler {if (player == IRON_caller) then {hintSilent format ["hits %1.", IRON_count]}};;
startRange.sqf:
// startRange.sqf
// parameters passed from the addAction "Start Range" in the unit's editor init line (not all variables are used).
_target = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_arguments = _this select 3;
// Record who initiated the new range session and broadcast it to the server and all clients.
IRON_caller = _caller;
publicVariable "IRON_caller";
// Indicate that a new range session has started and broadcast it to the server and all clients so a PVEH will start the popup script.
IRON_rangeStarted = true;
publicVariable "IRON_rangeStarted";
popup.sqf
*NOTE: I did not use the code in your script because without your mission and the range, targets, etc. set up properly I can't really test it...so, I used code that simulated a range session by increasing the hit count. Here it is:
//popup.sqf
// Only run this script on the server.
if (isServer) then
{
// Simulate targets popping up, and one gets hit.
IRON_count = 0; //Reset the hit count to 0.
IRON_count = IRON_Count+1; // Increase the hit count so we can see a result.
//After each round re-broadcast IRON_count so that tehe PVEH will fire and show a hint to the player on the range.
publicVariable "IRON_count"; // Broadcast the hit count and trigger a hint to the player.
// When the session is over reset the range.
IRON_rangeStarted = false; // Reset the range PV so if a new session is started the PVEH will fire again.
publicVariable "IRON_rangeStarted"; // Broadcast that the range is over.
};
I wanted you to see this so you could trace the methodology,this is untested, but I think your actual script should look like this I think:
_inc = 0;
_count = 0;
_targets = [t50,t75,t100,t125,t150,t200];
_many = count _targets-1;
if (isserver) then
{
nopop=true;
{_x animate["terc",1]} forEach _targets;
sleep 5;
while {_inc<40} do
{
_rnumber = random _many;
_rtarget = _targets select _rnumber;
_rtarget animate["terc", 0];
sleep 3;
if (_rtarget animationPhase "terc" > 0.1) then
{
IRON_count = _count+1; // Changed to make use of the PVEH
};
publicVariable "IRON_count"; // Broadcast the new hit count and trigger a hint to the player.
_rtarget animate["terc", 1];
sleep 1;
_inc = _inc + 1;
if ( _inc == 40) then
{
_command = format ["remotecommand=this; di_1 globalchat "" %1 out of : %2 "";",_count,_inc];
// Old ofp style hack
"RU_Citizen1" createUnit [[0,0,0], createGroup west, _command, 0, "PRIVATE"];
sleep(0.5);
deletevehicle remotecommand;
// When the session is over reset the range.
IRON_rangeStarted = false; // Reset the range PV so if a new session is started the PVEH will fire again.
publicVariable "IRON_rangeStarted"; // Broadcast that the range is over.
}
};//end of while loop
};//end of if-then statement
I am attaching the test mission I used to test it, just unzip it, open in the editor, and export it to your MP missions folder to test on a ded server (it will not work properly in the editor because of isServer and the PVEHs). There are two playable positions so you can see one get the hint and one doesn't. I hope this helps and good luck!
-Loyal