BIS_WF_AddUnitData

Description

Used to add units to a Warfare factory. If the unit already exists, the values will be updated.

Parameters:

Side – East, West, or Resistance
Type – “Barracks”, “Light”, “Heavy”, “Aircraft”, “WingedAircraft”, “Depot”.
Classname – Config classname (Example “USMC_Soldier” or “RU_Soldier”).
Cost – Cost of unit. Empty cost for vehicles.
Build time – Time in seconds for unit to be made.

Optional:

Points – Default: 0. Points earned towards increasing player rank when killing this unit.
Crew – Default: 1. Amount of crew for vehicle. Should only be 1-3 (Driver, Gunner, Commander).
Description – Default: Read from classname config
Image – Default: Read from classname config
Faction – Default: Read from classname config.

Notes

  • If setting barracks AND other factory type at game start then always set barracks first since it is used to calculate crew costs for vehicles.
  • In theory this function can be called any time during the mission to add/change the factory’s equipment list. However I noticed that the factory’s list doesn’t get refreshed. So if I change an existing units price the description gets updated and the unit will cost less, but the list of units will still show the original price. I think this is a client side issue.
  • If an Airport factory is synced to the Warfare module in the mission editor, any units added will show up on the equipment list. However when a unit is purchased it will sit on the queue and never be built. Units not modified/added by the function could still be purchased normally.
  • I haven’t tested this but instead of units, scripts can be added for purchase. Classname would contain the name of the script. Description and Image would then be required parameters.
  • calls function BIS_WF_ModifyUnitData

Example

west soldier cost: $100 build time: 5 seconds, rank points earned for killing: 3.
[West,”Barracks”,”USMC_Soldier”,100,5,3] Call BIS_WF_AddUnitData

See Adding Units to Warfare Factories

Adding Units to Warfare Factories

A while back I did a series of posts explaining how to add custom units to the Warfare modules’ Aircraft factory. see

It was long and involved and while correct, there is an easier way. So if you haven’t read those posts, read this one first and decide which one works for your mission.

The premise for this example is that you want to create a basically stock Warfare mission, but just want to add a CH-47 to the Aircraft Factory.

 

In The Mission Editor

Warfare Module Synced to USMC Rifleman

The first step is to insert a player unit (USMC Rifleman) and the Warfare module into the mission. As usual use F5 to sync the player to the module. Always make sure that the player unit is not grouped to the module. Note that I’m using the USMC Rifleman, as that unit is recognized by the module without any additional work on my part.

In the Warfare module’s initialization field, type the following code:

BIS_WF_Common SetVariable ["customInitMissionScript","InitMission.sqf"];

This will tell the module that I’m going to call a script (InitMission.sqf in this example) that will contain my custom initialization scripts. Save the mission then open up the text editor of your choice.

 

In The Text Editor

First create the file InitMission.sqf that we specified in the editor. This will contain some script telling the warfare module to call my custom init scripts. Cut and paste the following:

BIS_WF_Common SetVariable ["sidePlacement",[true,-1,-1]];
BIS_WF_Common SetVariable ["customInitClientScript",""];

BIS_WF_Common SetVariable ["customInitCommonScript","Init_Common.sqf"];

BIS_WF_Common SetVariable ["customInitServerScript",""];
BIS_WF_Common SetVariable ["customInitBasesScript",""];
BIS_WF_Common SetVariable ["customBaseLayoutsScript",""];
BIS_WF_Common SetVariable ["customTownsScript",""];

Note that the only script we actually want to call is Init_Common.sqf however if we don’t include the other blank script calls, the mission will hang on loading.

Next you will need to create a file called Init_Common.sqf that will add the CH-47 to the Aircraft factory.

 

Custom Init_Common.sqf

Even though we specified in the Warfare Module’s init that we were calling custom scripts, the module still goes through the motions and creates global variables, factions, factory equipment lists etc. exactly as if it were a stock warfare mission. Only once the module is completely initialized does it run our custom scripts, allowing us to overwrite/change the default settings.

One of the things the Warfare Module declares is a function called BIS_WF_AddUnitData, and we are going to use it to add our CH-47 to the equipment list. To do this, add the following code to your Init_Common.sqf

[West,"Aircraft","CH_47F_BAF",140,40,0,3,"","","USMC"] Call BIS_WF_AddUnitData;

Where:

  • West is the side we are going to add units to
  • Aircraft is the factory we are going to add units to
  • CH_47F_BAF is the class name of the unit we are adding
  • 140 is the cost of the unit
  • 40 is the build time in seconds
  • 0 is the points earned towards increasing player rank when killing this unit
  • 3 is the number of crew for the unit
  • the two sets of quotes “” are left blank; the module will use the description and image from the addon’s config
  • USMC is the faction that will be able to buy the unit.

And that is that. If I have made no typo’s I should see the CH-47 in my list of equipment when I run the mission.

Reference

BIS_WF_AddUnitData
See example mission below.

New Features on db’s Sandbox

Forums and Mission Repository

I’ve added a few new features to my little Sandbox.

The Arma Mission Repository

The mission repository is where I’m going to be putting all my sample missions, instead of having them linked here and there all over the blog. The cool thing though is people can upload missions as well.

 Up till now when people have questions about their missions I’ll usually get them to email it to me. That has sort of worked. Now though members can upload their missions and anyone can take a look at them and help out.

The only requirement is that you register on my site as a member. This should keep the ne’er-do-wells out.

So go ahead and upload a mission, then head over to the forums and let us know about it.

The Forums

I’ve been keeping the comments open on my blog posts instead locking them. This has worked out quite well. However… there is a tendency over time for the comments to drift away from the content of the post. On some topics the comments are longer than the post. So I setup the forums for discussion and I’m hoping that the comments will be used for things more specific to the post. We’ll see how it works out.

Again you can register an account on my Sandbox to comment, or you can sign in with your facebook, google, twitter and other accounts.

Leave a comment below and let me know what you think about all this.

Increasing AI Awareness with Locations

arma2OA 2012 AI Patrol

AI On Patrol

All stock Arma maps and most custom maps have locations hard coded into the Map data. These locations are classified by type and can tell your script about nearby towns, hills, vineyards etc.

Using the maps locations you can attempt to script some more strategic decisions for your AI. This could be of particular use if you have AI spawned randomly but want to generate them some useful, realistic waypoints.

To Illustrate this I’m going to build a simple script that will:

  1. find the locations that I’m interested in
  2. sort the locations by distance from the AI
  3. create waypoints to the locations
To start I’ve inserted an infantry group in the mission editor and placed the following script in the squad leader’s initialization:

_null = this execVM "findlocations.sqf"

This will call my script findlocations.sqf and pass a reference to the squad leader (this). Now I save my mission and alt-tab out to my trusty text editor to build my script.

The first two lines of my script look like this:

_pos = getPos _this;
_group = group _this;

This will create two local variables:  _pos holds the current position of the squad leader, _group will hold the name of the squad leaders group. We will need this to build waypoints for the group later.

Next I’m going to grab the positions of the nearest location types that I’m interested in.

The standard location types as listed in the biki are

Strategic
StrongpointArea
FlatArea
FlatAreaCity
FlatAreaCitySmall
CityCenter
Airport
NameMarine
NameCityCapital
NameCity
NameVillage
NameLocal
Hill
ViewPoint
RockArea
BorderCrossing
VegetationBroadleaf
VegetationFir
VegetationPalm
VegetationVineyard

 

I am only interested in two types of locations, “Strategic” and “StrongpointArea”. So I build an array of the location types I’m interested in:

_locations =  ["Strategic","StrongpointArea"];

nearestLocations calculates which location is closest to _pos (the current location of my AI squad leader) within a certain radius.

_myLocations = nearestLocations [_pos, _locations, 1000];

So in my example I’m grabbing all the “Strategic”,”StrongpointArea” locations within 1000m of my squad leader (as represented by _pos)  and stuffing them into the array _myLocations.

_myLocations is automatically is sorted from closest location to furthest, so all I need to do now is build a waypoint for my AI group and send them on their way.

_wp = _group addWaypoint [position (_myLocations select 0) , 0 ];
_wp setWaypointType "MOVE";

Where  (_myLocations select 0) is the first element of the _myLocations array – i.e. the closest location. I use the position of  that location to crate a waypoint for my ai _group.

If you put it all together my script looks like this:

_pos = getPos _this;
_group = group _this;

_locations = [“Strategic”,”StrongpointArea”];

_myLocations = nearestLocations [_pos, _locations, 1000];

_wp = _group addWaypoint [position (_myLocations select 0),0 ];
_wp setWaypointType “MOVE”;

 

So now, no matter where I place this group on the map they will automatically get assigned a waypoint to the nearest strategic or strongpoint location on the map.

 

Reference:

execVM
CfgLocationTypes
nearestLocations
addWaypoint

 

 

db’s Twitter Digest for 2012-07-02 to 2012-07-08