Jump to content
Nexo Ton

How to make an AI shoot or Simulate shots around me

Recommended Posts

Hey everyone,

I’m trying to script either of the following in Arma 3 - VR Editor:

 

AI Sniper:

  1. Spawn an AI with a loaded sniper rifle 50m away at 0° from the Player.
  2. Have it shoot one LRR (Sniper) shot in the air, wait 3 seconds, then despawn.
  3. Repeat this every 15°, increasing distance by 50m after completing a full 360° circle, until 3000m.

or-

Simulated Shots:

  1. Otherwise play sniper shot sounds from the same positions and directions without using an AI.

 

I'm not that experienced with Arma's scripting engine, but tried both with the help of ChatGPT.

While spawning the AIs worked, I can’t get them to fire reliably, they always reload first but then don't shoot.

The AI sound simulation also doesn't play a sound at all.

Any help or examples would be appreciated.

 

In case anyone wonders, I tried the AI Sound like this:

[] spawn {
    // Settings
    private _playerPos = getPos player;
    private _minDistance = 50;
    private _maxDistance = 3000;
    private _distanceStep = 50;
    private _angleStep = 15;
    private _sound = "A3_Sounds_F_Mark_Weapons_LRR_SingleShot"; // Sniper shot sound

    // Main logic
    for [{private _distance = _minDistance}, {_distance <= _maxDistance}, {_distance = _distance + _distanceStep}] do {
        for [{private _angle = 0}, {_angle < 360}, {_angle = _angle + _angleStep}] do {
            // Calculate position and angle in radians
            private _angleRad = _angle * (pi / 180);
            private _xOffset = _distance * cos _angleRad;
            private _yOffset = _distance * sin _angleRad;
            private _shotPos = [
                (_playerPos select 0) + _xOffset, 
                (_playerPos select 1) + _yOffset, 
                (_playerPos select 2)
            ];

            // Notify about the simulated shot
            player globalChat format ["Simulating sniper shot at Distance: %1m, Angle: %2°", _distance, _angle];

            // Play the sniper shot sound
            playSound3D [_sound, objNull, false, _shotPos, 1, 1, 500]; // Simulate sniper shot
            player globalChat "Sniper shot sound played.";

            // Delay before next sound
            sleep 3; // Wait 3 seconds before the next shot
        };
    };

    // Completion message
    player globalChat "Simulation completed!";
    hint "Simulation completed!";
};

 

Share this post


Link to post
Share on other sites

You can simulate bullets landing around you.

In my testing I started with smoke grenades landing around me because I can see the smoke.

Then I switched to night time and tried flares instead.

Once I figured that out, I switched to mortars. Very scary!

Then I tried other types of ammo and it all works.

Then I switched to bullets . A rain of bullets can kill you. 

 

Is that what you are after?

.

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Not sure I get wat you want here. Here is a script of a sniper firing all around player without hitting him.

mark being the name given to sniper.

Spoiler

[mark] spawn {
    params ["_marksman"];
    _logic = createGroup west createUnit ["Logic", [0,0,0], [], 0, "NONE"];
    while {alive _marksman} do {
        _random_Position = (getpos player) vectorAdd [(1 + random 3), (1 + random 3), (1.75 + random 3)];
        //_logic action ["useWeapon", player, player, 0]; // player fires single shot
        _marksman setUnitPos "MIDDLE";
        _marksman doWatch _random_Position;
        _marksman setBehaviour "COMBAT";//doTarget player; //isWeaponLowered = weaponLowered player;
        waitUntil {!(weaponLowered _marksman)}; sleep 1;
        _logic action ["UseWeapon", _marksman, _marksman, 1];
        sleep (5 + random 5);
    };
};

 

 

  • 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

×