OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Denisko-Redisko on 19 Apr 2009, 10:45:30
-
I wrote the following function:
/*
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:
Humvee = [
'HMMWV50',
getpos player,
east,
["driver", "cargo"]
] call funcCreateVehicle;
Watch that displays a Humvee:
hint str Humvee // displays "EAST 1-1-A:1"
but why then:
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?
-
The problem seems to be caused by the createUnit array (http://community.bistudio.com/wiki/createUnit_array) command.
A short test showed that there is no such problem when using the other createUnit (http://community.bistudio.com/wiki/createUnit) command.
-
@Worldeater
Oh, big thanks! After replacing the function of creating a unit to this:
{
_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 :)
-
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:
class Item0
{
position[]={2900.819580,17.506617,2750.763428};
id=6;
side="WEST";
vehicle="HMMWV50";
};
-
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.
class Zodiac... {
...
crew = "USMC_Soldier";
typicalCargo[] = { "USMC_Soldier", "USMC_Soldier_AT" };
...
};
-
Yes, but there is only one member of the crew - a driver.
A more accurate test would be the config:
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:
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 :)