Jump to content
Sign in to follow this  
Kolmain

Dynamic City Patrols/Battles/Spawning

Recommended Posts

Heres my code i jsut wrote, cant seem to get it working, the strings are messing me up:

//////////////////////////////////////////////////////////////////
// activatecity.sqf
// Created by: [97thRR]Kolmain
//////////////////////////////////////////////////////////////////
//Define local variables
_city = this select 0;
_city1 = this select 1;
_city2 = this select 2;
_fob = this select 3;
_side = this select 4;
_cityname = this select 5;

switch (floor random(4)) do
{
case 0: {
	//Create group with the name of whatever _city is defined as and have them patrol in 100M radii
	str _city = [getMarkerPos _city, EAST, 5] call BIS_fnc_spawnGroup;
	[group _city, getPos group _city, 100] call bis_fnc_taskPatrol;
	str _city setCombatMode "RED";
	str _city setBehaviour "SAFE";
	hint "5 Man East Patrol Spawned";
};
case 1: {
	//Create group with the name of whatever _city is defined as and have them patrol in 100M radii
	str _city = [getMarkerPos _city, EAST, 8] call BIS_fnc_spawnGroup;
	[group _city, getPos group _city, 100] call bis_fnc_taskPatrol;
	str _city setCombatMode "RED";
	str _city setBehaviour "SAFE";
	hint "8 Man East Patrol Spawned";
	};
case 2: {
	//Create group with the name of whatever _city defines and add west/east to the end of it (IE: moldovaeast OR moldovawest and set them to attack to each other's position.
	str _city + east = [getMarkerPos _city1, EAST, 10] call BIS_fnc_spawnGroup;
	str _city + west = [getMarkerPos _city2, WEST, 10] call BIS_fnc_spawnGroup;
	str _city + east setCombatMode "RED";
	str _city + east setBehaviour "SAFE";
	str _city + west setCombatMode "RED";
	str _city + west setBehaviour "SAFE";
	_attack = str _city + west addWaypoint [GetMarkerPos _city1, 0];
	_attack2 = str _city + east addWaypoint [GetMarkerPos _city2, 0];
	hint "10 Man Battle Spawned";
	};
case 3: {
	//Create group with the name of whatever _city is defined as and have them patrol in 100M radii
	str _city = [getMarkerPos _city, EAST, 5] call BIS_fnc_spawnGroup;
	[group _city, getPos group _city, 100] call bis_fnc_taskPatrol;
	str _city setCombatMode "RED";
	str _city setBehaviour "SAFE";
	hint "5 Man East Patrol Spawned";
	};
};
//Create a defensive team at _fob variable and name it definition of _city + fob (IE: moldovafob)
str _city + fob = [getMarkerPos _fob, _side, 7] call BIS_fnc_spawnGroup;
[group str _city + fob, getMarkerPos _fob] call bis_fnc_taskDefend;
hint "7 Man East FOB Spawned";

any ideas?

Share this post


Link to post
Share on other sites

Hi...I'm not sure without doing some testing.....but this does not look right (in red)

[color="Red"]str _city[/color] = [getMarkerPos _city, EAST, 5] call BIS_fnc_spawnGroup;
[group _city, getPos group _city, 100] call bis_fnc_taskPatrol;
[color="Red"]str _city[/color] setCombatMode "RED";
[color="Red"]str _city[/color] setBehaviour "SAFE";
hint "5 Man East Patrol Spawned";

Seems to me _city might already be a string???

Share this post


Link to post
Share on other sites

_city = this select 0;

_city is defined at the top as the marker name but i want to use the same name for the group name

Share this post


Link to post
Share on other sites
_city = this select 0;

_city is defined at the top as the marker name but i want to use the same name for the group name

Yes, but if _city is a marker then its already a String. like twirly said.

switch (floor random(4)) do

Can easily be converted to this:

_nr = floor (random 4);

switch (_nr) do

str _city = [getMarkerPos _city, EAST, 5] call BIS_fnc_spawnGroup; [group _city, getPos group _city, 100] call bis_fnc_taskPatrol;
str _city setCombatMode "RED";
str _city setBehaviour "SAFE";
hint "5 Man East Patrol Spawned";

to

_grp = [getMarkerPos _city, EAST, 5] call BIS_fnc_spawnGroup;
[_grp, (getPos (units _grp select 0)), 100] call bis_fnc_taskPatrol;
{ _x setCombatMode "RED"; _x setBehaviour "SAFE" } forEach units _grp;
hint "5 Man East Patrol Spawned";

And same thing with the other cases in the switch statement.

You were creating a group called ""markerName"" and then wanting to get the group of a group..:D

_neo_

Share this post


Link to post
Share on other sites

@neokika... That's great. I was just looking at the script and thought I'd re-write it for him also. It was a bit baffling!

---------- Post added at 01:33 PM ---------- Previous post was at 01:27 PM ----------

To delete the groups....they would have to have Global names....

_cntr = 0;
call compile format ["GroupWest_%1 = _grp",_cntr];
_cntr = _cntr +1;

You would end up with "GroupWest_0" ...."GroupWest_1" ...."GroupWest_2" etc..

You can also tack on the markenames instead of _cntr....or markernames and _cntr.

Think about this for a minute and you'll get it!!

EDITED: Actually _cntr might have to be Global too...depending on how and where you use it.

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites
But now how would I delete that group?

If you want to delete the group within that script just use the local variable. In that case is the _grp.

If you want to access it out of that script just assign a global variable to it.

TAG_Group1 = _grp;

Then in other script you can simply:

{ deleteVehicle _x } forEach units TAG_Group1;

@neokika... That's great. I was just looking at the script and thought I'd re-write it for him also. It was a bit baffling!

:D

Share this post


Link to post
Share on other sites

awesome! but to no avail.... doesnt work :(

//////////////////////////////////////////////////////////////////
// activatecity.sqf
// Created by: [97thRR]Kolmain
//////////////////////////////////////////////////////////////////
//Define local variables
_city = this select 0;
_city1 = this select 1;
_city2 = this select 2;
_fob = this select 3;
_side = this select 4;
_cityname = this select 5;

_nr = floor (random 4);

switch (_nr) do {

case 0: {
	//Create group with the name of whatever _city is defined as and have them patrol in 100M radii
_grp = [getMarkerPos _city, _side, 5] call BIS_fnc_spawnGroup;
[_grp, (getPos (units _grp select 0)), 100] call bis_fnc_taskPatrol;
{ _x setCombatMode "RED"; _x setBehaviour "SAFE" } forEach units _grp;
hint "5 Man Patrol Spawned";  
};
case 1: {
	//Create group with the name of whatever _city is defined as and have them patrol in 100M radii
_grp = [getMarkerPos _city, _side, 8] call BIS_fnc_spawnGroup;
[_grp, (getPos (units _grp select 0)), 100] call bis_fnc_taskPatrol;
{ _x setCombatMode "RED"; _x setBehaviour "SAFE" } forEach units _grp;
hint "5 Man Patrol Spawned";
	};
case 2: {
	//Create group with the name of whatever _city defines and add west/east to the end of it (IE: moldovaeast OR moldovawest and set them to attack to each other's position.
_grp1 = [getMarkerPos _city, EAST, 10] call BIS_fnc_spawnGroup;
{ _x setCombatMode "RED"; _x setBehaviour "SAFE" } forEach units _grp1;
	_grp2 = [getMarkerPos _city, WEST, 10] call BIS_fnc_spawnGroup;
{ _x setCombatMode "RED"; _x setBehaviour "SAFE" } forEach units _grp2;
	_grp1 addWaypoint [GetMarkerPos _city1, 0];
	_grp2 addWaypoint [GetMarkerPos _city2, 0];
	hint "10 Man Battle Spawned";
	};
case 3: {
	//Create group with the name of whatever _city is defined as and have them patrol in 100M radii
_grp = [getMarkerPos _city, _side, 5] call BIS_fnc_spawnGroup;
[_grp, (getPos (units _grp select 0)), 100] call bis_fnc_taskPatrol;
{ _x setCombatMode "RED"; _x setBehaviour "SAFE" } forEach units _grp;
hint "5 Man East Patrol Spawned";  
	};
};
//Create a defensive team at _fob variable and name it definition of _city + fob (IE: moldovafob)
_grpfob = [getMarkerPos _fob, _side, 7] call BIS_fnc_spawnGroup;
[group _grpfob, getMarkerPos _fob] call bis_fnc_taskDefend;
hint "7 Man FOB Spawned";

Share this post


Link to post
Share on other sites
awesome! but to no avail.... doesnt work :(

Check if you have the functions parameters correct. The BIS_fnc_spawnGroup etc.

If it still doesnt work, post what you have, and how you are calling it.

Edit: Also, do you have the FUNCTIONS module in the editor?

You must place it.

And also make sure the functions module is loaded before running the scripts by putting the following in the begginning of your script:

if (isNil "BIS_fnc_init") then { waitUntil { !isNil "BIS_fnc_init" } };

Edit: And you still have this:

//Create a defensive team at _fob variable and name it definition of _city + fob (IE: moldovafob)
_grpfob = [getMarkerPos _fob, _side, 7] call BIS_fnc_spawnGroup;
[group _grpfob, getMarkerPos _fob] call bis_fnc_taskDefend;
hint "7 Man FOB Spawned"; 

_neo_

Edited by neokika

Share this post


Link to post
Share on other sites

null = ["test","test1","test2","testfob",east,"test"] ExecVM "activatecity.sqf";

thats my init of the trigger, now i get the hint just not the spawn goona double check the spawn syntax now

Share this post


Link to post
Share on other sites
null = ["test","test1","test2","testfob",east,"test"] ExecVM "activatecity.sqf";

thats my init of the trigger, now i get the hint just not the spawn goona double check the spawn syntax now

I have updated my above post, do make sure to do all that and let us know if it works or not.

_neo_

Share this post


Link to post
Share on other sites
....i get the hint just not the spawn goona double check the spawn syntax now

Yes check that......I was getting the hint and not the spawn as well using that code you had there!

Share this post


Link to post
Share on other sites

nope still nothing with the change added

Heres my latest still doesnt work:

//////////////////////////////////////////////////////////////////
// activatecity.sqf
// Created by: [97thRR]Kolmain
//////////////////////////////////////////////////////////////////
//Define local variables
if (isNil "BIS_fnc_init") then { waitUntil { !isNil "BIS_fnc_init" } };  

_city = this select 0;
_city1 = this select 1;
_city2 = this select 2;
_fob = this select 3;
_side = this select 4;
_cityname = this select 5;

_nr = floor (random 4);

switch (_nr) do {

case 0: {
	//Create group with the name of whatever _city is defined as and have them patrol in 100M radii
_grp = [getMarkerPos _city, _side, 5] call BIS_fnc_spawnGroup;
[_grp, getMarkerPos _city, 100] call bis_fnc_taskPatrol;
{ _x setCombatMode "RED"; _x setBehaviour "SAFE" } forEach units _grp;
hint "5 Man Patrol Spawned";  
};
case 1: {
	//Create group with the name of whatever _city is defined as and have them patrol in 100M radii
_grp = [getMarkerPos _city, _side, 8] call BIS_fnc_spawnGroup;
[_grp, getMarkerPos _city, 100] call bis_fnc_taskPatrol;
{ _x setCombatMode "RED"; _x setBehaviour "SAFE" } forEach units _grp;
hint "5 Man Patrol Spawned";
	};
case 2: {
	//Create group with the name of whatever _city defines and add west/east to the end of it (IE: moldovaeast OR moldovawest and set them to attack to each other's position.
_grp1 = [getMarkerPos _city, EAST, 10] call BIS_fnc_spawnGroup;
{ _x setCombatMode "RED"; _x setBehaviour "SAFE" } forEach units _grp1;
	_grp2 = [getMarkerPos _city, WEST, 10] call BIS_fnc_spawnGroup;
{ _x setCombatMode "RED"; _x setBehaviour "SAFE" } forEach units _grp2;
	_grp1 addWaypoint [getMarkerPos _city1, 0];
	_grp2 addWaypoint [getMarkerPos _city2, 0];
	hint "10 Man Battle Spawned";
	};
case 3: {
	//Create group with the name of whatever _city is defined as and have them patrol in 100M radii
_grp = [getMarkerPos _city, _side, 5] call BIS_fnc_spawnGroup;
[_grp, getMarkerPos _city, 100] call bis_fnc_taskPatrol;
{ _x setCombatMode "RED"; _x setBehaviour "SAFE" } forEach units _grp;
hint "5 Man East Patrol Spawned";  
	};
};
//Create a defensive team at _fob variable and name it definition of _city + fob (IE: moldovafob)
_grpfob = [getMarkerPos _fob, _side, 7] call BIS_fnc_spawnGroup; 
[_grpfob, getMarkerPos _fob] call bis_fnc_taskDefend; 
hint "7 Man FOB Spawned"; 

Edited by Kolmain

Share this post


Link to post
Share on other sites

_city = this select 0;

_city1 = this select 1;

_city2 = this select 2;

_fob = this select 3;

_side = this select 4;

_cityname = this select 5;

blah blah blah....

Found your problem..... you need the underscore like _this

_city = [color="Red"]_this[/color] select 0;

The groups are spawning now for me.

Share this post


Link to post
Share on other sites
Found your problem..... you need the underscore like _this

_city = [color="Red"]_this[/color] select 0;

The groups are spawning now for me.

:)

Sometimes the most obvious is what ppl dont see..:bounce3:

Share this post


Link to post
Share on other sites

I have an issue; I'm using WaitUntil {_cityname == 0}; which works if I replace the local far with the actual variable but I want to use this script with plenty of cities so how can I get it to check if lopatino == 0 when _cityname = lopatino ?

Share this post


Link to post
Share on other sites
I have an issue; I'm using WaitUntil {_cityname == 0}; which works if I replace the local far with the actual variable but I want to use this script with plenty of cities so how can I get it to check if lopatino == 0 when _cityname = lopatino ?

So are you using markers or something to get the positions?

_neo_

Share this post


Link to post
Share on other sites

yea, but the last param in the EXEC is "lopatino" so _cityname = lopatino so i need the script to check for lopatino == 0

Share this post


Link to post
Share on other sites
yea, but the last param in the EXEC is "lopatino" so _cityname = lopatino so i need the script to check for lopatino == 0

I dont quite get what you mean,

Can you be more specific?

_neo_

Share this post


Link to post
Share on other sites

WaitUntil {lopatino == 0};
sleep 180;
{ deleteVehicle _x } forEach units _grp;  
{ deleteVehicle _x } forEach units _grp1;  
{ deleteVehicle _x } forEach units _grp2; 
{ deleteVehicle _x } forEach units _grpfob;  
player SideChat "Deactivated; Despawned"; 

this works

WaitUntil {_cityname == 0};
sleep 180;
{ deleteVehicle _x } forEach units _grp;  
{ deleteVehicle _x } forEach units _grp1;  
{ deleteVehicle _x } forEach units _grp2; 
{ deleteVehicle _x } forEach units _grpfob;  
player SideChat "Deactivated; Despawned"; 

this doesnt

Share this post


Link to post
Share on other sites

Just a very minor thing, but I don't get why you've got:

if (isNil "BIS_fnc_init") then { waitUntil { !isNil "BIS_fnc_init" } };   

Wouldn't this do just the same thing?

waitUntil {!isNil "BIS_fnc_init"};

Share this post


Link to post
Share on other sites

how can i check if _grpfob is x meters from s1 and s2 and etc up until s12?

Share this post


Link to post
Share on other sites
how can i check if _grpfob is x meters from s1 and s2 and etc up until s12?

Hi mate...I sent you a PM. It can be something along these lines

This will check each soldiers distance from _grpfob. But only does the check on the group once. Place it in a while loop to keep checking. Maybe change _found to a Global var and keep checking that.

for [{_i=0},{_i < count units _grp},{_i=_i+1}] do {
_dude = units _grp select _i;
if (_dude [url="http://community.bistudio.com/wiki/distance"]distance[/url] _grpfob >= 1500) then {_cnt = _cnt +1};
sleep 0.01;
};

if (_cnt >=1) then {
_found = true;
} else {
_found = false;
};

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  

×