Jump to content
Sign in to follow this  
palatine

Noob Question: What's wrong with my createVehicle?

Recommended Posts

Hi guys, sorry for a noob question..

I had a code to spawn a HMG turret something like this, but it didn't work as intended...

 

Original code: spawnHMG.sqf

 

_pos = player getPos [2, getDir player];

switch (side player) do
{
    case west:
    {
        _turret = createVehicle ["B_HMG_01_A_F", _pos, [], 0, "NONE"];
    };
    case east:
    {
        _turret = createVehicle ["O_HMG_01_A_F", _pos, [], 0, "NONE"];
    };
    case resistance;
    case independent:
    {
        _turret = createVehicle ["I_HMG_01_A_F", _pos, [], 0, "NONE"];
    }
};

 

_turret allowDamage false;
_turret setPosATL [(_pos select 0), (_pos select 1), (getPosATL player select 2) + 0.2];
_turret setDir direction player;

createVehicleCrew _turret;
_turret addeventhandler ["fired", {_this select 0 setVehicleAmmo 1}];

_turret addAction ["<t color='#FFAA7F'>Send unit back to HQ</t>.", "deleteVehicle (_this select 0);"];
--------- end of file ------------

 

But then the code seem like broken when executing "allowDamage" part to the rest of the code. So the vehicle created still take damage and don't have crew.

 

So then I modify the code to something like this:

 

new_spawnHMG.sqf 

 

_pos = player getPos [2, getDir player];

_unitStr = "B_HMG_01_A_F";


switch (side player) do
{
    case west:
    {
        _unitStr = "B_HMG_01_A_F";
    };
    case east:
    {
        _unitStr = "O_HMG_01_A_F";
    };
    case resistance;
    case independent:
    {
        _unitStr = "I_HMG_01_A_F";
    }
};

_turret = createVehicle [_unitStr, _pos, [], 0, "NONE"]; 

_turret allowDamage false;
_turret setPosATL [(_pos select 0), (_pos select 1), (getPosATL player select 2) + 0.2];
_turret setDir direction player;

createVehicleCrew _turret;
_turret addeventhandler ["fired", {_this select 0 setVehicleAmmo 1}];

_turret addAction ["<t color='#FFAA7F'>Send unit back to HQ</t>.", "deleteVehicle (_this select 0);"];

--------- end of file ------------

 

Then this work fine. Could somebody explain what's wrong with first one?

Thank you. Cheers

  • Like 1

Share this post


Link to post
Share on other sites

In your first case, the local variable ins undefined for the outter scope of switch do.

You can add:

private "_turret";

switch (side player) do ..... the rest of your code.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

A bit more elegant solution would be to ditch the switch (hee hee) and use something like this:

 

_turrets = ["O_HMG_01_A_F","B_HMG_01_A_F","I_HMG_01_A_F"];
_sides = [east,west,independent];
_turret = _turrets select (_sides find side player);
//0.0025 ms

 

Or reduce it even further (though a bit slower):

_turrets = ["O_HMG_01_A_F","B_HMG_01_A_F","I_HMG_01_A_F"]; 
_turret = _turrets select ([side player] call BIS_fnc_sideID);

//0.0091 ms

The first one would be roughly as fast as the switch, but the improved readability would well be worth it since it's 3 lines vs 15+.

 

Cheers

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Wow thanks @Grumpy Old Man  that's really help :)
Just a another noob question if you don't mind: is the side "resistant" and "independent" actually the same side or they're different? On the wiki says they're just alias or the same. But if they're the same, then how FIA enemy to AAF?

Share this post


Link to post
Share on other sites
49 minutes ago, palatine said:

Wow thanks @Grumpy Old Man  that's really help :)
Just a another noob question if you don't mind: is the side "resistant" and "independent" actually the same side or they're different? On the wiki says they're just alias or the same. But if they're the same, then how FIA enemy to AAF?

 

FIA and AAF are factions, if I remember correctly FIA existed for west/blufor first, opfor and resistance/independent FIA factions got added later down the road.

As far as sides are concerned in arma 3 theres blufor/west, opfor/east and resistance/independent for the 3 major sides as side datatype.

They can be used interchangeable, using blufor or west for a check will make no difference.

There are still some quirks with GUER being returned when checking for side player and the player is resistance/independent but that's how it goes, read through the link to get even more confused, heh.

 

Cheers

  • Thanks 1

Share this post


Link to post
Share on other sites

Whoa... I just know about that faction & side.. I wast thought fia=resistant, nato=west, csat=east.. I thought it was that simple.
And I didn't change the mission setting too much... my game just kinda point and shoot.
Thanks for the info :)

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  

×