Sign up Latest Topics

  Author   Comment  

Avatar / Picture

Posts: 455
Reply with quote  #1 

These code snippets have been organized into sections, but please note that some may be able to be used within other groups and are not always limited to the use I have exampled.
If I find anymore I will update this post, so check back often.

To place an unit or an object in this case on the map at a specific height use this in the on Activation box,the "5" being the height in meters, "this" could also be changed for the objects name. Typical use, to get units on the roof of a building maybe?, to stack objects, like making a sandbag wall?, placing static Mg's and guns correctly?

The give a unit unlimited ammunition use this in its init box (possible use, to stop AI running out in the middle of a fight):-

this addeventhandler ["fired", {(_this select 0) setvehicleammo 1}]

Unit or Object Init

this setPos [getpos this select 0, getpos this select 1, 5]

This following line forces a man object to stay standing, so they won't lie down as soon as they detect you.

You might want to use this for enemies in buildings, bunkers etc.

Unit Init

this setUnitPos "UP"

This on to have a unit kneeling down, maybe behind a sandbag wall

this setUnitPos "Middle"

this to have a unit lying down

this setUnitPos "Down"

To get a unit in a specific place in a building the 5 figure number is the map ID of the specific building (doesn't always work, but worth a try).

this setPos ((position this nearestObject 33559) buildingPos 7)

To have a unit move to a random postion within a building use this (the 7 is the number of positions a building might have, reduce or increase it to suit the building) Again this doesn't always work.

this setpos (nearestBuilding this buildingPos Random 7);

Clear a units backpack of gear (gives empty backpack)

clearMagazineCargo unitBackpack player

To find the class name of a unit, put following line in the init field of that unit

hint format ["%1", typeof this]

To have a message with the player who set it off's name in it

titletext [format ["%1 is here", name player], "Plain down"];

To remove all magazines from a player

{player removeMagazine _x} forEach magazines player;

To have a Unit move to the nearest vehicle use:-

player moveincargo (position player nearestObject "Car");

A couple of code lines to help put units into the trenches, the 1st is as used by OrganicHallucinosis and the 2nd used by HaZZarD. X in the 1st code is the height of the unit.

this setPosATL [getPosATL this select 0, getPosATL this select 1, X]; This SetUnitPos "UP"; DoStop this;

this setUnitPos "Up"; doStop this; this allowFleeing 0; this disableai "target"; this forceSpeed 0.5; this setBehaviour"combat";

On a mission where you have respawn, the amount of your dead bodies can build up, this line apparently removes the players dead bodies after 120 seconds, not tested though.
player addEventHandler ["respawn", {_this spawn {sleep 120; deleteVehicle (_this select 1)}}];


Use this code to name a group, this goes in the init of the group leader, in this example Grp1 will be the groups name.

Grp1 = group this;

Again this code is to save individually coding each unit in a group, just put this in the group leaders init, units still have to be individually moved in editor to each location in the trench.

{_x setUnitPos "UP"; doStop _x; _x allowFleeing 0; _x forceSpeed 0; _x setPosATL [getPosATL _x select 0, getPosATL _x select 1, 0.23];} forEach units group this;

To have all units in a group start in cargo of a vehicle (vehicle in the code change to the vehicle name), this codes goes in the group leaders init

{_x moveInCargo vehicle} forEach units group this;

The following forces a group to eject a vehicle. Plane1 = Name of Plane or Helicopter  and Man1 = name of the Group Leader, use = a trigger

{_x action ["EJECT",Plane1],unassignVehicle _x} foreach units Man1;

Trigger condition to check if all living members of a particular group are in a named vehicle (truck is called truck1 and the group is called Grp1)

{_x in truck1} count units Grp1 == count units Grp1;

Trigger condition to check to see if any member of a particular group is in a specific named vehicle (truck is named truck1 and group is called Grp1)

{_x in truck1} count (units grp1) >=  1;


To create a vehicle or object on a marker (class name and marker name reqired)

AIR1 = "LIB_FW190F8" createVehicle (getMarkerPos "Air1");

To create an vehicle or object on one of 3 random markers.

AIR1 = createVehicle ["LIB_FW190F8",getMarkerPos "marker1",["marker2","marker3"], 0, "NONE"]

To make a vehicle have unlimited fuel use this in it's init line:- (may be used to stop patrolling vehicles running out of fuel if present at start of a long mission)

nul = this spawn { waitUntil { if !(alive _this) exitWith {}; if (fuel _this < 0.25) then { _this setFuel 1 }; false } };

An addaction applied to a vehicle's init but is only available to the driver

act1 = this addAction ["menu name","your script",[1],0,false,true,""," driver _target == _this"];

add backpacks to vehicles and ammo boxes, the LIB bit is the class name of the back pack;

this addBackpackCargo ["LIB_backpack_us",2];

To open the tailgate of the Opel Blitz and a script that does it Open/Close tailgate script by BS

this animate ["doorzad_rotate",1];

To close it again

this animate ["doorzad_rotate",0];

To remove weapons and all items from the crew of a vehicle use this, vehicle1 being the name of the vehicle:-

{removeAllItems _x; removeAllWeapons _x}  foreach (crew vehicle1)

To remove all weapons from the crew of a vehicle and assign them new weapons, just change class names of weapons and mags to suit:-

{ removeAllWeapons _x; _x addWeapon "LIB_K98"; for [{i=0},{i<6},{i=i+1}] do { _x addMagazine "lib_5Rnd_792x57"}; reload _x; } forEach crew this;

To delete a vehicle and its crew use this line:-
{ deleteVehicle _x } forEach (crew vehiclename); deleteVehicle vehiclename;


To use the distance to an object as a condition for a trigger, try one of these individual lines:-

Unit distance object > 3 (greater than 3)
Unit distance object < 3 (less than 3)
Unit distance object >= 3 (Greater or equal to 3)
Unit distance object <= 3 (Less or equal to 3)

The following forces an object to be placed level and not following the land conture. If you add a building from the editor onto the map, this is useful. this code in the building/object init

this setVectorUp [0,0,0.01]

Use this version to place objects on their side

this setvectorup [0,0.1,0.01]

To make an object not get dammaged (e.g, a camo net to stop it falling down)

this addEventHandler ["HandleDamage", {false}];


To create a marker while mission is running (occupied is name of the marker created, marker1 is the position of an invisible marker that the new marker will be created on):-

marker = createMarker["Occupied", getmarkerpos "Marker1"];

marker setMarkerShape "ELLIPSE";

"Occupied" setMarkerSize [300, 300];

"Occupied" setMarkerColor "ColorRed";

Or (task1 being the name of an empty marker where you want the new visible marker to appear, Counter is the name of the created marker).

marker = createMarker["Counter", getmarkerpos "task1"];

marker setMarkerShape "icon";

"Counter" setMarkerType "mil_Arrow";

"Counter" setMarkerColor "ColorBlack";

"Counter" setMarkerText "Counter Attack";

"Counter" setMarkerSize [2, 2];

"Counter" setMarkerDir 135;


The following is used in a trigger to count the enemy left in an area, say you have 10 enemy and you want the trigger to activate when only 1 is left, basically when the count is less than 2. (This code goes in condition box of the trigger)

count thislist < 2;

To make sure a trigger is only activated by ground units put this in the an activation of the trigger

((vehicle player) in thisList) and ((getPos (vehicle player) select 2) < 2);

Trigger code to check if a unit has a particular backpack

Create a trigger with the following info:- Change FunkBag to the backpacks class name. (Funkbag in this example is the class name of the german Radio)

Settings: BLUFOR(Germany) / present / repeatedly


(typeOf unitBackpack player) == "FunkBag"

on Act.:

hint "textA" or your code

on Dea.:

hint "textB" or your code

We all know how difficult it is to actually kill a tank, with this code in the condition of a trigger it just waits for the tank to be out of action and the crew to bail. Name the tank tank1.

!canMove tank1 and  {alive _x} count crew tank1 == 0 or count crew tank1 == 0; 

Multiplayer trigger saftey net - triggers in multiplayer missions don't always behave as you would hope, due to triggers sometimes working on one client and not another, or doing the activation as many times as there is players. So one solution on mission critical triggers is to use the public variable. So to make sure a trigger works for all clients (players), this is a solution. For this we will use 2 triggers. Firstly make a trigger that activates when a condition is met (that condition is upto you) but for this example its when east is present.

1st Trigger:
- Condition:
East Present 

- OnActivation:
trig1Fired = True; publicVariable "trig1Fired"

If doesn't matter if the above trigger only activated on one players machine, because the public variable will send the message to all the others. Thus firing the 2nd trigger for all.

2nd Trigger:
- Condition:

- OnActivation:
hint "This will activate on all connected players machines"; [] exec "yourscript.sqf"


 To create a spawn protection in your base, so no team killing etc. Place an object in the editor, an invisible helipad is as good as any and name it NoKillZone. (basically creates an invisible shield of an approx 30m radius oround the helipad). Then place this code in your init.sqf:-

if (isServer) then 
_shield = "Lib_ProtectionZone_Invisible" createVehicle (position NoKillZone);


Posts: 106
Reply with quote  #2 


adds a bit of atmosphere to night missions.The trigger is designed that when player/enemy forces enter it it sends up a flare.I.E. "TRIPFLARE."
Goes like this
Place a trigger on the map 2metres wide by 10metres long make it for example
Activation: Germany  "present" "once" and for type "switch".

Name: pos

activation line   :  flare = "F_40mm_red" createVehicle [getPos pos select 0, getPos pos select 1, 250];

To make it more "realistic" you could have it synchronised with a cycle waypoint of a patroling force.

So what you have, is a flare fired off when somebody enters the trigger area and a patrol that goes in to investigate.Great for putting in gullies and such like!!

If you want more than one:

name:  pos1

activation line:  flare = "F_40mm_red" createVehicle [getPos pos1 select 0, getPos pos1 select 1, 250];   and so on.

Many thanks to Tay-uk for this, it's all his work.


Previous Topic | Next Topic

Quick Navigation:

Easily create a Forum Website with Website Toolbox.