red_ned

[Development] DMS roaming mission (non-static)

25 posts in this topic

Ok several people have been asking about missions which aren't static and as I pointed out in those threads it can all be a bit of a pain in the arse to work out, but I have created a single roaming mission and hope to develop some further once I get into the way the relative mapping works for objects.

Although this mission works fine it was made to be a starting point to learn how each function works and I have used code from static missions and old A2 missions (as they had some relative positions in)

Installation is simple,

1. Copy this code into a file called newmedical.sqf

2. Copy the newmedical.sqf file into your a3_dms.pbo into the folder missions/bandit

3. Open the DMS config.sqf and find DMS_BanditMissionTypes then inside the list of missions just insert ["newmedical",5], onto a line (making sure the last mission doesn't have a comma) and remembering the number is chance to spawn.

Here is the code to copy:

Spoiler

/*
 Medical Outpost - reworked by [CiC]red_ned http://cic-gaming.co.uk
 based on work by Defent and eraser1
 Called from DMS_selectMission
*/

private ["_num", "_side", "_pos", "_OK", "_difficulty", "_AICount", "_group", "_type", "_launcher", "_staticGuns", "_crate1", "_vehicle", "_crate_loot_values1", "_missionAIUnits", "_missionObjs", "_msgStart", "_msgWIN", "_msgLOSE", "_missionName", "_markers", "_time", "_added", "_cleanup", "_base", "_base0", "_base1", "_base2", "_base3"];

// For logging purposes
_num = DMS_MissionCount;


// Set mission side (only "bandit" is supported for now)
_side = "bandit";


// This part is unnecessary, but exists just as an example to format the parameters for "DMS_fnc_MissionParams" if you want to explicitly define the calling parameters for DMS_fnc_FindSafePos.
// It also allows anybody to modify the default calling parameters easily.
if ((isNil "_this") || {_this isEqualTo [] || {(typeName _this)!="ARRAY"}}) then
{
 _this =
 [
  [10,DMS_WaterNearBlacklist,DMS_MinSurfaceNormal,DMS_SpawnZoneNearBlacklist,DMS_TraderZoneNearBlacklist,DMS_MissionNearBlacklist,DMS_PlayerNearBlacklist,DMS_TerritoryNearBlacklist,DMS_ThrottleBlacklists],
  [
   []
  ],
  _this
 ];
};

// Check calling parameters for manually defined mission position.
// You can define "_extraParams" to specify the vehicle classname to spawn, either as _vehClass or [_vehClass]
_OK = (_this call DMS_fnc_MissionParams) params
[
 ["_pos",[],[[]],[3]],
 ["_extraParams",[]]
];

if !(_OK) exitWith
{
 diag_log format ["DMS ERROR :: Called MISSION newmedical.sqf with invalid parameters: %1",_this];
};


// Set general mission difficulty - "hardcore","difficult","moderate", or "easy"
_difficulty = "difficult";


// Create AI
_AICount = 8 + (round (random 4));

_group =
[
 _pos,     // Position of AI
 _AICount,    // Number of AI
 "random",    // "random","hardcore","difficult","moderate", or "easy"
 "random",     // "random","assault","MG","sniper" or "unarmed" OR [_type,_launcher]
 _side      // "bandit","hero", etc.
] call DMS_fnc_SpawnAIGroup;

_staticGuns =
[
 [
  [(_pos select 0)+(5+(random 5)),(_pos select 1)+(5+(random 5)),0],
  [(_pos select 0) + -1*(5+(random 5)),(_pos select 1) + -1*(5+(random 5)),0]
 ],
 _group,
 "assault",
 "static",
 "bandit"
] call DMS_fnc_SpawnAIStaticMG;


// Create Crate
_crate1 = ["Box_NATO_Wps_F",_pos] call DMS_fnc_SpawnCrate;

// Create Buildings with positions relative to the spawn centre
_base0 = createVehicle ["Land_Medevac_house_V1_F",[(_pos select 0) +2, (_pos select 1)+5,-0.3],[], 0, "CAN_COLLIDE"];
_base1 = createVehicle ["Land_Medevac_house_V1_F",[(_pos select 0) - 24, (_pos select 1) -5,0],[], 0, "CAN_COLLIDE"];
_base2 = createVehicle ["Land_Medevac_house_V1_F",[(_pos select 0) - 17, (_pos select 1) -5,0],[], 0, "CAN_COLLIDE"];
_base3 = createVehicle ["Land_Medevac_house_V1_F",[(_pos select 0) - 10, (_pos select 1) -5,0],[], 0, "CAN_COLLIDE"];

//build string to make all bases at once
_base = [
   [_base0],
   [_base1],
   [_base2],
   [_base3]
  ];
// Select vehicle and position relative to centre trying to avoid buildings - its a none persistant vehicle so needs to be sold but you can change DMS_fnc_SpawnNonPersistentVehicle to DMS_fn_SpawnPersistentVehicle for a permenant one.
_vehicle = ["I_Truck_02_medical_F",[(_pos select 0) - 18, (_pos select 1) -15,-0.3],[], 0, "CAN_COLLIDE"] call DMS_fnc_SpawnNonPersistentVehicle;

// Set crate loot values - notice i listed medical items from which to select 6
_crate_loot_values1 =
[
 3,  // Weapons
 [6,["Exile_Item_InstaDoc","Exile_Item_Bandage","Exile_Item_Bandage","Exile_Item_Bandage","Exile_Item_Vishpirin","Exile_Item_Vishpirin","Exile_Item_Vishpirin","Exile_Item_Bandage","Exile_Item_Bandage","Exile_Item_Bandage","Exile_Item_Vishpirin","Exile_Item_Vishpirin","Exile_Item_Vishpirin"]],  // Items
 3   // Backpacks
];


// Define mission-spawned AI Units
_missionAIUnits =
[
 _group   // We only spawned the single group for this mission
];

// Define mission-spawned objects and loot values
_missionObjs =
[
 [_base]+_staticGuns,
 [_vehicle],
 [[_crate1,_crate_loot_values1]]
];

// Define Mission Start message
_msgStart = ['#FFFF00',"A field hospital is under attack! Go kill the attackers"];

// Define Mission Win message
_msgWIN = ['#0080ff',"Convicts freed the hospital and got free meds"];

// Define Mission Lose message
_msgLOSE = ['#FF0000',"The attackers killed the medics and stole everything!"];

// Define mission name (for map marker and logging)
_missionName = "Hospital Attack";

// Create Markers
_markers =
[
 _pos,
 _missionName,
 _difficulty
] call DMS_fnc_CreateMarker;

// Record time here (for logging purposes, otherwise you could just put "diag_tickTime" into the "DMS_AddMissionToMonitor" parameters directly)
_time = diag_tickTime;

// Parse and add mission info to missions monitor
_added =
[
 _pos,
 [
  [
   "kill",
   _group
  ],
  [
   "playerNear",
   [_pos,DMS_playerNearRadius]
  ]
 ],
 [
  _time,
  (DMS_MissionTimeOut select 0) + random((DMS_MissionTimeOut select 1) - (DMS_MissionTimeOut select 0))
 ],
 _missionAIUnits,
 _missionObjs,
 [_missionName,_msgWIN,_msgLOSE],
 _markers,
 _side,
 _difficulty,
 []
] call DMS_fnc_AddMissionToMonitor;

// Check to see if it was added correctly, otherwise delete the stuff
if !(_added) exitWith
{
 diag_log format ["DMS ERROR :: Attempt to set up mission %1 with invalid parameters for DMS_AddMissionToMonitor! Deleting mission objects and resetting DMS_MissionCount.",_missionName];

 // Delete AI units and the crate. I could do it in one line but I just made a little function that should work for every mission (provided you defined everything correctly)
 _cleanup = [];
 {
  _cleanup pushBack _x;
 } forEach _missionAIUnits;

 _cleanup pushBack ((_missionObjs select 0)+(_missionObjs select 1));
 
 {
  _cleanup pushBack (_x select 0);
 } foreach (_missionObjs select 2);

 _cleanup call DMS_fnc_CleanUp;


 // Delete the markers directly
 {deleteMarker _x;} forEach _markers;


 // Reset the mission count
 DMS_MissionCount = DMS_MissionCount - 1;
};


// Notify players
[_missionName,_msgStart] call DMS_fnc_BroadcastMissionStatus;

 

if (DMS_DEBUG) then
{
 (format ["MISSION: (%1) :: Mission #%2 started at %3 with %4 AI units and %5 difficulty at time %6",_missionName,_num,_pos,_AICount,_difficulty,_time]) call DMS_fnc_DebugLog;
};

This is my 1st attempt at this so still looking through but will try to explain parts of the code so others can give it a go in next post, and remember although it functions properly it isn't really that different to other missions yet

Edited by red_ned
7 people like this

Share this post


Link to post
Share on other sites

Ok so I am no full on coder and basically I try to understand how things are put together then look at how to manipulate bits to do things I want, so that means not everything I do is perfectly as intended by the mod designer but it usually seems to function as I want.

Here is what I saw in the code:

Quote

private ["_num", "_side", "_pos", "_OK", "_difficulty", "_AICount", "_group", "_type", "_launcher", "_staticGuns", "_crate1", "_vehicle", "_crate_loot_values1", "_missionAIUnits", "_missionObjs", "_msgStart", "_msgWIN", "_msgLOSE", "_missionName", "_markers", "_time", "_added", "_cleanup", "_base", "_base0", "_base1", "_base2", "_base3"];

As always anything you define needs to be listed and some group together other things.

E.G. I defined my 4 objects that I wanted to be spawned with mission (we can look at the relative positioning after)

Quote

// Create Buildings with positions relative to the spawn centre
_base0 = createVehicle ["Land_Medevac_house_V1_F",[(_pos select 0) +2, (_pos select 1)+5,-0.3],[], 0, "CAN_COLLIDE"];
_base1 = createVehicle ["Land_Medevac_house_V1_F",[(_pos select 0) - 24, (_pos select 1) -5,0],[], 0, "CAN_COLLIDE"];
_base2 = createVehicle ["Land_Medevac_house_V1_F",[(_pos select 0) - 17, (_pos select 1) -5,0],[], 0, "CAN_COLLIDE"];
_base3 = createVehicle ["Land_Medevac_house_V1_F",[(_pos select 0) - 10, (_pos select 1) -5,0],[], 0, "CAN_COLLIDE"];

but wanted them to be done at the same time so you wrap the _baseX in one expression:

Quote

_base = [
   [_base0],
   [_base1],
   [_base2],
   [_base3]
  ];

this means when it comes to the main spawning of the mission we just have to call _base and we get all the objects (easier when dealing with multiple objects as you just define _base4/5/6 and add into the combination expression.

we also require vehicles and machine guns

Quote

_vehicle = ["I_Truck_02_medical_F",[(_pos select 0) - 18, (_pos select 1) -15,-0.3],[], 0, "CAN_COLLIDE"] call DMS_fnc_SpawnNonPersistentVehicle;

this is a non-persistent vehicle but you could change that with DMS_fn_SpawnPersistentVehicle; 

Quote

_staticGuns =
[
 [
  [(_pos select 0)+(5+(random 5)),(_pos select 1)+(5+(random 5)),0],
  [(_pos select 0) + -1*(5+(random 5)),(_pos select 1) + -1*(5+(random 5)),0]
 ],
 _group,
 "assault",
 "static",
 "bandit"
] call DMS_fnc_SpawnAIStaticMG;

2 guns, using a little random positioning so it changes the mission setup a little each time, now define some AI

Quote

_AICount = 8 + (round (random 4));

_group =
[
 _pos,     // Position of AI
 _AICount,    // Number of AI
 "random",    // "random","hardcore","difficult","moderate", or "easy"
 "random",     // "random","assault","MG","sniper" or "unarmed" OR [_type,_launcher]
 _side      // "bandit","hero", etc.
] call DMS_fnc_SpawnAIGroup;

With a bit of a random number to change the amount. Ok so last thing is the crate

Quote

_crate1 = ["Box_NATO_Wps_F",_pos] call DMS_fnc_SpawnCrate;

_pos is the randomised centre of the mission, now fill crate

Quote

_crate_loot_values1 =
[
 3,  // Weapons
 [6,["Exile_Item_InstaDoc","Exile_Item_Bandage","Exile_Item_Bandage","Exile_Item_Bandage","Exile_Item_Vishpirin","Exile_Item_Vishpirin","Exile_Item_Vishpirin","Exile_Item_Bandage","Exile_Item_Bandage","Exile_Item_Bandage","Exile_Item_Vishpirin","Exile_Item_Vishpirin","Exile_Item_Vishpirin"]],  // Items
 3   // Backpacks
];

As its a medical mission I am asking the main items to spawn from a list, I hope after some more testing rather than multiple listings I may be able to do:

[6,[["Exile_Item_InstaDoc",2],["Exile_Item_Bandage",8],["Exile_Item_Vishpirin",8]], //select 6 from a max 2 instadoc, 8 bandage, 8 visprin

but I haven't tested that yet but will let you know as it would make it simpler (may even set it as a string in the top of the mission to make it easier for modifying)

lastly we need to call all the objects in to the mission on spawn with:

Quote

_missionObjs =
[
 [_base]+_staticGuns,
 [_vehicle],
 [[_crate1,_crate_loot_values1]]
];

I am hoping to get this file working in more of a template way so you can easily knock out a load more missions but will post what I get when it looks and functions as I expect.

Please feel free to comment and post anything you have regarding the roaming missions

3 people like this

Share this post


Link to post
Share on other sites
Advertisement

Interesting. I'm going to add this to my server and then use the admin tools to become invisible so I can observe the mission Ai behavior.

Share this post


Link to post
Share on other sites

Okay, I installed this and tested it. At the mission site the Ai are standing around much like a static mission. Do they move around? What makes it a roaming mission?

Share this post


Link to post
Share on other sites
12 hours ago, Snakeyes1 said:

Okay, I installed this and tested it. At the mission site the Ai are standing around much like a static mission. Do they move around? What makes it a roaming mission?

its a roaming mission in the way the mission can be anywhere on the map rather than in a static position so it doesn't matter which map you are running (i.e. its not a static mission and is bound to coordinates on a specific map).

I am currently testing: adding the buildings into a single variable to prevent having to create a variable per object, randomising the loot crate contents - while making it easier to customise and seeing if I can put a patrol around one of these missions in a vehicle.

The idea of this was purely to try to understand how the non-static missions are put together and how complex they could be without affecting server performance and then making a template  so other people can understand and build them and expand easily.

I have been ill so it went slower than I hoped but will show better ways to put them together, I hope, as I go

1 person likes this

Share this post


Link to post
Share on other sites

This is awesome red! I look forward to hopefully, many more!!!

Share this post


Link to post
Share on other sites

@red_ned

I understand. It's on our mission rotation so I will get to play it soon. Matter of fact, it just spawned in. :)

Share this post


Link to post
Share on other sites

this is what my current crate setup looks like which I am testing

Quote

// Create Crate type
_crate1 = ["Box_NATO_Wps_F",_pos] call DMS_fnc_SpawnCrate;

// Set crate loot values - trying to have setup area for crate
// whats in crate variable trying random numbers
_crate_weapons   = 3;
_crate_items   = ((random 5)+1);
_crate_item_list = [["Exile_Item_InstaDoc",((random 1)+1)],["Exile_Item_Bandage",((random 3)+1)],["Exile_Item_Vishpirin",((random 3)+1)]];
_crate_backpacks  = 3;

// setup crate iteself with items
_crate_loot_values1 =
[
 _crate_weapons,  // Weapons
 [_crate_items,_crate_item_list],  // Items + selection list
 _crate_backpacks   // Backpacks
];

Moved all the parts of the crate together to simplify finding them all, added a variable section so you can change numbers (could move this to the top of the file once ready to create a variable section for editing) and adding in more comments to keep track of things

2 people like this

Share this post


Link to post
Share on other sites

Ok to the mapping bit - part 1

I want a standard design which I can use 3 or 4 times (to add some variation into current missions so I can swap vehicle, buildings and loot to change it up depending on what type of mission I want, like medical, building, guns etc).

I decided on a ring of 12 buildings which I think is enough for what I need, 4 machine guns, 1 crate, 1 vehicle. (see screenshot).

I decided to build somewhere flat without any obstruction so went with salt flats on Altis, put down the crate as my centre point then edited the coordinates to fall exactly on a 100 and pointing exactly north, the simpler the initial centre the easier the maths becomes. I then plotted a building (the centre one in each side) adjusted it by eye then manipulated the cords to be as simple as possible, then copied the other buildings each side and made sure the relative N/S, E/W we as whole a number as possible but allowing for the position to the next construction in the side to fit properly (some things you just cant mess with). Saved it and exported to SQF.

This part is for the machine gunner positions:

initial positions

Quote

 ["Land_Pallet_MilBoxes_F",[23700,18900,0],0,[[0,1,0],[0,0,1]],false],
 ["O_HMG_01_high_F",[23695,18905,0],0,[[0,1,0],[0,0,1]],false],
 ["O_HMG_01_high_F",[23695,18895,0],0,[[0,1,0],[0,0,1]],false],
 ["O_HMG_01_high_F",[23705,18905,0],0,[[0,1,0],[0,0,1]],false],
 ["O_HMG_01_high_F",[23705,18895,0],0,[[0,1,0],[0,0,1]],false],

luckily we don't need anything except the XYZ parts so strip them out

Quote

 //centre point [23700,18900,0]
 [23695,18905,0]
 [23695,18895,0]
 [23705,18905,0]
 [23705,18895,0]

next make the maths work!

Take each x and y away from the centre point coordinate

Quote

 [+5,+5,0]
 [-5,-5,0]
 [+5,-5,0]
 [+5,-5,0]

now make it relative to X,Y chosen by mission _pos select 0 and _pos select 1

Quote

  [(_pos select 0) -5,(_pos select 1)+5,0],
  [(_pos select 0) -5,(_pos select 1)-5,0],
  [(_pos select 0) +5,(_pos select 1)+5,0],
  [(_pos select 0) +5,(_pos select 1)-5,0]

ok so that's now statically placed 5m from each corner of the box, but if they are always there then they can be easily seen and taken out so lets randomise them a little as we know they could easily move 3 or 4 metres in any direction  without colliding with the structures, but lets play this safe with 0 to 2m variations, the random number cant do + and - so we just have to be a little creative here with what is + and what is -

Quote

  [(_pos select 0) -(5-(random 2)),(_pos select 1)+(5-(random 2)),0],
  [(_pos select 0) -(5+(random 2)),(_pos select 1)-(5+(random 2)),0],
  [(_pos select 0) +(5+(random 2)),(_pos select 1)+(5+(random 2)),0],
  [(_pos select 0) +(5-(random 2)),(_pos select 1)-(5-(random 2)),0]

This should now have placed 4 guns around the centre area without coming into contact with the crate or the buildings.... I hope!

Once I finish testing and learning the next bits I will post, even if I fail horribly

2016-02-15_00001.jpg

2 people like this

Share this post


Link to post
Share on other sites

After a full day working on really odd bugs and such I will release something a little later tonight :)

Oh yeh, I got a patrol working and found a better way of pulling in the mapping, still a bit of a pain but less than having a variable for each item!

Edited by red_ned
3 people like this

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.