No announcement yet.

[Script] Random Weapon Fire

  • Filter
  • Time
  • Show
Clear All
new posts

  • [Script] Random Weapon Fire

    // GeneralCarver Ambient Weapon Fire Script
    // by: GeneralCarver
    // Version: 1
    // Date: Nov. 1, 2009
    // Descrption: This script makes an A.I. unit repeatedly fire a weapon at a specific coordinate. Most aspects of the script can be customized, as described below. This script should be used only for a.i. you place around areas of your map for pure ambience and no combat function.
    How to use the script.
    Call it out in the following mannor in your mission init.sqf, a trigger or another script.
    Script callout format:
    scriptvariablename = [unitname, "MARKERNAME", heightabovemarker, magazinecapacity, "weaponname", "magazinename", maxnumberofshotperburst, maxdelaybetweenburstsinseconds, delaybetweenshots] execVM "scripts\ambientweaponfire.sqf";
    Callout explainations..
    scriptvariablename: just a normal variable, Any name you want.
    unitname: name of the a.i. unit that is doing the firing. Should be non-playable to cause any problems.
    "markername": name of reference marker in editor that a.i. will fire at.  in string format (i.e. "quoted text").
    heightabovemarker: regular number. ( 1, 3, 10 etc.) Is height in meters above ground for the "z" value of the coordinate the a.i. will watch.
    magazinecapacity: magazine capacity of the weapon the a.i. will be firing.
    weaponname: class name of the weapon the a.i. will fire. string format ("quoted text").
    "magazinename": magazine class name of the magazine in the weapon that the a.i. will fire. String value ("quoted text").
    maxnumberofshotsperburst: number. how many times the a.i. will shoot in a row during a burst of fire.
    maxdelaybetweenburstsinseconds: number. Max number of seconds to wait between bursts of fire. Actual value will be random and less.
    delaybetweenshots: number. Seconds (or milliseconds) between shots. (1, 10, 0.5, 0.2 etc.).
    // ==========================================
    // Define Variables
    // ==========================================
    private ["_unit", "_marker", "_heightoffset", "_magcap", "_weaponname", "_burstcnt", "_delay", "_counter", "_roundsleft", "_initialmagazinecount"];
    _unit = _this select 0;
    _marker = _this select 1;
    _heightoffset = _this select 2;
    _magcap = _this select 3;
    _weaponname = _this select 4;
    _magazineclass = _this select 5;
    _burstcnt = _this select 6;
    _delaymax = _this select 7;
    _shotdelay = _this select 8;
    _roundsleft = vehicle _unit ammo currentweapon vehicle _unit;
    _counter = 0;
    _delay = 0;
    _initialmagazinecount = count magazines vehicle _unit;
    // ==========================================
    // Begin Script
    // ==========================================
    // Have unit watch the marker.
    _unit dowatch [getmarkerpos _marker select 0, getmarkerpos _marker select 1, _heightoffset];
    sleep 5;
    // the following loop will shoot the gun in bursts repeatedly unitl the conditions are meet.
    while {((alive _unit) && (damage vehicle _unit < 1) && (gunner vehicle _unit == _unit))} do 
    	// if the weapon magazine is low, add another magazine (sets up infinite ammo for continous fire)
    	if (count magazines vehicle _unit < _initialmagazinecount) then
    		vehicle _unit addmagazine _magazineclass;
    	// While loop to fire repeatedly to create bursts of fire.
    	while {_counter <= _burstcnt} do 
    		vehicle _unit fire _weaponname;
    		_counter = _counter + 1;
    		sleep _shotdelay;
    	// reset counter, wait a random amount of time topped by the delay limit
    	_counter = 0;
    	_delay = floor(random _delaymax);
    	sleep _delay;


    KnyghtMare ~You could always tell the person holding the gun to your head you would like to play on a different server...



TeamSpeak 3 Server


Twitter Feed