Jump to content
Sign in to follow this  
Mongoose_84

need an array with a vehicle's cargo units

Recommended Posts

i know, there are fuctions to return a vehicle's gunner, commander, driver or the entire crew, but is there a way to return the cargo units only?

i want to find out in a script what position a certain unit has inside a vehicle. i could just assume, that if it isn't the driver, gunner or commander, it has to be in cargo - but since there are also turret positions (units in those positions can't be returned with a function either, right?), that wouldn't be a good idea, i guess.

edit: and another question... what's the best way of deleting or at least removing a unit from a vehicle (instantly, if possible) - deleteVehicle doesn't work on a unit inside of a vehicle.

Share this post


Link to post
Share on other sites

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

_myArray = [];

_myVehicle = XXXX;

{

if (!(driver _myVehicle == _x) and !(gunner _myVehicle == _x) and !(commander _myVehicle == _x) then

{

_myArray = _myArray + _x;

};

} forEach crew _myVehicle;

Not necessarilly 100% accurate code, it's close though, for sqf format.

Share this post


Link to post
Share on other sites
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_myArray = [];

_myVehicle = XXXX;

{

if (!(driver _myVehicle == _x) and !(gunner _myVehicle == _x) and !(commander _myVehicle == _x) then

{

_myArray = _myArray + _x;

};

} forEach crew _myVehicle;

Not necessarilly 100% accurate code, it's close though, for sqf format.

thx, but is it really given, that every unit that is not the commander, driver or gunner is automatically in cargo? aren't there other positions that can't be adressed like this? like "turrets"? that's my problem, actually. of course, most of the times it'll work, if i just assume that "cargo" is the only alternative, but will it always work?

in this post there's a rather long script of mine for which i need to know this, btw - just in case, you want to know the context

and now my brain needs some rest, after a hard day of scripting wink_o.gif . good night! goodnight.gif

Share this post


Link to post
Share on other sites

what i would do- which doesn't mean the other way wouldn't work - is creating two arrays. one with the whole crew, and one with the driver, gunner and commander. then substract the second from the first and you should have an array which contains only the 'non-functional' crewmembers.

Share this post


Link to post
Share on other sites
Quote[/b] ]thx, but is it really given, that every unit that is not the commander, driver or gunner is automatically in cargo? aren't there other positions that can't be adressed like this? like "turrets"? that's my problem, actually. of course, most of the times it'll work, if i just assume that "cargo" is the only alternative, but will it always work?

Yeah, I just checked. Vehicles with mutiple turrets only return a single gunner, if you use the crew or gunner command.

So if all your after is the cargo and not the extra gunners, then using the usual methods will work ok:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Cargo=(Crew _Vehicle)-((Driver _Vehicle)+(Gunner _Vehicle))

Quote[/b] ]edit: and another question... what's the best way of deleting or at least removing a unit from a vehicle (instantly, if possible) - deleteVehicle doesn't work on a unit inside of a vehicle.

First make a copy of the crew then Delete the vehicle, wait until the vehicle has been removed, then delete the crew array.

But if your going to do that you will need a function to return all the vehicles crew members for multi turreted vehicles, if you have any.

TotalCrew.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_Vehicle","_Result"];

_Vehicle=_This Select 0;

_Result=[];

{If ((Vehicle _x)==(Vehicle _Vehicle)) Then {_Result=_Result+[_x]} ForEach (Group _Vehicle)};

_Result=(Commander _Vehicle)+(Driver _Vehicle)+(_Result-(Crew _Vehicle))+(Gunner _Vehicle)+((Crew _Vehicle)-(Commander _Vehicle)+(Driver _Vehicle));

_Result

It looks like gunner returns the last gunner in.

Then use this:

<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;

TotalCrew=Compile PreProcessFile "TotalCrew.sqf";

_Crew=[_Vehicle] Call TotalCrew;

DeleteVehicle _Vehicle;

WaitUntil {IsNull _Vehicle};

{DeleteVehicle _x} ForEach _Crew;

If you going to call TotalCrew on more than one occasion, then best to compile in your init.sqs.

Edit: Bug fix.

Share this post


Link to post
Share on other sites

thx for all replies!

@UNN

thanks even more for the detailed answer!

just to be sure, i got this right: if the unit isn't the comm, driver or gunner of a vehicle, but is still in the crew, it's in the cargo - and if it's not (in the crew), it has an "unadressable" turret-position, right?

and secondly, wouldn't your suggested way of deleting crew-members cause problems in MP-games? i don't know much about localities yet, but this doesn't seem right to me. i mean, what if some crew members don't belong to the player's team? huh.gif

Share this post


Link to post
Share on other sites
Quote[/b] ]thanks even more for the detailed answer!

No worries, not saying you could not have done it yourself btw. Sometimes it’s easier just to type up the whole thing in one go.

Quote[/b] ]just to be sure, i got this right: if the unit isn't the comm, driver or gunner of a vehicle, but is still in the crew, it's in the cargo - and if it's not (in the crew), it has an "unadressable" turret-position, right?

Yeah, thats it exactly.

Quote[/b] ]and secondly, wouldn't your suggested way of deleting crew-members cause problems in MP-games? i don't know much about localities yet, but this doesn't seem right to me. i mean, what if some crew members don't belong to the player's team?

I'm just starting out on MP side myself, so bear with me. But if your vehicle has a driver, then the vehicle and any unit inside is made local to the driver. So if the driver is a player or a member of the players group, then it's local to him. Anything else is local to the server. But the deleteVehicle command is quite robust, for example if you try and delete a player, it will ignore the request. So you can probably get away with calling it just on the Server.

Share this post


Link to post
Share on other sites

i don't even know how to determine, whether a script should be run on the server or a client biggrin_o.gif . i guess, there's more to it than just the use of (local) variables...

Share this post


Link to post
Share on other sites

Since Arma 1.05, there's a new function, assignedVehicleRole.

See it here

The function returns detailed turret positions too biggrin_o.gif

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

_myArray = [];

_myVehicle = XXXX;

{

if ( (count (assignedVehicleRole _x)>0) && ((assignedVehicleRole _x) select 0) == "Cargo") then

{

_myArray = _myArray + _x;

};

} forEach crew _myVehicle;

(I did not test the code but you get the idea...)

Edit: I revived this old thread as it is linked on a biki page (which I closed and can't find back...)

Share this post


Link to post
Share on other sites

May I correct you UNN,

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Cargo=(Crew _Vehicle)-((Driver _Vehicle)-(Gunner _Vehicle))

is not quite correct. The correct line should be

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Cargo = (crew vehicle) - [driver vehicle, gunner vehicle]

Share this post


Link to post
Share on other sites
Quote[/b] ]May I correct you UNN

Please do. I hate to see such errors, raising thier ugly heads some time in the future.

It was supposed to be:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Cargo=(Crew _Vehicle)-((Driver _Vehicle)+(Gunner _Vehicle))

Which does the same as Hardrocks suggestion.

Quote[/b] ]Since Arma 1.05, there's a new function, assignedVehicleRole.

See it here

The function returns detailed turret positions too

Yeah and the crew command returns all the turret gunners now, so we can't use the old method. Your function does the job just fine.

BTW It might be better to post the code straight into the wiki and remove the link? The link here was just a temporary measure. The problem was already posted in the bug list by the time I added it.

Share this post


Link to post
Share on other sites
Quote[/b] ]i don't even know how to determine, whether a script should be run on the server or a client biggrin_o.gif . i guess, there's more to it than just the use of (local) variables...

As someone who helps support a very large server environment (~6,000 servers of various types), let me suggest that you don't want any scripts running on the client at all if you can help it. You must assume that anything on the client (and therefore out of a server admin's control) will be compromised by crackers and griefers. That's just Network Security 101.

Share this post


Link to post
Share on other sites

Nope, there is no a command to know who is in cargo seats in a fast command way.

This is how i got it (2nd gunners too).

First, you have to take into account if you want in that array included the dead players (normally dead AI, or disconnected human players).

2nd, remember that since ArmA 1.05, 2nd gunners is appearing now in the array made by the "crew" command.

It changes a bit the way you getting the final array.

With :

gunner (vehicle)

commander (vehicle)

driver (vehicle)

you can know who is in that seats.

Ok, nothing new but you know now 3 seats.

You'll have to check if nobody in those 3 seats.

You can do it as example with "isNull".

With this command: "emptyPositions" you can know how many free seats you have in your desired vehicle.

As example, use it with "cargo".

Well, if you know how many seats the vehicle having as maximum... it's easy to extract the cargo players from the original array that you must got with the command "crew".

Just delete or quit (inverse of add?) the gunner, driver and commander of the crew array (i recommend you: use a copy of that array). Then all what you have is cargo... and maybe the 2nd gunner too.

Well, now you have all cargo + 2nd gunner (if present and if UH60MG or RHIB2Turret).

How to reach the 2nd gunner?

I encourage you to make this tests:

A gunner, can move his position inside a vehicle, 2nd gunner too, as they can move his weapon, they are moving from a point of reference from the vehicle.

Where is that point of reference? who cares, yep, really who cares because you don't need it.

Just because the command "distance" can give you the solution directly.

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

How?

Well, try to check the distance from the vehicle to all those players you have in the array (cargo + possible 2nd gunner).

More or less in this way:

_posplayer = _seatplayer distance _unit

Where

_unit is the vehicle

_seatplayer is the player in array that you are checking with "Array select X" ---> _seatplayer = MaybeCargoArray select X

and _posplayer = the distance from the vehicle to your soldier that you are checking.

Well, its time to put that magic numbers. But please, you will learn this method, better, if you testing this. Not only copy and paste.

UH60MG Doorgunner: distances from the vehicle: MIN: 3.73m MAX: 3.737m

RHIB2Turret Reargunner: distances from the vehicle : MIN: 3.63m  MAX : in this case MIN is the MAX, so if you have a player more far than 3.63m, then he is not inside the boat whistle.gif  just he is playing with Nemo... or your sentences is wrong.

Then:

Player that meeting this criteria

? _posplayer > 3.73 AND _posplayer < 3.737 : _IKnowWhoWas = _seatplayer

is true for UH60MG, _seatplayer will be the player Doorgunner

and

? _posplayer > 3.63 : _IHuntedTheRearGunner = _seatplayer

is true for RHIB2Turret, _seatplayer will be the player Reargunner.

Then, if there is a player in that array matching this condition... you can quit him from the array, then, all what you have is 100% a cargo array.

Be carefull when 'null' objects in your arrays... be carefull with dead players in your arrays...

You will find that 2nd gunner in UH60MG and RHIB2Turret have a margin of distances, this means, not stable distances, because they can 'move' inside the vehicle.

But surely, the limits of the coordinates of that movements is not equal to any body more. Just because a body is occuping a space in the vehicle, and seats inside vehicles is not done in a symmetrical way in ArmA (thx ArmA, thx).

Well, this method of distance maybe you thinking that is a bit weird.. but... the real fact is that if you looping with a BH with the 2nd gunner inside... always he will be between that distances because... the chopper is a solid object, so, it can't be longer or smaller, just that distances are 'rocket science'. Maybe one fine day someone will say that numbers needing to be slightly adjusted. Ok. Just adjust it. I will spend time on this info only when in the future i have to test so good certain issues of RHIB2... because i think that UH60MG numbers is enough tested.

Some array more?

P.D. This method is working in MP.

Share this post


Link to post
Share on other sites

Since version 1.08 of Arma, you can now use this function to return all the Gunners in a vehicle:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[_Vehicle] Call {Private=["_Gunners"]; _Gunners=[]; {If (Count (AssignedVehicleRole _x)>1) Then {_Gunners=_Gunners+[_x]}} ForEach (Crew (_This Select 0)); _Gunners}

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  

×