Jump to content
PCanas

Make enemy miss on purpose

Recommended Posts

Hi folks :)

 

Is it possible to make enemies shoot at you, but always miss? I wanted to make an "intro" of a mission, where you are taken by heli to the AO, and at arrival AAs shoot at the heli, but always miss. It's meant to create a scene, not to actually shoot down the heli.

 

Can it be made to be active only for specific vehicles? For example, two helis coming in, but only one gets shot, the other is "immune".
(notice I don't want to make the heli invicible, I want the enemy to miss)

 

Thanks for the help :)

Share this post


Link to post
Share on other sites

This is close to what you are asking for.  I used it on an AI static missle launcher that was targeting player zodiacs.  When fired, missle is detected and direction and speed of missle altered.  Tweak it to your liking.  shooter1 and shooter2 were the names of the static AI launchers placed in editor.

// **********************************************************************
// Alter path of missles
// **********************************************************************
{
    _x addEventHandler ["Fired", 
    {
        _null = _this spawn 
        {
            _missile = _this select 6;
            _vel = velocity _missile;
            _dir_modifier = -3.5 + random(6);
            if (_dir_modifier >= -1 or  _dir_modifier <= 1) then
            {
                _dir_modifier = _dir_modifier * 2;
            };
            _dir = (direction _missile) + _dir_modifier;
            _speed = speed _missile;
            _velX = velocity _missile select 0;
            _velY = velocity _missile select 1;
            _velZ = velocity _missile select 2;
            _speed = _speed / 3;
            _z_modifier = 2.5 +     random(3);
            _dir_modifier = _dir_modifier * 2;
            _missile setVelocity [_speed * sin(_dir), _speed * cos(_dir), (_vel select 2)+_z_modifier];
        };
    }];
} foreach [shooter1, shooter2];

 

Share this post


Link to post
Share on other sites

I'm kinda noob in this scripting stuff...

 

JohnnyBoy, where am I supposed to put that code? It only works with missiles? What if AA is a Cheetah or something like that?

 

Grumpy Old Man, what exactly does that do? I read it, but I didn't get it...

Share this post


Link to post
Share on other sites

I named 2 static launchers shooter1 and shooter2 in the editor.  And I placed that code in the init.sqf.  Note I am using the Fired EventHandler mentioned by his Royal Grumpiness.   You could take my code and simply delete the missile/bullet instead of altering its direction.  Use deleteVehicle to delete bullet or missle.

 

  • Like 1

Share this post


Link to post
Share on other sites

Altering the missiles direction is neat, didn't think of that!

@PCanas: If by AA you mean the autocannon vehicles you could use something like this:

AAVehicle1 addEventHandler ["Fired",{
params ["_vehicle","_weapon","_muzzle","_ammo","_magazine","_projectile"];
deletevehicle _projectile;
};

This will delete all fired projectiles, so they can't harm the chopper.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Grumpy Old Man said:

Altering the missiles direction is neat, didn't think of that!

@PCanas: If by AA you mean the autocannon vehicles you could use something like this:


AAVehicle1 addEventHandler ["Fired",{
params ["_vehicle","_weapon","_muzzle","_ammo","_magazine","_projectile"];
deletevehicle _projectile;
};

This will delete all fired projectiles, so they can't harm the chopper.

 

Cheers

 

But the projectiles are still visible?

Share this post


Link to post
Share on other sites
8 minutes ago, PCanas said:

But the projectiles are still visible?

If missle is deleted it is not visible.   For small arms fire, deleting projectiles is fine, as you still hear the shots and see the muzzle flashes.  For missles, deleting the projectiles is visually bad IMO.  For that I would alter missle direction.  I would also consider setting the player chopper to invincible (allowdamage=false).  Having bullets hit the chopper is good for immersion, and bullets shouldn't bring the chopper down anyway.  For missles, I would alter direction so you have near misses (visually exciting).

  • Like 1

Share this post


Link to post
Share on other sites
47 minutes ago, johnnyboy said:

If missle is deleted it is not visible.   For small arms fire, deleting projectiles is fine, as you still hear the shots and see the muzzle flashes.  For missles, deleting the projectiles is visually bad IMO.  For that I would alter missle direction.  I would also consider setting the player chopper to invincible (allowdamage=false).  Having bullets hit the chopper is good for immersion, and bullets shouldn't bring the chopper down anyway.  For missles, I would alter direction so you have near misses (visually exciting).

 

That's the point ;) I'd like to have the tracers from AA autocanons visible but missing too, so mix of the delete projectile and change projectile direction. It wouldn't be very accurate to be continuously shot with an autocannon and not be destroyed...

  • Like 1

Share this post


Link to post
Share on other sites

Got it.  Then I think you need the near-miss technique for the auto-cannons.  With trial and error, you can determine how far to tweak direction of projectile for a near miss.  And by tweaking Z velocity lower or higher, you can alter near miss above and below your player chopper.

 

Another option is to attach some hidden targets to chopper (above, below, in front of , behind).  Then reveal the hidden targets to the auto-cannons and order them to fire.  You could setCaptive True on the player chopper so they don't target it.  I think that might be easier than calculating near miss trajectories.

 

My lawyer, @das attorney, posted here that when using an invisible target, you need to createVehicleCrew for the invisible target, so AI will fire on it.

  • Like 1

Share this post


Link to post
Share on other sites

Ha ha, I'm as much of a lawyer as Lionel Hutz !

 

I should have mentioned it sooner, but createVehicleCrew doesn't seem to work very well.

 

I reverted to creating a group like:

 

_tgtGrp = createGroup [west,true];

 

Then feeding it into an additional parameter into your doggy script (ex):

 

_leader = [objNull, _dogLeaderType, _packPos, false, _tgtGrp] call JBOY_dog_create;

 

Then JBOY_dog_create does this:

 

_dog = createAgent [_dogType, _pos, [], 0, "CAN_COLLIDE"];
_tgt = createVehicle ["Horde_InvisibleTargetMan2",_pos,[],0,"can_collide"];
_crew = _tgtGrp createUnit ["B_UAV_AI",_pos, [], 0, "can_collide"];
_crew assignAsGunner _tgt;
_crew moveInGunner _tgt;
_tgt attachTo [_dog,[0,0,1.1]];

 

"Horde_InvisibleTargetMan2" is just some class I made up in config but the normal invis targets can be done in this way as well.

 

Hope that helps (and thanks for the awesome script)!

 

  • Like 1

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

×