Strangle random error with bots and projectiles
by Artur Hallmann · in Technical Issues · 09/05/2005 (2:32 pm) · 4 replies
Hi!
I've set up my FPS game with AI Bots using pathfinding (based on the AI Guard resource).
But now i've got a strange random error.
I changed GameConnection::onDeath() to look like this:
----------------------------------------------------------------------------------------------
function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{
//reset AmmoAmountHud
%this.setAmmoAmountHud("100");
// Clear out the name on the corpse
%this.player.setShapeName("");
// Switch the client over to the death cam and unhook the player object.
if (isObject(%this.camera) && isObject(%this.player)) {
%this.camera.setMode("Corpse",%this.player);
%this.setControlObject(%this.camera);
}
%this.player = 0;
// Doll out points and display an appropriate message
if(%damageType $= "Suicide" || %sourceClient == %this)
{
%this.incScore(-1);
messageAll('MsgClientKilled','%1 takes his own life!',%this.name);
}
else
{
if(!%sourceClient) // If no source client, chances are it's a bot
{
%bot = %sourceObject.sourceObject;
if(%bot == 0 ) // big problem!! <------ HERE!!!!!!!!!!!!!!!1
{
error("bot = 0 (bot killed player)");
error("sourceObject = " @ %sourceObject);
}
else
%bot.incScore(1);
messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%bot.botname);
if(%bot.score >= $Game::EndGameScore && $Game::EndGameScore)
cycleGame();
}
else
{
%sourceClient.incScore(1);
messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%sourceClient.name);
if(%sourceClient.score >= $Game::EndGameScore && $Game::EndGameScore)
cycleGame();
}
}
}
-----------------------------------------------------------------------------------------------------
look where the HERE comment is. The problem is, that in about 50% of the bot kills, the projectile (%sourceObject) does not include the reference to the bot who shot it.
I think this is REALLY strange, any idea on how to fix it, or where to search for the error? for reference, here is my projectile shooting function
-----------------------------------------------------------------------------------------------------
function m4a1Image::onFire(%this, %obj, %slot)
{
%projectile = %this.projectile;
// Decrement inventory ammo. The image's ammo state is update
// automatically by the ammo inventory hooks.
%obj.decInventory(%this.ammo,1);
%currentAmmo = %obj.getInventory(%this.ammo);
if(%obj.client)
%obj.client.setAmmoAmountHud(%currentAmmo);
// Determin initial projectile velocity based on the
// gun's muzzle point and the object's current velocity
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));
// Create the projectile object
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}
-----------------------------------------------------------------------------------------------------
Could the problem maybe have to do with my projectiles have no shape, but only beeing particles?
I've set up my FPS game with AI Bots using pathfinding (based on the AI Guard resource).
But now i've got a strange random error.
I changed GameConnection::onDeath() to look like this:
----------------------------------------------------------------------------------------------
function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{
//reset AmmoAmountHud
%this.setAmmoAmountHud("100");
// Clear out the name on the corpse
%this.player.setShapeName("");
// Switch the client over to the death cam and unhook the player object.
if (isObject(%this.camera) && isObject(%this.player)) {
%this.camera.setMode("Corpse",%this.player);
%this.setControlObject(%this.camera);
}
%this.player = 0;
// Doll out points and display an appropriate message
if(%damageType $= "Suicide" || %sourceClient == %this)
{
%this.incScore(-1);
messageAll('MsgClientKilled','%1 takes his own life!',%this.name);
}
else
{
if(!%sourceClient) // If no source client, chances are it's a bot
{
%bot = %sourceObject.sourceObject;
if(%bot == 0 ) // big problem!! <------ HERE!!!!!!!!!!!!!!!1
{
error("bot = 0 (bot killed player)");
error("sourceObject = " @ %sourceObject);
}
else
%bot.incScore(1);
messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%bot.botname);
if(%bot.score >= $Game::EndGameScore && $Game::EndGameScore)
cycleGame();
}
else
{
%sourceClient.incScore(1);
messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%sourceClient.name);
if(%sourceClient.score >= $Game::EndGameScore && $Game::EndGameScore)
cycleGame();
}
}
}
-----------------------------------------------------------------------------------------------------
look where the HERE comment is. The problem is, that in about 50% of the bot kills, the projectile (%sourceObject) does not include the reference to the bot who shot it.
I think this is REALLY strange, any idea on how to fix it, or where to search for the error? for reference, here is my projectile shooting function
-----------------------------------------------------------------------------------------------------
function m4a1Image::onFire(%this, %obj, %slot)
{
%projectile = %this.projectile;
// Decrement inventory ammo. The image's ammo state is update
// automatically by the ammo inventory hooks.
%obj.decInventory(%this.ammo,1);
%currentAmmo = %obj.getInventory(%this.ammo);
if(%obj.client)
%obj.client.setAmmoAmountHud(%currentAmmo);
// Determin initial projectile velocity based on the
// gun's muzzle point and the object's current velocity
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));
// Create the projectile object
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}
-----------------------------------------------------------------------------------------------------
Could the problem maybe have to do with my projectiles have no shape, but only beeing particles?
About the author
#2
i just looked into projectile.cc and in processTick, i found:
if(mSourceObject && mCurrTick > SourceIdTimeoutTicks)
{
mSourceObject = 0;
mSourceObjectId = 0;
}
shit :P
09/05/2005 (3:06 pm)
Lol...i just looked into projectile.cc and in processTick, i found:
if(mSourceObject && mCurrTick > SourceIdTimeoutTicks)
{
mSourceObject = 0;
mSourceObjectId = 0;
}
shit :P
#3
Edit: Oh, I see you already found it. :)
09/05/2005 (4:00 pm)
I had this problem before. It is because after a certain number of ticks the server removes the sourceobjectid from the updates. Once you change that it should work fine.Edit: Oh, I see you already found it. :)
#4
09/05/2005 (5:17 pm)
Yeah, i don't see the point in it, because if you don't check this in the projectile collision function, the projectiles will still kill, but nobody will know who it was... maybe for secret snipers? ;-)
Torque Owner Artur Hallmann
if(!%obj.sourceObject)
return ;
so the shots will not create damage, when the sourceObject ( the bot shooting ) is not set...
and now i see when this problem occurs: when the bot shoots from far away. its like the bot comes to me, and when he is far away, the projectiles are not doing damage, when he comes nearer I die... well... but thats not how i want it ^^ the weapon should have a far range...
Does anyone have a clue why this could happen???