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.
OnPlayerLeaves?
Moderator: English Moderator
Re: OnPlayerLeaves?
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 arrayKaphene 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?
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?
Re: OnPlayerLeaves?
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.
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.
Re: OnPlayerLeaves?
good job finding the error!
next time i will just wait 5 more minutes before replying
next time i will just wait 5 more minutes before replying

Re: OnPlayerLeaves?
Alright new problem coming through.
I thought I had devised a workaround, but it's not working
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.
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.
Re: OnPlayerLeaves?
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
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
Re: OnPlayerLeaves?
I'll be honest, I actually did think they just became Null when somebody left >< lol anyhoo
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?
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;
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?
Re: OnPlayerLeaves?
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
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);
}
}
Re: OnPlayerLeaves?
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.
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.
Re: OnPlayerLeaves?
i don't think that there is actually a case where you NEED to do that ^.^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.
post it if you want me to take a look
Who is online
Users browsing this forum: No registered users and 2 guests