Jump to content
Sign in to follow this  
H3NRY

spawn group on triger in random places

Recommended Posts

allright, i could make a crude half errors script that does exactly what i want but i figured i would ask here.

i need a trigger to exec a script or even in its init if easier that will spawn a group or even single guys ( that i can define ) in a random radius ( also definable, want to do a lot of spawning with the one single script, even if i have to duplicate it and change a single value [best would be definable group and radus in the execvm eg; nill = execVM "script.sqf" [100,"Ins_Soldier_1"] or something)

i have no clue how to do any of that scripting but i am sure someone here is good enough to :)

( to define)

nill = execVM "script.sqf" [100,"Ins_Soldier_1"]

nill = execVM "script.sqf" [radius,"group/MAN name"]

Edited by H3NRY

Share this post


Link to post
Share on other sites

Get my random position generator and copy it to the mission folder: http://forums.bistudio.com/showthread.php?t=89376

Add this to init.sqf:

SHK_pos = compile preprocessfile "SHK_pos.sqf";

Place a Functions module in editor to the mission.

Create a new file to the mission folder with name script.sqf (not script.sqf.txt). Paste this into it:

/*
Parameters:
 unit type or an array of them
 side
 compass direction
 distance
 position from which direction and distance is calculated from

Examples:
 nul = ["Ins_Soldier_1",EAST,random 360,100,getpos player] execvm "script.sqf";
 nul = ["Ins_Soldier_1",EAST,[60,130],[100,150],getpos player] execvm "script.sqf";
 nul = [["USMC_Soldier_SL","USMC_Soldier_LAT","USMC_Soldier_MG","USMC_Soldier_GL"],WEST,0,300,(getmarkerpos "myMarker")] execvm "script.sqf";
*/
if (isserver) then {
 _u = _this select 0;
 _s = _this select 1;
 _d = _this select 2;
 _r = _this select 3;
 _p = _this select 4;
 if (typename _u == typename "") then {
   _u createunit [([_p,_d,_r] call SHK_pos),(creategroup _s)];
 } else {
   waituntil {!isnil "BIS_fnc_init"};
   waituntil {BIS_fnc_init};
   [([_p,_d,_r] call SHK_pos),_s,_u] call BIS_fnc_spawnGroup;
 };
};

As you can see, I added a couple of extra options for you. If you need help to how it works, don't be afraid to ask.

Here is a working example of the stuff above: http://derfel.org/arma2/spawnexample.utes.rar

Share this post


Link to post
Share on other sites

awesome thanks. ill be testing that out right now :)

question about it.. can i use a random compass direction and how would i?

trying this right now..

nul = [["USMC_Soldier_SL","USMC_Soldier_LAT","USMC_Soldier_MG","USMC_Soldier_GL"],WEST,0 + random 100,300,(getpos player)] execvm "script.sqf";

Edited by H3NRY

Share this post


Link to post
Share on other sites

...WEST,random 100,300...

That will create the group 300 meters away in a random direction (between 0 and 99.999).

You can also give the distance and direction as min/max values. Example:

...WEST,random 100,[200,400]...

That will create the group to a random distance between 200 and 400 meters.

Share this post


Link to post
Share on other sites

ah cool thank you again :)

the priests are pleased :) ( you will see why i say that later lol! )

oh also can i use a named trigger as the point of origin? dont want to have to make a trigger and a marker for each place i want them to spawn around

Share this post


Link to post
Share on other sites

Don't know if you can do it without naming the trigger, but that's not too bad probably.

So, give each trigger a name and then just use (getpos myTrig1) instead of (getpos player). MyTrig1 being the name of the trigger obviously.

Share this post


Link to post
Share on other sites

cool thanks. going to try right now and let you know :)

Share this post


Link to post
Share on other sites

see thats what i was saying! i didnt expect one reply at all lol

but i thinki am having problems cause i am taking civilian priests and giving them guns adn making them bluefor by giving them a leader with 0% presence so the trigger is not seeing them as bluefor.. not much of a problem cause i dont have ambient civies walking around yet but that is my end plan

scratch that.. miss named the spawn script lol

ok so great work man... loving the script

Edited by H3NRY

Share this post


Link to post
Share on other sites

alright now i got a question. some of the guys spawn dead, anything i can do about that? ALSO can i use a invisable helipad as the marker instead? if so then i should be able to use setposATL to set the "marker" (read "invisable heilipad") above ground to make the guys spawn there right?

ok so i got that working ( using an invisible H ) but they still spawn dead ( all but one, every time) no matter how high i set it to... even 2000 lol

ok said forget it and just made a trigger per unit i wanted to spawn.. every one is live when spawned now.. so anyone having the dead spawn problem, there is one way

Edited by H3NRY

Share this post


Link to post
Share on other sites

nothing of this works for me. i must be doing something wrong since all scripts i tried in the last 5 days didnt work for me (from arty over respawn to random spawn). ok i created a map. the map folder holds the mission.sqm,

init.sqf:

SHK_pos = compile preprocessfile "SHK_pos.sqf";

execVM "briefing.sqf";

description.ext:

respawn= BASE

respawndelay= 10

script.sqf:

/*

Parameters:

unit type or an array of them

side

compass direction

distance

position from which direction and distance is calculated from

Examples:

nul = ["Ins_Soldier_1",EAST,random 360,100,getpos player] execvm "script.sqf";

nul = ["Ins_Soldier_1",EAST,[60,130],[100,150],getpos player] execvm "script.sqf";

nul = [["USMC_Soldier_SL","USMC_Soldier_LAT","USMC_Soldier_MG","USMC_Soldier_GL"],WEST,0,300,(getmarkerpos "myMarker")] execvm "script.sqf";

*/

if (isserver) then {

_u = _this select 0;

_s = _this select 1;

_d = _this select 2;

_r = _this select 3;

_p = _this select 4;

if (typename _u == typename "") then {

_u createunit [([_p,_d,_r] call SHK_pos),(creategroup _s)];

} else {

waituntil {!isnil "BIS_fnc_init"};

waituntil {BIS_fnc_init};

[([_p,_d,_r] call SHK_pos),_s,_u] call BIS_fnc_spawnGroup;

};

SHK_pos.sqf:

/*

SHK_pos - Random position generator for Arma 2

Author: Shuko (IRC: shuko@quakenet, Email: miika@miikajarvinen.fi)

Version: 0.1

Parameters for marker area based position:

Area String Marker to define area from which the position is taken.

Water Boolean Allow position on water? Optional, default is false.

Usage examples:

myPos = ["markerName"] execvm "SHK_pos.sqf";

myPos = ["myMarker1",true] execvm "SHK_pos.sqf";

Parameters for relative position:

Point of Origin Position array The position from which direction and distance is calculated from.

Direction Number Compass direction (0-359) from Point of Origin.

Array Array can be used to give minimum and maximum directions.

Distance Number Distance in meters from Point of Origin.

Array Array can be used to give minimum and maximum distance.

Water Boolean Allow position on water? Optional, default is false.

Water solution Integer Water positions not allowed, what to do?

0: Do nothing, do not return any position. An empty array is returned.

1: Find closest land. Search is done with increasing radius until land is found, thus the resulting

position might not be exactly in the given direction and distance.

2: Decrease distance until land is found. Direction is kept the same.

3: Increase distance until land is found. Direction is kept the same.

4: Decrease direction (counter clock-wise) until land is found. Distance is kept the same.

5: Increase direction (clock-wise) until land is found. Distance is kept the same.

If no integer is given, solution 1 is used by default.

Usage examples:

myPos = [getpos player,random 360,200,true] execvm "SHK_pos.sqf";

myPos = [getmarkerpos "myMarker",125,random 500] execvm "SHK_pos.sqf";

myPos = [getpos player,random 360,[200,500],false,2] execvm "SHK_pos.sqf";

Example of creating multiple positions:

SHK_pos = compile preprocessfile "SHK_pos.sqf";

for "_i" from 0 to 500 do {

_p = [getpos player,random 360,random 1000] call SHK_pos;

if (count _p > 0) then {

call compile format ["

_m%1 = createMarker[""mySpot%1"",[_p select 0,_p select 1]];

_m%1 setMarkerShape ""ICON"";

_m%1 setMarkerType ""DOT"";

_m%1 setmarkercolor ""colorred"";

",_i];

};

};

*/

private "_getpos";

_getpos = {

private ["_origo","_dir","_dist"];

_origo = _this select 0;

_dir = _this select 1;

_dist = _this select 2;

if (typename _dir == typename []) then {

if ((_dir select 0) > (_dir select 1)) then { _dir set [1,((_dir select 1) + 360)] };

_dir = ((_dir select 0) + random((_dir select 1)-(_dir select 0)))

};

if (typename _dist == typename []) then {

_dist = ((_dist select 0) + random((_dist select 1)-(_dist select 0)));

};

[((_origo select 0) + (_dist * sin _dir)),((_origo select 1) + (_dist * cos _dir)),0];

};

private "_water";

if (typename (_this select 0) == typename "") then {

private ["_pos","_area","_cp","_cx","_cy","_as","_rx","_ry","_ad","_cd","_sd","_xo","_yo","_loop"];

_area = _this select 0;

if (count _this > 1) then {_water = _this select 1} else {_water = false};

_cp = getMarkerPos _area;

_cx = abs(_cp select 0);

_cy = abs(_cp select 1);

_as = getMarkerSize _area;

_rx = _as select 0;

_ry = _as select 1;

_ad = (markerDir _area) * -1;

_cd = cos _ad;

_sd = sin _ad;

_loop = true;

while {_loop} do {

_tx = (random (_rx*2))-_rx;

_ty = (random (_ry*2))-_ry;

_xo = if (_ad!=0) then {_cx+ (_cd*_tx - _sd*_ty)} else {_cx+_tx};

_yo = if (_ad!=0) then {_cy+ (_sd*_tx + _cd*_ty)} else {_cy+_ty};

_pos = [_xo,_yo,0];

if (_water) then {

_loop = false;

} else {

if (!surfaceIsWater [_pos select 0,_pos select 1]) then {_loop = false};

};

};

_pos

} else {

private ["_origo","_dir","_dist","_pos","_loop","_watersolution"];

_origo = _this select 0;

_dir = _this select 1;

_dist = _this select 2;

if (count _this > 3) then {_water = _this select 3} else {_water = false};

if (count _this > 4) then {_watersolution = _this select 4} else {_watersolution = 1};

_pos = [_origo,_dir,_dist] call _getpos;

if (!_water) then {

private ["_d","_l","_p"];

_l = true;

switch _watersolution do {

case 0: {

if (surfaceIsWater [_pos select 0,_pos select 1]) then {

_pos = +[];

};

};

case 1: {

_d = 10; _l = true;

while {_l} do {

for "_i" from 0 to 350 do {

_p = [_pos,_i,_d] call _getpos;

if (!surfaceIsWater [_p select 0,_p select 1]) exitwith {_l = false};

};

_d = _d + 10;

};

_pos = _p;

};

case 2: {

_d = _pos distance _origo;

while {_d = _d - 10; _l} do {

_pos = [_pos,_dir,_d] call _getpos;

if (!surfaceIsWater [_pos select 0,_pos select 1]) then {_l = false};

if (_d < 10) then {_l = false; _pos = + []};

};

};

case 3: {

_d = _pos distance _origo;

while {_d = _d + 10; _l} do {

_pos = [_pos,_dir,_d] call _getpos;

if (!surfaceIsWater [_pos select 0,_pos select 1]) then {_l = false};

if (_d > 10000) then {_l = false; _pos = + []};

};

};

case 4: {

if (typename _dir == typename []) then {

_d = _dir select 0;

_dir = _dir select 0;

} else {

_d = _dir;

};

while {_l} do {

_p = [_pos,_d,_dist] call _getpos;

if (!surfaceIsWater [_p select 0,_p select 1]) exitwith {_l = false};

if (_d < (_dir - 360)) then {_l = false};

_d = _d - 10;

};

_pos = _p;

};

case 5: {

if (typename _dir == typename []) then {

_d = _dir select 1;

_dir = _dir select 1;

} else {

_d = _dir;

};

while {_l} do {

_p = [_pos,_d,_dist] call _getpos;

if (!surfaceIsWater [_p select 0,_p select 1]) exitwith {_l = false};

if (_d > (_dir + 360)) then {_l = false};

_d = _d + 10;

};

_pos = _p;

};

};

};

_pos

};

and an still empty briefing.sqf.

in my map theres a function module, a marker with attributes ICON 1,1 name: NARF and a trigger with

attributes 0,0,0, activation: radio alpha, condition: this, on act.: nul = ["RU_Soldier_Officer",EAST,random 360,[20,50],getmarkerpos "NARF"] execVM "script.sqf";

i also tried ,getpos NARF],getpos "NARF"],(getmarkerpos "NARF")],(getmarkerpos NARF)] and changing the marker to ellipse without any luck. also changing the spawning guy back to "ins_soldier_1" didnt change anything. on your map it works on my map nothing works. same with arty and revive script all works only on the downloaded map i dont understand this sh**

Share this post


Link to post
Share on other sites
also changing the spawning guy back to "ins_soldier_1" didnt change anything.

You need to have at least one unit from the side you are trying to add on the map. Another option is to use the createcenter command, but placing one unit is simple.

ok said forget it and just made a trigger per unit i wanted to spawn.. every one is live when spawned now.. so anyone having the dead spawn problem, there is one way

I've experienced units getting injured when moved to the same position, but that's when moving, never seen that with spawning.

Share this post


Link to post
Share on other sites
You need to have at least one unit from the side you are trying to add on the map. Another option is to use the createcenter command, but placing one unit is simple.

im trying to do a coop map with a random spawned officer as second mission target. already got all west and east units placed on the map except the officer. in that case i see why the insurgent doesnt work but the russian guy doesnt work either

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  

×