Duke4.net Forums: Adding Iron Sights - Duke4.net Forums

Jump to content

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

Adding Iron Sights

#1

I'm interested in adding iron sights functionality to my game, and was wondering what would be involved in making it work. I've already learned how to add custom ART and reload functionality to duke weapons, but right now that's about as far as my experience goes.

I would like the iron sights to be similar to those in ARMA 2 as seen in the attachment:

Attached Image: ironsights.jpg
No zoom in, just animating the weapon placement/view on screen. I have a couple of questions with this:

1.) How do I go about making custom animations? I assume I have to use the "action <name> <startframe> <frames> <viewtype> <incvalue> <delay>" language, but I am unsure how to utilize it; i.e. where it goes and how to reference it within an "onevent EVENT_x" command.

2.) What other knowledge might I need to pull this off?

Any tips or suggestions would be much appreciated. I've been looking through various confaqs, but can't really seem to find anything that fits what I would like to do. I know it's weird wanting iron-sights in a run-'n-gun, but I always feel they add to the tension and immersion by having to take the extra action of aiming beyond a crosshair. Or it may turn into an unmitigated disaster, who knows?! But I aim to find out.
1

User is offline   Daedolon 

  • Ancient Blood God

#2

The action command is used for actors (like enemies and such) and not for HUD drawing. For actual weapons you'll be using one of the screen drawing commands, such as one of the Myos commands.

You'll need to hijack one of the keyboard controlling events for your iron sight key and hook up a variable for it. Then within the drawing code of the weapon, you'll check for the boolean variable and display custom artwork accordingly. It could be sprites or a model animation / frame.

How you'll go about it kind of depends if you want to use the original weapons or new custom ones.

Sorry if I'm sounding convoluted but I just woke up. If you're having trouble figuring it out, just throw some additional questions and I'm sure people will help you with it, possibly with example code as well.
2

User is offline   Jblade 

#3

It's as Daedolon said - you would check for a keypress, set the weapon tile animations to your centered ones and then use EVENT_GETSHOTRANGE to improve the gun's accuracy. If a visual example would help check the AMC TC in my sig since it has a couple of weapons with holosights you can use.
2

#4

Thanks for the help, guys!

View PostDaedolon, on 03 August 2013 - 08:07 PM, said:

The action command is used for actors...


Thanks a lot for the links! I'm trying read through the wiki, but there's just so much info on there, I sometimes get lost. After looking further into the action command, I kind of figured that it was for actors, but I wasn't sure if it could also be used for other things. I haven't seen the screen drawing commands before, just references to rotatesprite, which I now finally understand :P.
For the animation, I read on rtcm that the weapons aren't actually animated, the game just pulls the art tiles up in sequence. Would I set it up the same way for my iron sights sprites, or would I have to set the tiles to be animated in editart?

View PostJames, on 03 August 2013 - 10:43 PM, said:

It's as Daedolon said - you would check for a keypress, set the weapon tile animations to your centered ones and then use EVENT_GETSHOTRANGE to improve the gun's accuracy. If a visual example would help check the AMC TC in my sig since it has a couple of weapons with holosights you can use.


Thanks, I started the TC during school, then kinda forgot about it :P 'cause school does that. I'll start looking through the con files to see what I can glean, and definitely get back to playing it!
0

User is offline   Daedolon 

  • Ancient Blood God

#5

You generally wouldn't use the tile animation feature of Editart for weapons, but instead show the tiles sequentially from the code according to the specific weapon animation speeds, like WEAPONx_TOTALTIME. Unless someone else knows better, I haven't really been editing weapons in Duke3D for a year or two. The last time I made weapons was with sprites so I'm not entirely sure how to work with models. You'll still need to have proper totaltime and reload times, though you can get away with just checking for the kickback_pic a few times instead for every frame, assuming your model has been animated (read: timed) properly.

You'll be checking for player's current weapon in EVENT_DRAWWEAPON. If that weapon has an ironsight option to it, you check against the ironsight variable you created, then call a separate state for either drawing the gun regularly or the ironsight version. Here's a stripped down example of how I'm handling it:

onevent EVENT_DRAWWEAPON
	ifvare CURRENT_WEAPON 1
	{
		ifvare IRONSIGHT_ON 1 { ifvarg PISTOL_AMMO 0 { state drawpistolironsight } } else { state drawpistol }
	}
endevent


Some stuff to note, WEAPONx_TOTALTIME will be the total time your gun takes to fire, so if you set it to 5 for example, you'll have five frames of animation for the firing of the gun.

For instance here's some older code from one of my mods (meant for sprite weapons), the TOTALTIME is set to 5 so there's five frames of animation for the weapon:

state drawpistolironsight
	setvar RETURN -1 // I forgot if this is even necessary
	setvar weaptile 2513 // the idling frame of the pistol

	getplayer[THISACTOR].reloading GUN_RELOAD // checking if player is reloading
	ifvare GUN_RELOAD 1 { setvar IRONSIGHT_ON 0 } // if so, turn iron sight off

	getplayer[THISACTOR].kickback_pic GUN_FIRE // get the weapon's current frame number and play through them
	{
		ifvare GUN_FIRE 0 { setvar weaptile 2513  } // ironsight idle
		ifvare GUN_FIRE 1 { setvar weaptile 2514  } // ironsight firing frame 1
		ifvare GUN_FIRE 2 { setvar weaptile 2515  } // firing frame 2
		ifvare GUN_FIRE 3 { setvar weaptile 2516  } // firing frame 3
		ifvare GUN_FIRE 4 { setvar weaptile 2517  } // firing frame 4
		ifvare GUN_FIRE 5 { setvar weaptile 2518  } // firing frame 5
	}

	setvar weapx 155 // setting the horizontal positionwhere the weapon will be drawn
	addvarvar weapx weapon_xoffset // add horizontal weapon sway
	subvarvar weapx looking_angSR1 // another thing I forgot :P
	setvar weapy 225 // setting the vertical position
	addvarvar weapy looking_arc // adding the vertical sway
	subvarvar weapy gun_pos // adding the vertical sway pt2

	myospal weapx weapy weaptile weapshade weapor weappal // drawing the weapon
ends


For the regular version of the gun that has the reloading animation, you'd use exactly the same code (creating another state called drawpistol), except just with added kickback_pics for the reloading animation. The WEAPONx_RELOAD will be the the number of frames the weapon uses for the reloading animation (and reloading time in general). Notice that if you use say, 50 as the reload time, it will need to be total of 50, not 55, as the reloading animation is started from the first frame after the firing animation. Basically you'll just add to the code like this:

		ifvare GUN_FIRE 5 { setvar weaptile 2524 } // normal firing frame 2 -- this is where the kickback_pic checking ends in the ironsight drawing code

		ifvare GUN_FIRE 6 { setvar weaptile 2528 } // reloading animation
		// ...
		ifvare GUN_FIRE 50 { setvar weaptile 2524 } // end of reloading animation, usually the weapon idle frame


I hope that helps.

This post has been edited by Daedolon: 04 August 2013 - 07:29 AM

4

#6

View PostDaedolon, on 04 August 2013 - 07:27 AM, said:

You generally wouldn't use the tile animation feature...


Wow, that was a much better explanation than I was expecting! Thank you, that is extremely helpful. I guess I'll start making those sprites now :P
1

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