Jump to content
Sign in to follow this  
HulkingUnicorn

Spawn ai to return unused vehicles

Recommended Posts

In missions with respawning and vehicles, there are always someone who will leave a vehicle somewhere in the bushes without telling anyone... With this script I'm trying to make some ai spawn and fly (with a spawned chopper) to the abandoned vehicle - well, you can see the rest from the script wink_o.gif

The first problem seems to appear in the monitorscript (called by radio for the moment) - I'm not getting any hints; it doesn't seem to matter if there are any retrievable vehicles at hand.

Retrieve.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vehicle = this select 0;

if {(alive retrieverchopper) || (alive retrieverpilot) || (alive retrieverdriver)} exitWith {echo "One or more retrivers alive";};

if !(canmove _vehicle) exitWith {echo "Vehicle can move";};

hint format ["%1 can move...", _vehicle];

retrieverchopper = createVehicle ["MH6", position "retrieverbase", [], 0, "NONE"];

retrieverpilot = officials createUnit ["SoldierWB", position "retrieverbase", [], 0, "NONE"];

retrieverdriver = officials createUnit ["SoldierWB", position "retrieverbase", [], 0, "NONE"];

sleep 1;

[retrieverpilot, retrieverdriver] join grpnull;

{_x disableai "target";} foreach units [retrieverpilot, retrieverdriver]; {_x disableai "autotarget";} foreach units [retrieverpilot, retrieverdriver];

retrieverpilot moveindriver retrieverchopper; retrieverdriver moveincargo retrieverchopper;

while {(retrieverdriver distance _vehicle) > 100} do {retrieverpilot domove (getpos _vehicle); sleep 5; hint "working?";};

retrieverdriver action["Eject",retrieverchopper]; retrieverpilot domove (getpos retrieverbase);

retrieverdriver assignasdriver _vehicle; retrieverdriver ordergetin true;

while (driver _vehicle) != retrieverdriver do {sleep 5; hint "Driver in vehicle!"};

while {((driver _vehicle) == retrieverdriver) && ((_vehicle distance west_parking) > 400)} do {retrieverdriver domove (getpos west_parking); sleep 5;};

retrieverdriver action["Eject",_vehicle]; [retrieverdriver, retrieverpilot, retrieverchopper] setdammage 1;

hint format ["%1 (hopefully) retrieved...", _vehicle];

Monitorvehicles.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">carstoretrieve = 0

publicvariable "carstoretrieve"

? (wcar1 distance west_parking) > 1000 && !isplayer (driver wcar1) : {r=[wcar1] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (wcar2 distance west_parking) > 1000 && !isplayer (driver wcar2) : {r=[wcar2] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (wcar3 distance west_parking) > 1000 && !isplayer (driver wcar3) : {r=[wcar3] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (wcar4 distance west_parking) > 1000 && !isplayer (driver wcar4) : {r=[wcar4] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (wcar5 distance west_parking) > 1000 && !isplayer (driver wcar5) : {r=[wcar5] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (wcar6 distance west_parking) > 1000 && !isplayer (driver wcar6) : {r=[wcar6] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (wcar7 distance west_parking) > 1000 && !isplayer (driver wcar7) : {r=[wcar7] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (wcar8 distance west_parking) > 1000 && !isplayer (driver wcar8) : {r=[wcar8] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (wcar9 distance west_parking) > 1000 && !isplayer (driver wcar9) : {r=[wcar9] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (ammo1 distance west_parking) > 1000 && !isplayer (driver ammo1) : {r=[ammo1] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (ammo2 distance west_parking) > 1000 && !isplayer (driver ammo2) : {r=[ammo2] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (ammo3 distance west_parking) > 1000 && !isplayer (driver ammo3) : {r=[ammo3] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (fuel1 distance west_parking) > 1000 && !isplayer (driver fuel1) : {r=[fuel1] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (fuel2 distance west_parking) > 1000 && !isplayer (driver fuel2) : {r=[fuel2] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (fuel3 distance west_parking) > 1000 && !isplayer (driver fuel3) : {r=[fuel3] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (fuel4 distance west_parking) > 1000 && !isplayer (driver fuel4) : {r=[fuel4] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (repair3 distance west_parking) > 1000 && !isplayer (driver repair3) : {r=[repair3] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (repair2 distance west_parking) > 1000 && !isplayer (driver repair2) : {r=[repair2] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

? (repair1 distance west_parking) > 1000 && !isplayer (driver repair1) : {r=[repair1] spawn scr_retrieve; carstoretrieve = (carstoretrieve + 1); publicvariable "carstoretrieve";};

publicvariable "carstoretrieve"

? (carstoretrieve > 0) then {hint format ["Ran check, found %1 vehicles to retrieve", carstoretrieve];};

? (carstoretrieve == 0 then {hint "No vehicles to retrieve"};

carstoretrieve = 0

publicvariable "carstoretrieve"

1 line from init:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

scr_retrieve=compile preprocessfile "retrieve.sqf";

Share this post


Link to post
Share on other sites

just skimming over your script and i do believe your real problem lies in the init file. you never called the script. just precompiled it

EDIT: looking at it again this line in the first script stand out to me:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x disableai "target";} foreach units [retrieverpilot, retrieverdriver]; {_x disableai "autotarget";} foreach units [retrieverpilot, retrieverdriver];

you are grabbing a unit from an array? the units command should be used when you want to grab an array of units from a group. in this case, they are part of a null group, so their group is undefined. since you already have an array of the units, take out the units command. try this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x disableAI "target"; _x disableAI "autotarget";} forEach [retrieverpilot, retrieverdriver];

short and simple.

also it's a good habit to get into putting capital letters in your variable names and commands, it makes them easier to read.

Share this post


Link to post
Share on other sites

it might be a good idea to give their group a name, as well. add the chopper and the vehicle that will be picked up to the group, too.

oh and i noticed this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">retrieverchopper = createVehicle ["MH6", position "retrieverbase", [], 0, "NONE"];

retrieverpilot = officials createUnit ["SoldierWB", position "retrieverbase", [], 0, "NONE"];

retrieverdriver = officials createUnit ["SoldierWB", position "retrieverbase", [], 0, "NONE"];

you can't grap the position of a string. type string, expected object. if "retrieverbase" is a marker, use getMarkerPos.

Share this post


Link to post
Share on other sites

Mmmm, I did some stupid mistakes there smile_o.gif

I do have a radiotrigger to launch this one:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[] exec "monitorvehicles.sqs"

And Retrieve.sqf should be launched by MonitorVehicles.sqs - providing the conditions are right. Look at the last four lines in MonitorVehicles - isn't it odd that the hints don't show up when the script is executed?

Never thought of using several statements with ForEach - guess I follow the biki examples too closely.

CreateVehicle/CreateUnit:

Quote[/b] ]Syntax: createVehicle [type, position, markers, placement, special]

Quote[/b] ]Example 1:veh = createVehicle ["ah1w", position player, [], 0, "FLY"]

I suppose I wanted to do:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">retrieverchopper = createVehicle ["MH6", [0,0,0], ["retrieverbase"], 0, "NONE"];

Would that place it at the marker or at the pos? Guess I'll go with your suggestion though - getmarkerpos, I mean.

Thank you for the quick response!

Edit: The vehicles in need of retrieval are empty at start - as they aren't units there isn't any point in giving them a group right? I'm assuming CreateVehicle creates empty vehicles as well.

Edit:

Updated script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vehicle = this select 0;

if {(alive RetrieverChopper) || (alive RetrieverPilot) || (alive RetrieverDriver)} exitWith {echo "One or more retrivers alive";};

if !(canmove _vehicle) exitWith {echo "Vehicle can move";};

hint format ["%1 can move...", _vehicle];

RetrieverChopper = createVehicle ["MH6", (GetMarkerPos "RetrieverBase"), [], 0, "NONE"];

RetrieverPilot = officials createUnit ["SoldierWPilot", (GetMarkerPos "RetrieverBase"), [], 0, "NONE"];

RetrieverDriver = officials createUnit ["SoldierWCrew", (GetMarkerPos "RetrieverBase"), [], 0, "NONE"];

sleep 1;

[RetrieverPilot, RetrieverDriver] join Retrievergroup;

{_x disableAI "target"; _x disableAI "autotarget";} forEach [RetrieverPilot, RetrieverDriver];

RetrieverPilot moveindriver RetrieverChopper; RetrieverDriver moveincargo RetrieverChopper;

while {(RetrieverDriver distance _vehicle) > 100} do {RetrieverPilot doMove (getpos _vehicle); sleep 5; hint "working?";};

RetrieverDriver action["Eject",RetrieverChopper]; RetrieverPilot doMove (GetMarkerPos "RetrieverBase");

RetrieverDriver assignasdriver _vehicle; RetrieverDriver ordergetin true;

while (driver _vehicle) != RetrieverDriver do {sleep 5; hint "Driver in vehicle!"};

while {((driver _vehicle) == RetrieverDriver) && ((_vehicle distance west_parking) > 400)} do {RetrieverDriver doMove (getpos west_parking); sleep 5;};

RetrieverDriver action["Eject",_vehicle]; [RetrieverDriver, RetrieverPilot, RetrieverChopper] setdammage 1;

hint format ["%1 (hopefully) retrieved...", _vehicle];

Share this post


Link to post
Share on other sites
Quote[/b] ]CreateVehicle/CreateUnit:

I suppose I wanted to do:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">retrieverchopper = createVehicle ["MH6", [0,0,0], ["retrieverbase"], 0, "NONE"];

Would that place it at the marker or at the pos? Guess I'll go with your suggestion though - getmarkerpos, I mean.

oh yeah you're right. that should work fine, then.

Quote[/b] ]Edit: The vehicles in need of retrieval are empty at start - as they aren't units there isn't any point in giving them a group right? I'm assuming CreateVehicle creates empty vehicles as well.

the AI is far from intelligent in this game. usually if you don't add the vehicle to the group, the guys like to get out immediately.

here is the script after a few changes

retrieve.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vehicle = this select 0;

_base = getMarkerPos "RetrieverBase";

_lot = getPos west_parking;

if {(alive RetrieverChopper) || (alive RetrieverPilot) || (alive RetrieverDriver)} exitWith {echo "One or more retrivers alive";};

if !(canMove _vehicle) exitWith {echo "Vehicle can't move";};

hint format ["%1 can move...", _vehicle];//can objects be turned into strings?

RetrieverGroup = createGroup west;

RetrieverChopper = createVehicle ["MH6", _base, [], 0, "NONE"];

//i threw out the reference to 'officials' and put the retriever group in its place

RetrieverPilot = RetrieverGroup createUnit ["SoldierWPilot", _base, [], 0, "NONE"];

RetrieverDriver = RetrieverGroup createUnit ["SoldierWCrew", _base, [], 0, "NONE"];

sleep 1;

[RetrieverPilot, RetrieverDriver, RetrieverChopper] join RetrieverGroup;

{_x disableAI "target"; _x disableAI "autotarget";} forEach [RetrieverPilot, RetrieverDriver];

RetrieverPilot moveInDriver RetrieverChopper;

RetrieverDriver moveInCargo RetrieverChopper;

while {(RetrieverDriver distance _vehicle) > 100} do

{

RetrieverPilot doMove (getPos _vehicle);

sleep 15; //i raised this a bit so that the ai doesn't stop and pause after 5 seconds of moving

hint "ordering pilot to get in the vehicle";

};

RetrieverDriver action ["Eject", RetrieverChopper];

RetrieverPilot doMove _base;

_vehicle join RetrieverGroup; //added vehicle to the group

RetrieverDriver assignAsDriver _vehicle;

[RetrieverDriver] orderGetIn true; //this command takes an array as it's parameter

while {((driver _vehicle) != RetrieverDriver) && (alive RetrieverDriver)} do //added curly braces

{

sleep 5;

hint "Player in vehicle or retriever not in vehicle yet.";

};

while {(alive RetrieverDriver) && ((driver _vehicle) == RetrieverDriver) && ((_vehicle distance _lot) > 400)} do

{

RetrieverDriver doMove _lot;

sleep 15; //i raised this a bit so that the ai doesn't stop and pause after 5 seconds of moving

};

RetrieverDriver action ["Eject", _vehicle];

RetrieverChopper setPos [0,0,0]; //move the chopper so it doesn't expolode and kill someone.

//according to the biki, setDammage doesn't take arrays as a parameter

{_x setDammage 1; sleep 0.001; } forEach [RetrieverDriver, RetrieverPilot, RetrieverChopper];

hint format ["%1 (hopefully) retrieved...", typeOf _vehicle];

//assuming that it is...

carstoretrieve = carstoretrieve - 1;

i also noticed that your monitorvehicles.sqs file is a bit jacked up. using the publicVariable command WAY too much. crazy_o.gif don't put it in every if statement; only once after all the vehicles are checked. using publicVariable too much is bad...very bad.

also, you should decide on whether you are using sqs or sqf syntax on there...because it looks like both were thrown in there. whistle.gif if i were you, i'd change it all to sqf because you appear to have that down correctly. and sqf

the last few lines were a bit messed up for sqs syntax, so here's the proper stuff:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? (carstoretrieve > 0) : hint format ["Ran check, found %1 vehicles to retrieve", carstoretrieve]

? (carstoretrieve == 0) : hint "No vehicles to retrieve"

[/code]

and you don't need to use curly braces anywhere in sqs.

Share this post


Link to post
Share on other sites

Where to begin, lol...

Retrieve.sqf

It isn't enough to assign them to the vehicle? Stupid ai tounge2.gif

Do units count as objects? I did pull unitnames (the name given in editor, not the random ones) out that way with eventhandler and hint format before, so I just assumed it would work.

Nice touch at the end (-1), but wouldn't you need publicVariable?

MonitorVehicles.?

Yes, this script is a mess wink_o.gif

I originally wanted to create a quick test script to launch the other one... so I picked sqs (which I thought myself more familiar with - but I also wanted to use goto). However, at some point I decided to... mess it up (not what I decided, but what I did). I had planned to just put a goto "lastPart" without checking the other vehicles - that way, less pubVars would have been ran.

For some reason I got a lot of errors with the script, so I tried changing the format 'a bit'.

I guess I should just rewrite it - this time in sqf whistle.gif

Thanks a lot!

Update:

Retrieving script is WORKING! I had to change the curlybraces in the initial alivecheck for parantheses and put the last _vehicle join in an array (actually I'm removing that one, as it wasn't needed - keeping it for the guys and the chopper though). I also had to use _this select instead of this select in the beginning...

Now I just have to make the findVehicle.sqf work - after that I will put in the finished thing for all to use wink_o.gif

Share this post


Link to post
Share on other sites

V 1.01:

- Added markertracking

- Script will stop if a player enters the vehicle

- Script will stop if the driver in retrieval team dies

- Script will stop if chopper/pilot goes down while the team is flying to the vehicle

findVehicle.sqf :

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_carsToRetrieve = 0;

_lot = west_parking;

_vehicleList = [wcar1,wcar2,wcar3,wcar4,wcar5,wcar6,wcar7,wcar8,wcar9,ammo1,ammo2,ammo3,ammo4,fuel1,fue

l2,fuel3,fuel4,repair1,repair2,repair3];

_counter = count _vehicleList;

_i = 0;

while {_i < _counter} do

{

_timer = 0;

while { (_carsToRetrieve == 0) && (_timer < 1) } do

{

if ( (((_vehicleList select _i) distance _lot) > 800) && (canMove (_vehicleList select _i)) && ((fuel (_vehicleList select _i)) > 0) && !isPlayer (driver (_vehicleList select _i)) ) then

{r=[_vehicleList select _i] spawn scr_retrieve; _carsToRetrieve == 1;};

_timer = _timer + 1; sleep 0.001;

};

_i = _i + 1;

};

retrieve.sqf :

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vehicle = _this select 0;

_base = getMarkerPos "RetrieverBase";

_lot = getPos west_parking;

if ((alive RetrieverChopper) || (alive RetrieverPilot) || (alive RetrieverDriver)) then

{

hint "Retrieval team in action;\nwait until they finish before trying to retrieve more vehicles...";

};

if ((alive RetrieverChopper) || (alive RetrieverPilot) || (alive RetrieverDriver)) exitWith {echo "";};

if !(canMove _vehicle) exitWith {echo "";};

hint format ["%1 is selected for retrieval", typeOf _vehicle];

"m_rtrv_veh" setmarkerpos (getpos _vehicle);

RetrieverGroup = createGroup west;

RetrieverChopper = createVehicle ["MH6", _base, [], 0, "NONE"];

RetrieverPilot = RetrieverGroup createUnit ["SoldierWPilot", _base, [], 0, "NONE"];

RetrieverDriver = RetrieverGroup createUnit ["SoldierWCrew", _base, [], 0, "NONE"];

sleep 1;

[RetrieverPilot, RetrieverDriver, RetrieverChopper] join RetrieverGroup;

{_x disableAI "target"; _x disableAI "autotarget";} forEach [RetrieverPilot, RetrieverDriver];

RetrieverPilot moveInDriver RetrieverChopper;

RetrieverDriver moveInCargo RetrieverChopper;

while {(RetrieverDriver distance _vehicle) > 100} do

{

if isPlayer (driver _vehicle) then {hint "Vehicle now occupied - retrieval cancelled"; RetrieverDriver setDammage 1;};

if ( !alive RetrieverPilot || !alive RetrieverChopper || !alive RetrieverDriver || !canMove _vehicle ) then

{

RetrieverChopper setPos [0,0,0];

{_x setDammage 1; sleep 0.001;} forEach [RetrieverDriver, RetrieverPilot, RetrieverChopper];

if !isPlayer (driver _vehicle) then {hint "Retrieval team failed - consider securing their path before trying again...";};

};

if ( !alive RetrieverPilot || !alive RetrieverChopper || !alive RetrieverDriver || !canMove _vehicle ) exitWith {echo "";};

RetrieverPilot doMove (getPos _vehicle);

hint "Retriever team moving to collect the vehicle...";

"m_rtrv_veh" setmarkerpos (getpos _vehicle);

"m_rtrv_chpr" setmarkerpos (getpos RetrieverChopper);

sleep 15; //i raised this a bit so that the ai doesn't stop and pause after 5 seconds of moving

};

"m_rtrv_chpr" setmarkerpos [0,0];

RetrieverDriver action ["Eject", RetrieverChopper];

RetrieverPilot doMove _base;

//Optional: [_vehicle] join RetrieverGroup;

RetrieverDriver assignAsDriver _vehicle;

[RetrieverDriver] orderGetIn true;

while {((driver _vehicle) != RetrieverDriver) && (alive RetrieverDriver)} do

{

if isPlayer (driver _vehicle) then {hint "Vehicle now occupied - retrieval cancelled"; RetrieverDriver setDammage 1;};

"m_rtrv_veh" setmarkerpos (getpos _vehicle);

"m_rtrv_drv" setmarkerpos (getpos RetrieverDriver);

hint "Driver approaching vehicle.";

sleep 5;

};

while {(alive RetrieverDriver) && ((driver _vehicle) == RetrieverDriver) && ((_vehicle distance _lot) > 250)} do

{

"m_rtrv_veh" setmarkerpos (getpos _vehicle);

RetrieverDriver doMove _lot;

hint format ["%1 is being returned to base", typeOf _vehicle];

sleep 15;

};

if ( !alive RetrieverDriver || !canMove _vehicle ) then

{

RetrieverChopper setPos [0,0,0]; sleep 0.5;

{_x setDammage 1; sleep 0.001;} forEach [RetrieverDriver, RetrieverPilot, RetrieverChopper];

if !isPlayer (driver _vehicle) then {hint "Retrieval team failed - consider securing their path before trying again...";};

};

if ( !alive RetrieverDriver || !canMove _vehicle ) exitWith {echo "";};

RetrieverDriver action ["Eject", _vehicle]; sleep 1; RetrieverDriver moveInCargo RetrieverChopper;

RetrieverChopper setPos [0,0,0]; //move the chopper so it doesn't explode and kill someone.

{_x setDammage 1; sleep 0.001; } forEach [RetrieverDriver, RetrieverPilot, RetrieverChopper];

if ((_vehicle distance _lot) <= 250) then {hint format ["%1 retrieved...", typeOf _vehicle];};

Works in MP (atleast getting the driver near the vehicle - seems like he got stuck last time I tested...)

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  

×