Jump to content
Sign in to follow this  
Grinher1988

Delete an array selection?

Recommended Posts

I made a really simple enemy convoy script but besides the A3 AI being terrible drivers theres a bigger problem a little town called "Sagonisi" is sometimes selected as a destination for the convoy and its inaccessible to land vehicles. I tried _townlist = _townlist - ["Sagonisi"]; but that doesn't seem to work can anyone help? Also a related question how can I spawn more vehicles but in a way they aren't spawned on top of the previously spawned vehicle?

TLDR; how can I blacklist/delete a selected town from an array?

//==============Enemy Convoy Script============
//place null = [] execVM "randomConvoy.sqf"; in init.sqf or whatever :P
//place an object on the map named myAmmoBox or change it on line 12
//line 33 change side west,east, or resistance
//line 36 change vehicle type
//***THIS SCRIPT LOOPS SO ONLY CALL IT ONCE!***
//================By Grinher==============

if (!isServer) exitWith {};//Should prevent 40+ convoy spawning on mission start 

//===========================Random time before next convoy===========================================================

_delay = 900 max (floor(random 1800));//in seconds default is 15~30mins after the first convoy spawn

//============================Create List of Towns====================================================================

_townlist = nearestLocations [getpos myAmmoBox, ["NameCityCapital","NameCity","NameVillage"],15000];//get list of towns
_townlist = _townlist - ["Sagonisi"];//Blacklist doesn't work yet :c

_rnd = floor random (count _townlist);
_townStart = _townlist select _rnd;

_roadList = (getPos _townStart) nearRoads 100;
_rndRoad = floor random (count _roadList);
_roadStart = _roadList select _rndRoad;

_townlist = _townlist - [_townStart];

_townEnd = _townlist select _rnd;

_town_Start = text (_townStart);
_town_End = text (_townEnd);


//=================================================Create Convoy======================================================

_convoyGroup = createGroup east;

_vehA = [position _roadStart, 180, "O_Truck_03_ammo_F", _convoyGroup] call bis_fnc_spawnvehicle;
sleep 5;

_convoyGroup setBehaviour "CARELESS";

hint format ["A convoy has been sighted leaving %1, reports indicate the convoy is heading towards %2.", _town_Start, _town_End];
//=================================================Set convoy dest=====================================================


_wp1 = _convoyGroup addWaypoint [position _townEnd, 0];
_wp1 setWaypointType "MOVE"; 
_wp1 setWaypointCompletionRadius 25;

//=================================================Create Markers=====================================================

_marker = createMarker ["Tracker", position _townStart];
_marker setMarkerShape "ICON";
_marker setMarkerType "hd_ambush";
_marker setMarkerColor "ColorRED";
_marker setMarkerText "Convoy";
_marker setMarkerAlpha 1;

_markerTS = createMarker ["Start", position _townStart];
_markerTS setMarkerShape "ICON";
_markerTS setMarkerType "hd_start";
_markerTS setMarkerColor "ColorRED";
_markerTS setMarkerText "Start";
_markerTS setMarkerAlpha 1;

_markerTE = createMarker ["End", position _townEnd];
_markerTE setMarkerShape "ICON";
_markerTE setMarkerType "hd_end";
_markerTE setMarkerColor "ColorRED";
_markerTE setMarkerText "End";
_markerTE setMarkerAlpha 1;

//keep track of leader
while {alive leader _convoyGroup} do {

"Tracker" setMarkerPos getpos leader _convoyGroup;

sleep 1;

};

while {true} do
{
waitUntil{{alive _x} count units _convoyGroup < 1 or (leader _convoyGroup) distance _townEnd < 25};
};

hint "The convoy has either been destroyed, or has left the area.";//not skilled at coding enough to detect difference xD

deleteMarker "Tracker";
deleteMarker "Start";
deleteMarker "End";

{ deleteVehicle _x } forEach units _convoyGroup;
deleteGroup _convoyGroup;  

sleep _delay;

[] execVM "randomConvoy.sqf";

---------- Post added at 02:09 ---------- Previous post was at 02:06 ----------

OH! I forgot that I figured out how to delete the first town picked to prevent start/end being in the same place with _townlist = _townlist - [_townStart]; but I don't understand why _townlist = _townlist - ["Sagonisi"]; does nothing!

Share this post


Link to post
Share on other sites

_townlist = nearestLocations [getpos myAmmoBox, ["NameCityCapital","NameCity","NameVillage"],15000];

is giving you a list of grid locations not the names of the towns.

You will need to do a little work to retrieve then actual name.

_Names_of_Towns = [];
_Town_Locations = nearestLocations [position player, ["NameCityCapital","NameCity","NameVillage"], 6000];// array of locations

{
_Names_of_town = pushback classname _x;// gets the name & makes an array of town names   
} foreach _Town_Locations;

 hint str _Names_of_Towns;
// or  hint str (_Names_of_Towns - ["Agis_Marina"]);// you can now manipulate the array

Share this post


Link to post
Share on other sites

Thank you F2k, I figured out a way of deleting the grid coordinates from your example. I have another question for some reason this line of code is failing but not sure why?

while {true} do
{
waitUntil{{alive _x} count units _convoyGroup < 1 or (leader _convoyGroup) distance getMarkerPos "End" < 25};
};

Share this post


Link to post
Share on other sites

waitUntil is a loop itself, no need to put a while loop around it.

Share this post


Link to post
Share on other sites

Thanks I finally got everything working, but because of how horrible the AI drive compared to A2 this is a waste of time.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×