Author Topic: When a bot is killed...  (Read 1060 times)

Can someone give me the function for detecting a bot death? I need it really badly.

EDIT: I need both when the bot is killed by another player, and when the bot just Self Deletes or something like that.
« Last Edit: November 24, 2009, 04:28:47 PM by Club559 »

armor::onDisabled(%datablock, %object)

You'll have to check if %object is a bot, though.

Would that be checking if it was an AIPlayer? I don't know the datablock of a bot.

Would that be checking if it was an AIPlayer? I don't know the datablock of a bot.
PlayerStandardArmor
...I think.

Bots can use any datablock a player can. Use this to check if the object is a bot:
if(%obj.getClassName() $= "AIPlayer")

How do you detect the spawn that the bot was made on?
« Last Edit: November 24, 2009, 06:45:40 PM by Club559 »

How do you detect the spawn that the bot was made on?
Check the content mod thing, it has if the vehicle is caught the vehicle gets respawned by the spawn.

Usually it will be %object.spawnBrick but some bots don't have this variable so you should make sure the spawnbrick exists before doing anything with it.

This code is seriously failing.

Code: [Select]
package TehFail
{
function armor::onDisabled(%datablock, %object)
{
if(%obj.getClassName() $= "AIPlayer" || %obj.getClassName() $= "WheeledVehicle")
{
if(%obj.isBeingControlled == 1)
{
if(!%object.spawnBrick)
{
%client = %object.client;
%this = %object.spawnBrick;
if(!%client.mainP)
{
messageClient(%client,'',"Error: \c6Not in control of a bot.");
}
else
{
%clientz = %this.controller;
%clientz.player = %clientz.mainP;
%clientz.setControlObject(%clientz.mainP);
%clientz.mainP = 0;
%this.vehicle.isBeingControlled = 0;
%this.onVehicleExitControl(%clientz);
%this.vehicle.client = findClientByBL_ID(getBrickGroupFromObject(%this).bl_id);
%this.controller = 0;
}
}
else
{
%clientz = %object.client;
%clientz.player = %clientz.mainP;
%clientz.setControlObject(%clientz.mainP);
%clientz.mainP = 0;
messageClient(%client,'',"Error: \c6The bot spawn got deleted while you were controlling it.");
}
}
}
Parent::onDisabled(%datablock, %object);
}
};

What's wrong with this?

A: You're using %obj in some places and %object in others.
B: You're not activating the package (if you are you, left that line out).
C: You should change if(!%object.spawnBrick) to if(isObject(%object.spawnBrick)) as the spawnbrick could be deleted, but the variable would stay on the bot (although the bot would probably be deleted).

You may want to use %obj.getControllingClient() instead of a variable since you wouldn't need to use a variable to keep track of who's controlling the bot.

%obj.getControllingClient()

Oh crap. That would've been useful. T_T
Ok thanks. Now, only one problem left. The corpses always stay visible.

The corpses always stay visible.
Make sure that the variables in the parent line are correct.

Make sure that the variables in the parent line are correct.

Function in package:
Code: [Select]
armor::onDisabled(%datablock, %object)
Calling the parent:
Code: [Select]
Parent::onDisabled(%datablock, %object);
I dont see anything wrong there.

%object
%object

%datablock
%datablock

Compared. Nothing is wrong.

The parent might need to be returned.