OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: whiskey on 12 Dec 2010, 00:51:01

Title: createVehicle and getPos without name.
Post by: whiskey on 12 Dec 2010, 00:51:01
I've got a group of men that I've attached and action to with this line...

Code: [Select]
{_x addAction ["Detonate Vest","detvest.sqf"]} forEach units group this;
...but the only thing my scripting challenged mind can think to put in detvest.sqf is...

Code: [Select]
bomb = "BO_GBU12_LGB" createvehicle getPos guy;

guy removeAction 0;


...but that just blows up the one unit. How do I setPos a bomb to the AI who I ordered to detonate (F#>6>1)? Without having to name 20 men and having 20 detvest#.sqf files in the mission folder.
Title: Re: createVehicle and getPos without name.
Post by: JamesF1 on 12 Dec 2010, 02:02:36
Change detvest.sqf to (untested, but should work):

Code: [Select]
bomb = "BO_GBU12_LGB" createvehicle getPos (_this select 1);

(_this select 0) removeAction (_this select 2);

When using addAction (http://community.bistudio.com/wiki/addAction), it automatically passes the unit the action is attached to, the unit who used the action and the action ID number to the script.  So we've used those here.
Title: Re: createVehicle and getPos without name.
Post by: whiskey on 12 Dec 2010, 02:23:55
Despite making missions since CWC, being able to use and tinker with other peoples scripts or using the functions from A2/OA this stuff is still like black magic when it comes to writing my own. :dry:

What should I read to explain the whole 'this select 0' thing?

Thank you James, works perfectly.

Title: Re: createVehicle and getPos without name.
Post by: JamesF1 on 12 Dec 2010, 02:36:04
Well, "_this" is the information (or parameters) passed to the script.  In this case, it's an array of values (the three I mentioned above).  In order to access the values in an array, we use the keyword 'select'.  The first value is '_this select 0', the second is '_this select 1' and so on...

So, if we had an array:
Code: [Select]
_myArray = [1, 4, 3, 8, 9];
To get the number 3, we'd do:
Code: [Select]
_myNumber = _myArray select 2;
To make the script above more obvious, we could do:
Code: [Select]
_parameters = _this;
_attachedTo = _parameters select 0;
_user = _parameters select 1;
_id = _parameters select 2;

bomb = "BO_GBU12_LGB" createVehicle getPos _user;

_attachedTo removeAction _id;

This has no real difference* but is just a more readable version.
* Technically it is more resource-intensive but by such a minuscule amount that you'd never notice it, even if the script was run 100 times simultaneously.

Hope that helps :)
Title: Re: createVehicle and getPos without name.
Post by: whiskey on 12 Dec 2010, 04:33:44
Lol, you're first description made far more sense than the second. :confused:

The script works but not if the unit is in a vehicle, the bomb doesn't spawn. Looking at the Biki for if/else & vehicle commands seems to be what I need but again the syntax is beyond me, to check if he's in a vehicle and spawn the bomb at the vehicle instead....

Code: [Select]
_inVeh = if (? vehicle player != player : hint "Player is in a vehicle")

then

{bomb = "BO_GBU12_LGB" createvehicle getPos (_this select not_sure?);}

else

{bomb = "BO_GBU12_LGB" createvehicle getPos (_this select 1);};

hint str _inVeh

I can only assume that to those who script ^this^ is ugly... and broken. :whistle:
Title: Re: createVehicle and getPos without name.
Post by: NightJay0044 on 12 Dec 2010, 05:49:30
so you just want to have the player have the bomb? That's your objective?
Title: Re: createVehicle and getPos without name.
Post by: whiskey on 12 Dec 2010, 06:23:11
In this scenario the player is a terrorist leader with 10 men under him, each of these men strapped with a bomb vest. The objective at the moment is to cause as many civilian casualties as possible with these ten men. I already have the civilian kill counter in. Eventually I hope to have a small but fully populated island where the player can pick the locations of the bombings. There will be options other than instant suicide but just tinkering really.

The problem I have above is that the setposing of the bomb doesn't work if they're in a vehicle, so I need it to setpos it to the vehicle instead (in that case).
Title: Re: createVehicle and getPos without name.
Post by: Mamba6 on 13 Dec 2010, 04:42:31
Code: [Select]
_unit = _this select 1;
_actionID = _this select 2;
bomb = "BO_GBU12_LGB" createvehicle getPos (vehicle _unit);

_unit removeAction _actionID;

That should work, no guarantees. :)

When then man is not in a vehicle, the command
Code: [Select]
getPos (vehicle _unit) will just return the unit's position. Otherwise, it will return the vehicle's position.

NB: Speaking of resource efficiency, IIRC getPosASL or getPosATL is up to 10 fold faster than getPos...