id Tech Forums

id Tech 4 (Doom3/Prey/Q4) => id Tech 4 Needs Help => Topic started by: EoceneMiacid on June 13, 2016, 06:31:01 AM

Title: Ironsights aiming (scripting?)
Post by: EoceneMiacid on June 13, 2016, 06:31:01 AM
Hi,

I would like to add ironsights capability to my mod.

It's actually pretty easy to achieve, by tweaking the g_gunX, g_guny and g_gunz cvars - but obviously, I would like to add a function that allows me to toggle between the default and tweaked values.

So how do I create this function, and how do I execute it? It's probably a script, I guess?
Title: Re: Ironsights aiming (scripting?)
Post by: 0x29a on June 13, 2016, 08:13:10 AM

Code: [Select]
//I dunno how do you realise it on your side
// I just take "zoom" button and see if it's pressed

/* in weapon_base
    void        ADS_IN();
    void        ADS_OUT();
    float buttons;
    boolean isZoomed;
    boolean aimOnce; */

/* In idle
   After while(1){}
*/
 buttons = $player1.getButtons();

        if ( buttons == 20 )
        {
            isZoomed = 1;
        }
        if (buttons != 20)
        {
            isZoomed = 0;
        }

        if ( isZoomed && !WEAPON_ATTACK )
        {

            if(!aimOnce)
            {
               
                aimOnce = !aimOnce;
                ADS_IN();
     
            }
  if ( !isZoomed && !WEAPON_ATTACK )
            {
                if(aimOnce)
                {

                    aimOnce = !aimOnce;
                    ADS_OUT();
                }
            }
        }



ADS_IN and OUT are just a functions that do lots and lots of set gunx/y/z in a row
HF && GL
Title: Re: Ironsights aiming (scripting?)
Post by: EoceneMiacid on June 13, 2016, 09:52:06 AM
Thanks for your reply, but you're overestimating my familiarity with idTech4 here.

So I need to copy this code into weapon_base.script I copied over from Doom 3?
Title: Re: Ironsights aiming (scripting?)
Post by: The Happy Friar on June 13, 2016, 10:28:55 AM
I just modified the models to add the sights & setup the zoom appropriately. 

After firing real guns, if you're firing "at the hip" you're pretty much wasting ammo. You have little idea where the bullets go, it should always be ironsights/scope. 

But it's a game and most players think "aiming" down the gun makes it more accurate vs YOU more accurate.  :)

But yeah, I modified the models & adjusted the zoom per weapon.
Title: Re: Ironsights aiming (scripting?)
Post by: EoceneMiacid on June 13, 2016, 11:24:33 AM
Okay, and how does that info help me getting iron sights into the game? :p

In the meantime, I've cobbled together this simple hack:

bind "MOUSE2" "toggle g_guny 0 4;toggle g_gunx 0 -3"



Title: Re: Ironsights aiming (scripting?)
Post by: 0x29a on June 13, 2016, 11:40:32 AM
Nasty hack, indeed.
Code I've posted goes to the script of the weapon you want to mod. For more info, download my mod (Overthinked) and look at script files. Dedicated ADS_IN/OUT methods give you nice continuity if you don't have proper animations for iron sights.
Title: Re: Ironsights aiming (scripting?)
Post by: The Happy Friar on June 13, 2016, 12:40:24 PM
Okay, and how does that info help me getting iron sights into the game? :p

Just modify the model/texture so you have iron sights on the models & adjust the zoom in values for each weapon. 

Looking at the stock models in game, the pistol needs a rear sight, shotgun should have it's narrowed (or have an open sight added), machinegun needs a front & rear one, plasma needs a rear one (the ammo counter could have one ontop), RL needs to be hollowed out like the plasma.

The RL should be the easiest, it's just modifying the texture/material so it's transparent on the proper areas.  For the pistol, machinegun & plasma wouldn't need any changes to the model, just a new sight model added on top of it would do the trick.  The new model would be bound to the same bone as the weapon body, that makes it even easier. 
Title: Re: Ironsights aiming (scripting?)
Post by: EoceneMiacid on June 13, 2016, 05:00:13 PM
Okay, and how does that info help me getting iron sights into the game? :p

Just modify the model/texture so you have iron sights on the models & adjust the zoom in values for each weapon. 

Looking at the stock models in game, the pistol needs a rear sight, shotgun should have it's narrowed (or have an open sight added), machinegun needs a front & rear one, plasma needs a rear one (the ammo counter could have one ontop), RL needs to be hollowed out like the plasma.

The RL should be the easiest, it's just modifying the texture/material so it's transparent on the proper areas.  For the pistol, machinegun & plasma wouldn't need any changes to the model, just a new sight model added on top of it would do the trick.  The new model would be bound to the same bone as the weapon body, that makes it even easier.

Um... ok :p

I just barely managed to understood what all that means. Please understand, I'm nowhere near experienced enough with the engine to do all this and there's a distinct lack of thorough documentation out there.
Title: Re: Ironsights aiming (scripting?)
Post by: VGames on June 13, 2016, 09:03:08 PM
Then stop trying to do such advanced things. Start small and learn the layout. Specialize in something. Plenty of mods to borrow assets from. You're moving to fast.
Title: Re: Ironsights aiming (scripting?)
Post by: EoceneMiacid on June 14, 2016, 05:55:34 AM
Then stop trying to do such advanced things. Start small and learn the layout. Specialize in something. Plenty of mods to borrow assets from. You're moving to fast.

That's probably true, but I'm already quite pleased with where I stand given the time I've had learning the tech.



Title: Re: Ironsights aiming (scripting?)
Post by: oneofthe8devilz on June 14, 2016, 07:29:06 AM
I think this mechanic is what you might be looking for...


It's been a while since I have implemented ironsights to MCS, but if I remember correctly no significant C++ code was involved. So you could take a look at how it was implemented by inspecting the MCS asset files (defs,models,animations and scripts) and then accordingly apply your own solution to your own idtech4 project.