Advertisement

Author Topic: My weapon in hand (ACCEPTED)  (Read 2153 times)

0 Members and 1 Guest are viewing this topic.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
My weapon in hand (ACCEPTED)
« on: 06 Oct 2007, 11:19:38 »
Function that returns the weapon in hand of the passed unit.
Compile the function first in your init.sqs or init.sqf file:
mando_my_weapon = compile (preprocessFileLineNumbers "mando_my_weapon.sqf");

Usage example:
hint format["%1", [vehicle player] call mando_my_weapon]
« Last Edit: 27 Oct 2007, 18:16:24 by LeeHunt »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: My weapon in hand
« Reply #1 on: 06 Oct 2007, 13:02:39 »
 :clap: :good:
Brilliant.

How the hell you come up with this stuff..
Project MCAR   ---   FWW2 - Finland At War 1939-1945
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Blanco

  • Former Staff
  • ****
Re: My weapon in hand
« Reply #2 on: 06 Oct 2007, 13:21:08 »
Brilliant, very usefull stuff. :good:


Search or search or search before you ask.

Offline ViperMaul

  • Members
  • *
    • Theatre Of War (Team PvP Campaign)
Re: My weapon in hand
« Reply #3 on: 10 Oct 2007, 04:07:03 »
Excellent.
Does this work for the Laser Designator I bet??
ViperMaul
Theatre of War (Co-Lead Dev)
ACE (Jr Project Manager)

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
Re: My weapon in hand
« Reply #4 on: 10 Oct 2007, 14:15:42 »
The return value is a string?
And what happened if the player has no any weapon?
Fix bayonet!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: My weapon in hand (ACCEPTED)
« Reply #5 on: 15 Nov 2007, 12:48:32 »
I've found a situation where this function breaks. When you have NV goggles (worn or not) and are using a weapon, it sometimes returns "NVGoggles". It does depend where the NVGoggles are in your inventory though (if goggles are before the current weapon in the weapons list, then the current weapon will be returned as "NVGoggles").

Test case: Place a BLUFOR SF Assault, preview and switch to M9 Silenced. In this case, the function only breaks if using the pistol, since the initial order of weapons is ["M4A1GL", "NVGoggles", "M9SD"].

Fix: Just need to take ["NVGoggles"] away from (weapons player) before you use it, though a more generic solution would ignore all weapons that extend NVGoggles.

Once you've fixed that, return to the test case outlined above. When holding the rifle, you can stand and go prone and the current weapon is always the rifle. When holding the pistol, standing and going prone causes the current weapon to be sometimes the pistol and sometimes the rifle, presumably because the slung rifle is sometimes pointing in the right direction during the animation. I think that giving rifle weapons lower priority than pistols or launchers might fix this (so if _myweapons array has more than one member, choose the weapon that isn't the rifle, though not sure if that works either; Just a suggestion since this might be unfixable).
« Last Edit: 15 Nov 2007, 17:20:57 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Michael

  • Members
  • *
  • www.zonekiller.ath.cx
    • ZoneKillers
Re: My weapon in hand (ACCEPTED)
« Reply #6 on: 23 Nov 2007, 21:49:18 »
Thanks for the function Mandoble

i use it with the Function binoLOS by Mr.Peanut ,Binotarget v1.01
so the AI can target through there guns and call airstrikes by having a eventhandler "fired"
what ever the AI are looking at when they fire can be the target and it works very well and is a key script for my support pack

Thanks its a realy handy function.
 

Code: [Select]

private ["_unit", "_obj", "_ds", "_max", "_offset", "_dvec", "_mpos", "_wpos", "_gl_north", "_breakflag", "_i", "_weapon"];

_ds = 0.50;
_max = 3000;
_offset =  0;

_unit = _this select 0;
if (count _this > 1) then {_obj = _this select 1;};
_weapon =  format["%1", [_unit] call mando_my_weapon];
_dvec = _unit weaponDirection _weapon;
_mpos = getPos _unit;
_height = -((_unit modelToWOrld [0,0,0]) select 2);
_wpos = [];
_gl_north = "LOGIC" createVehicleLocal _mpos;
_gl_north setPos _mpos;
_gl_north setDir 0;
_breakflag = TRUE;
for [{_i = _ds},{_i <= _max && _breakflag},{_i = _i + _ds}] do
{
      _mpos = [_i * (_dvec select 0), _i * (_dvec select 1), _i * (_dvec select 2) + _offset];
      _wpos = _gl_north modelToWorld _mpos;
      if (((_wpos select 2)) <= _height) then {_breakflag = FALSE;};
};
deleteVehicle _gl_north;
if _breakflag then
{
}
else
{
   if (isnil "_obj") then
   {
      _wpos
   }
   else
   {
      _obj setPos _wpos;
      TRUE
   };
};


Offline Denisko-Redisko

  • Members
  • *
Re: My weapon in hand (ACCEPTED)
« Reply #7 on: 23 Apr 2009, 03:57:06 »
Now I read with interest this forum. This topic, of course, very old, and maybe there is some movement in that direction. But still, I will share a way free from the above-mentioned shortcomings.
Code: [Select]
// Initially, several useful functions

#define arg(X)            (_this select (X))

//
// funcReadActionsProp
// syntax: [string unitClassName, string targetAnimation, string propertyName] call funcReadActionsProp
//

funcReadActionsProp = {
    private "_moves";
    _moves = getText ( configFile >> "CfgVehicles" >> arg(0) >> "moves" );
    configFile >> _moves >> "Actions" >> getText (
        configFile >> _moves >> "States" >> arg(1) >> "actions"
    ) >> arg(2)
};

//
// funcReadUpDegree
// syntax: (object soldier) call funcReadUpDegree
// Returns the value of the property UpDegree (AI Animation State) of the animation for the specified unit. Number type
// Possible values are defined in config game:
//   enum {
//       MANPOSNOWEAPON = 12,
//       MANPOSHANDGUNSTAND = 9,
//       MANPOSCROUCH = 6,
//       MANPOSHANDGUNLYING = 5,
//       MANPOSHANDGUNCROUCH = 7,
//       MANPOSBINOCSTAND = 14,
//       MANPOSDEAD = 0,
//       MANPOSCOMBAT = 8,
//       MANPOSBINOCLYING = 2,
//       MANPOSSTAND = 10,
//       MANPOSSWIMMING = 11,
//       MANPOSWEAPON = 1,
//       MANPOSLYING = 4,
//       MANPOSLYINGNOWEAPON = 3,
//       MANPOSBINOC = 13
//   }
//

funcReadUpDegree = {
    getNumber ( [typeOf _this, animationState _this, "upDegree"] call funcReadActionsProp )
};

//
// funcReadWeaponType
// syntax: (string weaponClassName) call funcReadWeaponType
// Returns the type of the weapon slot.
// One of the following:
//       WeaponNoSlot            0   // Dummy weapons
//       WeaponSlotPrimary       1   // Primary weapon
//       WeaponSlotHandGun       2   // Handgun slot
//       WeaponSlotSecondary     4   // Secondary weapon (launcher)
//       WeaponSlotHandGunMag   16   // Handgun magazines (8x)(or grenades for M203/GP-25)
//       WeaponSlotMag         256   // Magazine slots (12x / 8x for medics)
//       WeaponSlotGoggle     4096   // Goggle slot (2x)
//       WeaponHardMounted   65536   //
//

funcReadWeaponType = {
    getNumber ( configFile >> "CfgWeapons" >> _this >> "type" )
};

/*
So, based on the definitions upDegree, we have

    Rifle   = 6, 8, 10, 4
    Pistole = 9, 5, 7
    AT      = 1
    Binoc   = 2, 13, 14

thus, funcWeaponInHand as follows:
*/

funcWeaponInHand = {
    private "_upDegree";
    _upDegree = _this call funcReadUpDegree;
    {
        if( _upDegree in (
            switch (_x call funcReadWeaponType) do {
                case 1: {[6, 8, 10, 4]};    // primary weapon
                case 5: {[6, 8, 10, 4]};    // and maschinegun also (primary and secondary weapon slot)
                case 2: {[9, 5, 7]};        // handgun slot
                case 4: {[1]};              // secondary weapon slot
                case 4096: {[2, 13, 14]};   // goggle slot
                default {[]};
            }
        ))exitWith{ _x }; ""
    } foreach weapons _this
};
« Last Edit: 23 Apr 2009, 05:43:48 by Denisko-Redisko »
sorry for my english

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: My weapon in hand (ACCEPTED)
« Reply #8 on: 23 Apr 2009, 06:15:32 »
That's a great solution! Very clean, very inspiring.  :good:

But it has a small problem (first suspected, then verified): it can't distinguish binoculars from a laserdesignator. It will report the one that has been added first to the unit.

This is because here it is possible to have two items in your inventory that both share the same animation (the same would happen with, for example, handguns if a soldier could carry more than one).
try { return true; } finally { return false; }

Offline Denisko-Redisko

  • Members
  • *
Re: My weapon in hand (ACCEPTED)
« Reply #9 on: 23 Apr 2009, 07:57:47 »
Hmm, thanx, it is a bug really. And fix it within the framework of used methods not possible. (within terms of methods used, without changing the used method, how to say?)
The hard way to fix it - to cut functionality, comment out the line "case 4096". Referring to the fact that the glasses don't shoots ("Is not a bug, it's a feature" (с)) :( Or, maybe, other ideas?
« Last Edit: 23 Apr 2009, 14:18:22 by Denisko-Redisko »
sorry for my english

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: My weapon in hand (ACCEPTED)
« Reply #10 on: 23 Apr 2009, 14:06:01 »
I made a SPON_Recog_currentWeapon function in the current version of SPON Recognise that seems to work correctly (Compared to "My weapon in hand"), but it is based on looking for certain patterns in the animation string. That, however, is fine assuming that no 3rd party has made weapon-based animations that have failed to follow BIS naming conventions.

Not really sure what an upDegree is meant to represent, so I'm not sure if new weapons could use different values and mess this suggested solution up. Nevertheless, it seems like an inspired solution to the problem...
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Denisko-Redisko

  • Members
  • *
Re: My weapon in hand (ACCEPTED)
« Reply #11 on: 23 Apr 2009, 15:40:02 »
I made a SPON_Recog_currentWeapon function in the current version of SPON Recognise
Thanks, it will be interesting.
Not really sure what an upDegree is meant to represent, so I'm not sure if new weapons could use different values and mess this suggested solution up. Nevertheless, it seems like an inspired solution to the problem...
Regarding upDegree. upDegree - it is the property of the animations (it is not from the cfgWeapons, but from (for example) "CfgMovesBasic >> Actions >> SomeActions >> upDegree")
It works correctly in all situations.
I had to deal with the animation graph for some OFP-mods, and I can vouch for that  :)
It's reliably because the script does the same as the game itself. Only the game does this to find the animation. And while the animation will be consistent with the type of weapons - everything will work properly.

I'm not sure that I will explain this in english, but, be that as it may:
Classes in "CfgMovesBasic >> Actions" can have any name. So which group of animations ("CfgMovesMC >> Actions >> someClass") will be chosen AI (to play animation) depends on the upDegree.

If any addons (of animation) would use an arbitrary (inappropriate) value for upDegree - it's just violates AI-behavior

Using upDegree can provide good opportunities for scripting. I'm often use it

PS.

I looked over your script. script dependent on the classname - this approach may be inconsistent with the modified config of animations. Of course, in real life (and at AramA age) is unlikely to happen. But, nevertheless.

I will try to explain some features of config:
Any class in the "CfgMovesMaleSdr >> Actions" can have any name. What it will be - depends on upDegree.
Any class in the "CfgMovesMaleSdr >> States" can have any name. What it will be - depends on the linking (to the common graph) and on the "actions"-property.
Any soldier can have an different value in the "moves"-property - and then, in all cases you should use this value instead CfgMovesMaleSdr.

I'm sorry that my posts are often changing. I always think that everything I wrote was unclear. For example, I don't know how to say "on arma age" - "during the life of the arma"   :dunno:

[offtopic]
@Spooner
I downloaded many of your scripts now, and I like it a lot. Could I learn - this project is related to the RPG, or it is the framework is not tied to a specific genre? Where I could find it (any link) ?
[/offtopic]
« Last Edit: 23 Apr 2009, 20:28:53 by Denisko-Redisko »
sorry for my english

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: My weapon in hand (ACCEPTED)
« Reply #12 on: 24 Apr 2009, 01:36:55 »
I'm not sure what you mean. The SPON modular system is just a big bunch of things that interested me enough at various times to make. Not associated with any other projects at all; some parts are commonly used in other people's mods and missions, some less so and others that are just proofs of concept that I'd be surprised if they get used at all! I'm not really actively developing anything right now, but I'm sure I'll be back in the hamster-wheel soon enough (when things start to feel like "work" rather than "fun", I always step away and do other things)!
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Denisko-Redisko

  • Members
  • *
Re: My weapon in hand (ACCEPTED)
« Reply #13 on: 24 Apr 2009, 07:51:36 »
Thanx. I agree that the scripting can be a fascinating pastime, I always say that I am doing this just for fun. :)
sorry for my english

Offline Denisko-Redisko

  • Members
  • *
Re: My weapon in hand (ACCEPTED)
« Reply #14 on: 28 Apr 2009, 22:35:06 »
I have now found an interesting thing. If read upDegree as follows:
getText ([typeOf player, animationState player, "upDegree"] call funcReadActionsProp)
then it will return a string: "ManPosStand", "ManPosCombat" etc. There! I didn't know this before. I like that.

I have been using a simple library for reading config, it would be cool to expand it in various useful things. Wherever it could be discussed?
« Last Edit: 28 Apr 2009, 23:27:43 by Denisko-Redisko »
sorry for my english