Jump to content
Sign in to follow this  
evans d [16aa]

Getting possition of smoke grenade

Recommended Posts

Well, simple question, I'm guessing not so simple answer. I want to enable the player to determine where a helo will land for extraction by throwing a smoke grenade and then the helo will land on or near its possition.

Is this possible and if it is, can someone let me know the code/script I'll need to write to do it?

Thanks.

Share this post


Link to post
Share on other sites

Short form pseudo code:

-Event Handler fired

-Figure out what type of object was fired

if(smokegrenade) then getPos _this select X

Then you got it! questions? Ask!

Share this post


Link to post
Share on other sites

You could use fired -eventhandler. Another way, if the extraction place is defined, to use nearobjects.

Share this post


Link to post
Share on other sites

Gonna write you an example when I got my arma running again.That's in about 2 hours.

Share this post


Link to post
Share on other sites

Place the following to your init.sqf for example:

TAG_fired =
{
    _unit = _this select 0; //The unit that fired the weapon
    _wpn = _this select 1; //The weapon that was fired
    _muzzle = _this select 2; //The muzzle of the weapon that fired
    _ammo = _this select 4; //The ammunition type (classname) of the fired projectile

    if (_wpn == "Throw" && _muzzle == "SmokeShellMuzzle") then //A smoke grenade was thrown
    {
         _smoke = (getPos _unit) nearestObject _ammo; //Get the object
         if (!isNull _smoke) then //Make sure the above didn't fail
         {
              hint format ["The smoke grenade is: %1", _smoke];
              //Some addition handling, do not forget to spawn/execVM if you want to use sleep/waitUntil!
         };
    };
};
unit addEventHandler ["fired", {_this call TAG_fired}];

Edited by Deadfast

Share this post


Link to post
Share on other sites

Doesn't it work with move an invisible H to the smoke?

Share this post


Link to post
Share on other sites

Perhaps I'm out of date, but I thought a thrown grenade didn't generate a fired EH?

Share this post


Link to post
Share on other sites
Perhaps I'm out of date, but I thought a thrown grenade didn't generate a fired EH?

It does. A grenade is thrown by "firing" the "Throw" weapon which does trigger the EH.

Share this post


Link to post
Share on other sites

No one can post that guide? If someone could I'd be really greatful. It'd be an awesome addition to my mission.

Share this post


Link to post
Share on other sites
Yeah, I'm not sure what I did wrong but the code didn't work. :(

Any other hints?

Whoops, missed this.

I tested the code and it worked, did you get any errors? They are not shown by default BTW, you must enable that via the -showScriptErrors startup parameter.

Share this post


Link to post
Share on other sites

Sorry, just seen how unclear that post is. When I say it didn't work I mean I couldn't get a chopper to fly over and land at the LZ. It's probably something really basic hiding in plain sight, but I'm really bad at this whole scripting/coding aspect of things.

Share this post


Link to post
Share on other sites

@Deadfast: Doesn't the newer updates on addEventHandler "fired" simplify obtaining the object/projectile by simply using _this select 6? Never tested with smoke though. Note: This requires a beta version though, it won't work with 1.54.

@Tankbuster: Afaik the firednear eventhandler isn't triggered by throw. Haven't tested though, just from my memory.

Share this post


Link to post
Share on other sites

@Tankbuster: Afaik the firednear eventhandler isn't triggered by throw. Haven't tested though, just from my memory.

I understood that to be the case, but others seem to think otherwise.

Share this post


Link to post
Share on other sites
@Deadfast: Doesn't the newer updates on addEventHandler "fired" simplify obtaining the object/projectile by simply using _this select 6? Never tested with smoke though. Note: This requires a beta version though, it won't work with 1.54.

It does indeed. I'd advise to ignore it for the beginning scripters until the final patch comes out though. If you were to ever release your mission to others you'd have to carter for people who run no/older beta and that's just an unnecessary level of complexity.

@Bashkire: Can you get the position of the smoke grenade? Could actually be a problem further on with forcing the helicopter to land.

Share this post


Link to post
Share on other sites

There may be other options.

Basically, the premise is that you can use the player's position and the findEmptyPosition (or its related commands) to find a proper landing area, and place the invisibleH there.

Now, you can do this by either a fired EH, testing for whether the smoke grenade has been thrown (it really won't matter where it ends up, the player's position will be the key), or you can use a radio call, or even an addaction to 'call' the helo.

This command is what I've used to find an appropriate place for a Huey:

_pos = getPos player;
_loc = _pos findEmptyPosition [20, 100, "UH1Y"];
_elZee = 'HeliHEmpty' createVehicle _loc;

(That's untested, BTW, but an idea of what you could do.)

Share this post


Link to post
Share on other sites

@Tankbuster: the issue with the fired event handler and smokeshells is that, for some reason, "throw" only fires an event locally, not MP.

If you wish to see how the old ArmA1 DMSmokeGrenade addon achives a similar effect to the one needed in this addon, then feel free to download & view the method in the old JTD_SmokeEffects available in my sig. Instead of spawning a viewblock, spawn an invisible heli landing pad :)

Share this post


Link to post
Share on other sites

Yeah, sorry, I'm completely lost when it comes to scripting and I've never dealt with this sorta thing before. It's really helpful what you're doing but I really need some kind of guide to tell me exactly what to do to get it to work.

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  

×