Problem with score system
by To-mos · in Torque Game Engine · 04/20/2011 (7:48 pm) · 9 replies
Hello everyone I am having problems with the scoring system...It seems when I kill a player it says they took their own life. Ive looked into the player.cs file and it seams that %sourceObject.client and %sourceObject are empty every time the player is shot so %sourceClient = %sourceObject ? %sourceObject.client : 0; is returning 0 every time. What is going on?
About the author
#2
04/21/2011 (1:04 pm)
Oh I see, It should become a little resource for people to reference, you know.
#3
08/19/2011 (9:06 pm)
Since I'm getting a bit better at this scripting thing any chance you could cook up some example code?
#4
Just comment that out, and the sourceObject information shouldn't be deleted.
08/20/2011 (10:44 am)
In projectile.cc, search for this bit of code near the top of ::processTickif(mSourceObject && mCurrTick > SourceIdTimeoutTicks)
{
mSourceObject = 0;
mSourceObjectId = 0;
}Just comment that out, and the sourceObject information shouldn't be deleted.
#5
08/20/2011 (10:58 am)
That shouldn't create the problem that it was implemented for? Like having the projectile explode in my face?
#6
08/20/2011 (11:07 am)
Nope. When the projectile is created, it ignores the sourceObject anyway (to my understanding). That block of code that I posted deletes the source object info after it hits something, I'm not sure why. I've had that disabled for a long time without any issues.
#7
08/20/2011 (11:39 am)
Alright sounds like a plan, thanks a bunch.
#8
You'll see that the first argument of the damage and radiusDamage calls, which specifies the shooter (sourceObject), is %obj. The issue with that is %obj in that context refers to the projectile object, not the shooter.
For everything to be hooked up properly, you'll need to change those arguments to %obj.sourceObject:
That'll do it. Now, when a player is killed by projectile damage, the sourceObject is properly handed off to Armor::damage() in player.cs. The client object is determined, GameConnection::onDeath() is called, and the scoring happens as it should.
08/21/2011 (12:30 am)
There's also another issue that needs a'fixin. Have a look at your projectile ::onCollision methods:function CrossbowProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"CrossbowBolt");
// Radius damage is a support scripts defined in radiusDamage.cs
// Push the contact point away from the contact surface slightly
// along the contact normal to derive the explosion center. -dbs
radiusDamage(%obj, %pos, %this.damageRadius, %this.radiusDamage, "Radius", %this.areaImpulse);
}You'll see that the first argument of the damage and radiusDamage calls, which specifies the shooter (sourceObject), is %obj. The issue with that is %obj in that context refers to the projectile object, not the shooter.
For everything to be hooked up properly, you'll need to change those arguments to %obj.sourceObject:
function CrossbowProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj.sourceObject,%pos,%this.directDamage,"CrossbowBolt");
// Radius damage is a support scripts defined in radiusDamage.cs
// Push the contact point away from the contact surface slightly
// along the contact normal to derive the explosion center. -dbs
radiusDamage(%obj.sourceObject, %pos, %this.damageRadius, %this.radiusDamage, "Radius", %this.areaImpulse);
}That'll do it. Now, when a player is killed by projectile damage, the sourceObject is properly handed off to Armor::damage() in player.cs. The client object is determined, GameConnection::onDeath() is called, and the scoring happens as it should.
#9
This removes the pointer mSourceObject, but retains the ID number mSourceObjectId, which is the one that scripts can access. If I remember correctly.
Removing all that stuff entirely will mean that mSourceObject will never be struck by that projectile. Depending on your game, this may be fine.
08/23/2011 (1:05 am)
Alternatively, just do this://
if(mSourceObject && mCurrTick > SourceIdTimeoutTicks)
{
mSourceObject = 0;
//mSourceObjectId = 0;
}This removes the pointer mSourceObject, but retains the ID number mSourceObjectId, which is the one that scripts can access. If I remember correctly.
Removing all that stuff entirely will mean that mSourceObject will never be struck by that projectile. Depending on your game, this may be fine.
Associate Michael Hall
Big Kid Games
A way to work around this is to substitute a new dynamic property when you spawn a projectile, and reference this new property in the damage and projectile callbacks instead of the self-deleting ones.
Granted this should have been fixed long before now, but it is such a simple thing...