Duke4.net Forums: Looking for help improving my alternate-fire CON script - Duke4.net Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Looking for help improving my alternate-fire CON script

User is offline   Padlowan 

#1

Current code is as follows:

GAME.CON:
//ALTERNATE FIRE MODE FOR PISTOL (Laser Pistol)
gamevar ALT_WEAP1 0 //var to store the pistol's current fire mode
onevent EVENT_WEAPKEY2	//when pistol select button pressed
ife WEAPON 1 			//if pistol already selected
{
	soundonce SELECT_WEAPON		//sounds
	soundonce PISTOL_BODYHIT
	ife ALT_WEAP1 0				//if alt fire off
	{
		quote 128
		setvar ALT_WEAP1 1			//turn alt fire on
		setvar WEAPON1_SHOOTS FIRELASER  
		setvar WEAPON1_FIRESOUND PRED_ATTACK  

	}
	else 						//if alt fire on
	{
		quote 128
		setvar ALT_WEAP1 0			//turn alt fire off 
		setvar WEAPON1_SHOOTS SHOTSPARK1 
		setvar WEAPON1_FIRESOUND PISTOL_FIRE 
	}
}
endevent

//ALTERNATE FIRE MODE FOR RPG (Morter Launcher)
//The default morter seems to explode when near the player (I.E as soon as the player fires it), so a new projectile is created
defineprojectile PLAYERMORTER PROJ_WORKSLIKE 6150
defineprojectile PLAYERMORTER PROJ_SPAWNS EXPLOSION2
defineprojectile PLAYERMORTER PROJ_VEL 1000
defineprojectile PLAYERMORTER PROJ_DROP -256
defineprojectile PLAYERMORTER PROJ_ISOUND PIPEBOMB_EXPLODE
defineprojectile PLAYERMORTER PROJ_HITRADIUS 2560
defineprojectile PLAYERMORTER PROJ_BOUNCES 3
defineprojectile PLAYERMORTER PROJ_OFFSET 224
defineprojectile PLAYERMORTER PROJ_CLIPDIST 24
defineprojectile PLAYERMORTER PROJ_TRAIL SMALLSMOKE

gamevar ALT_WEAP4 0 //var to store the RPG's current fire mode
onevent EVENT_WEAPKEY5	//when RPG select button pressed
ife WEAPON 4 			//if RPG already selected
{
	soundonce SELECT_WEAPON		//sounds
	soundonce PISTOL_BODYHIT
	ife ALT_WEAP4 0				//if alt fire off
	{
		quote 128
		setvar ALT_WEAP4 1			//turn alt fire on
		setvar WEAPON4_SHOOTS PLAYERMORTER

	}
	else 						//if alt fire on
	{
		quote 128
		setvar ALT_WEAP4 0			//turn alt fire off 
		setvar WEAPON4_SHOOTS RPG

	}
}
endevent

//Alternate fire modes using alt fire button
onevent EVENT_ALTWEAPON	//When alt-fire button pressed
ife WEAPON 1 			//if pistol selected
{
	soundonce SELECT_WEAPON		//sounds
	soundonce PISTOL_BODYHIT
	ife ALT_WEAP1 0				//if alt fire off
	{
		quote 128
		setvar ALT_WEAP1 1			//turn alt fire on
		setvar WEAPON1_SHOOTS FIRELASER  
		setvar WEAPON1_FIRESOUND PRED_ATTACK  

	}
	else 						//if alt fire on
	{
		quote 128
			setvar ALT_WEAP1 0			//turn alt fire off 
			setvar WEAPON1_SHOOTS SHOTSPARK1 
		setvar WEAPON1_FIRESOUND PISTOL_FIRE 

	}
}
ife WEAPON 4 			//if RPG selected
{
	soundonce SELECT_WEAPON		//sounds
	soundonce PISTOL_BODYHIT
	ife ALT_WEAP4 0				//if alt fire off
	{
		quote 128
		setvar ALT_WEAP4 1			//turn alt fire on
		setvar WEAPON4_SHOOTS PLAYERMORTER

	}
	else 						//if alt fire on
	{
		quote 128
			setvar ALT_WEAP4 0			//turn alt fire off 
			setvar WEAPON4_SHOOTS RPG 

	}
}
endevent


USER.CON:
definequote 128		  SWITCHED FIRE MODE


This code seems to function correctly, however there is no way to see which fire-mode is currently selected without firing the weapon. Ideally, I would like to change the weapon texture depending on current selection, or change the ammo symbol. If that isn't possible, I could have a simple HUD addition in a corner somewhere showing which is selected.

I'm already confident in adding new textures to the ART files, but I can't find a way to swap out textures on screen (weapon texture & ammo symbol).

I'd love to hear any general suggestions for improvements or additions I can make too.
0

User is offline   Danukem 

  • Duke Plus Developer

#2

You could make right-mouse shoot altfire and left-mouse shoot regular fire, then there's no need switch modes. EDuke32 supports this.
0

User is offline   Danukem 

  • Duke Plus Developer

#3

 Padlowan, on 08 July 2025 - 09:50 PM, said:

I'm already confident in adding new textures to the ART files, but I can't find a way to swap out textures on screen (weapon texture & ammo symbol).


I have bad news for you. You can't just "swap out" textures on screen.

Any different tiles appearing on the HUD from the hardcoded ones requires that you have your own HUD code that pretty much redraws the relevant parts of the HUD from scratch. You can try copying from another mod that does this and then changing them to your own tile numbers, but its still going to require tweaking to fit what you want to do, and judging from your post you have zero knowledge in that area.

EDuke32 downloads do come with a CON file written by Hendricks266 (at least I think its still included) that completely replicates all the hardcoded HUD stuff. If you start with that, it can make the job easier.
0

User is offline   Padlowan 

#4

View PostDanukem, on 09 July 2025 - 10:41 AM, said:

You could make right-mouse shoot altfire and left-mouse shoot regular fire, then there's no need switch modes. EDuke32 supports this.

Realising now this will probably work a lot better than what I had in mind lol :/. For context, I was originally going for something similar to swapping out attachments in DOOM Eternal, but I think I'll just make it more akin to the way altfire works in Blood.

Thanks for all your help!
0

User is offline   Padlowan 

#5

This is what I ended up with, if anyone comes across this thread:
//PROJECTILES
//The default morter seems to explode when near the player (I.E as soon as the player fires it), so a new projectile is created
//Player Morter, will bounce 3 times before exploding - or if it hits an enemy
defineprojectile PLAYERMORTER PROJ_WORKSLIKE 6150
defineprojectile PLAYERMORTER PROJ_SPAWNS EXPLOSION2
defineprojectile PLAYERMORTER PROJ_VEL 1000
defineprojectile PLAYERMORTER PROJ_DROP -256
defineprojectile PLAYERMORTER PROJ_ISOUND PIPEBOMB_EXPLODE
defineprojectile PLAYERMORTER PROJ_HITRADIUS 2560
defineprojectile PLAYERMORTER PROJ_BOUNCES 3
defineprojectile PLAYERMORTER PROJ_OFFSET 224
defineprojectile PLAYERMORTER PROJ_CLIPDIST 24
defineprojectile PLAYERMORTER PROJ_TRAIL SMALLSMOKE

//Double shotgun projectile, not quite as powerful as two actual shots for balancing reasons (*REMINDER TO CREATE 'SMALLBURNING' TO USE AS PROJ_SPAWNS)
defineprojectile DOUBLESHOTGUN PROJ_WORKSLIKE 1
defineprojectile DOUBLESHOTGUN PROJ_EXTRA 18
defineprojectile DOUBLESHOTGUN PROJ_EXTRA_RAND 9
defineprojectile DOUBLESHOTGUN PROJ_ISOUND PISTOL_RICOCHET
defineprojectile DOUBLESHOTGUN PROJ_SPAWNS SMALLBURNING
defineprojectile DOUBLESHOTGUN PROJ_TXREPEAT 2
defineprojectile DOUBLESHOTGUN PROJ_TYREPEAT 2
defineprojectile DOUBLESHOTGUN PROJ_RANGE 6144 //BALANCING OPTION- reduced range for balancing


//ALT-FIRE for weapons
//When Alt-fire key pressed:
onevent EVENT_ALTFIRE
	setvar ANGRANGE 256
  //Pistol - Laser Pistol (less spread, but slower projectile)
	ife WEAPON 1
	{
		setvar WEAPON1_SHOOTS FIRELASER
		setvar WEAPON1_FIRESOUND PRED_ATTACK 
		//If the weapon is ready, fire
		ifvare player [THISACTOR] .kickback_pic 0 setplayer [THISACTOR] .kickback_pic 1
	}
  //Shotgun - Double Shotgun (I know it doesn't make sense with the sg texture but)
	ife WEAPON 2
	{
		ifvarg player [THISACTOR] .ammo_amount 2 1 //ensure the player has at least 2 shells before allowing double-shot
		{
			setvar WEAPON2_SHOOTS DOUBLESHOTGUN

			ifvare player [THISACTOR] .kickback_pic 0  
			{
				//calling addamo when the shotgun is at max doesn't work, so the player can perform double-shot using only one shell if at maxammo
				ifvare player [THISACTOR] .ammo_amount 2 50 nullop else addammo SHOTGUN_WEAPON -1
				sound RPG_SHOOT
				//wackplayer //BALANCING OPTION- wackplayer can be used to make it more difficult to aim a double shot
				
				ifrnd 128 //BALANCING OPTION- increased recoil/kickback means there is a chance the player will lose health
				{
					palfrom 32 32 //red
					addphealth -1	
					ifrnd 64 addphealth -1
				}
				else palfrom 32 32 16 //amber
			}
		}
		//If the weapon is ready, fire
		ifvare player [THISACTOR] .kickback_pic 0 setplayer [THISACTOR] .kickback_pic 1
	}
  //TODO Chaingun - Shrapnel Shredder
  //RPG - Grenade Launcher
	ife WEAPON 4
	{
		//change projectile to PLAYERMORTER
		setvar WEAPON4_SHOOTS PLAYERMORTER
		//If the weapon is ready, fire
		ifvare player [THISACTOR] .kickback_pic 0 setplayer [THISACTOR] .kickback_pic 1
	}
  //TODO Devastator - Cluster Bomb Launcher (similar to RPG ALT-Fire)
  //TODO Freezethrower - Flamethrower
endevent
//switch back to regular projectiles when primary fire key pressed
onevent EVENT_PRESSEDFIRE
	ife WEAPON 1
	{
		setvar WEAPON1_FIRESOUND PISTOL_FIRE 
		setvar WEAPON1_SHOOTS SHOTSPARK1
	}
	ife WEAPON 2 setvar WEAPON2_SHOOTS SHOTGUN
	ife WEAPON 4 setvar WEAPON4_SHOOTS RPG
endevent

0

User is offline   Danukem 

  • Duke Plus Developer

#6

player[].weapon_pos should also be 0 before you allow the firing sequence to begin, and the player should be alive
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


All copyrights and trademarks not owned by Voidpoint, LLC are the sole property of their respective owners. Play Ion Fury! ;) © Voidpoint, LLC

Enter your sign in name and password


Sign in options