View Full Version : Getting the actor type?
salmo
12-22-2011, 09:49 AM
This is probably very obvious, but I just can't seem to crack it. I'm trying to get the actor type when the actor is destroyed ie ship, car, plane etc. here's what I tried
code removed by author
41Sqn_Banks
12-22-2011, 10:07 AM
If you want to observer the individual ground actors use this:
public override void OnActorDestroyed(int missionNumber, string shortName, maddox.game.world.AiActor actor)
{
if (actor is AiGroundActor)
{
AiGroundActor groundActor = actor as AiGroundActor;
if (groundActor.Type() == AiGroundActorType.ShipTransport /* || groundActor.Type() == AiGroundActorType.ShipDestroyer || ... */)
{
GamePlay.gpHUDLogCenter("Ship destroyed");
}
}
}
If you are interested in the complete ground group (e.g. a column or tank group) use this:
public override void OnActorDestroyed(int missionNumber, string shortName, maddox.game.world.AiActor actor)
{
if (actor is AiGroundGroup)
{
AiGroundGroup groundGroup = actor as AiGroundGroup;
if (groundGroup.GroupType() == AiGroundGroupType.Ship)
{
GamePlay.gpHUDLogCenter("Ship destroyed");
}
}
}
salmo
12-22-2011, 10:07 AM
Thanks Banks :)
Octocat
12-22-2011, 11:25 AM
Something like this:
if (actor != null)
{
if (actor is AiAirGroup)
{
var airgrp = (AiAirGroup)actor;
// processing air group
}
else if (actor is AiAircraft)
{
var aircft = (AiAircaft)actor;
// processing aircraft
}
else
{
LogMessage("Destroyed unknown actor type: {0}", actor.GetType().Name);
}
}
Real problem for me, is in ActorDead handler, to separate between actor killed / disapeared events. Has someone solution? :cool:
pupo162
05-27-2012, 10:36 AM
here comes pupo ressutecting the dead again.
As anyoen foudn a solution for what Octocat was asking?
i need to creat an exception for the actor destroyd, so that planes who are reflown dont count as destroyed.
FG28_Kodiak
05-27-2012, 01:14 PM
All disapearing Actors are registered in
OnActorDestroyed(..)
If this was the Question.
pupo162
05-27-2012, 02:03 PM
No kodiak.
in my code i give points to teams on a plane his destroyed. yet the game also uses destroy to get rid of planes. so if i refly, the plane i refly gets caught by onactordestryed, and a kill is given to the enemy.
is there a way to avoid this?
FG28_Kodiak
05-27-2012, 02:37 PM
You can use two events:
public override void OnAircraftKilled(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftKilled(missionNumber, shortName, aircraft);
}
and
public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
{
base.OnActorDead(missionNumber, shortName, actor, damages);
}
On OnAircraftKilled is called when a plane is not longer flyable, for example if the pilot get killed or its too heavy damaged, but you get not the damager.
OnActorDead is called later after a plane is hitting the ground or a GroundActor or AiPerson or AiGroup (a Ships is an AiGroup) is killed. And you can check the damagers.
OnActorDestroyed is called every time a Actor is removed from the game, so its also called if a script removed a empty plane. So you should use OnAircraftKilled or OnActorDead.
pupo162
05-27-2012, 03:57 PM
You can use two events:
public override void OnAircraftKilled(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftKilled(missionNumber, shortName, aircraft);
}
and
public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
{
base.OnActorDead(missionNumber, shortName, actor, damages);
}
On OnAircraftKilled is called when a plane is not longer flyable, for example if the pilot get killed or its too heavy damaged, but you get not the damager.
OnActorDead is called later after a plane is hitting the ground or a GroundActor or AiPerson or AiGroup (a Ships is an AiGroup) is killed. And you can check the damagers.
OnActorDestroyed is called every time a Actor is removed from the game, so its also called if a script removed a empty plane. So you should use OnAircraftKilled or OnActorDead.
thanks! that puts some light on waht each one does. i started by using onactordead, but its giving some issues with exception errors, so im tryign on aircraft killed, still not workin.... yet.
Also, since you are here ( :P ), im havign were a damaged plane, when landed is not destroyed.
code here
public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftLanded(missionNumber, shortName, aircraft);
Player player = null;
int value = 0;
if (aircraft.Player(0) != null)
{
for (int i = 0; i < aircraft.Places(); i++)
{
if (aircraft.Player(i) != null)
{
// TODO: Account for more than one player in an aircraft
player = aircraft.Player(i);
break;
}
}
if (player != null)
switch (player.Army())
{
case 1:
if (rafa.TryGetValue((aircraft as AiAircraft).InternalTypeName(), out value))
{
rafa[(aircraft as AiAircraft).InternalTypeName()] = value + 1;
bluescore = bluescore - rafv[(aircraft as AiAircraft).InternalTypeName()];
GamePlay.gpHUDLogCenter(new Player[] { player }, "Welcome Home, {0} : saved!", new object[] { SplitName((aircraft as AiAircraft).InternalTypeName()) }); // THIS MESSAGE IS STILL DISPLAYED!
Timeout(5, () =>
{ destroyPlane(aircraft); });
}
break;
case 2:
if (lwa.TryGetValue((aircraft as AiAircraft).InternalTypeName(), out value))
{
lwa[(aircraft as AiAircraft).InternalTypeName()] = value + 1;
redscore = redscore - lwv[(aircraft as AiAircraft).InternalTypeName()];
GamePlay.gpHUDLogCenter(new Player[] { player }, "Welcome Home, {0} : saved!", new object[] { SplitName((aircraft as AiAircraft).InternalTypeName()) }); // THIS MESSAGE IS STILL DISPLAYED!
Timeout(5, () =>
{ destroyPlane(aircraft); });
}
break;
}
}
}
FG28_Kodiak
05-27-2012, 04:44 PM
You would like to destoy a plane only if a player is present in that plane?
pupo162
05-27-2012, 05:31 PM
YES!
it works nicely, only if plane is intact.
you cant create a new airplane utni lthe previus one is destoyed or back to base and disappeared.
FG28_Kodiak
05-27-2012, 05:38 PM
Can i have the complete code, please? :rolleyes:
vBulletin® v3.8.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.