Results 1 to 14 of 14

Thread: How to check if Actor is player

  1. #1
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    How to check if Actor is player

    Hi,

    What is the simplest way to check if an Actor is the player please?

    I've been able to check myself if an aircraft is the player by using the shortname, but I think I have seen the actor being directly checked before (so without the need for the name or anythign else)

    (I'm wanting to check if the player has bailed, is dead etc.)

    Thanks for any help.
    I am Yo-Yo not YoYo (that's someone else)

  2. #2
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: How to check if Actor is player

    I tried this:

    Code:
    public override void OnActorDead(int missionNumber, string shortName, maddox.game.world.AiActor actor, System.Collections.Generic.List<maddox.game.world.DamagerScore> damages)
    
            {
    
    if (actor is AiAircraft) { 
                GamePlay.gpHUDLogCenter("Is AI aircraft  dead" + shortName);
    				return;
    				}
    if (actor is AiGroundActor) {
                GamePlay.gpHUDLogCenter("Is AI ground target  dead " + shortName);
    			return;
    			} else {
    
                GamePlay.gpHUDLogCenter("Player  dead" + shortName);
    return;
            }
        }
    But if I, the player crash, into the ground it fires the 'Is AI Aircraft' message only.
    I am Yo-Yo not YoYo (that's someone else)

  3. #3
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: How to check if Actor is player

    The thing is, I want to capture what is happening to the pilot, not the aircraft anyway, so I might be barkign up the wrong tree?

    In the info messages, it says the pilot is dead etc. how does one find these events, and use them?
    I am Yo-Yo not YoYo (that's someone else)

  4. #4
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: How to check if Actor is player

    You mean:
    Code:
    if (actor == player)
    To keep track of where the player is use these events, actor is the aircraft you are entering or leaving:
    Code:
            public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex) { }
            public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex) { }

  5. Likes Yo-Yo liked this post
  6. #5
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: How to check if Actor is player

    Ahhh, thank you. I will give it a try.
    I am Yo-Yo not YoYo (that's someone else)

  7. #6
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: How to check if Actor is player

    So I think I got it working using this, thankyou.:

    Code:
        public class Mission : AMission
        {
    
    	public AiActor thePlayerActor;
    
    	public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    			 {
    						thePlayerActor = actor;
       						
    			 }
    
    
    public override void OnActorDead(int missionNumber, string shortName, maddox.game.world.AiActor actor, System.Collections.Generic.List<maddox.game.world.DamagerScore> damages)
    			{
    
    						if (actor == thePlayerActor)
    
    						{
    
    	        			GamePlay.gpHUDLogCenter("Alas poor player, I knew him well... ");
    
    						} else {
    
    	        			GamePlay.gpHUDLogCenter("Death to the AI machines.");
    
    						}
    
    			}
    
    }
    My question that I'm still not sure on for what I'm trying to do, is how to determine if a pilot dies whilst bailing/having bailed? OnPlaceEnter means entry to the aircraft does it? If so, does OnPlaceLeave mean when they exit, so (if before landing) is bailing, or when they leave the mission/battle. Either way, how can I find if they bail, and the result of bailing (as sometimes the chute doesn't deploy)

    I can use onAircraftLanded to determine a safe landing
    I can use onActorDead to determine death by crash...

    But how to denote if pilot bailed and alive or pilot bailed and dead...
    I am Yo-Yo not YoYo (that's someone else)

  8. #7
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: How to check if Actor is player

    Your code will never work. Please read my previous post.

    actor is the aircraft you are entering or leaving:

  9. #8
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: How to check if Actor is player

    Code:
    public override void OnActorDead(int missionNumber, string shortName, maddox.game.world.AiActor actor, System.Collections.Generic.List<maddox.game.world.DamagerScore> damages)
    			{
    
    						if (actor == GamePlay.gpPlayer())
    
    						{

  10. #9
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: How to check if Actor is player

    Quote Originally Posted by ATAG_Oskar View Post
    Your code will never work. Please read my previous post.
    Well that's a bit harsh.

    It 'seems' to work, i.e when my aircraft goes down, it tells me the 'alas' message... when the AI aircraft goes down it tells me the 'death to AI machines' message. That is what I intended, prehaps it seeming to do the right thing is just somethign happening by fluke?

    I read your post (repeatedly) and then made my code to try and identify and note the aircraft that I enter as a player, then when an aircraft 'dies' it checks if it was the one the player had entered and shows either of the messages as applicable. I felt your contribution had clarified something for me and I was getting somewhere for which I was grateful, but you say it will never work? Can you maybe clarify why it is never going to work, when it seems to, what is it that you see that is wrong? I appreciate you probably tire of people like me who know next to nothing, so please don't feel an obligation to do explain.
    I am Yo-Yo not YoYo (that's someone else)

  11. #10
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: How to check if Actor is player

    In your code you are setting the value of thePlayerActor to the aircraft you are entering, not a Player.

    Then your OnActorDead code catches that aircraft being killed. Not the same as the player being killed.

    EDIT: When an aircraft is shot down OnActorDead events will be generated for the aircraft plus one for every crew member including human players. Of course this does not apply to any human or AI crew that bail out.
    Last edited by ATAG_Oskar; Feb-24-2023 at 15:11.

  12. #11
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: How to check if Actor is player

    Quote Originally Posted by ATAG_Oskar View Post
    In your code you are setting the value of thePlayerActor to the aircraft you are entering, not a Player.

    Then your OnActorDead code catches that aircraft being killed. Not the same as the player being killed.
    Yes I understood exactly that this what it was doing, due to your post saying the actor was the aircraft, for which I am grateful. So whilst not my ultimate aim, it is good to know my code was functioning to determine if the players aircraft (or at least the one that the player had gone into) or the AI's aircraft had triggered the onActorDead. this gets me a step closer to what I am trying to do.

    However my pursuit of player bail/ditch/death though, is still active, my current holy grail so to speak. I can see that there is some IPlayerStats thing for deaths and ditches, but I don't yet understand if that is of any use for determining if a player dies in a mission that is part of a SP campaign, or how to use it. Something in the game prompts the message 'parachute failed to deploy', and I think I've seen it on-line where it was then judged wether you can get back to base or not, suggesting someone captured the result and used it in code. This is what I want to try and understand, and use, next, for a single player mission in a campaign if that is possible.
    I am Yo-Yo not YoYo (that's someone else)

  13. #12
    Combat pilot
    Join Date
    Oct 2021
    Posts
    114
    Post Thanks / Like
    Total Downloaded
    12.95 MB

    Re: How to check if Actor is player

    Deleted by GANIX.
    Last edited by GANIX; Apr-11-2023 at 13:33.

  14. Likes Yo-Yo liked this post
  15. #13
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: How to check if Actor is player

    Quote Originally Posted by GANIX View Post
    Hi Yo-Yo, here are few methods you may play arround with, to get an idea what happens behind the 'curtain' ...
    Thank you, much appreciated.
    I am Yo-Yo not YoYo (that's someone else)

  16. #14
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: How to check if Actor is player

    Quote Originally Posted by GANIX View Post
    [EDIT] I forgot this:

    Code:
    public override void OnPersonMoved(AiPerson person, AiActor fromCart, int fromPlaceIndex)
        {
            base.OnPersonMoved(person, fromCart, fromPlaceIndex);
            if (person.Player() != null)
            {
                if (((person.Cart() == null)
                && (fromCart as AiAircraft).IsAirborne()))
                {
                    GamePlay.gpHUDLogCenter(null, "Bailed out!!");
                }
            }
        }
    This is exactly the sort of thing I was looking for,... many many thanks.
    I am Yo-Yo not YoYo (that's someone else)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •