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:
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:
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
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
#22
08/27/2001 (3:52 pm)
A dummy just stole my airplane!!!!!! I had to shoot him for that... *evil grin*
#23
i want to vary the damage amount by figuring how close to the player you are
08/27/2001 (9:17 pm)
is there a way to figure out how far away the player you hit is? getRange or something like that?i want to vary the damage amount by figuring how close to the player you are
#24
I haven't tested it yet... but that should be the basic idea.
08/27/2001 (9:36 pm)
if(%scanTarg && !(%scanTarg.getType() & $TypeMasks::InteriorObjectType))
{
// Distance to Target
%clPos = %client.player.getWorldBoxCenter();
%targPos = %scanTarg.player.getWorldBoxCenter();
%distance = VectorDist(%clPos, %targPos);
// a target in range was found
%target = firstWord(%scanTarg);
%target.getDataBlock().damageObject(%target, %obj, VectorAdd(%target.getPosition(),%vec), 50, $DamageType::Ground);
// Do damage functions here
}I haven't tested it yet... but that should be the basic idea.
#25
08/27/2001 (10:35 pm)
thanks!!
#26
08/31/2001 (7:59 pm)
Hey I went through this tutorial to get an idea of how to do weapons, its great very insightful. But for me I have to be like right on top of the dummy player to kill him, and even then I have to like fire 2 or three times to kill him, I thought it was a one shot one kill type thing. Anyone else having this??? or am I the only retard in the group. ;)
#27
08/31/2001 (10:52 pm)
You're not the only one with troubles. But I prefer to think of us as "special" ... :-)
#28
Anyone?
09/02/2001 (4:35 pm)
How can I set the reticle to not be there usind the 3rd person camera tutorial?Anyone?
#29
help! :(
thanks,
-Mark
09/04/2001 (9:49 am)
Everytime I type "commandtoserver('x')" it just says "syntax error in input".help! :(
thanks,
-Mark
#30
09/04/2001 (9:59 am)
dont forget to add ";" after it
#31
Is anyone else having this problem, and can anyone suggest anything?
09/04/2001 (11:45 pm)
Our group has had mucho probs with the Max2Dts Exporter. Whenever we've tried to export a model (following relevant tutorials aswell), Max ends up causing an error and crashing. We're all running 3dsmax 3.1, and our coder has tried recompiling with no luck.Is anyone else having this problem, and can anyone suggest anything?
#32
but it still doesn't quite work, I can add a weapon, and that drops in, but I get an error message in my console.
server/weapons/scripts/weapons.cs (0): preload failed for RifleImage: Unable to load shape ~/weapons/shapes/weapon_thumper.dts.
--scripts/weapons.cs--
datablock ItemData(Rifle)
{
className = Weapon;
catagory = "Spawn Items";
// IT LOADS IT HERE
shapeFile = "~/weapons/shapes/weapon_thumper.dts";
image = RifleImage;
mass = 1;
elasticity = 0.2;
friction = 0.6;
pickupRadius = 2;
pickUpName = "a weapon";
emap = true;
};
datablock ShapeBaseImageData(RifleImage)
{
className = WeaponImage;
// BUT IT WON'T LOAD IT HERE :(
shapeFile = "~/weapons/shapes/weapon_thumper.dts";
item = Rifle;
ammo = RifleAmmo;
offset = "0 0 0";
emap = true;
// SNIPPED OUT THE REST OF THE SCRIPT
};
but it's getting the file from the same place? Does anyone know why it loads fine the first time but not the second?? :(
thanks
-Mark
09/05/2001 (4:09 am)
thanks, it was the ; I was missing :)but it still doesn't quite work, I can add a weapon, and that drops in, but I get an error message in my console.
server/weapons/scripts/weapons.cs (0): preload failed for RifleImage: Unable to load shape ~/weapons/shapes/weapon_thumper.dts.
--scripts/weapons.cs--
datablock ItemData(Rifle)
{
className = Weapon;
catagory = "Spawn Items";
// IT LOADS IT HERE
shapeFile = "~/weapons/shapes/weapon_thumper.dts";
image = RifleImage;
mass = 1;
elasticity = 0.2;
friction = 0.6;
pickupRadius = 2;
pickUpName = "a weapon";
emap = true;
};
datablock ShapeBaseImageData(RifleImage)
{
className = WeaponImage;
// BUT IT WON'T LOAD IT HERE :(
shapeFile = "~/weapons/shapes/weapon_thumper.dts";
item = Rifle;
ammo = RifleAmmo;
offset = "0 0 0";
emap = true;
// SNIPPED OUT THE REST OF THE SCRIPT
};
but it's getting the file from the same place? Does anyone know why it loads fine the first time but not the second?? :(
thanks
-Mark
#33
had to change the line of code in
datablock ShapeBaseImageData(RifleImage)
from
shapeFile = "~/weapons/shapes/weapon_thumper.dts";
to
shapeFile = "server/weapons/shapes/weapon_thumper.dts";
apparently the ~ is some linux convention I don't understand, and it was being resolved to "~" instead of "server" like the first example of shpeFile
fixed now, and weapons work - thanks for your help people!
-Mark
09/05/2001 (7:16 am)
D'oh!had to change the line of code in
datablock ShapeBaseImageData(RifleImage)
from
shapeFile = "~/weapons/shapes/weapon_thumper.dts";
to
shapeFile = "server/weapons/shapes/weapon_thumper.dts";
apparently the ~ is some linux convention I don't understand, and it was being resolved to "~" instead of "server" like the first example of shpeFile
fixed now, and weapons work - thanks for your help people!
-Mark
#34
Then you need to invoke the mod with '-mod weapons' on the command line. No one actually came out and said these things all in one place... It took me forever to piece together ... :-)
09/05/2001 (5:28 pm)
Sean Vogt - if you haven't figured it out yet, you put the weapons mod directory inside the examples directory, so that it is at the same level as base, data, client, etc.Then you need to invoke the mod with '-mod weapons' on the command line. No one actually came out and said these things all in one place... It took me forever to piece together ... :-)
#35
How to get the LabRat's weapons mod to load without needing to use the '-mod' command-line switch, and bound to keys:
1. Open example\main.cs
2. Near the top, locate $baseMods = "data;client;server;base"; and change it to $baseMods = "data;client;server;base;weapons"; Save your change.
3. Ensure that the weapons mod directory is in the examples folder, ie. examples\weapons
4. add the following functions and key bindings to examples\client\scripts\default.bind.cs
function spawnDummy(%val)
{
if (%val)
commandToServer('createdummy');
}
function spawnWeapon(%val)
{
if (%val)
commandToServer('addweapon');
}
moveMap.bind(keyboard, d, spawnDummy);
moveMap.bind(keyboard, w, spawnWeapon);
6. launch your game. press d to spawn a dummy and
w to spawn a weapon. Or make up your own bindings. Enjoy !
Regards,
CERDIP
09/05/2001 (6:33 pm)
OK, after all my pleas (mostly answered, thanks guys !) for help in both the closed and open forums, I finally get a chance to give something back:How to get the LabRat's weapons mod to load without needing to use the '-mod' command-line switch, and bound to keys:
1. Open example\main.cs
2. Near the top, locate $baseMods = "data;client;server;base"; and change it to $baseMods = "data;client;server;base;weapons"; Save your change.
3. Ensure that the weapons mod directory is in the examples folder, ie. examples\weapons
4. add the following functions and key bindings to examples\client\scripts\default.bind.cs
function spawnDummy(%val)
{
if (%val)
commandToServer('createdummy');
}
function spawnWeapon(%val)
{
if (%val)
commandToServer('addweapon');
}
moveMap.bind(keyboard, d, spawnDummy);
moveMap.bind(keyboard, w, spawnWeapon);
6. launch your game. press d to spawn a dummy and
w to spawn a weapon. Or make up your own bindings. Enjoy !
Regards,
CERDIP
#36
09/22/2001 (11:44 pm)
EDIT: never mind =)
#37
i didnt realize what the heck the scripts were for, things are starting to fall into place now
I have a question.
how would i get forward and backward movement on the mouse? i have tried this in default bind cs
moveMap.bind( mouse, button3, moveforward );
moveMap.bind( mouse, button2, movebackward );
doesnt work, is there somthing else i need to do (i have nt received my tribes2 yet so i have no optional reference)
the correct lines for the dummy and weapons binds are:
moveMap.bind( keyboard,shift d, spawnDummy);
moveMap.bind( keyboard,shift w spawnWeapon);
now can all
this be done in the engine and compiled so itsnot a mod?
09/25/2001 (9:42 am)
this is a very informitive thread (showed me afew things) altho i am new to this engine, c++ andvc++ , i am no stranger to c programming,batch files, and modsi didnt realize what the heck the scripts were for, things are starting to fall into place now
I have a question.
how would i get forward and backward movement on the mouse? i have tried this in default bind cs
moveMap.bind( mouse, button3, moveforward );
moveMap.bind( mouse, button2, movebackward );
doesnt work, is there somthing else i need to do (i have nt received my tribes2 yet so i have no optional reference)
the correct lines for the dummy and weapons binds are:
moveMap.bind( keyboard,shift d, spawnDummy);
moveMap.bind( keyboard,shift w spawnWeapon);
now can all
this be done in the engine and compiled so itsnot a mod?
#38
%damLoc = %targetObject.getDamageLocation(%position);
Stole that from T2 :)
Dark
09/27/2001 (7:35 pm)
%damLoc isn't defined.%damLoc = %targetObject.getDamageLocation(%position);
Stole that from T2 :)
Dark
#39
I had a go at putting it in the other day, and while the weapon seemed to fire (animations, & shell casings), it didn't actually kill anything. It certainly didn't harm "Bob" the dummybot.
Any help would be appreciated. =]
Thanks,
Craig.
10/23/2001 (7:18 am)
Has anybody been able to get this mod to work, post Release 1.1b (the new cvs tag release)?I had a go at putting it in the other day, and while the weapon seemed to fire (animations, & shell casings), it didn't actually kill anything. It certainly didn't harm "Bob" the dummybot.
Any help would be appreciated. =]
Thanks,
Craig.
Torque Owner Matthew Shapiro