Game Development Community

dev|Pro Game Development Curriculum

Not wasting ammo reloading

by Joseph Jonathan · 04/18/2007 (1:54 pm) · 2 comments

This tutorial is based off of Tim's tutorial found Here

You need to follow his tutorial to the end before attempting this one.

This is a short but usfull tutorial, lets get started.

Starting:

Find this in Rifle.cs

function RifleImage::ReloadAmmoClip(%this, %obj) {
	if(%obj.getInventory(%this.clip) > 0) {
				%message = "I push a stripperclip of ammo into the gun..." @
                 "I shove another shot into the chamber as I push the lever back.  " @
                 "This would be cooler with a animation...huh?";
		%time = 5;
		%lines = 2;
		centerPrint( %obj.client, %message, %time, %lines );
                //remember to change this first number to the number of milliseconds
                 //that your animation lasts

                schedule(2000, 0, "reloadBullets",%this,%obj);

		%obj.playReloadAnimation();
	} else {
	    %message = "Shazbot!  I don't have any clips!";
		%time = 5;
		%lines = 1;
		centerPrint( %obj.client, %message, %time, %lines );
	}
}

Right above the if(%obj.getInventory(%this.clip) > 0) {

add

if (%obj.getInventory(%this.ammo) == 20) {
	%message = "weapon already reloaded";
	%time = 3;
	%lines = 1;
	centerPrint( %obj.client, %message, %time, %lines );
}

change the 20 to whatever your ammos max inventory is.

Now change the
if(%obj.getInventory(%this.clip) > 0) {
to
else if(%obj.getInventory(%this.clip) > 0) {


Thats it. Now when you try to reload when you already have a full clip in the weapon it will not reload and waste your clips.

About the author

Recent Blogs


#1
04/18/2007 (2:07 pm)
thank you Joseph, good job
#2
08/09/2008 (5:39 am)
Nice work man