Author Topic: Ironsights aiming (scripting?)  (Read 584 times)

0 Members and 1 Guest are viewing this topic.

EoceneMiacid

  • Jr. Member
  • **
  • Posts: 74
  • Karma: +4/-15
  • Doom Newbie
    • View Profile
Ironsights aiming (scripting?)
« 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?

0x29a

  • PD3 Beta Testers
  • Jr. Member
  • *
  • Posts: 51
  • Karma: +3/-19
  • Doom Newbie
    • View Profile
Re: Ironsights aiming (scripting?)
« Reply #1 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

EoceneMiacid

  • Jr. Member
  • **
  • Posts: 74
  • Karma: +4/-15
  • Doom Newbie
    • View Profile
Re: Ironsights aiming (scripting?)
« Reply #2 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?

The Happy Friar

  • Happy Happy Joy Joy
  • Administrator
  • Hero Member
  • *****
  • Posts: 866
  • Karma: +42/-4
  • Semi-Newbie.
    • View Profile
    • EarthQuake
Re: Ironsights aiming (scripting?)
« Reply #3 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.

EoceneMiacid

  • Jr. Member
  • **
  • Posts: 74
  • Karma: +4/-15
  • Doom Newbie
    • View Profile
Re: Ironsights aiming (scripting?)
« Reply #4 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"




0x29a

  • PD3 Beta Testers
  • Jr. Member
  • *
  • Posts: 51
  • Karma: +3/-19
  • Doom Newbie
    • View Profile
Re: Ironsights aiming (scripting?)
« Reply #5 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.

The Happy Friar

  • Happy Happy Joy Joy
  • Administrator
  • Hero Member
  • *****
  • Posts: 866
  • Karma: +42/-4
  • Semi-Newbie.
    • View Profile
    • EarthQuake
Re: Ironsights aiming (scripting?)
« Reply #6 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. 

EoceneMiacid

  • Jr. Member
  • **
  • Posts: 74
  • Karma: +4/-15
  • Doom Newbie
    • View Profile
Re: Ironsights aiming (scripting?)
« Reply #7 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.

VGames

  • PD3 Beta Testers
  • Hero Member
  • *
  • Posts: 754
  • Karma: +17/-69
    • View Profile
Re: Ironsights aiming (scripting?)
« Reply #8 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.
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

EoceneMiacid

  • Jr. Member
  • **
  • Posts: 74
  • Karma: +4/-15
  • Doom Newbie
    • View Profile
Re: Ironsights aiming (scripting?)
« Reply #9 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.




oneofthe8devilz

  • Sr. Member
  • ****
  • Posts: 371
  • Karma: +93/-84
  • Doom Newbie
    • View Profile
    • Scared Pixel Studios
Re: Ironsights aiming (scripting?)
« Reply #10 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.
« Last Edit: June 14, 2016, 07:32:02 AM by oneofthe8devilz »
I got six little friends and they all run faster than you ;)


Check out our mods at
moddb or the SPS Homepage