Doom3world

The world is yours! Doom 3 - Quake 4 - ET:QW - Prey - Rage
It is currently Sun May 19, 2013 11:26 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: [Help] Toggle gunlights?
PostPosted: Wed Jun 13, 2012 2:39 pm 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 06, 2012 5:56 pm
Posts: 22
All right, i have been helped here before, so i will ask again in the hopes of being lucky for a second time. My mod is almost complete.
The only feature that's missing is a light on some of the weapons that can be toggled. Now, putting a light on the guns is not the problem ofc.

Toggling it is. Any way to do it without SDK work? I want to avoid touching the SDK as i suck at programming even more than i do at scripting.

Also, any way to fix the no muzzleflash bug when the gun has a light on it?

Thanks if you've helped me.

EDIT:Come on, guys. 56 views and no reply? It's the easiest thing to do for any advanced modder. Please share the information.


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sat Jun 16, 2012 3:32 am 
Offline
picked up 75 health

Joined: Thu Aug 19, 2004 3:50 am
Posts: 81
How are you currently implementing your weapon lights?


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sat Jun 16, 2012 9:11 am 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 06, 2012 5:56 pm
Posts: 22
blender81 wrote:
How are you currently implementing your weapon lights?


I'll paste the relevant part of my pistol script.

You see, i've made a new float called "lightstate".
I set it to false at the beginning of the Idle state.
Then i use these ugly Ifs to toggle it.

Code:
if ( WEAPON_RELOAD && ammoClip == clip_size && lightstate == true ) {
                WEAPON_RELOAD = false;
                lightstate = false;
                flashlight( lightstate );         
      }
                if ( WEAPON_RELOAD && ammoClip == clip_size && lightstate == false ) {
                WEAPON_RELOAD = false;
                lightstate = true;
                flashlight( lightstate );         
      }

Also, i've already got around the "no muzzleflash" problem.
What would be awesome is to be able to toggle it with a separate key.


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sat Jun 16, 2012 11:02 am 
Offline
is sad because his cool title went away
User avatar

Joined: Tue Sep 07, 2004 6:23 pm
Posts: 709
Location: Bracknell UK
Quick ugly way for you.

In your doomconfig.cfg or autoexec.
Code:
set myflashlight "off"
bind "j" "script playerActions::toggleFlashLight()"


New script in script folder (remember to include it in your doom_main.script.
playerUtils.script
Code:
namespace playerActions{
 
  void toggleFlashLight(){
    if (sys.getcvar("myflashlight") =="on"){
      sys.setcvar("myflashlight","off");
    }else{
      sys.setcvar("myflashlight","on");
    }
  }

}
The above just takes care of toggling the cvar myflashlight between on and off when you press j.


There where ever you need it check the state of this cvar to turn on your light.
e.g
Code:
if (sys.getcvar("flashlight") =="on"){
  flashlight ( true );
}else{
  flashlight ( false );
}


Above untested but ive used this type of setup loads of times for testing pieces so should be good to go.


Top
 Profile  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sat Jun 16, 2012 11:10 am 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 06, 2012 5:56 pm
Posts: 22
I want to do this without editing any .cfg file, though. I've tried editing mainmenu.gui. Now i can bind any button to "toggle gunlight_state" but whenever i press said button the console tells me there's no such CVAR.


EDIT: I've used your method, but tied it to the weapon script-- no CFG modification required. Thank you very much sir :D


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sat Jun 16, 2012 4:48 pm 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 06, 2012 5:56 pm
Posts: 22
Any way to play a sound when this happens? I have a .wav file ready, but i don't know how to play it from within the scripts.


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sat Jun 16, 2012 6:30 pm 
Offline
picked up the chaingun
User avatar

Joined: Mon Jul 18, 2011 5:58 am
Posts: 193
maybe
Code:
startSoundShader("flashlight_switch",SND_CHANNEL_ANY);


You need to create a sound shader with the name "flashlight_switch"

_________________
FFYL
------
Doom 3: S.T.A.R 1088


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sat Jun 16, 2012 7:04 pm 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 06, 2012 5:56 pm
Posts: 22
chimueloeldragon2011 wrote:
maybe
Code:
startSoundShader("flashlight_switch",SND_CHANNEL_ANY);


You need to create a sound shader with the name "flashlight_switch"


/gives you a virtual cake

EDIT: It is looping now, though. Any way to stop this?


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sat Jun 16, 2012 7:39 pm 
Offline
picked up the chaingun
User avatar

Joined: Mon Jul 18, 2011 5:58 am
Posts: 193
Well, if you added the 'looping' key to the sound shader it'll surely loop. Otherwise I have no idea?

_________________
FFYL
------
Doom 3: S.T.A.R 1088


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sat Jun 16, 2012 7:42 pm 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 06, 2012 5:56 pm
Posts: 22
chimueloeldragon2011 wrote:
Well, if you added the 'looping' key to the sound shader it'll surely loop. Otherwise I have no idea?


I've even added no_dups to make sure it does NOT loop. Also, i've moved it outside the While(1) loop, thinking that it was looping because of that. But nope.

Is the Idle state called again and again maybe? I don't think so.

EDIT: Full pistol script, if anyone wants to fix it for me.

Code:
#define PISTOL_FIRERATE         0.04
#define PISTOL_LOWAMMO         4
#define PISTOL_NUMPROJECTILES   1

// blend times
#define PISTOL_IDLE_TO_LOWER   2
#define PISTOL_IDLE_TO_FIRE      1
#define   PISTOL_IDLE_TO_RELOAD   3
#define PISTOL_RAISE_TO_IDLE   3
#define PISTOL_FIRE_TO_IDLE      4
#define PISTOL_RELOAD_TO_IDLE   4

object weapon_pistol : weapon_base {
   float      next_attack;
   float      spread;
   float           cooldown;
        float           intensity;
        float           lightstate;

   void      init();
   void      Lower();
   void      Raise();
   void      Idle();
   void      Fire();
   void      Reload();
   void      ExitCinematic();

};

void weapon_pistol::init() {
   next_attack = 0;
   spread      = getFloatKey( "spread" );
        sys.setcvar("gunlight_state","0");
   weaponState( "Raise", 0 );
}

void weapon_pistol::Raise() {
   weaponRising();
   playAnim( ANIMCHANNEL_ALL, "raise" );
   waitUntil( animDone( ANIMCHANNEL_ALL, PISTOL_RAISE_TO_IDLE ) );
   weaponState( "Idle", PISTOL_RAISE_TO_IDLE );
}

void weapon_pistol::Lower() {
   weaponLowering();
   playAnim( ANIMCHANNEL_ALL, "putaway" );
   waitUntil( animDone( ANIMCHANNEL_ALL, 0 ) );
   weaponHolstered();
   waitUntil( WEAPON_RAISEWEAPON );
   weaponState( "Raise", 0 );
}

void weapon_pistol::Idle() {
   float currentTime;
   float ammoClip;
   float avail;
   float clip_size;
        float cooldown;       //Needed only for lowering the spread(because i felt like connecting it to a float for better control)
   clip_size = clipSize();

        cooldown = 1;  // set our new float to 1 so when the weapon is in the Idle state, spread decreases
        lightstate = false;
        sys.getcvar("gunlight_state");   
   weaponReady();
                if (sys.getcvar("gunlight_state") == "1") {
                startSoundShader("flashlight_switch",SND_CHANNEL_ITEM);
                lightstate = true;
                flashlight( lightstate );         
      }
                if (sys.getcvar("gunlight_state") == "0") {
                lightstate = false;
                flashlight( lightstate );         
      }       
   if ( !ammoInClip() ) {
      playCycle( ANIMCHANNEL_ALL, "idle_empty" );
   } else {
      playCycle( ANIMCHANNEL_ALL, "idle" );
   }
   while( 1 ) {
      if ( WEAPON_LOWERWEAPON ) {
         weaponState( "Lower", PISTOL_IDLE_TO_LOWER );
      }
      currentTime = sys.getTime();
      ammoClip = ammoInClip();
      if ( ( currentTime >= next_attack ) && WEAPON_ATTACK ) {
         if ( ammoClip > 0 ) {
            weaponState( "Fire", PISTOL_IDLE_TO_FIRE );
         } else if ( ammoAvailable() > 0 ) {
            if ( autoReload() ) {
                                        cooldown = 1;
                                        spread = 1;
               netReload();
               weaponState( "Reload", PISTOL_IDLE_TO_RELOAD );
            }
         }
      }
      if ( WEAPON_RELOAD && ( ammoAvailable() > ammoClip ) && ( ammoClip < clip_size ) ) {
                        cooldown = 1;  //set it to 1 again just to be safe
                        spread = 1;
         netReload();
         weaponState( "Reload", PISTOL_IDLE_TO_RELOAD );
      }
                if (sys.getcvar("gunlight_state") == "1") {
                startSoundShader("flashlight_switch",SND_CHANNEL_ITEM);
                lightstate = true;
                flashlight( lightstate );         
      }
                if (sys.getcvar("gunlight_state") == "0") {
                lightstate = false;
                flashlight( lightstate );         
      }
      if ( WEAPON_NETRELOAD ) {
                        spread = 1;
                        cooldown = 1;   //...and again!
         WEAPON_NETRELOAD = false;
         weaponState( "Reload", PISTOL_IDLE_TO_RELOAD );      
      }
                if ( cooldown == 1 ) {    // the code itself. Note that adding a sys.wait will make reloading happen only 5 out of 10 times
                spread = spread - 0.080;  // this will loop numerous times...
                }
                if ( spread < 1 ) {       // but spread can never go below 1.
                     spread = 1;
                }
      waitFrame();
   }
}

void weapon_pistol::Fire() {
   float ammoClip;

   next_attack = sys.getTime() + PISTOL_FIRERATE;
   
   ammoClip = ammoInClip();
   if ( ammoClip == PISTOL_LOWAMMO ) {
      startSound( "snd_lowammo", SND_CHANNEL_ITEM, true );
   }
   
   launchProjectiles( PISTOL_NUMPROJECTILES, spread, 0, 1.0, 1.0 );
        startFx( "fx/muzzlelight.fx" );
   playAnim( ANIMCHANNEL_ALL, "fire" );
        if ( spread < 8 ) {    // for some reason placing this code under the next_attack line results in only the first shot having increased spread.
               spread = spread + 1.3; // this code loops as long as the mouse button is held due to the function being called over and over again.
        }
   waitUntil( animDone( ANIMCHANNEL_ALL, PISTOL_FIRE_TO_IDLE ) );
   weaponState( "Idle", PISTOL_FIRE_TO_IDLE );
}

void weapon_pistol::Reload() {
   weaponReloading();
   playAnim( ANIMCHANNEL_ALL, "reload" );
   waitUntil( animDone( ANIMCHANNEL_ALL, PISTOL_RELOAD_TO_IDLE ) );
   addToClip( clipSize() );
   weaponState( "Idle", PISTOL_RELOAD_TO_IDLE );
}

void weapon_pistol::ExitCinematic() {
   next_attack = 0;
   weaponState( "Idle", 0 );
}



I know it's messy. The toggle on & toggle off binds are at the beginning of the Idle state. No idea why the sound loops.

EDIT2: I'm stupid. Left the startSoundShader in the while loop. Will check if this is the source of the problem.
EDIT3: Yes, this was the problem. However, now i can't toggle my light without firing the weapon first. Weird.


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sat Jun 16, 2012 8:19 pm 
Offline
picked up the chaingun
User avatar

Joined: Mon Jul 18, 2011 5:58 am
Posts: 193
Well since I'm awful at scripting I can't really tell you what's the source of the problem.
Anyway, 'no_dups' doesn't mean the sound doesn't loop, but it makes the sound not to be played twice (this only works if you have 2 or more wave files, otherwise it's useless)

Quote:
now i can't toggle my light without firing the weapon first


I Definatelly have no idea what could be causing that. I hope someone with scripting skills will help you

_________________
FFYL
------
Doom 3: S.T.A.R 1088


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sat Jun 16, 2012 8:43 pm 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 06, 2012 5:56 pm
Posts: 22
chimueloeldragon2011 wrote:
Well since I'm awful at scripting I can't really tell you what's the source of the problem.
Anyway, 'no_dups' doesn't mean the sound doesn't loop, but it makes the sound not to be played twice (this only works if you have 2 or more wave files, otherwise it's useless)

Quote:
now i can't toggle my light without firing the weapon first


I Definatelly have no idea what could be causing that. I hope someone with scripting skills will help you


The problem is, it doesn't go back to the beginning of the Idle state unless you fire, reload, put the weapon away, etc. And i have no idea how to make it go back.


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sun Jun 17, 2012 9:21 am 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 06, 2012 5:56 pm
Posts: 22
Does anyone know how to check if a cvar's value has been changed?


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sun Jun 17, 2012 9:32 am 
Offline
Invisibility
User avatar

Joined: Fri Aug 13, 2004 4:39 pm
Posts: 3654
Location: Right there! Look!
MadHacker wrote:
Does anyone know how to check if a cvar's value has been changed?

Yes, use 'sys.getcvar(string cvar)'

e.g.

Code:
string difficulty;
difficulty = sys.getcvar("g_skill");


Then you can check periodically if it's changed.

_________________
Check out GRIMM Quest for the Gatherer's Key!
Grimm's Youtube Channel

Follow Grimm Quest on Twitter!


Top
 Profile E-mail  
 
 Post subject: Re: [Help] Toggle gunlights?
PostPosted: Sun Jun 17, 2012 9:52 am 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 06, 2012 5:56 pm
Posts: 22
BloodRayne wrote:
MadHacker wrote:
Does anyone know how to check if a cvar's value has been changed?

Yes, use 'sys.getcvar(string cvar)'

e.g.

Code:
string difficulty;
difficulty = sys.getcvar("g_skill");


Then you can check periodically if it's changed.


Awesome, thanks Bloodrayne:P. Although i've already solved the problem with a much uglier method, i will now remember to use strings whenever i need to check CVar states :). I will mention you and everyone else who helped me in the readme file when i release this mod.


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Cataflexia and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group