Home   Help Search Login Register  

Author Topic: Creating a Humvee (or any west unit) on the side of the east  (Read 1958 times)

0 Members and 1 Guest are viewing this topic.

Offline Denisko-Redisko

  • Members
  • *
I wrote the following function:

Code: [Select]
/*

    funcCreateVehicle
    Creates the specified vehicle
    Syntax:
        [
            string vehicleType,
            position position,
            side or group or object (optional),
            array of string crewSlots (optional),
            array of soldiers unitList (optional)
        ] call funcCreateVehicle

    vehicleType --  the type of vehicle
    position    --  position of the vehicle
    group       --  group of the vehicle crew,
                    if the soldier - will be used his group
                    if the side - will create a new group by this side
                    if the other value (eg 0 or "" or "default"), will create a new group
                    owned by a native vehicle side
    crewSlots   --  equipment of the crew. А list containing some of the following
                    values: "commander", "driver", "gunner", "cargo".
    unitList    --  if present - the units will take the crew one by one from this list
*/


//#include "\lib\common"
#define arg(X)            (_this select (X))
#define argIf(X)          if(count _this > (X))
#define argIfType(X,T)    if(if(count _this > (X))then{typeName arg(X) == (T)}else{false})
#define argSafe(X)        argIf(X)then{arg(X)}
#define argSafeType(X,T)  argIfType(X,T)then{arg(X)}
#define argOr(X,V)        (argSafe(X)else{V})
#define xor(A,B)    (!(A && B) && (A || B))
#define inc(N)      (call { N = N + 1; N })
#define dec(N)      (call { N = N - 1; N })

funcCreateVehicle = {
    private [
        "_vehicleType", "_position", "_group",
        "_crewSlots", "_getNextUnit", "_unitList",
        "_unitIndex", "_crewType", "_vehicle", "_topPlace", "_moveIn"
    ];
    _vehicleType = arg(0);
    _position = arg(1);
    _group = argOr(2, 0) call {
        switch ( typeName _this ) do {
            case "GROUP" : { _this };
            case "OBJECT" : { group _this };
            case "SIDE" : { createGroup createCenter _this };
            default {
                createGroup ( createCenter (
                    [
                        east, west, resistance, civilian, nil, enemy, friendly, nil
                    ] select getNumber (
                        configFile >> "CfgVehicles" >> _vehicleType >> "side"
                    )
                ))
            }
        }
    };
    // print str _group;
    _crewSlots = argSafeType(3, "array")else{
        ["commander", "driver", "gunner", "cargo"]
    };
    _getNextUnit = argIf(4)then{
        _unitList = arg(4);
        _unitIndex = count _unitList;
        { _unitList select dec(_unitIndex) }
    }else{
        _crewType = getText( configFile >> "CfgVehicles" >> _vehicleType >> "crew" );
        { _group createUnit [_crewType, _position, [], 0, "none"] }
    };
    _vehicle = _vehicleType createVehicle _position;
    {
        _topPlace = (_vehicle emptyPositions _x) - 1;
        _moveIn = (switch (_x) do {
            case "commander" : {{ _this moveInCommander _vehicle }};
            case "driver"    : {{ _this moveInDriver _vehicle }};
            case "gunner"    : {{ _this moveInTurret [_vehicle, [_pos]] }};
            case "cargo"     : {{ _this moveInCargo _vehicle }};
            default { player sideChat "error in funcCreateVehicle, cargo type mismatch" }
        });
        for "_pos" from 0 to _topPlace do {
            call _getNextUnit call _moveIn
        }
    } foreach _crewSlots;
    _vehicle
};

Next, I create a Humvee with a crew belonging to the east side:

Code: [Select]
Humvee = [
    'HMMWV50',
    getpos player,
    east,
    ["driver", "cargo"]
] call funcCreateVehicle;

Watch that displays a Humvee:
Code: [Select]
hint str Humvee // displays "EAST 1-1-A:1"
but why then:

Code: [Select]
hint str side Humvee // displays "WEST"
hint str side driver Humvee // displays "WEST"

Does this mean that there is no ability to create units with a side with not specified in the arma config?
And does this mean that all functionality associated with a flexible choice of the group (in funcCreateVehicle) does not make sense?

any ideas?
« Last Edit: 19 Apr 2009, 10:49:26 by Denisko-Redisko »
sorry for my english

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Creating a Humvee (or any west unit) on the side of the east
« Reply #1 on: 20 Apr 2009, 06:43:39 »
The problem seems to be caused by the createUnit array command.

A short test showed that there is no such problem when using the other createUnit command.
try { return true; } finally { return false; }

Offline Denisko-Redisko

  • Members
  • *
Re: Creating a Humvee (or any west unit) on the side of the east
« Reply #2 on: 20 Apr 2009, 08:19:07 »
@Worldeater
Oh, big thanks! After replacing the function of creating a unit to this:
Code: [Select]
        {
            _crewType createUnit [ _position, _group, "", .7];
            units _group select ((count units _group)-1)
        }
the problem disappeared.
I vainly ignore old ofp-commands, considering them obsolete. Thank you once again  :)
sorry for my english

Offline Denisko-Redisko

  • Members
  • *
Re: Creating a Humvee (or any west unit) on the side of the east
« Reply #3 on: 08 Aug 2009, 23:29:46 »
Another small question.
I've been using the "crew"-property, to take the type (class) of units, whether it is a correct? And what sense is a "typicalCargo"-property in CfgVehicles?

I intend to use this script (or similar) for ingame-loading (&unloading) some missions in to the main mission (various mission.sqm #included to the description.ext).

And so far as the vehicle with its crew is described in the mission.sqm just one class, I need to clarify this point.  :dunno:
Code: [Select]
class Item0
{
    position[]={2900.819580,17.506617,2750.763428};
    id=6;
    side="WEST";
    vehicle="HMMWV50";
};
sorry for my english

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Creating a Humvee (or any west unit) on the side of the east
« Reply #4 on: 09 Aug 2009, 18:19:51 »
So you suspect typicalCargo to be used by the editor instead of crew?

Hmmm, you could do a simply test: find a vehicle where different units types are listed in typicalCargo (see below). Then place this vehicle in the editor and check its crew.

Code: [Select]
class Zodiac... {
  ...
  crew = "USMC_Soldier";
  typicalCargo[] = { "USMC_Soldier", "USMC_Soldier_AT" };
  ...
};
try { return true; } finally { return false; }

Offline Denisko-Redisko

  • Members
  • *
Re: Creating a Humvee (or any west unit) on the side of the east
« Reply #5 on: 09 Aug 2009, 20:42:10 »
Yes, but there is only one member of the crew - a driver.  
A more accurate test would be the config:
Code: [Select]
crew = "USMC_Soldier";
typicalCargo [] = ( "USMC_Soldier_AT", "USMC_Soldier");

and preferably in vehicle with two crew members (driver + gunner)
I will make a сonfig-addon to verify, thanx.
PS.
I don't understand the meaning of the typicalCargo, where it is used?
=====================
OK, I checked it on this config:
Code: [Select]
class CfgVehicles {
    class HMMWVTOW;
    class HMMWVTOW_test_typicalCargo_and_crew: HMMWVTOW {
        displayName = "-- HMMWVTOW_test_typicalCargo_and_crew";
        typicalCargo[] = {"SoldierWBOfficer", "SoldierWAT", "SoldierWB"};
        crew = "SoldierWPilot";
    };
};
On the driver's and the gunner's seats - the pilots.
As I understand it, the editor fills vehicle based on the values: hasDriver, hasGunner, hasCommander.
Hopefully this is the case, and any pitfalls there is no  :)
« Last Edit: 09 Aug 2009, 22:00:09 by Denisko-Redisko »
sorry for my english