Basic Dual Weilding
by Scooby Brown · 04/17/2005 (7:36 pm) · 15 comments
ever wanted to at least get simple dual weilding into your game, well now you can!
this was very easy to implement. started it after reading this thread www.garagegames.com/mg/forums/result.thread.php?qt=23585
this resource only has limited functionality so any feedback and help code will be apreciated.
for now you can only dual weild when you spawn.
well now we shall get to business.
1. open your weapon.cs and add this line under $WeaponSlot
i perfer to do it like this because it keeps my code clean.
2. open your client/config.cs file and add this to the end:
also open your client/default.bind.cs file and add this to the end:
this maps your right mouse button to fire the left gun.
EDIT: I think i have created a different way to mount on contact. This will replace step 3. Open your weapon.cs and change from this:
to
go to the weapon datablock and add a dualImage
now open your weapon you want to dual weild and copy your ShapeBaseImage and rename it( I perfer to put "Dual" at the end).
now you should have two image datablocks. the image and the dualImage. make shure you also change the mount point and offset. when you pickup a second weapon it should auto dual.
ps i havent had time to test yet.
/EDIT
4. open your game.cs and add the following lines to gameConnection::createPlayer
5 start your game and try it out
ps: this is my first resource so if it sounds confusing just post here and i will change it.
i am also constantly updating this resorce so it can have the maximum nuber of features possible.
this was very easy to implement. started it after reading this thread www.garagegames.com/mg/forums/result.thread.php?qt=23585
this resource only has limited functionality so any feedback and help code will be apreciated.
for now you can only dual weild when you spawn.
well now we shall get to business.
1. open your weapon.cs and add this line under $WeaponSlot
$DualWeaponSlot = 1
i perfer to do it like this because it keeps my code clean.
2. open your client/config.cs file and add this to the end:
movemap.bind (mouse0, "button1", altTrigger);
also open your client/default.bind.cs file and add this to the end:
movemap.bind (mouse0, "button1", altTrigger);
this maps your right mouse button to fire the left gun.
EDIT: I think i have created a different way to mount on contact. This will replace step 3. Open your weapon.cs and change from this:
function Weapon::onPickup(%this, %obj, %shape, %amount)
{
// The parent Item method performs the actual pickup.
// For player's we automatically use the weapon if the
// player does not already have one in hand.
if (Parent::onPickup(%this, %obj, %shape, %amount)) {
serverPlay3D(WeaponPickupSound,%obj.getTransform());
if (%shape.getClassName() $= "Player" &&
%shape.getMountedImage($WeaponSlot) == 0) {
%shape.use(%this);
}
}
}to
function Weapon::onPickup(%this, %obj, %shape, %amount)
{
// The parent Item method performs the actual pickup.
// For player's we automatically use the weapon if the
// player does not already have one in hand.
if (Parent::onPickup(%this, %obj, %shape, %amount)) {
serverPlay3D(WeaponPickupSound,%obj.getTransform());
if (%shape.getClassName() $= "Player" &&
%shape.getMountedImage($WeaponSlot) == 0) {
%shape.use(%this);
}
if (%shape.getClassName() $= "Player" &&
%shape.getMountedImage($WeaponSlot) == 1 &&
%shape.getMountedImage($DualWeaponSlot) == 0) {
%shape.mountImage(%this.dualImage, $DualWeaponSlot);
}
if (%shape.getClassName() $= "Player" &&
%shape.getMountedImage($WeaponSlot) == 1 &&
%shape.getMountedImage($DualWeaponSlot) == 1) {
%shape.throw(%obj.dualImage, 1);
%shape.mountImage(%this.dualImage, $DualWeaponSlot);
}
}go to the weapon datablock and add a dualImage
datablock ItemData(Crossbow)
{
// Mission editor category
category = "Weapon";
// Hook into Item Weapon class hierarchy. The weapon namespace
// provides common weapon handling functions in addition to hooks
// into the inventory system.
className = "Weapon";
// Basic Item properties
shapeFile = "~/data/shapes/crossbow/weapon.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;
// Dynamic properties defined by the scripts
pickUpName = "a crossbow";
image = CrossbowImage;
[b]dualImage = DualCrossbowImage;[/b]
};now open your weapon you want to dual weild and copy your ShapeBaseImage and rename it( I perfer to put "Dual" at the end).
//////////////////////////////////////////////////////////////////////////////////////
////
//// Dual image for dual weilding
////
//////////////////////////////////////////////////////////////////////////////////////
datablock ShapeBaseImageData(DualCrossbowImage)
{
// Basic Item properties
shapeFile = "~/data/shapes/crossbow/weapon.dts";
emap = true;
// Specify mount point & offset for 3rd person, and eye offset
// for first person rendering.
mountPoint = 1;
eyeOffset = "-0.1 0.4 -0.6";
// When firing from a point offset from the eye, muzzle correction
// will adjust the muzzle vector to point to the eye LOS point.
// Since this weapon doesn't actually fire from the muzzle point,
// we need to turn this off.
correctMuzzleVector = false;
// Add the WeaponImage namespace as a parent, WeaponImage namespace
// provides some hooks into the inventory system.
className = "WeaponImage";
// Projectile && Ammo.
item = Crossbow;
ammo = CrossbowAmmo;
projectile = CrossbowProjectile;
projectileType = Projectile;
// Images have a state system which controls how the animations
// are run, which sounds are played, script callbacks, etc. This
// state system is downloaded to the client so that clients can
// predict state changes and animate accordingly. The following
// system supports basic ready->fire->reload transitions as
// well as a no-ammo->dryfire idle state.
// Initial start up state
stateName[0] = "Preactivate";
stateTransitionOnLoaded[0] = "Activate";
stateTransitionOnNoAmmo[0] = "NoAmmo";
// Activating the gun. Called when the weapon is first
// mounted and there is ammo.
stateName[1] = "Activate";
stateTransitionOnTimeout[1] = "Ready";
stateTimeoutValue[1] = 0.6;
stateSequence[1] = "Activate";
// Ready to fire, just waiting for the trigger
stateName[2] = "Ready";
stateTransitionOnNoAmmo[2] = "NoAmmo";
stateTransitionOnTriggerDown[2] = "Fire";
// Fire the weapon. Calls the fire script which does
// the actual work.
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Reload";
stateTimeoutValue[3] = 0.2;
stateFire[3] = true;
stateRecoil[3] = LightRecoil;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
stateSound[3] = CrossbowFireSound;
// Play the relead animation, and transition into
stateName[4] = "Reload";
stateTransitionOnNoAmmo[4] = "NoAmmo";
stateTransitionOnTimeout[4] = "Ready";
stateTimeoutValue[4] = 0.8;
stateAllowImageChange[4] = false;
stateSequence[4] = "Reload";
stateEjectShell[4] = true;
stateSound[4] = CrossbowReloadSound;
// No ammo in the weapon, just idle until something
// shows up. Play the dry fire sound if the trigger is
// pulled.
stateName[5] = "NoAmmo";
stateTransitionOnAmmo[5] = "Reload";
stateSequence[5] = "NoAmmo";
stateTransitionOnTriggerDown[5] = "DryFire";
// No ammo dry fire
stateName[6] = "DryFire";
stateTimeoutValue[6] = 1.0;
stateTransitionOnTimeout[6] = "NoAmmo";
stateSound[6] = CrossbowFireEmptySound;
};now you should have two image datablocks. the image and the dualImage. make shure you also change the mount point and offset. when you pickup a second weapon it should auto dual.
ps i havent had time to test yet.
/EDIT
4. open your game.cs and add the following lines to gameConnection::createPlayer
%player.setInventory(yourweapon, 1);
%player.setInventory(yourweaponAmmo, 100);
%player.mountImage(yourweapon, $WeaponSlot);
%player.setInventory(yoursecondweapon, 1);
%player.setInventory(yoursecondweaponAmmo, 100);
%player.mountImage(yoursecondweapon, $DualWeaponSlot);5 start your game and try it out
ps: this is my first resource so if it sounds confusing just post here and i will change it.
i am also constantly updating this resorce so it can have the maximum nuber of features possible.
About the author
#2
04/18/2005 (9:44 am)
Nice resource. I'll have to try it out.
#3
rather than config.cs
To get the changes to take effect you must delete both client/config.cs and client/config.cs.dso
(note: If you have added other keybindings into config.cs you should move those changes into
default.bind.cs BEFORE deleting config.cs...obviously)
04/18/2005 (2:20 pm)
I think it would be better to put that moveMap entry into the default.bind.cs filerather than config.cs
To get the changes to take effect you must delete both client/config.cs and client/config.cs.dso
(note: If you have added other keybindings into config.cs you should move those changes into
default.bind.cs BEFORE deleting config.cs...obviously)
#4
Edit @firas unless I'm mistaken button1 is the right mouse button which is not the normal firing button so you would fire one weapon with the right and one with the left. Darn theres not enough buttons on the mouse were well my special moves go? I've wondered if it would be akward pressing both mouse buttons in dual wielding I don't think anyones done it so far time to find out.
04/18/2005 (4:33 pm)
awesome dual rocket launchers ahoy ;) I'll implement it after I redownload my seriouly screwed up torque SDK.Edit @firas unless I'm mistaken button1 is the right mouse button which is not the normal firing button so you would fire one weapon with the right and one with the left. Darn theres not enough buttons on the mouse were well my special moves go? I've wondered if it would be akward pressing both mouse buttons in dual wielding I don't think anyones done it so far time to find out.
#5
04/18/2005 (8:15 pm)
I think you may need to create a left arm recoil animation for that particular weapon's State to get it to look proper, not too sure. There are only few hard coded recoil animations for the player's armThread to run. It may mean giving up another weapon's slot for the dual weapons, not too sure on that either...looks good; just need another mountpoint on the left hand. I wonder if the left hand Node could be used instead of a mountPoint?? That may make it easier for a default player. Might need some node axis rotations and offset to get it just right, or art in another Node.. Good luck.
#6
edit: if you want more information ask
04/19/2005 (5:26 pm)
you actually don't need to copy an entire new script for the left handed weapon. you just need to make a left weapon and tell it to use the normal crossbow projectile and ammo.edit: if you want more information ask
#7
havent been able to test it yet so please bear with me:)
04/24/2005 (7:09 am)
i changed the resource. havent updated or checked recently sorry. not sure if ti will work but i have created a method of picking up the left weapon if the right one is mounted.havent been able to test it yet so please bear with me:)
#8
edit: doesn't work :P
doesn't like the W in Weapon::oninventory the function below the one changed. I'm looking for a solution.
04/26/2005 (2:54 pm)
ok I can maybe help testedit: doesn't work :P
doesn't like the W in Weapon::oninventory the function below the one changed. I'm looking for a solution.
#9
05/01/2005 (11:43 pm)
@Treb: It sounds (although I have no way to tell for certain) that you may have forgotten a semi-colon or a terminating brace in the function you changed, causing the next one down to exhibit odd syntax errors.
#10
05/02/2005 (4:27 pm)
okay yeah it was the braces the weapon on pickup script is missing one though it still doesn't work (on my pottentialy glitched up version of torque)
#11
yes i know there is a problem but i cant figure it out.
i fixed the braces but no help. im looking into it but it may take awhile.
05/27/2005 (11:56 am)
sorry about the delay.yes i know there is a problem but i cant figure it out.
i fixed the braces but no help. im looking into it but it may take awhile.
#12
09/28/2005 (3:22 pm)
yeah I have a weapon pick up model that should work well in helping this get back on its feet I'll try again today.
#13
09/28/2005 (4:17 pm)
I got dual wielding in just give me a day to work out the kinks and I'll post a new resource thanks Hugh I used a lot of your basic Ideas to get it going.
#14
01/11/2007 (7:43 am)
guys. in the $DualWeaponSlot in the beginning of what you have to add code needs the ";"
#15
08/06/2007 (8:29 am)
I have $DualWeaponSlot = 1; in mine but it still does not work
Torque Owner Firas
but I have a question, I think this code will fire from the 2 weapons at the same time
for ex: I have 2 guns so when I click on the mouse it will shoot from both guns.
but how can I make them shoot one after one like: click on the mouse the right gun is shoot then click agine and the left gun is shoot?