OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Delta on 08 Dec 2007, 22:32:52

Title: Addeventhandler "fired" for vehicles: crew cheif or door gunner shot?
Post by: Delta on 08 Dec 2007, 22:32:52
Hi,

 
My problem is that I have 2 gunners both in the same vehicle with the same weapon and cant figure out a way to idenrify the shooter as the 'crew chief',or the 'door gunner'.

I cant fathom out how to ID which side the gunner is  :confused:
Title: Re: Addeventhandler "fired" for vehicles: crew cheif or door gunner shot?
Post by: Spooner on 08 Dec 2007, 22:56:13
The crew chief uses a "M134" and the door gunner uses a "M134_2".
Title: Re: Addeventhandler "fired" for vehicles: crew cheif or door gunner shot?
Post by: Delta on 08 Dec 2007, 23:25:47
Yeah, true for the BIS models,but I'm working with something where both guns are "M2" :blink:
Title: Re: Addeventhandler "fired" for vehicles: crew cheif or door gunner shot?
Post by: Spooner on 08 Dec 2007, 23:35:27
Well, you could have been more specific! You could always tell the mod maker to rename one of the weapons, since it is his/her fault for doing it wrong (it is incredibly simple to do, if you just look at what BIS did!).

Anyway, you could do a nearestObject on the ammo type used and then use "_helo worldToModel (getPos _ammo)". If the position is left of centre in the model coordinates, then it is the left gun. To the right of the centre it is the right gun. This assumes, of course, that the two guns don't have overlapping arcs...
Title: Re: Addeventhandler "fired" for vehicles: crew cheif or door gunner shot?
Post by: Delta on 09 Dec 2007, 00:20:55
Cheers Spooner,

     Good idea there - thanks.


_u = _this select 0;

_ammo = _u ammo (_this select 1);

_b = nearestObject [_u, _this select 1];

_pos = _u  modelToWorld (getpos_b);

If ((_pos select 0)< 0) then {hint"its the door gunner"};



But this is as far as I can get.

What would be a better way of doing this?
Title: Re: Addeventhandler "fired" for vehicles: crew cheif or door gunner shot?
Post by: Spooner on 09 Dec 2007, 12:21:40
That looks like what I was suggesting. Hopefully it works!

In the fired handler, the ammo type fired is the 5th parameter, so you don't have to work that out (the command ammo tells you how many rounds you have left anyway, so wouldn't work):
Code: (in fired handler) [Select]
_helo = _this select 0;
_ammo = _this select 4;

_bullet = nearestObject [_helo, _ammo];
// etc...

Incidentally, if you want anyone else to understand your code, please don't use obscure one-letter variable names, since that style went out with Fortran 77... ::) Since SQF can be compiled during initiation, there will be absolutely no run-time cost for having longer variable names (The only cost is that the sqf files are ~5% bigger on the disk drive because of the extra characters you are using!).
Title: Re: Addeventhandler "fired" for vehicles: crew cheif or door gunner shot?
Post by: Mr.Peanut on 13 Dec 2007, 02:30:23
F77 could have 6 characters for variable names. I know. I was there.
Title: Re: Addeventhandler "fired" for vehicles: crew cheif or door gunner shot?
Post by: Spooner on 13 Dec 2007, 12:12:03
Good point, though I meant the style rather than the physical limitation of the language and just mentioned an older language, in spite of the fact that this style is still quite common in brand new languages ;P