Jump to content
Sign in to follow this  
mrcurry

BIS_fnc_spawnVehicle error

Recommended Posts

Oke here's the deal... I've written a function that uses BIS_fnc_spawnVehicle to create a generic vehicle in a new group, add a waypoint to the group and return it. I also got a similar function for generic infantry groups. (Henceforth called spawn_vec and spawn_inf respectively)

I tested with separate triggers calling the functions and they both work flawlessly, both infantry and vehicles (with crew) spawned and moved towards the waypoint.

Trigger 1:
Infgrp  = [getPos inf1, infantry_groups, getPos fb_hill, east] call SPAWN_INF;
Trigger 2:
Vecgrp = [getPos vec1, l_vehicles, getPos fb_hill, east] call SPAWN_VEC;

executing Script:
script=[ 20, 5, wave_number, 1, [3,1], enemy_spawns, infantry_groups, l_vehicles, h_vehicles, getPos fb_hill,east] spawn SCRIPT;
Calling the functions in script:
_grp = [getPos _spawn, _infArray, _target, _side] call SPAWN_INF;
_grp = [getPos _spawn, _lVehiclesArray, _target] call SPAWN_VEC;
_grp = [getPos _spawn, _hVehiclesArray, _target] call SPAWN_VEC;

Then I wrote a script calling both functions... and here's where the problem began. When calling only spawn_inf it works fine, but when I try to call spawn_vec as well, the whole thing is terminated when its supposed to spawn the vehicle and I get the following in the arma2.rpt

Error in expression <NONE"];

_crew = _crew + [_unit];

_unit moveInDriver _vehicle;

}

else

{

_crew = >

Error position: <moveInDriver _vehicle;

}

else

{

_crew = >

Error moveindriver: Type Nothing, expected Object

File ca\modules\functions\spawning\fn_spawnCrew.sqf, line 90

I could easily fix this by writing my own spawnVehicleWithCrew function but it would be a pain when there is all ready one defined that should work ;)

Share this post


Link to post
Share on other sites

I found that when spawning a vehicle like that, it required a bit of a delay - I think I used sleep .4 - for it to return the array from the vehicle spawn.

Also, double check that your return variable references the correct parameter from the spawnvehicle function.

Could you post the script that calls both functions?

Another problem I had with calls is that any variable you have in the main script can interfere with a variable of the same name in the function. Might look at that, too.

Share this post


Link to post
Share on other sites
I found that when spawning a vehicle like that, it required a bit of a delay - I think I used sleep .4 - for it to return the array from the vehicle spawn.

How could this sort out the problem? I mean it fails on spawning the first vehicle so there's no other call to the fnc_spawnVehicle it can collide with, unless the fnc_spawnGroup interferes with it?

Also, double check that your return variable references the correct parameter from the spawnvehicle function.

Sorry but I didn't follow you there, I don't return it using the parameter array but... since I use call to execute the function I can just drop the return line as the last line in the function (without the ; ofc).

My best guess without testing would be that it's the script that calls both functions that causes this error somehow

Could you post the script that calls both functions?

Another problem I had with calls is that any variable you have in the main script can interfere with a variable of the same name in the function. Might look at that, too.

player sideChat "Test: spawning infantry";		
_grp = [getPos _spawn, _infArray, _target, _side] call SPAWN_INF;

_counter = _counter - 1;
_spawnedUnits = _spawnedUnits + units _grp;

player sideChat "Test: spawning vehicle";		
if(random 1 < _lVehiclePercentage) then
{
_grp = [getPos _spawn, _lVehiclesArray, _target] call SPAWN_VEC;
_counter = _counter - 1;
_spawnedUnits = _spawnedUnits + units _grp;
};

if(random 1 < _hVehiclePercentage) then
{
_grp = [getPos _spawn, _hVehiclesArray, _target] call SPAWN_VEC;
_counter = _counter - 1;
_spawnedUnits = _spawnedUnits + units _grp;
};

that is the main part of the code concerning vehicles... the _xVehiclePercentage is just a value between 0 and 1.

(I'd prefer not to release more code as of yet as this project is still in the alpha stage)

Share this post


Link to post
Share on other sites

I'm sorry, I'm not following when you call the BIS function spawnVehicle.

When you call that, it returns:

Returns:

Array:

0: new vehicle (Object).

1: all crew (Array of Objects).

2: vehicle's group (Group).

So, I've used it as:

// create aircraft
_spawn = [_pos,_azim, _unit, _side] call BIS_fnc_spawnVehicle;
//hint format ["spawned %1", _spawn select 0];
///sleep 1;
_airGrp = _spawn select 2;
//	hint format ["%1 _airGrp = %2", _unit, _airGrp];
//	sleep 1;

To use it as you do, you'd then use the (units _airGrp) to add to your _spawnedUnits.

Also, one thing I've experienced is that A2 is more picky about parens.

This:

_spawnedUnits = _spawnedUnits + (units _grp);

Is more reliable than:

_spawnedUnits = _spawnedUnits + units _grp;

In my experience.

Hope this helps, otherwise, I'm as confused as you are. :)

Share this post


Link to post
Share on other sites

Oh i see what you mean now...

but yea use select to get the parameter im interested in (which is just the group)

aka

_spawnedGrp = ([...] call fnc_spawnVehicle) select 2;

and about the parenthesis it seem to work just fine with infantry so i dunno :s

anyways i sorting it out by designing my own function by creating 1 vehicle and 4 riflemen and making them get in the vehicle using createVehicle and createUnit

It would mean that tanks and vehicles with less then 4 seats would have 1 or 2 soldiers escorting them, though i could just delete the excess soldiers if i wanted to :P

i can post it here later if anyone's interested

Share this post


Link to post
Share on other sites

Yes, please post whatever solution you find! I enjoy seeing how other people solve certain issues, and it is useful later when people search.

Thanks!

Share this post


Link to post
Share on other sites

In a similar vein, I'm using

[getMarkerPos "b3", 180, "ZU23_Ins", EAST] call bis_fnc_spawnvehicle;

as part of script to spawna ZU at one of a number of marker locations.

How do I name the ZU that is spawned (ie call it "AA1")? Setname only works for a location, Set identity throws an array error (the zu I guess is group comprising an object and a soldier?).

Do i need to to create a group and name it? Important note: there is trigger elsewhere that is checking whether AA1 is alive or not, so really want the ZU to be called AA1, not the soldier manning it.

Bascially want to name the Zu just as if I placed a manned zu and populated its name field in the editor.

Edit

I've tried

AA1 = createGroup EAST;
[getMarkerPos "b2", 180, "ZU23_Ins", AA1] call bis_fnc_spawnvehicle;

But the !(alive AA1) trigger now returns an error that AA1 is a group, not an object, which I didn't get when the ZU was manually placed and named in the editor...

Share this post


Link to post
Share on other sites

In a similar vein, I'm using...

try setVehicleVarName

This page is your friend when scripting for arma2, look there first (properly look) before posting here mate ;)

Share this post


Link to post
Share on other sites
try setVehicleVarName

This page is your friend when scripting for arma2, look there first (properly look) before posting here mate ;)

Cheers, bokkmarked it now, I've actually been searching the Biki all morning, but never found it, with any search criteeria specified (Vehicle or name don't find it.)

That command should do the job!

Share this post


Link to post
Share on other sites

varName = ([_pos, 0, "C130J", _grp] call BIS_fnc_spawnVehicle) select 0;

Share this post


Link to post
Share on other sites

Hi all!

I trying create "BMP3" vehicle with name. How to do that?

[getPos mySpawnPos, 180, "BMP3", EAST] call bis_fnc_spawnvehicle

Share this post


Link to post
Share on other sites
Hi all!

I trying create "BMP3" vehicle with name. How to do that?

[getPos mySpawnPos, 180, "BMP3", EAST] call bis_fnc_spawnvehicle

Why don't you start by re-reading post #7 and post #8 in this thread, then use the search function if you're still not getting it.

There are hundreds of posts on this...

Share this post


Link to post
Share on other sites
Why don't you start by re-reading post #7 and post #8 in this thread, then use the search function if you're still not getting it.

There are hundreds of posts on this...

I've read this posts yet two days and don't have answer.

_VarName = "apc";

_veh SetVehicleVarName _VarName;

_veh = [getPos mySpawnPos, 180, "BMP3", EAST] call bis_fnc_spawnvehicle

I know that make a mistake somewhere and I just do not write there.

regards

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  

×