Jump to content
Sign in to follow this  
Koni

Random spawn script assign waypoint

Recommended Posts

I'm trying to spawn random enemy units at random markers and have them drive to a location.

The random spawn at random markers works fine but I can't figure out how to move them, ie start driving.

markers = ["spawn1","spawn2","spawn3","spawn4","spawn5"];

_pos = markers select (floor random 5);

_pos = getmarkerPos _pos;

_vehicles = ["BMP3", "2S6M_Tunguska", "BTR90","T72_RU", "GAZ_Vodnik_HMG", "GAZ_Vodnik"] call BIS_fnc_selectRandom;

_spawn = [_Pos, 1, _vehicles , East] call bis_fnc_spawnvehicle;

{

_x setskill ["aimingAccuracy",0.75];

_x setskill ["spotDistance",0.95];

_x setskill ["spotTime",0.85];

_x setskill ["courage",0.85];

_x setskill ["commanding",0.85];

_x setskill ["aimingShake",0.65];

_x setskill ["aimingSpeed",0.85];

} foreach units _spawn;

sleep 0.5;

_pos1 = getMarkerPos "airbase";

_grp = _spawn;

_wp = _grp addWaypoint [_pos1, 0];

[_grp, 0] setWaypointType "SAD";

Where am I going wrong, I guess it's an issue calling them _spawn ?!

Thanks

Share this post


Link to post
Share on other sites

I have added a waypoint which works fine when spawning single units but when I try using the same way of adding a waypoint spawning a random unit it dosen't seem to work.

_pos1 = getMarkerPos "airbase";

_grp = _spawn;

_wp = _grp addWaypoint [_pos1, 0];

[_grp, 0] setWaypointType "SAD";

Normally I would spawn a unit like this

//////////////////////////////////////////////////////////////////////////////////////////////////

_pos = getmarkerPos "spawn1";

_skill = [0.1, 0.5];

_side = east;

_units = ["T72_RU"];

r1 = [_pos, _side, _units, [], [], _skill] call BIS_fnc_spawnGroup;

{

_x setskill ["aimingAccuracy",0.75];

_x setskill ["spotDistance",0.95];

_x setskill ["spotTime",0.85];

_x setskill ["courage",0.85];

_x setskill ["commanding",0.85];

_x setskill ["aimingShake",0.65];

_x setskill ["aimingSpeed",0.85];

} foreach units a1;

sleep 0.5;

_pos1 = getMarkerPos "airbase";

_grp = a1;

_wp = _grp addWaypoint [_pos1, 0];

[_grp, 0] setWaypointType "SAD";

//////////////////////////////////////////////////////////////////////////////////////////////////

and the waypoint works fine, but it seems that using bis_fnc_spawnvehicle you can't name the group like using bis_fnc_spawnGroup, and using spawngroup dosen't spawn a random unit

Share this post


Link to post
Share on other sites

An extract from BIS_fnc_spawnVehicle:

Parameter(s):
_this select 0: desired position (Array).
_this select 1: desired azimuth (Number).
_this select 2: type of the vehicle (String).
_this select 3: side or existing group (Side or Group).

Returns:
Array:
0: new vehicle (Object).
1: all crew (Array of Objects).
2: vehicle's group (Group).

So, the problem is that you are using an array to add the waypoint, and not a group or vehicle.

Do something like this instead:

_list = [_pos, _dir, _class, _side] call BIS_fnc_spawnVehicle;//array
_vehicle = _list select 0;//object
_crew = _list select 1;//array
_grp = _list select 2;//group

_wp = _grp addWaypoint [_pos1, 0];
[_grp, 0] setWaypointType "SAD";

_neo_

Share this post


Link to post
Share on other sites

Thanks for your reply but I don't understand how I join up my code for spawning a random unit and what you have replied with.

Sorry for being a bit slow on this.

markers = ["spawn1","spawn2","spawn3","spawn4","spawn5"];

_pos = markers select (floor random 5);

_pos = getmarkerPos _pos;

_vehicles = ["BMP3", "2S6M_Tunguska", "BTR90","T72_RU", "GAZ_Vodnik_HMG", "GAZ_Vodnik"] call BIS_fnc_selectRandom;

_spawn = [_Pos, 1, _vehicles , East] call bis_fnc_spawnvehicle;

That bit obviously chooses a random marker to spawn at and a random Armoured unit too.

What I don't understand is what I do with this

_list = [_pos, _dir, _class, _side] call BIS_fnc_spawnVehicle;//array

_vehicle = _list select 0;//object

_crew = _list select 1;//array

_grp = _list select 2;//group

_wp = _grp addWaypoint [_pos1, 0];

[_grp, 0] setWaypointType "SAD";

Sorry.

---------- Post added at 15:08 ---------- Previous post was at 14:16 ----------

Got it working now but by bodging it a lot.

I ended up changing side as EAST to a exsisting group name of the same side hidden where I wanted the random spawned unit to move to.

markers = ["spawn1","spawn2","spawn3","spawn4","spawn5"];

_pos = markers select (floor random 5);

_pos = getmarkerPos _pos;

_vehicles = ["BMP3", "2S6M_Tunguska", "BTR90","T72_RU", "GAZ_Vodnik_HMG", "GAZ_Vodnik"] call BIS_fnc_selectRandom;

_spawn = [_Pos, 1, _vehicles , a1] call bis_fnc_spawnvehicle;

{

_x setskill ["aimingAccuracy",0.75];

_x setskill ["spotDistance",0.95];

_x setskill ["spotTime",0.85];

_x setskill ["courage",0.85];

_x setskill ["commanding",0.85];

_x setskill ["aimingShake",0.65];

_x setskill ["aimingSpeed",0.85];

} foreach units a1;

sleep 4;

_pos1 = getPos "airbase";

_grp = a1;

_wp = _grp addWaypoint [_pos1, 0];

[_grp, 0] setWaypointType "SAD";

I used a Russian soldier with no ammo with this lot in it's init field

a1= group this; this hideobject true; this setcaptive true; this allowdamage false;

and in my test it works fine, though not a propper way to get it working :)

Just need to transfer this into the mission im making to make sure it still fits ok.

If anyone could explain exactly how to do this propperly I'd like to learn.

Thanks

Edited by Koni

Share this post


Link to post
Share on other sites

You need to understand arrays and how to select the elements:

http://community.bistudio.com/wiki/Array

Arma2 Functions

http://community.bistudio.com/wiki/Category:ArmA_2:_Functions

BIS_fnc_spawnVehicle

http://community.bistudio.com/wiki/BIS_fnc_spawnVehicle

You will see on the BIS_fnc_spawnVehicle that using the command returns an array that is stored in the variable you call it with (you use _spawn).

Return Value:

Array - 0: created vehicle (Object), 1: all crew (Array of Objects), 2: vehicle's group (Group)

so _spawn is actually an array containing the following elements: [vehicle, crew, group]

Now you can use those three items you just have to select them which is what Neo was explaining.

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  

×