View Full Version : [EDITING] Collection of ARPS published scripts and snippets

14-03-2012, 06:32 PM
I'll collect both the bigger scripts we come up with and those small nifty snippets in this thread. Feel free to post any small code bits as answers to this post. I'll hotlink them in the OP

Bigger scripts:

wave spawn script (http://www.rockpapershotgun.com/forums/showthread.php?3442-EDITING-Super-Duper-Simple-Wave-Spawn-Script)

civilian assassins (ALICE compatible) (http://www.rockpapershotgun.com/forums/showthread.php?3521-EDITING-Wolfenswan-s-random-and-not-so-random-armed-civilians-and-concealed-gunmen)

IED factory (http://www.rockpapershotgun.com/forums/showthread.php?2889-EDITING-Washington-s-IED-Factory-v0-7)

Bodyarmor for Players aka ASS (http://www.rockpapershotgun.com/forums/showthread.php?2523-EDITING-Body-Armour-for-players)

Code Snippets

Checking unit speed with speed vectors. (http://www.rockpapershotgun.com/forums/showthread.php?2578-EDITING-Checking-a-units-speed-using-speed-vectors)

Creating a burning ruin of an ingame building (http://www.rockpapershotgun.com/forums/showthread.php?3541-EDITING-Collection-of-ARPS-published-scripts-and-snippets&p=102098&viewfull=1#post102098) (or a complete town!)

Elegant Artillery barrage script (http://www.rockpapershotgun.com/forums/showthread.php?3541-EDITING-Collection-of-ARPS-published-scripts-and-snippets&p=102721&viewfull=1#post102721)


Add-Action Tutorial (http://www.rockpapershotgun.com/forums/showthread.php?2520-EDITING-AddAction-tutorial)

14-03-2012, 06:38 PM
Depending on the settings these two can destroy the framerate. Take care.
Also note that these won't work when testing locally, only on dedicated servers!
To make them work locally (but not on servers!) remove the if !(isServer) exitWith {}; part (but not it's contents).

Creating a burning ruin of a building:
Put down a game logic -> location over the building you want destroyed and put this code in it's init:

nul = [this] execVM "ws_burningbuilding.sqf";

ws_burningbuilding.sqf is:

// Burning buildings mini script
// By Wolfenswan: wolfenswanarps@gmail.com
// Feature: Destroys a selection of buildings and sets them on fire
// Usage:
// In the editor place gamelogics named burn, burn_1, etc on top of the buildings you want to destroy/see burn
// add object names to _firearray below
// [] execVM "ws_burningbuilding.sqf" in the init.sqf
// Customization:
// Change _minfirestrength if you want a bigger/smaller fire

private ["_firearray","_fire","_building","_firestrength","_burn","_pos","_minfirestrength"];

BIS_Effects_Burn=compile preprocessFile "\ca\Data\ParticleEffects\SCRIPTS\destruction\burn. sqf";

//All objects placed over a building, named accordingly
_firearray = [burn,burn_1,burn_2];
_minfirestrength = 5;

_pos = getPos _x;
_x setPos [_pos select 0, _pos select 1, 0.1];
_building = _pos nearestObject "Building";
_building setdamage 1;
_firestrength = _minfirestrength + (ceil (random 4));
_burn = [_x,_firestrength,time,false,false] spawn BIS_Effects_Burn;
} forEach _firearray;

see this entry (http://wiki.zspecialunit.org/index.php?title=ArmA_2_Mission_Editing_Code_Exampl es_and_Hints#Burn_that_stuff.21) for an explanation of the parameters

for only a ruin without fire it's enough to create a logic over the building and put in it's init:

(getPos this nearestObject "Building") setdamage 1;


Destroying a complete city AND setting it on fire:
Create a logic in the center of the town you want to destroy and put

nul = [this,500,50,100] execVM "ws_cityinruins.sqf"; in the init

Note: Locality for this needs further testing, it might not be identical for all clients.

The ws_cityinruins.sqf:

// City in ruins mini script
// By Wolfenswan: wolfenswanarps@gmail.com
// Feature:
// Destroy a random selection of buildings and sets them on fire
// Usage:
// In the editor place a gamelogic with [this,300,50,50] execVM "ws_cityinruins.sqf" in the init.sqf
// Adjust values accordingly
// Customization:
// Second Number: radius around the gamelogic where buildings are affected
// Third number: chance in 100 that a building in the radius is destroyed
// Fourth number: chance in 100 that a destroyed building is burning
// Note:
// Not JIP-compatible

private ["_center","_radius","_destructometer","_firechance","_buildings","_count","_firestrength","_minfirestrength","_firearray","_destroyarray"];

BIS_Effects_Burn=compile preprocessFile "\ca\Data\ParticleEffects\SCRIPTS\destruction\burn. sqf";
_center = _this select 0;
_radius = _this select 1;
_destructometer = _this select 2;
_firechance = _this select 3;

_minfirestrength = 5;
_buildings = nearestObjects [_center, ["building"], _radius];
_count = count _buildings;
_destroyarray = [];
_firearray = [];

if (isServer) then {
for "_i" to _count do {
if (round random 100 <= _destructometer) then {
_building = _buildings select _i;
_destroyarray = _destroyarray + _building;
if (round random 100 <= _firechance) then {
format ["_fire%1",_i] = "LocationLogic" createVehicle (getPos _building);
_firearray = _firearray + format ["_fire%1",_i];
ws_firearray = _firearray; publicvariable "ws_firearray";
ws_destroyarray = _destroyarray; publicvariable "ws_destroyarray";

waituntil {(!isNil "ws_destroyarray")};

{_x setdamage 1;} forEach ws_destroyarray;
_firestrength = _minfirestrength + (ceil (random 4));
_burn = [_x,_firestrength,time,false,false] spawn BIS_Effects_Burn;
} forEach ws_firearray;

16-03-2012, 02:33 AM
A simple but effective script to emulate artillery barrages without the need for placing actual units. It's highly customizable and all possible options are explained in the script itself further below.

To start it place markers for the targetlocations on the map and call
nul = [] execVM "ws_mortars.sqf"; during the mission. To end it use a trigger or a script to flag ws_shelling to false or exchange ws_shelling with a loopcounter in the script itself. Or remove the while wrap completely and call it every time you need something shelled to smithereens.


if !(isServer)exitWith {};
private ["_string","_targets","_shell","_frequency","_barrages","_shotsperbarrage","_extrabarrages","_extrashots",

//Define these variables to your leisure
_targets = ["mortartarget_1"]; //the stuff you want to be shelled, have to be markers
_shell = "ARTY_Sh_81_HE"; //type of shell.
_illumshell = "F_40mm_red"; //illumination round. if set to "" this is ignored, otherwise every barrage will be announced by one illumination round
_illumsleep = 20; //how long the illumination round lingers in seconds before the real rounds hit
_frequency = 1500; //frequency of target changing in seconds
_barrages = 3; //minium number of barrages fired on one target before change
_extrabarrages = 1; //Up to this many more barrages could be fired
_timebetweenbarrages = 30; //the time in seconds between each single barrage
_shotsperbarrage = 4; //minimum shots/shells that come down per barrage
_extrashots = 2; //Up to this many more shells could come down
_disperson = 100; //the disperson of shells (0 = all spot on)
_height = 250; //the minium height where the shell will spawn (250 is good)

//These are needed for the script itself, don't alter these
if (isNil "ws_shelling") then {ws_shelling = true;};

sleep 0.1;
while {ws_shelling} do {
_pos = getMarkerPos (_targets call BIS_fnc_selectRandom);
for "_i" from 1 to (_barrages + round(random(_extrabarrages))) do {
if !(isNil "_illumshell") then {_illum = createVehicle [_illumshell , _pos, [], _disperson, "NONE"];_illum setPos [getPos _illum select 0,getPos _illum select 1,_height + random 60];sleep _illumsleep;};
for "_y" from 1 to (_shotsperbarrage + round(random (_extrashots))) do {
_boom = createVehicle [_shell, _pos, [], _disperson, "NONE"];
_boom setPos [getPos _boom select 0,getPos _boom select 1,_height];
sleep 1;
sleep (_timebetweenbarrages + random(15));
sleep _frequency;

You could also change _targets to = [_this select 0] and then call the script with nul = ["mytarget"] execVM "ws_mortars.sqf"; with, for example, a radio trigger. This could be used in an offensive mission to weaken a target/an area once.

05-10-2012, 03:03 PM
This is a simple script to improve vehicle behavior. They won't bail because of a broken tire but they will when all guns are destroyed.
This script creates a loop for every crewed vehicle on the map, by default for all sides, and requires F2 (but can easily be adapted not to). It's not fully tested so bugs might occur.

Run it from the init.sqf

if !(isServer) exitWith {};
sleep 0.0001;
// ================================================== ==================================

// Before executing this script, we wait for the script 'f_setLocalVars.sqf' to run:

waitUntil {scriptDone f_setLocalVars};

// ================================================== ==================================

// _vehicles = vehicles;
_vehicles = f_var_vehicles; //f_var_vehicles_BLU f_var_vehicles_RES f_var_vehicles_OPF
_sleep = 1; //increase _sleep when using a lot of vehicles
_alloweddamage = 0.8; //damage allowed before the crew bails no matter what

_x allowCrewInImmobile true;
[_x] spawn {
_unit = _this select 0;
while {damage _unit < _alloweddamage && canFire _unit} do
sleep _sleep;
_unit allowCrewInImmobile false;
{_x action ["eject", _unit];} forEach crew _unit;
} forEach _vehicles;