Jump to content
Sign in to follow this  
flanker

SmokeShell place of impact script

Recommended Posts

Hi people.

Im new to the forums so please have some patience with me if i do something wrong...

I was trying to solve a problem of mine regarding script im working on.

Im working on a script that has to determine the place a smokeshell has landed:

I am providing the code for it:

_objectForEH = player;
objPos = getPos player;
_smokeShellHandler = _objectForEH addEventHandler ["Fired", {
   muzzleFired = _this select 2;
   ammoFired = _this select 4;
   projectileObj = _this select 6;
   tmpCount = 0;

   if (muzzleFired == "SmokeShellMuzzle") then{
       //Sleep does not work when in this context - it would have to execute a differrent script to work
       height = ((getPosATL projectileObj) select 2);
       while {height > 0.1} do {
           height = ((getPosATL projectileObj) select 2);
           tmpCount = tmpCount + 1;
       };
       landPosProj = getPos projectileObj;
       "Sign_Checkpoint" createVehicle landPosProj;
       hint "Smoke shell landed and marked!";  
   }else{
       hint "You have used a differrent weapon!";
   };
}];

The pseudologic is:

  1. Attach a fire event handler to the objewct being monitored
  2. Check if its a smoke shell that has been fired...
  3. Get the projectile height above the ground
  4. Loop till that height is above 0.1
  5. Get the position of the projectile before impact
  6. Place a sign object on that position (for debugging purpose)

The problem is: For some reason the hint at the end of the if is being executed right after the smokeshell leave soldiers hand, tmpCount is allways 10000 (this is a variable for debugging purposes), and player and projectile positions are slightly differrent but the sign object that should be placed near the position of impact is placed near the position of soldier throwing the smokeshell.

Its as if the loop was not executed at all but according to that variable it is.... the only thing that comes to my mind is that perhaps the tmpCount experienced an overflow? Previously i put a "sleep" command right before the first height reading like 3 seconds and i got a feeling that it was being skipped because next to the sleep i had a debugging hint which was displayed instantly...

Anyone any idea?

Oh and last thing: Arma 2 wiki - Event Handlers you are able to get an object of the projectile. Using debugging console i verified that indeed i got the object. So i assume that using the object and script that one should be able to monitor the current position of the projectile in the ballistic path towards the place of impact?

Any help is appreciated.

Share this post


Link to post
Share on other sites

As you noticed you can't use Sleep and the same applies to while, waituntil, the script just bypasses it so that's why the hint fires instantly.

You can get around that by either spawning the code or by placing it in a script and then execute that script from the EVH.

I made a few other changes.

"Sign_Checkpoint" spawned nothing

Used speed Check to make sure smoke shell wasn't moving

Removed some lines for easier reading

Used full version of createvehicle as it's more efficient.

_objectForEH = player;
objPos = getPos player;
_smokeShellHandler = _objectForEH addEventHandler ["Fired", {
   muzzleFired = _this select 2;
   ammoFired = _this select 4;
   projectileObj = _this select 6;

   if (muzzleFired == "SmokeShellMuzzle") then {   
     null=projectileObj spawn { 
      waituntil {speed  _this  == 0};
     _obj = createVehicle ["FlagChecked_F",getPos _this,[],0,"can_collide"];

       hint "Smoke shell landed and marked!";  
  }; } else {
       hint "You have used a differrent weapon!";
   }; 
}];

Share this post


Link to post
Share on other sites

Thank you for your guidance.

I will try it and hopefully it will work.

I personally don't see under the hood of the arma 2 engine so if you know why: could you please explain to me or guide me to a resource (other then BI wiki) why the loop doesn't work like that? From technical point of view i thought that it would create a separate thread and that could be interruptible with sleep and act as a normal process?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×