OnPlayerLeaves?

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Kaphene
Posts: 37
Joined: 02 Apr 2013, 21:38

OnPlayerLeaves?

Post by Kaphene »

I'm sure this has been asking before, but I searched on google and here and nothing really came up. Is there an easyish way to tell when a player leaves the game?

also in a related workaround question. I'm doing something like
for(I, 0, myarray.count -1)
if(myarray == Null){
myarray.remove
}

but it says that myarra == Null is comparing two invalid data types... how do I tell if an array contains a null value? I know it can contain a Null value because I get errors saying that it's Null... but I can't seem to test to see if it's Null before I run the function that is causing the error lol.
User avatar
steeffeen
Translator
Translator
Posts: 2463
Joined: 14 Oct 2012, 16:22
Location: Germany

Re: OnPlayerLeaves?

Post by steeffeen »

Kaphene wrote:I'm sure this has been asking before, but I searched on google and here and nothing really came up. Is there an easyish way to tell when a player leaves the game?
you will have to hold all the players in your own array and check if someone of your array is missing in the game's player array
Kaphene wrote:also in a related workaround question. I'm doing something like
for(I, 0, myarray.count -1)
if(myarray == Null){
myarray.remove
}
but it says that myarra == Null is comparing two invalid data types... how do I tell if an array contains a null value? I know it can contain a Null value because I get errors saying that it's Null... but I can't seem to test to see if it's Null before I run the function that is causing the error lol.

how is your array defined?
if i remember correctly the error wasn't exactly that the value is Null, could you please post a screenshot?
    Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

    ManiaControl, FancyManiaLinks
    Kaphene
    Posts: 37
    Joined: 02 Apr 2013, 21:38

    Re: OnPlayerLeaves?

    Post by Kaphene »

    This is actually a whole new gamemode lol, but um I figured out the Null part, I just had to use NullId.... seems like whenever I post something on here I instantly solve it.

    too bad there isn't a CSmModeEvent OnPlayerLeaves

    or a ModeBase script for

    ***OnPlayerLeaves***

    but O well.. I think I got a work around working. Thanks for the quick reply as always.
    User avatar
    steeffeen
    Translator
    Translator
    Posts: 2463
    Joined: 14 Oct 2012, 16:22
    Location: Germany

    Re: OnPlayerLeaves?

    Post by steeffeen »

    good job finding the error!

    next time i will just wait 5 more minutes before replying :lol:
      Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

      ManiaControl, FancyManiaLinks
      Kaphene
      Posts: 37
      Joined: 02 Apr 2013, 21:38

      Re: OnPlayerLeaves?

      Post by Kaphene »

      Alright new problem coming through.

      I thought I had devised a workaround, but it's not working

      Code: Select all

      // ---------------------------------- //
      // Player Left? 
      // ---------------------------------- //
      for(I, 0, (IsAttacking.count -1))
      {
      	if(IsAttacking[I] == NullId)
      	{
      		IsAttacking.removekey(I);
      	}
      }

      so I basically have this, except it goes on for 20 more lines, but you don't need to see all of that.
      I was HOPING that when a player left, this would determine that their value was now Null and remove it, the problem is that now this throws an error saying that IsAttacking is a Null Object or Reference.... that's what I was checking for, but it's erroring my error checking function before it can remove them from the array and stop the Errors in the important functions lol.
      User avatar
      steeffeen
      Translator
      Translator
      Posts: 2463
      Joined: 14 Oct 2012, 16:22
      Location: Germany

      Re: OnPlayerLeaves?

      Post by steeffeen »

      again: i need your array declarations!
      error screenshots are helpful as well

      and Ident[] arrays won't just get managed on its own if a player leaves btw, the elements won't become NullIds out of nowhere
        Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

        ManiaControl, FancyManiaLinks
        Kaphene
        Posts: 37
        Joined: 02 Apr 2013, 21:38

        Re: OnPlayerLeaves?

        Post by Kaphene »

        I'll be honest, I actually did think they just became Null when somebody left >< lol anyhoo

        Code: Select all

        declare CSmBlockSpawn[] G_ListofAttackSpawns;		// Attacker Spawns
        declare CSmBlockSpawn[] G_ListofDefenseSpawns;		// Defender Spawns
        declare CSmBlockPole[] G_ListofGoals;				// Goals
        declare Ident[] IsAttacking;						// Player is Attacking
        declare Ident[] IsDefending;						// Player is Defending
        declare CSmPlayer[] LaneOne;
        declare CSmPlayer[] LaneTwo;
        declare CSmPlayer[] LaneThree;
        declare CSmPlayer[] LaneFour;
        declare CSmPlayer[] LaneFive;
        declare Boolean SwitchRound;
        declare Boolean InRound;
        declare Integer NbPlayers;
        I will get a screenshot next time it happens.

        here ya go

        http://www.illhome.net/wp-content/uploads/Untitled.jpg



        do you think if I set IsAttacking and IsDefending to CSmPlayer instead of Ident, that might help?
        User avatar
        steeffeen
        Translator
        Translator
        Posts: 2463
        Joined: 14 Oct 2012, 16:22
        Location: Germany

        Re: OnPlayerLeaves?

        Post by steeffeen »

        thanks :p

        actually i'm not sure how CSmPlayer objects in an own array are handled when the player leaves, they could possibly be Nulled
        even though it doesn't really make sense that the count says that there is another object but you can't access it at all...
        did you try to check .existskey()? shouldn't be necessary though :|

        if i'm allowed to suggest something: use the player Ids, it needs less memory and should fix your problem as Idents are types of which you have full control while players are objects managed by the game

        Code: Select all

        declare Ident[] LaneOne;
        LaneOne.add(Player.Id);
        
        foreach (PlayerId in LaneOne) {
        if (!Players.existskey(PlayerId)) {
        declare Temp = LaneOne.remove(PlayerId);
        }
        }
          Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

          ManiaControl, FancyManiaLinks
          Kaphene
          Posts: 37
          Joined: 02 Apr 2013, 21:38

          Re: OnPlayerLeaves?

          Post by Kaphene »

          Unfortunately I ran into an issue where LaneOne - LaneFive needed to be CSmPlayer because I use them directly in a for loop for which players to spawn where.

          I have updated my script to try !LaneOne.existskey(I)

          I will edit if that doesn't work... seems to be working right now but who knows.
          User avatar
          steeffeen
          Translator
          Translator
          Posts: 2463
          Joined: 14 Oct 2012, 16:22
          Location: Germany

          Re: OnPlayerLeaves?

          Post by steeffeen »

          Kaphene wrote:Unfortunately I ran into an issue where LaneOne - LaneFive needed to be CSmPlayer because I use them directly in a for loop for which players to spawn where.
          i don't think that there is actually a case where you NEED to do that ^.^
          post it if you want me to take a look
            Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

            ManiaControl, FancyManiaLinks
            Post Reply

            Return to “ManiaScript”

            Who is online

            Users browsing this forum: No registered users and 2 guests