Jump to content
Sign in to follow this  
Uncle Imshi

Looking for a vehicle + Crew spawn script for Dedi

Recommended Posts

Hey,

I'm a complete scripting novice, and after spending the last couple of days trawling this forum and OFPEC and trying to piece together a script I've got nothing to show for it.

Can someone provide or advise me on how to create a script for use on a fairly intensive dedicated server mission that will create crewed opfor vehicles allow for some sort of waypointed action, and the ideally delete the vehicles after a certain time period has lapsed?

Basically what I want to simulate is a number of armed pick ups arriving over the horizon, engaging the players' position and then disappearing off again unless they have been destroyed.

Share this post


Link to post
Share on other sites

Once again I can present a function to you that I am using all the time:

func_spawnVehicle:

private ["_Grp","_type","_side","_vec","_unit","_pos","_radius"]; 

_type = _this select 0;
_side = _this select 1;
_pos = _this select 2;
_radius = _this select 3;

_x = _pos select 0;
_y = _pos select 1;

_Grp = createGroup _side;

_spawnpos = [0,0];
While{surfaceIsWater _spawnpos} do {
_spawnpos = [_x + _radius - random (_radius*2), _y + _radius - random (_radius*2)];
};
_spawnpos set [2,0];

_vec = _type createVehicle _spawnpos;

_crewtype = getArray (configFile >> "CfgVehicles" >> _type >> "typicalCargo");
_max = (count _crewtype)-1;

if(count(_crewtype - ["Soldier"])==0) then{
if(_side==EAST) then{_crewtype = ["RU_Soldier"]}
else {_crewtype = ["USMC_Soldier"]};
};

if((_vec emptyPositions "commander") > 0) then {
_unit = _grp createUnit [_crewtype select (round random _max), _pos, [], 0.5, "NONE"];
_unit moveinCommander _vec;
};

if((_vec emptyPositions "gunner") > 0) then {
_unit = _grp createUnit [_crewtype select (round random _max), _pos, [], 0.5, "NONE"];
_unit moveinGunner _vec;
};		

if((_vec emptyPositions "driver") > 0) then {
_unit = _grp createUnit [_crewtype select (round random _max), _pos, [], 0.5, "NONE"];
_unit moveinDriver _vec;
};

_Grp

Precompile it by writing into the Init.sqf:

spawnVehicle = compile (preprocessFileLineNumbers "func_spawnVehicle.sqf");

The first parameter is the vehicle type, second is the side the vehicle's crew is assigned to, third is the spawn position (in form of [x,y,z]) and last is the spawnradius. It returns the group the vehicles crew is assigned to.

Example:

grp = ["BMP3",EAST,pos,50] call spawnVehicle;

creates a russian BMP3 in a radius of 50 around the position pos and stores the crew's group into the grp variable.

Edited by Bon

Share this post


Link to post
Share on other sites

Hmm, I'll give it a go. But the last one of these FNC func scripts I tried just crashed my PC.

Also I'm struggling to figure out how to get the pos working.

Edited by Uncle Imshi

Share this post


Link to post
Share on other sites
Hmm, I'll give it a go. But the last one of these FNC func scripts I tried just crashed my PC.

Also I'm struggling to figure out how to get the pos working.

Last time my example was about spawning about 1000 enemy infantry units. Don't know if you used exactly this example, but I am quite sure this would crash my PC, independend on the script itself. I never had any problems with these functions.

For the position it is very simple. Big_Daddy gave you the hint last time: Place an invisible HeliH in the editor, name it as you like, lets say, testH.

Now you call the function with

grp = ["BMP3",EAST,getPos testH,50] call spawnVehicle;

Ok?

Share this post


Link to post
Share on other sites

No Joy I'm afraid.

Have copied the init verbatim, used an invisible helipad with the same name as the example.

I have copied the precompile line into my init

Could the fact I'm using a radio trigger to test it be the problem?

Btw: I was using your last script to spawn 10...didn't fancy subjecting my PC to 1000 units.

Share this post


Link to post
Share on other sites

Just remember to run it only on server, as the script doesn't check for it. Or you will get a unit created per player.

Share this post


Link to post
Share on other sites

I think the problem is that the statement in the radio trigger is initialized BEFORE the function gets compiled.

Use addAction instead. Also as shk mentioned, never use a radio trigger to spawn units since radio trigger statements are executed on each machine.

You of course can use the function as a normal script by:

- cutting out the last line containing the _Grp,

- add the line

if(not isServer) exitWith{};

at the beginning of the script.

Then you don't have to precompile it and can use it out of a radio trigger, call it with

_spawn = ["BMP3",EAST,getPos testH,50] execVM "spawnVehicle.sqf";

(rename the func_spawnVehicle.sqf to spawnVehicle.sqf).

But then you have to abdicate the main benefit of a function, that it can return the group of the recently spawned enemies. Then it will be a bit harder to handle events with these units.

Edited by Bon

Share this post


Link to post
Share on other sites

Bingo, the radio trigger was the problem.

I don't want this to be a player call - so I'll probably use a present or detected trigger.

Is the script as above ok to run on a dedi or do I need to add if (!isserver) exitwith {};

Edit: the crew aren't spawning in the vehicle

Edited by Uncle Imshi

Share this post


Link to post
Share on other sites
Bingo, the radio trigger was the problem.

I don't want this to be a player call - so I'll probably use a present or detected trigger.

Is the script as above ok to run on a dedi or do I need to add if (!isserver) exitwith {};

First of all, a trigger of any kind SHOULD be executed on each machine, so the if(!isServer) exitWith{} is important, most definetly.

I said "SHOULD", because I often experienced a trigger being executed on a client machine but NOT on the dedicated server machine. Weird, but true. So this could cause some more problems. A quick and dirty workaround is to write into your trigger condition something like

this || trigger_executed

and in the activation field you add

trigger_executed=true; publicVariable "trigger_executed"

That makes sure the trigger is executed on the dedicated server, too.

As I said, this really is dirty, but it will do the trick.

---------- Post added at 01:09 PM ---------- Previous post was at 12:55 PM ----------

Edit: the crew aren't spawning in the vehicle

I changed the skillset in the script before posting it, because I am using a mission parameter for it, and just replaced it by "random 1". Maybe there is a number of form 0.1 or 0.2 or 0.3 ... expected, but the random function creates numbers of 0.122345 whatever.

I just replaced these areas above with skill 0.5 in hope that will create the crew now.

Share this post


Link to post
Share on other sites

Hey,

The crew are working now - but they don't seem willing to engage.

In terms of getting the vehicle to do things, can I now just copy and paste a series of waypoint commands in from another script or alternatively get them to execute the UPS script?

I'm experimenting away but advance notice of what might break the script would be very helpful.

Share this post


Link to post
Share on other sites

No reason for me to assume some waypoint statements or another script call at the end of the script would break it.

Share this post


Link to post
Share on other sites
if(!isServer) exitWith{};

private ["_Grp","_type","_side","_vec","_unit","_pos","_radius"];

_type = _this select 0;

_side = _this select 1;

_pos = _this select 2;

_radius = _this select 3;

_x = _pos select 0;

_y = _pos select 1;

_Grp = createGroup _side;

_spawnpos = [0,0];

While{surfaceIsWater _spawnpos} do {

_spawnpos = [_x + _radius - random (_radius*2), _y + _radius - random (_radius*2)];

};

_spawnpos set [2,0];

_vec = _type createVehicle _spawnpos;

_crewtype = getArray (configFile >> "CfgVehicles" >> _type >> "typicalCargo");

_max = (count _crewtype)-1;

if(count(_crewtype - ["Soldier"])==0) then{

if(_side==EAST) then{_crewtype = ["RU_Soldier"]}

else {_crewtype = ["USMC_Soldier"]};

};

if((_vec emptyPositions "commander") > 0) then {

_unit = _grp createUnit [_crewtype select (round random _max), _pos, [], random 1, "NONE"];

_unit moveinCommander _vec;

};

if((_vec emptyPositions "gunner") > 0) then {

_unit = _grp createUnit [_crewtype select (round random _max), _pos, [], random 1, "NONE"];

_unit moveinGunner _vec;

};

if((_vec emptyPositions "driver") > 0) then {

_unit = _grp createUnit [_crewtype select (round random _max), _pos, [], random 1, "NONE"];

_unit moveinDriver _vec;

};

_nul=[_vec,""markerToPatrol""] execVM ""ups.sqf"";

_Grp

I can get the script working in its basic format. But when I add the line

_nul=[_vec,""markerToPatrol""] execVM ""ups.sqf"";

It ceases to work.

Also is there something in the script that sets the crew to never fire? I can't get a violent reaction from them no matter what I do.

Share this post


Link to post
Share on other sites

No joy with that, and I've also tried adding this:

{_x enableAI} forEach units group _grp;

To get the AI to actually do something when they are on the map - this also stops the script from working.

I had pasted the line into the script just about the final instance of '_grp' at the end of the script.

Share this post


Link to post
Share on other sites

I can get the script working in its basic format. But when I add the line

_nul=[_vec,""markerToPatrol""] execVM ""ups.sqf""; 

It ceases to work.

Ok a simple script call for an extern script CANNOT break the current script. If just the content of this "ups.sqf" doesn't work it must be a failure in the ups.sqf script. Otherwise here are my only suggestions:

- First of all do as I said and remove the very last line "_Grp". This was the return statement of the former function and doesn't belong to a normal script.

- Then (I know it should'nt matter but just in case to make sure) write

[_vec,"markerToPatrol"] execVM "ups.sqf";

instead of

_nul=[_vec,""markerToPatrol""] execVM ""ups.sqf"";

.

Also is there something in the script that sets the crew to never fire? I can't get a violent reaction from them no matter what I do.

This script only creates a vehicle with its crew, it is not responsible for its behaviour. To give them particular behavior

{_x enableAI} forEach units group _grp;

is completely wrong, as you can read out in the list of scripting commands.

Give them a waypoint or use setCombatMode or setBehaviour.

In case you meet problems with these statements, read its description in the biki carefully and use the advanced search function of this forum before posting it in this thread, since it is a bit out of topic.

EDIT: add

-showScriptErrors

to your ArmA2 shortcut to list all script syntax errors ingame.

Edited by Bon

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  

×