OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: six6six on 28 Apr 2008, 18:49:28

Title: Finding Magazines
Post by: six6six on 28 Apr 2008, 18:49:28
What i want to do is write a script to make it so a soldier acts as an ammo bearer, and i need a way of telling what ammo another soldier
Title: Re: Finding Magazines
Post by: Gcfungus on 28 Apr 2008, 20:40:02
Can you please make it exactly clear what you want, try to give as many details as you can.
Title: Re: Finding Magazines
Post by: six6six on 28 Apr 2008, 21:48:54
What I want is prferably a way to find the aray of magazines on a unit.
Title: Re: Finding Magazines
Post by: Gcfungus on 28 Apr 2008, 22:42:02
Try checking the comref.

Quote from: COMREF
magazines vehicle
Operand types:
vehicle: Object

Type of returned value:
Array
Description:
Returns array of types names of all vehicle's magazines.
Used In:
OFP/ArmA
Example:
_mags = magazines player

-=GC=-Fungus1999
Title: Re: Finding Magazines
Post by: six6six on 29 Apr 2008, 16:23:32
Thanks, but can i just ask, what order in the array do they come?
Title: Re: Finding Magazines
Post by: schuler on 29 Apr 2008, 16:29:13
_mags
"M16"
edit this is a good question  :yes:
 More info would be better, please, cut?!?!?, in play gaming?1?!?!?
 You can place an ammo box near the ammo bearer and the Ap [player] can tell him want ammo to take or reload. Make it an U.S. ammo box from you editor, they will get what they need. place a soldier near the ammo box,  It would look like the ammo bearer is giving it to the soldiers
And more is i.e. ,,,     ammo box 
AddWeaponCargo
AddMagazineCargo

If it is in a cutsence a playMove would look nice!
editors choice award here  :P  ;)
Title: Re: Finding Magazines
Post by: six6six on 05 May 2008, 15:43:15
Anyone? what order in the array do the weapons come in?
Title: Re: Finding Magazines
Post by: schuler on 05 May 2008, 16:24:09
hi Six,, please do not say array again :no:
tell us what you are looking for :clap:
here is one way of many!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

_unit = _this Select 0


RemoveAllWeapons _unit


_unit AddMagazine "AK47"
_unit AddMagazine "AK47"
_unit AddMagazine "AK47"
_unit AddMagazine "AK47"
_unit AddMagazine "AK47"
_unit AddMagazine "AK47"
_unit AddWeapon "AK47"
_unit SelectWeapon "AK47"
_unit AddMagazine "GlockMag"
_unit AddMagazine "GlockMag"
_unit AddMagazine "GlockMag"
_unit AddMagazine "GlockMag"
_unit AddWeapon "Glock"
_unit AddMagazine "HandGrenade"
_unit AddMagazine "HandGrenade"
_unit AddMagazine "HandGrenade"
_unit AddMagazine "HandGrenade"
_unit AddWeapon "Binocular"
_unit AddWeapon "NVGoggles"
exit

hope i am sending you on the right track  :good:
cheers schuler
Title: Re: Finding Magazines
Post by: six6six on 05 May 2008, 19:01:52
What i want to know, is what order the different types of magazine are arranged in when i use the magazine command.
eg. [m16,m16,m16,m16,handgrenade,handgrenade,law,law]
or [handgrenade,handgrenade,m16,m16,m16,m16,law,law]
etc.
Title: Re: Finding Magazines
Post by: Gcfungus on 05 May 2008, 20:51:50
I tried a test and it gave me all the types from the comref. Ie:

Ak47, M16, MM1mag, g36amag ect.

It gives you it without the "s. However be careful, as if you check one without a mag in that slot (either if it is empty or if something takes up 2 slots then u will not have 10 mag slots) it will give you an odd result, such as:
Code: [Select]
scalar bool array string 0xfcffffefI'm not sure of the order, but i would presume it would be the same as on the gear screen.

Hope this helps.  :D

-=GC=-Fungus1999

Title: Re: Finding Magazines
Post by: six6six on 06 May 2008, 08:50:59
One last question. How do i find what members are in a group?
Title: Re: Finding Magazines
Post by: Gcfungus on 06 May 2008, 17:53:17
Try:

Code: [Select]
_group = group player
_max = count _group
_counter = 1
_selecter = 0
#loop
_subject = _group select _selecter

<do what you want here>
_subject command whatever

_counter = _counter + 1
?(_counter > _max): exit
goto "loop"

This is untested, but should work.
Title: Re: Finding Magazines
Post by: six6six on 01 Jun 2008, 12:21:52
Try:

Code: [Select]
_group = group player
_max = count _group
_counter = 1
_selecter = 0
#loop
_subject = _group select _selecter

<do what you want here>
_subject command whatever

_counter = _counter + 1
?(_counter > _max): exit
goto "loop"


This is untested, but should work.

Im sorry to dig this up, but this doesnt work. It just gives me the error
'_subject = _group select _selecter
Title: Re: Finding Magazines
Post by: Garcia on 01 Jun 2008, 12:46:58
Code: [Select]
_group = group player
_max = count _group
_counter = 0

#loop
_subject = (units _group) select _counter

<do what you want here>
_subject command whatever

_counter = _counter + 1
?(_counter >= _max): exit
goto "loop"

First of all, you need (units _group). "Units groupName" creates an array with the soldiers within the group. Also, no point in using the _selecter variable that way, because it didn't change during the looping. It would stay at 0, and that would make it select the first element in the array all the time (which means it would select the same unit over and over again).
Title: Re: Finding Magazines
Post by: six6six on 01 Jun 2008, 13:57:06
Code: [Select]
'_max = count _group[#]'; Error count: type group, expected array
is what im getting now.

Ive changed the defines to this:

_group = _this select 2
_max = count _group
_counter = 0
as ive intergrated it with my script.
please help.


Fixed it, it should be
Code: [Select]
_max = count units _groupnot
Code: [Select]
_max = count _group
Title: Re: Finding Magazines
Post by: Garcia on 01 Jun 2008, 17:42:58
Exactly ;)
Title: Re: Finding Magazines
Post by: six6six on 04 Jun 2008, 13:27:35
How can I find out if a unit has no ammo via script?
Title: Re: Finding Magazines
Post by: Mr.Peanut on 04 Jun 2008, 16:24:02
Read the OFP ComRef start to finish over and over again, even if you do not understand it all.
ammo (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=a#20)
forEach (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=f#140)
magazines (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=m#209)
Code: [Select]
_magsleft = 0
{_magsleft = _magsleft + (_myUnit ammo _x)} forEach magazines _myUnit
Will have to test how this behaves when unit is in vehicle.