Home   Help Search Login Register  

Author Topic: AI won't use binoculars continously  (Read 3565 times)

0 Members and 1 Guest are viewing this topic.

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
AI won't use binoculars continously
« on: 07 Feb 2007, 21:55:27 »
I can't get the AI to use binoculars for more than a short second at a time.  I've tried:

Code: [Select]
man switchWeapon "Binocular";

And I've tried switchmove commands for every binocular related animation move I can find in the BIKI.

In every case, the AI lifts binoculars briefly, then switches back to weapon.

A loop  just repeats the lift/switch back to weapon process...and looks stupid.

Any ideas out there?

Thanks.
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: AI won't use binoculars continously
« Reply #1 on: 08 Feb 2007, 11:07:17 »
this was a problem in OFP and seems to remain in ArmA. not much you can do about it i'm afraid. if it's for a cutscene, the way i get around it is to show the unit raising the binoculars and then about a second later switch to whatever he's looking at.

Offline pyro05x

  • Members
  • *
  • teh uber scriptz0r
    • My Biki user page
Re: AI won't use binoculars continously
« Reply #2 on: 17 Feb 2007, 06:23:30 »
making up some code as i go...i'm not asserting it's accuracy.  in fact, i started doing this an extremely hard way (comparing 2 different vectors)

EDIT: this script does not work.
Code: [Select]
if !(local server) exitWith {};

_idiotPos = getPos idiot;
_targetPos = getPos targ;

//we have to loop this because the waitUntil command is too slow
for [{},{true},{true}] do
{
    //pick up x and y offsets to calc the angle
    _x = ( (_targetPos select 0) - (_idiotPos select 0) );
    _y = ( (_targetPos select 1) - (_idiotPos select 1) );
    _z = ( (_targetPos select 2) - (_idiotPos select 2) );

    //direction from x-axis to the target
    _theta = atan (_x/_y);
    if (_x<0) then
    {
        if (_y<0) then
        {
            _theta = _theta+180;
        }
        else
        {
            _theta = _theta+360;
        };
    }
    else
    {
        if (_y<0) then
        {
            _theta = _theta+180;
        };
    };
//ok i'm pretty sure the above is correct....gives us a 0-360 angle from the north point


    //grab the direction vector of the idiot's binoculars
    _vec = idiot weaponDirection "Binocular";

    //now we have to do it all over again on the direction vector.
//i chose to recycle my variables here =)
    _x = _vec select 0;
    _y = _vec select 1;

    _dir = atan (_x/_y);
    if (_x<0) then
    {
        if (_y<0) then
        {
            _dir = _dir+180;
        }
        else
        {
            _dir = _dir+360;
        };
    }
    else
    {
        if (_y<0) then
        {
            _dir = _dir+180;
        };
    };

    if (round (_dir) == round(_theta)) then
    {
        _idiot disableAI "ANIM";
    };

    sleep 0.25;
};

try that!....i just wrote it hehe

EDIT: oh and if you want the guy to be playable again, make sure you idiot enableAI "ANIM";

EDIT: realized that the <tt></tt> tags don't work on this board.  otherwise it would have been in a monospace font...

EDIT: ok now this is driving me crazy.....was looking over my code again and i forgot to change weaponDirection from a vector to an angle...one possible problem i can think of is if he is looking at teh guy before the binoculars are against his face.  so this might have all been in vain.  what really needs to be figured out is how to lock onto a specific animation state...that would be teh best say to do it, if it were possible.
« Last Edit: 18 Feb 2007, 23:55:38 by Cory B »
while {alive pyro05x} do {
    newScript = pyro05x execVM "writeScript.sqf";
    waitUntil {scriptDone newScript}; sleep 0;  };

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: AI won't use binoculars continously
« Reply #3 on: 17 Feb 2007, 11:40:33 »
Quote
idiot enableAI "ANIM"
To avoid any possible misunderstanding maybe you should at least italiclize that part..
As you might realise that sentence, no matter how you read it, calls the author of the guestion an idiot  :scratch:  :cop:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline pyro05x

  • Members
  • *
  • teh uber scriptz0r
    • My Biki user page
Re: AI won't use binoculars continously
« Reply #4 on: 18 Feb 2007, 05:44:35 »
hehe my bad...i was in a hurry.....

forgot to click the preview button =)
while {alive pyro05x} do {
    newScript = pyro05x execVM "writeScript.sqf";
    waitUntil {scriptDone newScript}; sleep 0;  };

Offline pyro05x

  • Members
  • *
  • teh uber scriptz0r
    • My Biki user page
Re: AI won't use binoculars continously
« Reply #5 on: 18 Feb 2007, 06:38:52 »
ok....well......i decided to re-write it using a comparison of 2 vectors.  it wasn't near as hard as i thought it would be.
it might even be easier on the processor than the crap above  ::)

this might actually work...

anyways...make sure your guy is stopped and pulling up his binoculars before executing this crap.

Code: [Select]
if !(local server) exitWith {};

_idiotPos = getPos idiot;
_targetPos = getPos targ;

//this is a lot easier than using pythagorean theorem...
_dist = _idiotPos distance _targetPos;


//we have to loop this because the waitUntil command is too slow

//pick up x and y offsets to get a vector....then turn it into a unit vector
_x = ( (_targetPos select 0) - (_idiotPos select 0) ) / _dist;
_y = ( (_targetPos select 1) - (_idiotPos select 1) ) / _dist;
_z = ( (_targetPos select 2) - (_idiotPos select 2) ) / _dist;

//round to hundredths and stick it in a vector
_v1 = [round(_x*100), round(_y*100), round(_z*100)];

for [{},{true},{true}] do
{
    //grab the direction vector of the idiot's binoculars
    _wDir = idiot weaponDirection "Binocular";
    _v2 = [round((_wDir select 0)*100), round((_wDir select 1)*100), round((_wDir select 2)*100)];

    //this does seem like an awful lot to do in such a short amount of time.....but we shall see...
    if (v1 == v2) then
    {
        _idiot disableAI "ANIM";
    };

    sleep 0.05; //this might be a bit too generous for short animations....but i'd rather round the vectors to tenths before i lower this to 0.01.
};

and don't forget to idiot enableAI "ANIM";
while {alive pyro05x} do {
    newScript = pyro05x execVM "writeScript.sqf";
    waitUntil {scriptDone newScript}; sleep 0;  };

Offline pyro05x

  • Members
  • *
  • teh uber scriptz0r
    • My Biki user page
Re: AI won't use binoculars continously
« Reply #6 on: 18 Feb 2007, 23:53:52 »
haha i was looking around on the Biki for event handlers to use in my script and it was right there!

the AnimDone event handler will be triggered every time the unit completes an animation.  since i don't know what anim causes him to lift his binoculars (and i'm too lazy to find out) i'll use "BinocAnimName" instead...and you fill in the blanks.

stick this in the unit's init field:
Code: [Select]
this addEventHandler ["AnimDone", {_this execVM "binocs.sqf"}];
Code: (binocs.sqf) [Select]
_duration = 5; // specify the duration length here

_unit = this select 0;
_anim = this select 1;
if (_anim == "BinocAnimName") then
{
    _unit disableAI "ANIM"
};

sleep _duration;

_unit enableAI "ANIM";
and that's it.
now i feel like an overachiever (or an idiot) for writing the hopeless crap above.....

by the way... this will not work in multiplayer if the unit is placed in the editor.  this is because the enableAI and disableAI commands are args:local and effects:local.  units can be created locally for cutscenes and stuff like that, though.
while {alive pyro05x} do {
    newScript = pyro05x execVM "writeScript.sqf";
    waitUntil {scriptDone newScript}; sleep 0;  };

Offline SaBrE

  • Members
  • *
  • I was once a Llama
    • www.Armed-Assault-Zone.com
Re: AI won't use binoculars continously
« Reply #7 on: 10 Mar 2007, 14:24:26 »
So does your last script incorporate all that's needed to keep an AI holding his binoculars out? If it definitely works (anyone?) then thanks a million. :)
Can you HELP?

Offline ARMAVIDZ

  • Members
  • *
Re: AI won't use binoculars continously
« Reply #8 on: 22 Aug 2007, 07:40:18 »
I used this if anyone is still interested. This is a quick and dirty script for making the Ai use binoculars while prone. Tested for actual targeting while the unit is running the script and it works well. Looks good for movies. Feel free to do what you want with it, including improve it for functionality (encouraged). IDK why the units runs after the scripts ends - maybe something to do with the animation itself.

Code: [Select]
; ArmAVidz' Script to Use Binoculars Continuously

_unit = this

_unit setUnitPOS "down";
_unit disableAI "anim";
_unit playmove "AwopPknlMstpSoptWbinDnon_AwopPpneMstpSoptWbinDnon_rifle";
~30
_unit enableAI "anim";
_unit setUnitPOS "Up";

exit


- Save the code as a .SQS file, in your mission's directory. Name it binocs.sqs, or w/e you like if you know.
-Change ~30 to amount of time you want the script to run once activated. Do not include any text, only numbers. Example of valid number: 30
- Execute the script in the init line(be sure to name your soldier): [this]exec "binocs.sqs"
- Execute via trigger (be sure to name your soldier): SF4 exec "binocs.sqs"

 :clap: I'm actually happy I figured this out today too, need it for a new movie  :shhh:
« Last Edit: 22 Aug 2007, 08:18:22 by ARMAVIDZ »

Offline smoke52

  • Members
  • *
Re: AI won't use binoculars continously
« Reply #9 on: 22 Aug 2007, 08:09:42 »
to add to the above solutions all i did was use
Code: [Select]
unit DisableAI "ANIM"
if you need him to move again use
Code: [Select]
unit EnableAI "ANIM"
unit switchmove ""