Official 1C Company forum

Official 1C Company forum (http://forum.1cpublishing.eu/index.php)
-   FMB, Mission & Campaign builder Discussions (http://forum.1cpublishing.eu/forumdisplay.php?f=203)
-   -   Getting the actor type? (http://forum.1cpublishing.eu/showthread.php?t=28611)

salmo 12-22-2011 09:49 AM

Getting the actor type?
 
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:
Code:

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:
Code:

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:

Code:

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:

Code:

public override void OnAircraftKilled(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftKilled(missionNumber, shortName, aircraft);
    }

and
Code:

    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

Quote:

Originally Posted by FG28_Kodiak (Post 429584)
You can use two events:

Code:

public override void OnAircraftKilled(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftKilled(missionNumber, shortName, aircraft);
    }

and
Code:

    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

Quote:

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?


All times are GMT. The time now is 11:11 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2007 1C Company. All rights reserved.