OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: LCD on 19 Sep 2007, 00:02:26

Title: iskindof weapon
Post by: LCD on 19 Sep 2007, 00:02:26
is dere a way 2 check if a string iskindof weapon  ? like we wud use "T72" iskindof "tank" ???

so lets say i wanna check if "M16A2" iskindof "Weapon" ??? does it work dat way ? if it does what is da parent calss name of all weapons ?

LCD OUT
Title: Re: iskindof weapon
Post by: Planck on 19 Sep 2007, 01:36:53
I have a feeling that isKindOf is only for vehicle type objects, I don't think it works with weapons, at least my small experiments turned up no results with weapons.


Planck
Title: Re: iskindof weapon
Post by: Spooner on 19 Sep 2007, 02:00:25
You need to use inheritsFrom (http://community.bistudio.com/wiki/inheritsFrom_config). The thing is that this just tells you the parent class, so isn't quite as easy to use as isKindOf, but that just means you need to keep finding out the parent until there isn't another parent or you find a class you recognise.

e.g. to find out if a given weapon is a rifle (simplified from working code, so not 100% sure it will work, but you should get the idea ;P):
Code: [Select]
_unknownConfig = configFile >> "CfgWeapons" >> _unknownWeaponClass;
_rifleConfig = configFile >> "CfgWeapons" >> "RifleCore";

_isRifle = false;
while {isClass _unknownConfig} do
{
    if (_unknownConfig == _rifleConfig) exitWith
    {
        _isRifle = true;
    };

    _unknownConfig = inheritsFrom _unknownConfig;
};

***EDIT***

Might have misunderstood you there; if you just want to know if "M16A2" is a weapon or a magazine or whatnot, then just:
Code: [Select]
_item = "M16A2";
_isWeapon = isClass (configFile >> "CfgWeapons" >> _item); // => true
_isMagazine = isClass (configFile >> "CfgMagazines" >> _item); // => false
Title: Re: iskindof weapon
Post by: LCD on 19 Sep 2007, 05:59:43
thx... exactly what i needed :D

LCD OUT
Title: Re: iskindof weapon
Post by: Spooner on 19 Sep 2007, 12:19:17
Remember that some class names exist in CfgWeapons, CfgMagazines and/or CfgAmmo at the same time (They are different classes, serving different purposes, but since they are in different "namespaces" BIS were safe to give them the same name). May not be an issue for you, but it caused me minor headaches when I first used this code to build by shopping interface. E.g. "PipeBomb" exists as a magazine type and an ammo type.
Title: Re: iskindof weapon
Post by: Planck on 19 Sep 2007, 14:04:57
"PipeBomb" also exists as a weapon class too.    :P


Planck
Title: Re: iskindof weapon
Post by: LCD on 19 Sep 2007, 15:08:24
doesnt matter i found workaround :P finished building my own weapon trading script :D  :cool2:

prob solved :D

LCD OUT
Title: Re: iskindof weapon
Post by: Cheetah on 19 Sep 2007, 17:53:29
You going to upload it to the beta board? Might be a script usable for others around. Don't know what's possible with you weapon trading script however..
Title: Re: iskindof weapon
Post by: LCD on 19 Sep 2007, 18:09:16
i think after my next mision is gona b reviewed ill post some scripts (dat is after it passes beta testing nd stuff... :P)... i just hate writing documentation 4 my scripts  :no: wich keeps a lot of good scripts in my comp or w/ ppl who ask 4 em :P

as 4 my trade script... right now it just gives da player option 2 order magazines/weapons/vehicles  :cool2: nd... special stuff (im not realy gonna deliver em :P) like beers or cigis or watever u want (u can add nything u want)... it sends da stuff into array da maker can use :D next phase is 2 arrange choper droping everything down  :yes: on ny position player wants (onmapsingleclick)

LCD OUT