Scripts

All scripts shown are for Virtual Battlespace 3 (VBS3) using their SQF scripting language.  Other script examples in their .sqf format can be found here.

I created this moveToPos script after I felt that the default avatar movement did not give me enough control.  I set it up so that you place hidden objects on the ground and the avatar will move from object to object.  There are two options to set.  The first is to allow the default game pathplanning and the second is whether or not the avatar should run.

//nul=[guy,[waypoint1,waypoint2,waypoint3,waypoint4],pathplanning_on,run] execVM “moveToPos.sqf”;

#include “\vbs2\headers\function_library.hpp”;

_guy = _this select 0;
_waypoints = _this select 1;
_pathplanning = _this select 2;

_loop = 0;
_waypointCount = count _waypoints;

unassignVehicle _guy;
doGetOut _guy;

_guy enableAI “move”;
_guy enableAI “anim”;
_guy setUnitPos “UP”;
sleep 0.1;
_guy setSpeedMode “LIMITED”;
_guy forceSpeed 1;
_guy allowDammage false;
_guy setExactMovement true;

if( !_pathplanning ) then {
_guy disableAI “pathplan”; };

if( run ) then {
_guy setSpeedMode “FULL”; };

while{_loop < _waypointCount} do {

_moveToPos = getPos (_waypoints select _loop);

_randPosNeg = [1,-1];
_randX = (random 3)*(_randPosNeg select (round (random 1)));
_randY = (random 3)*(_randPosNeg select (round (random 1)));
_randPos = [(_moveToPos select 0)+_randX,(_moveToPos select 1)+_randY,(_moveToPos select 2)];

_guy doMove _randPos;

waitUntil{ (_guy distance _randPos) < 4 };

_loop = _loop + 1;
};

This script creates an artillery round called an Excalibur a specified distance away from the target so that it impacts directly on the building.  It also deploys the fins on the round and spins the tail section.

_target = impact;
_gun = gun;

_center = getPos _target;
_gunPos = getPos _gun;

_round = “vbs2_ammo_sh_155_HE”;
//_round = “tcoic_m982_excalibur”;

_gunDir = [_gun,_target] call fn_vbs_dirTo;
_dist = 490;
_pos2 = [((_center select 0)-((sin _gunDir)*_dist)),(_center select 1)-((cos _gunDir)*_dist),(800)];
_shell = _round createVehicle _pos2;

_excalibur = “tcoic_m982_excalibur” createVehicle [0,0,0];
_excalibur attachTo [_shell,[0,0,0]];
_excalibur setDir ((getDir _shell) + 180);

sleep 0.1;

_shell disableGeo [true,true,true,true];

rock attachTo [_shell,[0,0.5,0]];
rock disableGeo [true,true,true,true];

_shell setdir _gunDir;
// [_shell,-90,0] call fn_vbs_setPitchBank;
[_shell,-65,0] call fn_vbs_setPitchBank;
_vel = 100;
_vel = [_vel * sin _gunDir, _vel * cos _gunDir, -130];
_shell setvelocity _vel;

_excalibur animate [“front_fin_1_1_r_x”, 1];
_excalibur animate [“front_fin_3_1_r_x”, 1];
_excalibur animate [“front_fin_2_1_r_y”, 1];
_excalibur animate [“front_fin_4_1_r_y”, 1];
_excalibur animate [“rear_fin_1_1_r_z”, 1];
_excalibur animate [“rear_fin_2_1_r_z”, 1];
_excalibur animate [“rear_fin_3_1_r_z”, 1];
_excalibur animate [“rear_fin_4_1_r_z”, 1];
_excalibur animate [“rear_fin_5_1_r_z”, 1];
_excalibur animate [“rear_fin_6_1_r_z”, 1];
_excalibur animate [“rear_fin_7_1_r_z”, 1];
_excalibur animate [“rear_fin_8_1_r_z”, 1];
_excalibur animate [“tail_section_rotation”, 1000];

_excalibur disableGeo[false,false,false,true];

  This script allows the user to force the avatar to use his binoculars to look at a specific target for a specific amount of time.

//nul=[guy,target,time] execVM “useBinos.sqf”;

#include “\vbs2\headers\function_library.hpp”;

_guy= _this select 0;
_target = _this select 1;
_time = _this select 2;

_pos = unitPos _guy;

_sleepTime = 0.1;

_guy lookAt _target;

sleep 1;

_guyWeapons = weapons _guy;

if( count _guyWeapons > 0 ) then {
if( _pos == “MIDDLE” ) then {

_guy playMove “AmovPknlMstpSrasWrflDnon_AwopPknlMstpSoptWbinDnon”;
_guy playMove “AmovPknlMstpSrasWrflDnon_AwopPknlMstpSoptWbinDnon_end”;
_guy disableAI “anim”;

_loop = 0;
while{ _loop < _time } do {

_guyDir = [_guy,_target] call fn_vbs_dirTo;
_guy setDir _guyDir;
sleep _sleepTime;
hint str _loop;
_loop = _loop + _sleepTime;
};

_guy playMove “AwopPknlMstpSoptWbinDnon_AmovPknlMstpSrasWrflDnon”;
_guy playMove “AwopPknlMstpSoptWbinDnon_AmovPknlMstpSrasWrflDnon_end”;
_guy enableAI “anim”;
};

if( _pos == “UP” ) then {

_guy playMove “AmovPercMstpSrasWrflDnon_AwopPercMstpSoptWbinDnon”;
_guy playMove “AmovPercMstpSrasWrflDnon_AwopPercMstpSoptWbinDnon_end”;
_guy disableAI “anim”;

_loop = 0;
while{ _loop < _time } do {

_guyDir = [_guy,_target] call fn_vbs_dirTo;
_guy setDir _guyDir;
sleep _sleepTime;
hint str _loop;
_loop = _loop + _sleepTime;
};

_guy playMove “AwopPercMstpSoptWbinDnon_AmovPercMstpSrasWrflDnon”;
_guy playMove “AwopPercMstpSoptWbinDnon_AmovPercMstpSrasWrflDnon_end”;
_guy enableAI “anim”;
};

if( _pos == “DOWN” ) then {

_guy playMove “AmovPpneMstpSrasWrflDnon_AwopPpneMstpSoptWbinDnon”;
_guy playMove “AmovPpneMstpSrasWrflDnon_AwopPpneMstpSoptWbinDnon_end”;
_guy disableAI “anim”;

_loop = 0;
while{ _loop < _time } do {

_guyDir = [_guy,_target] call fn_vbs_dirTo;
_guy setDir _guyDir;
sleep _sleepTime;
hint str _loop;
_loop = _loop + _sleepTime;
};

_guy playMove “AwopPpneMstpSoptWbinDnon_AmovPpneMstpSrasWrflDnon”;
_guy playMove “AwopPpneMstpSoptWbinDnon_AmovPpneMstpSrasWrflDnon_end”;
_guy enableAI “anim”;
};
} else {

_guy addWeapon “binocular”; sleep 1;
//_guy selectWeapon “binocular”;

if( _pos == “MIDDLE” ) then {

//_guy playMove “AmovPercMstpSnonWnonDnon_AwopPercMstpSoptWbinDnon”;
//_guy playMove “AmovPercMstpSnonWnonDnon_AwopPercMstpSoptWbinDnon_end”;
_guy playMove “AwopPercMstpSoptWbinDnon_AwopPknlMstpSoptWbinDnon_pst”;

_loop = 0;
while{ _loop < _time } do {

_guyDir = [_guy,_target] call fn_vbs_dirTo;
_guy setDir _guyDir;
sleep _sleepTime;
hint str _loop;
_loop = _loop + _sleepTime;
};

_guy playMove “AwopPercMstpSoptWbinDnon_AmovPercMstpSrasWnonDnon”;
_guy playMove “AwopPercMstpSoptWbinDnon_AmovPercMstpSrasWnonDnon_end”;
};

if( _pos == “UP” ) then {

_guy playMove “AmovPercMstpSnonWnonDnon_AwopPercMstpSoptWbinDnon”;
_guy playMove “AmovPercMstpSnonWnonDnon_AwopPercMstpSoptWbinDnon_end”;

_guy disableAI “anim”;

_loop = 0;
while{ _loop < _time } do {

_guyDir = [_guy,_target] call fn_vbs_dirTo;
_guy setDir _guyDir;
sleep _sleepTime;
hint str _loop;
_loop = _loop + _sleepTime;
};

_guy playMove “AwopPercMstpSoptWbinDnon_AmovPercMstpSnonWnonDnon”;
_guy playMove “AwopPercMstpSoptWbinDnon_AmovPercMstpSnonWnonDnon_end”;
_guy enableAI “anim”;
};

if( _pos == “DOWN” ) then {

_guy playMove “AmovPpneMstpSnonWnonDnon_AwopPpneMstpSoptWbinDnon”;
_guy playMove “AmovPpneMstpSnonWnonDnon_AwopPpneMstpSoptWbinDnon_end”;

_guy disableAI “anim”;

_loop = 0;
while{ _loop < _time } do {

_guyDir = [_guy,_target] call fn_vbs_dirTo;
_guy setDir _guyDir;
sleep _sleepTime;
hint str _loop;
_loop = _loop + _sleepTime;
};

_guy playMove “AwopPpneMstpSoptWbinDnon_AmovPpneMstpSnonWnonDnon”;
_guy playMove “AwopPpneMstpSoptWbinDnon_AmovPpneMstpSnonWnonDnon_end”;
_guy enableAI “anim”;
};

};

This script I created to quickly establish an assembly area type scene where Soldiers are actively going through specific animations (drinking from a canteen, stretching, coughing, etc). As some animations in VBS2 do not automatically repeat themselves, the script times the length of the animation on the first run through, and uses that time to repeat the animation. This script also checks the desired animation as to whether it requires a weapon or not. If not, it removes the weapon and places it on the ground. The script “personTalking” is also called to simulate these Soldiers having conversations with each other as they stand around.

//nul=[guy,animation] execVM “repeatAnimation.sqf”;

#include “\vbs2\headers\function_library.hpp”;

_guy = _this select 0;
_anim = _this select 1;

_weaponClass = primaryWeapon _guy;

_guy enableAI “anim”;

_guyPos = getPos _guy;
_weaponPos = _guyPos;
_guyDir = getDir _guy;
_dir = _guyDir + 90;
_dist = 0.25;
_pos = getPos _guy;
_animLength = 5;

if(( _weaponClass != “” ) && ( “Wnon” in _anim ) )then {

removeAllWeapons _guy;

_weaponPos = [((_guyPos select 0)+((sin _dir)*_dist)),(_guyPos select 1)+((cos _dir)*_dist),(_guyPos select 2)];
_weaponHolder = “weaponHolder” createVehicle (_weaponPos);
_weaponHolder addWeaponCargo [_weaponClass,1];
_weaponHolder setDir (_guyDir – 85);
_weaponHolder setPos _weaponPos;
};
_guy playMove _anim;

if( “Psit” in _anim ) then {

_animLength = 15 + random 5;

} else {

waitUntil{ (animationState _guy) == _anim };

_startTime = time;

waitUntil{ (animationState _guy) != _anim };

_endTime = time;

_animLength = _endTime – _startTime;

};

_guy disableAI “anim”;

nul=[_guy] execVM “personTalking.sqf”;

while{ alive _guy } do {

_guy switchMove _anim;

sleep (_animLength + random 3);
};

4 thoughts on “Scripts

  1. can these scripts just be copied and pasted into the develpers console or a text doc saved in the mp missions folder?

    1. The scripts listed here work best when in their own .sqf file in the mpmission folder. I usually call them, when needed, from the init.sqf script that VBS2 automatically runs at start-up. I’ve found that to be the most stable and reliable way to use scripts in VBS2. If you need any scripting help, don’t hesitate to contact me.

      1. Thank you, because I’m looking to talk to someone like yourself with an extensive back ground in VBS2. I use VBS2 to train military members and scripting is something that we don’t do much of, because no one knows a lot about scripting. We do small things, but I would like to expand some of things that I already do. Currently, I type [this allowDammage false;] in the initialization statements of every vehicle and unit I create. Or I give the unit or vehicle created a name, and then I replace this with the given name of that unit or vehicle and run the script from the developer’s console. Example, [vehicle1 allowDammage false;]. I’m looking for a way to apply the script without all the typing in the initialization statements. Although I haven’t tried it, I’m sure I could give them all names and run each script from an .sqf file within the mp missions folder. And I need to be able to remove the script while the simulation is in use. I’ve been trying to run the script on by playerSide but I can’t figure it out. I’m interseted in applying the script to the Blufor side, becuase we play the Opfor to drive the scenario. Can you help? By the way, VBS2 V.1.40, and I use a dedicated server.

      2. I can absolutely help you out. Email me at brian.t.hall1@gmail.com and I’ll send some example mission your way so you can see how we set VBS2 up to run with scripts. You can also check out facebook.com/TBOCSIMS for updates on our projects. I look forward to hearing from you.

Leave a reply to Brian T. Hall Cancel reply