Jump to content
Sign in to follow this  
igor drukov

Random Urban Combat

Recommended Posts

Here is a template mission for two .sqf functions (used with "compile preprocessfile" then) which will enable you to set up a quick urban battle.

Put it in your ArmA\YourProfile\Missions folder and open it from your editor (island: Sahrani; mission name: SpawnBuild_Template).

<ul>[*]What it does:

It spawns an adjustable number of units, randomly copied from a given group, INSIDE buildings, within an adjustable radius around a center.

[*]More technical details:

The mission contains:

<ul>[*] an init.sqf from which the two functions are preprocessed and called;

[*] a function called BuildPos which returns the array of positions of a given building;

[*] a function called SpawnBuild which spawns and places the units randomly according to the following parameters:

<ul>[*] the group from which the new units will be copied;

[*] the centre around which the units will be spawned (ideally this centre should be located inside a town);

[*] the range around the center within which the units will be spawned;

[*] the number of units you want to spawn.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[MyGroup,MyCenter,MyRadius,NumberOfUnitsSpawned] call spawnbuild;

SpawnBuild should work on dedi servers provided the mission has a logic called "Server" (not tested as I have no dedi ArmA servers handy yet). This is also true for SP missions.

[*]Two last remarks:

All units are spawned within the same group on purpose: they can thus share the information they have.

The example mission spawns 160 (one hundred and sixty! ) units. Give your cpu the time to run the function to the end!

Feedback more than welcome, hope you'll enjoy it!

Regards,

Igor.

Share this post


Link to post
Share on other sites

Nice script!!!

But i have a little problem, using it. i'm doing a french mission based on the recent events in ivory coast. So, i set up a group (group01 = group this, like you did) of civilians within init of each: this setface "face27";this addmagazine "30Rnd_545x39_AK";this addmagazine "30Rnd_545x39_AK";this addmagazine "30Rnd_545x39_AK";This addweapon "ak74"

But, when they spawn due to your (excellent) script, they have no weapon nor black face. :/

How can i conserve the weapon and face setting for each unit?

Share this post


Link to post
Share on other sites

Hello

@ deanosbeano

Thank you mate, hope you'll find some interest in this!

@ jomi_satchel

Replace "this" by "_sol" and insert your lines of code on line 23:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_r=random (count units _group_orig);_r=_r - _r mod 1;_sol=_group_orig CreateUnit [format ["%1",typeof (units (_this select 0) select _r)],position player,[],0,"none"];_r=random (count _array_pos);_r=_r - _r mod 1;_sol setpos (_array_pos select _r);_sol setdir random 360;_sol disableAI "move";removeallweapons _sol;_sol setface "face27";_sol addmagazine "30Rnd_545x39_AK";_sol addmagazine "30Rnd_545x39_AK";_sol addmagazine "30Rnd_545x39_AK";_sol addweapon "ak74";sleep 0.1;_i=_i+1

I've added a "removeallweapons" just in case...

Thank you for your interest!

Regards,

Igor.

Share this post


Link to post
Share on other sites

thx for this quick answer, igor! smile_o.gif

But, still a question here, the _sol solution doesn't mean that all soldiers will have that same face27? is there a way to get rid of this?

i have to admit this is not important, but, hey, small things makes the difference. ^^

going to check this!

Share this post


Link to post
Share on other sites

@jomi_satchel

Yes, with this modification, they would all have the same face. What you'd need to do is to create an array of all the different faces you'd like and select one element randomly.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_array_faces=["MyFace1","MyFace2",...,"MyFacen"];_u=random (count _array_faces);_u=_u - _u mod 1;_sol setface _arrayfaces select _u

Share this post


Link to post
Share on other sites

Works fine. notworthy.gif

Last question: is it possible to activate your script with a trigger? The city fight taking place in the second part of my mission, it would make the mission less heavier if the units spawned only in for that part. Sorry for my bad english and my noob questions. whistle.gif

Very nice script, it suits so well my mission! in fact i can"t do 2 step in the city, lol, but, as the mission is suited for mp, it won't be a problem.

i'll let you know if it work in mp when it will be tested, an also i'll give you the mission, when it'll be duely tested and translated in english. wink_o.gif

Share this post


Link to post
Share on other sites

@ jomi_satchel

Yes of course you can call the script from a trigger.

It should work in MP as it's only a spawning script, nothing more really. Only the server should execute it, but the safety line "if (local Server) then {}" has already been inserted.

Share this post


Link to post
Share on other sites

Is it possible to use a Init.sqf and a init.sqs at the same time?

Edit: Nevermind you can i tested it. yay.gif

Share this post


Link to post
Share on other sites

Well done again M8! Thanks!

notworthy.gif

Share this post


Link to post
Share on other sites
Well done again M8! Thanks!  

notworthy.gif

aaeeemm ... late? icon_rolleyes.gif

some time has pased and (nothing against Igor) I think there is a more complete solution: http://kronzky.info/ups/

just to avoid confusing newbies

QuietMan

Share this post


Link to post
Share on other sites

i get an error with this script

Quote[/b] ]

Error in expression <lim=_this select 3;

_i=0;

_array_build=NearestObjects [_ctr,["HouseBase"],_rge]>

 Error position: <NearestObjects [_ctr,["HouseBase"],_rge]>

 Error 0 elements provided, 3 expected

And here is the script itsself, can anyone help me  smile_o.gif

Quote[/b] ]

if (local server) then {

private ["_group_orig","_ctr","_rge","_lim","_i"

,"_array_build","_p","_r","_typ_array","_grou

p_dru","_obj"];

_group_orig=_this select 0;

_ctr=_this select 1;

_rge=_this select 2;

_lim=_this select 3;

_i=0;

_array_build=NearestObjects [_ctr,["HouseBase"],_rge];

_array_pos=[];

while {_i<count (_array_build)} do {

_p=[_array_build select _i] call BuildPos;

if (count (_p)>0) then {

_r=random (count _p);_r=_r - _r mod 1;_array_pos=_array_pos+[_p select _r]

};

_i=_i+1;

};

if (count _array_pos>1) then {

_i=0;

while {_i<_lim} do {

_r=random (count units _group_orig);_r=_r - _r mod 1;_sol=_group_orig CreateUnit [format ["%1",typeof (units (_this select 0) select _r)],position player,[],0,"none"];_r=random (count _array_pos);_r=_r - _r mod 1;_sol setpos (_array_pos select _r);_sol setdir random 360;_sol disableAI "move";sleep 0.1;_i=_i+1

};

};

};

and the init.sqf

Quote[/b] ]

BuildPos=compile preprocessfile "BuildPos.sqf";

SpawnBuild=compile preprocessfile "SpawnBuild.sqf";

Sleep 1;

[group01,obj1,300,160] call spawnbuild;

Share this post


Link to post
Share on other sites

Hmm, does anybody know if there's a script similar to this out there that is in a loop and creates, lets say 20-30 enemies in a radius of 100m, constantly, removing the dead ones, creating new ones and the circle moves with you? That'd be awsome for a moving mission in a humvee, always feeling like under attack.

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  

×