Game Development Community

Complete Working Weapon Example

by Harold "LabRat" Brown · in Torque Game Engine · 08/23/2001 (12:38 am) · 39 replies

Complete Working Weapon Example:

Step 1.

Edit shapeImage.cc line 254

Change from:

dSprintf(fullName,sizeof(fullName),"shapes/%s",shapeName);

to:

dSprintf(fullName,sizeof(fullName),"%s",shapeName);

Compile a new Test Application

Step 2.
Edit PlayGui.gui

add:
new GuiBitmapCtrl(reticleHud) { 
	profile = "GuiButtonProfile"; 
	horizSizing = "center"; 
	vertSizing = "center"; 
	position = "192 112"; 
	extent = "32 32"; 
	minExtent = "2 2"; 
	visible = "1"; 
	setFirstResponder = "0"; 
	modal = "1"; 
	helpTag = "0"; 
	wrap = "0"; 
	fillColor = "0.250000 0.250000 0.250000 0.250000"; 
	frameColor = "0.000000 1.000000 0.000000 1.000000"; 
	opacity = "0.5"; 
	bitmap = "data/textures/crosshair.png"; 
	autoCenter = "1"; 
	autoResize = "1"; 
};

before the last }; in the file.

create a crosshair.png file, create the textures folder in the data directory and place the image there.

Step 3.

Edit Player.cs

replace the Armor::damageObject function with this one:

function Armor::damageObject(%data, %targetObject, %sourceObject, %position, %amount, %damageType, %momVec)
{
   if (%targetObject.getState() $= "Dead")
      return;

   %targetClient = %targetObject.getControllingClient();
   %sourceClient = %sourceObject ? %sourceObject.getControllingClient() : 0;

   %flash = %targetObject.getDamageFlash() + (%amount * 2);
   if (%flash > 0.75)
      %flash = 0.75;

   %targetObject.setDamageFlash(%flash);
   %targetObject.applyDamage(%amount);
   %targetClient.onClientDamaged(%sourceClient, %damageType, %sourceObject);

   //now call the "onKilled" function if the client was... you know...
   if (%targetObject.getState() $= "Dead")
   {
      // Disable movement temporarly.
      %targetObject.disableMove(true);
      // If we were killed, max out the flash
      %targetObject.setDamageFlash(0.75);
      // Call the death handler.
      %targetClient.onClientKilled(%sourceClient, %damageType, %sourceObject, %damLoc);
      // Play the death animation.
      playDeathAnimation(%targetObject, %damLoc, %damageType);
      // Schedule the respawn.
      schedule(6000,0,"spawnPlayer",%targetClient);
   }
   else
      if (%amount > 0.1)
         %targetObject.playPain();
}

Step 4.
Download this simple weapon MOD Weapon Mod


This is currently a 1 shot kill up to a range of 400 meters. Unlimited Ammo, and no special FX.



Credits:

Tenebrae of Trinity Armaments for the weapon model used.
Nelson Rush for the Death Animation and Respawn Delay
Chris Evans for the Respawn information
Mark Smith for the crosshair / reticleHUD
AJ for the Shape file fix and Tips on adding weapons
Page «Previous 1 2
#1
08/23/2001 (1:04 am)
Erm, i sound really stupid saying this, but nothing seems to happen, or do i have to call the gun with a console command?
#2
08/23/2001 (1:07 am)
Whoops... forgot a couple things


Start the MOD with the commandline: -mod weapons

After you start a mission add the weapon with:

commandtoserver('addrifle');

to spawn a target dummy use:

commandtoserver('createdummy');
#3
08/23/2001 (1:25 am)
Thankyou so much Labrat and all others who contributed to this.


Sorry to be a pain, but dummy works fine, but it doesn't create the weapon, says command is wrong or something
#4
08/23/2001 (2:47 am)
kewl stuff :), you are really helpfunn to this forum, thanks a lot.

I'm actually working on a sample for an options menu to set the resolution. I'm gonna post it soon.. just need to get rit of all the little buggies in there :]
#5
08/23/2001 (5:07 am)
ahhh, sorted it, it's not addrifle, it's addweapon


any ideas on how to add effects?
#6
08/23/2001 (9:21 am)
NP... I was about to pass out about the time I posted that message last night. Forgot I had changed the add weapon call at the last minute.

I did remember when I woke up this morning though LoL
#7
08/23/2001 (9:43 am)
hmm, I saw that player disableMove function and wondered what it was. The player's move input is already disable when you die, so it seems like a redundant function...

looked through the code, and it turns out that this doesn't do anything different, except that whoever put it in disabled part of the friction code in the process, so if you use disableMove your body won't stay still. I have no idea why this function was added, either somebody didn't know what they were doing, or there's some special use for frictionless corpses.

Anyway, I'll look into it, but you might want to stay away from that function for now. You don't need it anyway.
#8
08/23/2001 (9:50 am)
I know they use it in T2.. Maybe they liked watching the dead body slide down the hill.


Other then that I think Nelson mentioned something on IRC about if you didn't use that function the model would stand back up after the death animation was played.


Edit:

OK did a quick run through of the T2 scripts it's mapped to the Player::setMoveState function that seems to be called any time you use a station.

They set your velocity to 0 , snap you to the center of the station pad, and lock your controls.
#9
08/23/2001 (10:12 am)
hmm, nothing in the code seem to indicate it would solve that problem. It only affects move processing and clears out the player's x,y velocity every tick. Which means people killed in the air would stop all forward motion and fall straight down. What's that about?
#10
08/23/2001 (11:17 am)
Yeah... it's not for death code.

I'll play with it at lunch and see how things behave without it.
#11
08/23/2001 (11:50 am)
If I was already dead (killed in midair by a wandering projectile) the least of my concerns would be wether I fell straight down, or flew forward for another mile :)
#12
08/23/2001 (12:15 pm)
Hey Mr. Brown: Mind if I take your wonderfull mod here and, with some creative copy and paste, turn it into a tutorial? That way newbies that dont read EVERY forum post will be able to see it and learn from it too. The more tutorials the better I say.

Thank you very much for this! It has helped alot!
#13
08/23/2001 (12:19 pm)
Go ahead... The files contain the bare minimum to load, pickup, mount and fire a weapon.
#14
08/23/2001 (8:27 pm)
The reticle HUD still gets displayed when you switch to third person view, which of course is undesireable.

About line 182 in client/scripts/default.bind.cs replace the function toggleFirstPerson with the following code:

function toggleFirstPerson(%val)
{
   if (%val)
   {
      $firstPerson = !$firstPerson;
      reticleHud.setVisible($firstPerson);
   }
}
#15
08/23/2001 (8:30 pm)
Here's a crosshair I made in photoshop with alpha transparency, its nice looking, hope it helps:

palisade.rm-f.net/crosshair.png
#16
08/23/2001 (8:33 pm)
Tim, it may not be the right way to solve the problem but it proved itself as a workaround since the script now correctly kills the player. I'm kindof new to this stuff so if you could point me in the right direction I'll fix it. Thanks.
#17
08/24/2001 (6:50 am)
Nevermind, I figured it out. Such a dumb mistake it was
too. I wasn't using the rebuilt version of the example program. Oh, well. I guess I must have had a brain fart or something.

-------------------------------------------------------
Sorry, I'm having some trouble. I've edited all of the files and downloaded the mod. The console accepts my command to add a rifle and the status box even says "You picked up a weapon." However the model for the rifle isn't displayed and I don't get the crosshair on the HUD.

What am I doing wrong? Is it possible I put the MOD in the wrong place? I just stuck it in the same directory as the example program. Any help you guys can give me would be appreciated. I know this isn't a lot of info, so if you need more, please let me know.

Sorry if this is obvious, I just downloaded the engine a couple of days ago, and I thought this looked pretty cool to try.
#18
08/24/2001 (7:44 am)
Instead of using the console to call the weapons, anyone tried to bind the call to a key?
#19
08/24/2001 (6:11 pm)
How do we allow the player to throw items with a key binding and function, and drop them on death?
#20
08/25/2001 (6:04 am)
Erm, when the player stands still, the gun points away and looks stupid (and unreallistic when you shoot) is there anyway to fix this?
Page «Previous 1 2