How to make a sprint key

From EDukeWiki
Jump to navigation Jump to search

This simple tutorial will show you how to make a sprint key similar to the one in HL2 or Doom 3.

Open up Game.con and add these lines somewhere near the top:

define SPRINTSPEED 60200 // Duke's default speed is 53200

This speed is incredibly fast, but Duke already moves at a freakish speed anyways so it's worth tuning this depending on the kind of mod you're making.

definegamefuncname 36 SPRINT // Changes the 'Turn Around' keyname in the options menu to Sprint

onevent EVENT_TURNAROUND setvar RETURN -1 endevent // Disables the Turn around key

Once again the poor turnaround key gets the chop to make way for our sprint key. At the moment adding new keys isn't possible so we have to get rid of one of the somewhat reduntant keys to make way for our own.

gamevar SPRINTING 100 1 // This is the player's sprint 'strength'
gamevar digx 0 1
gamevar digy 0 1
gamevar TEMP 0 2
gamevar TEMP2 0 2
gamevar TEMP3 0 2

Here are the neccesary gamevars - if you already have a selection of temporary vars available than simply replace my definitions in the following code with your own (They're here just to make copying + pasting easier)

ifvarl SPRINTING 100 // Bar code from DukePlus by DeeperThought
	setvar digy 175
	setvar digx 130
	setvarvar TEMP3 digx
	addvarvar TEMP3 SPRINTING
	setvar TEMP 0
	whilevarn TEMP 1
		  ifvarvarg digx TEMP3 setvar TEMP 1
		  rotatesprite digx digy 16384 0 199 0 21 1 0 0 xdim ydim
		  addvar digx 1
	ifvarl SPRINTING 0 setvar TEMP3 2 else setvar TEMP3 0 // turn the icon red if he's out of sprint strength
	rotatesprite 125 175 16384 0 1431 0 TEMP3 0 0 0 xdim ydim // Places a small Duke running icon

This code creates a bar that appears in the bottom middle of the screen when you're sprinting. If you wish to change the position of the bar, modify the values 'digy' and 'digx' which basically hold where it appears on screen.

Now, search for 'actor APLAYER MAXPLAYERHEALTH' and then add this in the actor code:

ifvarl SPRINTING 100 addvar SPRINTING 1 // This 'recharges' the bar

getinput[THISACTOR].bits TEMP // Get the player's input into a temporary variable
ifvarand TEMP 268435456 // Is the player holding the Sprint key down?
	ifvarg SPRINTING 0 // If they have sprint strength left
	getplayer[THISACTOR].angvel TEMP3 // Get how fast the player is turning
	divvar TEMP3 4
	mulvar TEMP3 -1
	setplayer[THISACTOR].rotscrnang TEMP3 // Tilts the player's screen when he's turning
	subvar SPRINTING 2 // Reduce his sprint strength
	setplayer[THISACTOR].runspeed SPRINTSPEED // And change his speed to the faster one
	else ifvare SPRINTING 0 // If the player sprints till the bar is competely empty...
        sound DUKE_GASP 
        setvar SPRINTING -20 // Give it a 'cool-down' period 
        setplayer[THISACTOR].runspeed 42100 // and make him move slower for a short period
setplayer[THISACTOR].runspeed RUNNINGSPEED // Sets it to the default speed