Page 2 of 3
Re: array (when player leave game)
Posted: 17 Aug 2013, 11:00
by steeffeen
just remove the id when the player doesn't exist anymore
(you shouldn't alter the array while looping through it, save the ids of players who left and remove them later)
Code: Select all
declare LeftPlayerIds = Ident[];
foreach (PlayerId in MyPlayerIds) {
if (!Players.existskey(PlayerId)) {
// Player left
LeftPlayerIds.add(PlayerId);
} else {
// Player still exist
declare Player <=> Players[PlayerId];
// Do stuff
}
}
// Remove players who left
foreach (PlayerId in LeftPlayerIds) {
declare Removed = MyPlayerIds.remove(PlayerId);
}
Re: array (when player leave game)
Posted: 17 Aug 2013, 11:45
by alividerci
steeffeen wrote:just remove the id when the player doesn't exist anymore
(you shouldn't alter the array while looping through it, save the ids of players who left and remove them later)
Code: Select all
declare LeftPlayerIds = Ident[];
foreach (PlayerId in MyPlayerIds) {
if (!Players.existskey(PlayerId)) {
// Player left
LeftPlayerIds.add(PlayerId);
} else {
// Player still exist
declare Player <=> Players[PlayerId];
// Do stuff
}
}
// Remove players who left
foreach (PlayerId in LeftPlayerIds) {
declare Removed = MyPlayerIds.remove(PlayerId);
}
and what me do with
Code: Select all
declare CSmPlayer[] WhoPickupedArtefact;
declare CSmPlayer ArtefactPlayerAllias;
Re: array (when player leave game)
Posted: 17 Aug 2013, 11:57
by steeffeen
steeffeen wrote:
save the player ids in
Re: array (when player leave game)
Posted: 17 Aug 2013, 15:11
by Usul
alividerci wrote:
I want the player who picked up the artifact was removed it from an array when disconnecting...
i can do it without id?
No you can't do it, without id. (perhaps with magic but not with code

)
I had the same problem in the past and I resolved it with some functions
Code: Select all
CSmPlayer GetPlayerByID(Ident _PlayerId)
{
if (_PlayerId==NullId) return Null;
if (Players.existskey(_PlayerId))
return Players[_PlayerId];
return Null;
}
// ---------------------------------- //
Ident GetIDByPlayer(CSmPlayer _Player)
{
if (_Player==Null) return NullId;
if (Players.existskey(_Player.Id))
return _Player.Id;
return NullId;
}
// ---------------------------------- //
Boolean IsValidPlayerId(Ident _PlayerId)
{
declare CSmPlayer pl = GetPlayerByID(_PlayerId);
if (pl==Null) return False;
return (pl.SpawnStatus != CSmPlayer::ESpawnStatus::NotSpawned && !pl.RequestsSpectate && pl.Armor>0);
}
// ---------------------------------- //
Boolean IsValidCSmPlayer(CSmPlayer _Player)
{
if (_Player==Null) return False;
return IsValidPlayerId(_Player.Id);
}
Re: array (when player leave game)
Posted: 17 Aug 2013, 19:14
by alividerci
ok, what about if i want to made something
example
Code: Select all
ArtefactPlayerAllias.AmmoPower = 4.;
how me do it with id...i think it is not possible or possible

Re: array (when player leave game)
Posted: 18 Aug 2013, 11:16
by Usul
With my functions like this
Code: Select all
foreach( Player in YourArtefactPlayerList){
If (IsValidCSmPlayer(Player)){
Player.AmmoPower = 4.;
}else{
//Player is disconnected or dead or spectator
Ident pID = GetIDByPlayer(Player);
if (pID == NullId)
//Player is disconnected
else
//Player is dead (or spectator)
}
}
Re: array (when player leave game)
Posted: 20 Aug 2013, 10:09
by alividerci
Usul wrote:With my functions like this
Code: Select all
foreach( Player in YourArtefactPlayerList){
If (IsValidCSmPlayer(Player)){
Player.AmmoPower = 4.;
}else{
//Player is disconnected or dead or spectator
Ident pID = GetIDByPlayer(Player);
if (pID == NullId)
//Player is disconnected
else
//Player is dead (or spectator)
}
}
IsValidCSmPlayer - fake

Re: array (when player leave game)
Posted: 20 Aug 2013, 11:41
by steeffeen
use ids!...
alividerci wrote:i can do it without id?
nope
Re: array (when player leave game)
Posted: 20 Aug 2013, 12:33
by alividerci
steeffeen wrote:use ids!...
alividerci wrote:i can do it without id?
nope
I try to do with ID
In any case, I can ask you, where my mistake

Re: array (when player leave game)
Posted: 20 Aug 2013, 16:14
by Usul
alividerci wrote:IsValidCSmPlayer - fake

look my previous post I give you the function IsValidCSmPlayer ...
if you don't read the answers to your question, I can not help you.