OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting Multiplayer => Topic started by: unknownx9 on 25 May 2011, 05:47:29

Title: Counting problem
Post by: unknownx9 on 25 May 2011, 05:47:29
Hello,

I have these two scripts I am working with:

Script 1:
private["_target","_instructor"];

_target = AR49;
_instructor = player;
endNumber = 0;
cnt = 0;

_instructor commandChat "Welcome to the AR range.";
sleep 2;
_instructor commandChat "Setting up course.";
sleep 2;
_instructor commandChat "Ready";

_target animate["terc", 0];   

while{endNumber == 0}do
{
   _target addEventHandler ["hit",{cnt = cnt + 1;}];
   waitUntil {_target animationPhase "terc" != 0};
   _target animate["terc", 0];
};

if(endNumber != 0)exitWith{};

Script 2:
private["_target","_instructor"];

endNumber = 1;
_target = AR49;
_instructor = player;

_target animate["terc", 0];

_target removeEventHandler ["hit", 0];
_instructor commandChat format ["Targets hit: %1", cnt];
cnt = 0;
_instructor commandChat "Training complete";

The problem I am having is with the counting. When I finish firing on the target I am getting 11000+ count on the number of hits, which is not real based on a M249 "200" magazine round.

Any assistance would be much appreciated.
Title: Re: Counting problem
Post by: F2kSel on 25 May 2011, 15:30:13
this section is wrong it's assigning multiple eventhandlers to the target.

Code: [Select]
_target animate["terc", 0];  

while{endNumber == 0}do
{
   _target addEventHandler ["hit",{cnt = cnt + 1;}];
   waitUntil {_target animationPhase "terc" != 0};
   _target animate["terc", 0];
};


make it look like this
Code: [Select]
_target animate["terc", 0];  
   _target addEventHandler ["hit",{cnt = cnt + 1;}];

while{endNumber == 0}do
{
  waitUntil {_target animationPhase "terc" != 0};
   _target animate["terc", 0];
};

Also answered in the other forum.
Title: Re: Counting problem
Post by: unknownx9 on 26 May 2011, 02:15:25
Thanks.

I am having a problem now when I put it on a dedicated server. The counting works fine when hosted locally, but when I test it on a dedicated server the count always returns 0. Any ideas?