Weapon with no ammo
by Mike Daly · in Torque Game Engine Advanced · 11/13/2007 (12:48 am) · 12 replies
I am making a boomerang (i.e., a projectile weapon that uses no ammo) and I am having trouble getting the boomerang's onFire function called. My image datablock is:
And the onFire is:
All I need right now is to get THROW echoed to the console so I know the function is being called. I've defined:
Everything else is exactly the same as the crossbow yet it never seems to get to the onFire function. Any help would be greatly appreciated.
datablock ShapeBaseImageData(boomImage)//image for boomerang
{
shapeFile = "~/data/shapes/Boomerang/boomerang.dts";
emap = true;
mountPoint = 2;
firstPerson = false;
className = "WeaponImage";
item = boomerang;
projectile = boomProjectile;
projectileType = Projectile;
stateName[0] = "Pre-throw";
stateTransitionOnLoaded[0] = "Ready";
//stateTransitionOnNoAmmo[0] = "Ready";
stateName[1] = "Ready";
stateTransitionOnTriggerDown[1] = "Throw";
stateName[2] = "Throw";
stateScript[2] = "onFire";
stateTransitionOnTimeout[2] = "Ready";
};And the onFire is:
unction boomImage::onFire(%this, %obj, %slot)
{
echo("THROW");
%projectile = %this.projectile;
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}All I need right now is to get THROW echoed to the console so I know the function is being called. I've defined:
maxInv[boomerang] = 1; maxInv[boomAmmo] = 1;
Everything else is exactly the same as the crossbow yet it never seems to get to the onFire function. Any help would be greatly appreciated.
#2
11/13/2007 (1:20 am)
Searched my code meanwhile. You would need there something like this:%player.incInventory(boom, 1); %player.incInventory(boomAmmo, boomAmmo.maxInventory); %player.use(boomerang);
#3
I have the "use" command mapped to the 2 key-is that what you mean by use(boomerang)?
11/13/2007 (11:14 am)
No, but I don't see anything like that for the crossbow either. It has:%player.setInventory(Crossbow,1); %player.setInventory(CrossbowAmmo,10); %player.mountImage(CrossbowImage,0);
I have the "use" command mapped to the 2 key-is that what you mean by use(boomerang)?
#4
11/13/2007 (11:21 am)
Yeah, in the client/scripts/default.bind.cs there's the weapon "button" number. But if you assigned the 2 key to the boomerang, then you're fine. Would you posting a bit more code, it's hard to tell now where you error is. Useful would be the game.cs createPlayer function as well as the complete boomerang weapon script.
#5
The boomerang image, onFire, and projectile scripts:
11/13/2007 (11:51 am)
CreatePlayer:function GameConnection::createPlayer(%this, %spawnPoint)
{
if (%this.player > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
}
// Create the player object
%player = new Player() {
dataBlock = PlayerBody;
client = %this;
};
MissionCleanup.add(%player);
// Player setup...
%player.setTransform(%spawnPoint);
%player.setShapeName(%this.name);
// Starting equipment
%player.setInventory(Crossbow,1);
%player.setInventory(CrossbowAmmo,10);
%player.mountImage(CrossbowImage,1);
//add the weed wacker by default-need to get this to become a pick-uppable item
%player.setInventory(boomerang,1);
%player.mountImage(boomImage,2);
// Update the camera to start with the player
%this.camera.setTransform(%player.getEyeTransform());
// Give the client control of the player
%this.player = %player;
%this.setControlObject(%player);
}The boomerang image, onFire, and projectile scripts:
datablock ShapeBaseImageData(boomImage)//image for boomerang
{
shapeFile = "~/data/shapes/Boomerang/boomerang.dts";
emap = true;
mountPoint = 2;
firstPerson = false;
className = "WeaponImage";
item = boomerang;
projectile = boomProjectile;
projectileType = Projectile;
stateName[0] = "Pre-throw";
stateTransitionOnLoaded[0] = "Ready";
stateName[1] = "Ready";
stateTransitionOnTriggerDown[1] = "Throw";
stateName[2] = "Throw";
stateScript[2] = "onFire";
stateTransitionOnTimeout[2] = "Ready";
};
function boomImage::onFire(%this, %obj, %slot)
{
echo("THROW");
%projectile = %this.projectile;
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}
datablock ProjectileData(boomProjectile)
{
projectileShapeName = "~/data/shapes/Boomerang/boomerang.dts";
directDamage = 10;
radiusDamage = 0;
damageRadius = 1;
//explosion = pistolExplosion;
//particleEmitter = pistolBoltEmitter;
muzzleVelocity = 700;
velInheritFactor = 0.3;
armingDelay = 0;
lifetime = 5000;
fadeDelay = 5000;
bounceElasticity = 0;
bounceFriction = 0;
isBallistic = false;
gravityMod = 0.00;
hasLight = false;
lightRadius = 1;
//lightColor = "0.5 0.5 0.25";
hasWaterLight = false;
//waterLightColor = "0 0.5 0.5";
};
#6
Questions:
1) Do you have any error in the console?
2) Have you tried putting in the line "%player.incInventory(boomAmmo, boomAmmo.maxInventory);"?
3) Go into server/scripts/weapon.cs and put in at the beginning this one here (bold):
4) Can you post the definition of "boomerang"?
11/13/2007 (12:02 pm)
Hmm, hard to tell using remote debugging (tm) :-)Questions:
1) Do you have any error in the console?
2) Have you tried putting in the line "%player.incInventory(boomAmmo, boomAmmo.maxInventory);"?
3) Go into server/scripts/weapon.cs and put in at the beginning this one here (bold):
function Weapon::onUse(%data,%obj)
{
[b]error("Weapon->onUse called: %data: " @ %data SPC " obj: " @ %obj);[/b]
...to see if it gets called when you press the 2 key for activating the boomerang?4) Can you post the definition of "boomerang"?
#7
2) No changes.
3) It outputs "Weapon->onUse called: %data: boomerang obj: 1766"
4) Do you mean the item data? If so, it's below. If not, what do you mean?
Thank you for your help so far.
11/13/2007 (12:18 pm)
1) No, no errors.2) No changes.
3) It outputs "Weapon->onUse called: %data: boomerang obj: 1766"
4) Do you mean the item data? If so, it's below. If not, what do you mean?
datablock ItemData(boomerang)
{
// Mission editor category
category = "Weapon";
className = "Weapon";
// Basic Item properties
shapeFile = "~/data/shapes/Boomerang/boomerang.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;
rotate = true;
// Dynamic properties defined by the scripts
pickUpName = "a boomerang";
image = boomImage;
};Thank you for your help so far.
#8
Hmm, damn hard. Ok, one next thing please. Put in the bold line in weapon.cs:
Is it getting called in the console output?
11/13/2007 (12:27 pm)
Yes, I meant the item data, thanks. :-)Hmm, damn hard. Ok, one next thing please. Put in the bold line in weapon.cs:
function Weapon::onUse(%data,%obj)
{
// Default behavoir for all weapons is to mount it into the
// this object's weapon slot, which is currently assumed
// to be slot 0
if (%obj.getMountedImage($WeaponSlot) != %data.image.getId()) {
[b]error("Mounting weapon " @ %data.image);[/b]
serverPlay3D(WeaponUseSound,%obj.getTransform());
%obj.mountImage(%data.image, $WeaponSlot);
if (%obj.client)
messageClient(%obj.client, 'MsgWeaponUsed', '\c0Weapon selected');
}
}Is it getting called in the console output?
#9
Try changing
mountPoint = 2;
to
mountPoint = 0;
and see if it works.
11/13/2007 (12:33 pm)
Hah! I think I know the bug! In your image data block the mount point is 2, not 0 like in the crossbow!Try changing
mountPoint = 2;
to
mountPoint = 0;
and see if it works.
#10
11/13/2007 (12:36 pm)
No changes. And FYI, 2 is the correct mountPoint for my character, so that isn't the problem.
#11
which should be:
So it wasn't the mount POINT, but the mount SLOT that was the problem. Thanks for pointing me in the right direction :)
11/14/2007 (9:24 am)
Found the problem-I had:%col.mountImage(boomImage,2);
which should be:
%col.mountImage(boomImage,0);
So it wasn't the mount POINT, but the mount SLOT that was the problem. Thanks for pointing me in the right direction :)
#12
11/14/2007 (9:46 am)
Haha, great, glad you got it working! :-)
Torque Owner Martin Schultz