OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: bdfy1 on 28 Jul 2005, 01:25:06

Title: How to track unit's primary weapon ammo ?
Post by: bdfy1 on 28 Jul 2005, 01:25:06
"some ammo" seems to be not very helpfull command , cause it will return true when primary weapons mags expired , but HandGrenades remains.
I can get primary weapon name, all magazines, number of cartridges in the current mag - but all this won't help me in common case:( Name of mag and weapon can be the same but usually they don't
Sugestions how to track unit's ammo?
Title: Re:How to track unit's primary weapon ammo ?
Post by: Lean Bear on 28 Jul 2005, 13:38:17
Not sure I really get what you mean, but if you use the EH "fired" then that will return the weapon, the muzzle its using (if any), the firing mode (single, burst or auto) and the ammo.

If you had that in a simple loop, you could easily keep track of all of it.

eg. (syntax prob not 100% correct)

Code: [Select]
#Ammo

_unit addEventHandler ["fired", {goto "DisplayAmmo"}]
~0.01

goto "Ammo"

#DisplayAmmo

; Get the values
_ammo = _this select 0
_muzzle = _this select 1
_mode = _this select 2
_weapon = _this select 3

; Return the values in a hint
_displayAmmo = hint Format["Unit is using a %1\nWith a %2 muzzle\nOn %3\n\nRounds left: %4", _weapon, _muzzle, _mode, _ammo]
~1

goto "DisplayAmmo"
Title: Re:How to track unit's primary weapon ammo ?
Post by: bdfy1 on 28 Jul 2005, 15:27:36
not bad idea...
ammo returns number of cartriges in the magazine. If it equals zero for 10 sec or so that means that unit can't reload and he is out of ammo.
Title: Re:How to track unit's primary weapon ammo ?
Post by: bdfy1 on 28 Jul 2005, 16:44:00
solution (addon included )
Title: Re:How to track unit's primary weapon ammo ?
Post by: Blanco on 29 Jul 2005, 05:16:38
Smart  :)
I hope units will reload within those 10 seconds, I'll try it out.
I was working on another way, but it's not finished yet.
Title: Re:How to track unit's primary weapon ammo ?
Post by: General Barron on 05 Aug 2005, 11:17:22
Ah... I never thought of finding the classname of a unit's muzzle via the 'fired' eventhandler. I was always thinking that the closest you could get was with the 'primaryweapon' command. I guess this makes the 'ammo' command a little more useful than I had last written it off as.

Only problem with this method is that you can only check it when the unit fires, not at your whim. So I guess storing the data in a global variable after each check would be the best way to go if you need this info when they aren't firing...
Title: Re:How to track unit's primary weapon ammo ?
Post by: Triggerhappy on 06 Aug 2005, 02:52:29
well someone could grab a different weapon and you wouldn't know til they fired, if they fired at all...