Page 1 of 3

array (when player leave game)

Posted: 16 Aug 2013, 21:21
by alividerci
i have this code

Code: Select all

if(WhoPickupedArtefact.count > 0){
foreach(ArtefactPlayerAllias in WhoPickupedArtefact){
log(ArtefactPlayerAllias); ///this stroke catch error
if(ArtefactPlayerAllias == Null){
if(!WhoPickupedArtefact.exists(ArtefactPlayerAllias)){
log("Null");
WhoPickupedArtefact.remove(ArtefactPlayerAllias);
}
}
what is it?
When player pickup artefact he become ArtefactPlayerAllias on 30 sec...
and what me doing when player lost connection or disconnected
when i use this code i got this error
Invalid access to parameter (Null object or elem not found in array) : Players[###blablabla]
log
(CSmPlayer*)#blablabla
(CSmPlayer*)#blablabla
(CSmPlayer*)#blablabla
(CSmPlayer*)#blablabla
(CSmPlayer*)#blablabla
(CSmPlayer*)#blablabla
(CSmPlayer*)Null
[/*this numbers*/]Invalid access to parameter (Null object or elem not found in array) : Players[###blablabla]

Re: array (when player leave game)

Posted: 16 Aug 2013, 21:27
by steeffeen
you should save the Ids of the players instead of the player objects/aliases

lets say

Code: Select all

declare MyPlayer <=> Players[0];
now you have got an alias for the call Players[0]

some-when the player 0 leaves the game and there's no Players[0] anymore

Code: Select all

if (MyPlayer == Null)
is the same like

Code: Select all

if (Players[0] == Null)
which obviously fails because there is no element 0 in the Players array

save the player ids in

Code: Select all

declare Ident[] MyPlayerIds;
and check for the existence of the player before using it

Code: Select all

foreach (PlayerId in MyPlayerIds) {
if (Players.existskey(MyPlayerId)) {
declare Player <=> Players[MyPlayerId];
// Do stuff
} else {
// Player left the game
declare Temp = MyPlayerIds.remove(PlayerId);
}
}
(the remove code doesn't work like that but you get the point i hope)

Re: array (when player leave game)

Posted: 16 Aug 2013, 21:29
by alividerci
i have not ids :!:

Re: array (when player leave game)

Posted: 16 Aug 2013, 21:34
by steeffeen
and? you have the players, so you can save the ids

Code: Select all

MyPlayerIds.add(Player.Id);

Re: array (when player leave game)

Posted: 16 Aug 2013, 21:36
by alividerci
steeffeen wrote:and? you have the players, so you can save the ids

Code: Select all

MyPlayerIds.add(Player.Id);
i want to use my code without ids

Re: array (when player leave game)

Posted: 16 Aug 2013, 21:38
by alividerci

Code: Select all

Void PickUp(CSmPlayer _Player) {
ArtefactPlayerAllias <=> Players[_Player];
}
and what?
i adding in array throught void function, that code in playloop

Re: array (when player leave game)

Posted: 16 Aug 2013, 21:45
by steeffeen
alividerci wrote:and what?
i adding in array throught void function, that code in playloop
your code doesn't make any sense..

Code: Select all

Players[_Player]
wtf? you have the player object and want to use it as a key to get the same player object again?

just use

Code: Select all

ArtefactPlayerId = _Player.Id;
no idea what you want to tell because i don't understand your english

Re: array (when player leave game)

Posted: 17 Aug 2013, 07:46
by alividerci
steeffeen wrote:
alividerci wrote:and what?
i adding in array throught void function, that code in playloop
your code doesn't make any sense..

Code: Select all

Players[_Player]
wtf? you have the player object and want to use it as a key to get the same player object again?

just use

Code: Select all

ArtefactPlayerId = _Player.Id;
no idea what you want to tell because i don't understand your english
:evil:
ok, if i give more code, you must understand

Code: Select all

///Play loop
if(WhoPickupedArtefact.count > 0){
foreach(ArtefactPlayerAllias in WhoPickupedArtefact){
log(ArtefactPlayerAllias);
if(ArtefactPlayerAllias == Null){
if(!WhoPickupedArtefact.exists(ArtefactPlayerAllias)){
log("Null");
WhoPickupedArtefact.remove(ArtefactPlayerAllias);
}
}
declare DestroyPowerArtefact for ArtefactPlayerAllias = 0;
   if (Now >= DestroyPowerArtefact) {
					if(WhoPickupedArtefact.exists(ArtefactPlayerAllias)){
					WhoPickupedArtefact.remove(ArtefactPlayerAllias);
			} 
		}
	}
}

Code: Select all

//function
Void PickUp (CSmPlayer _Player) {
ArtefactPlayerAllias <=> Players[_Player];
WhoPickupedArtefact.add(ArtefactPlayerAllias);
declare DestroyPowerArtefact for WhoPickupedArtefact[ArtefactPlayerAllias] = 0;
DestroyPowerArtefact = Now + C_TimerDestroyBoxBonus;
}
:)

Re: array (when player leave game)

Posted: 17 Aug 2013, 08:02
by steeffeen
i know what you want to do even though i didn't understand your english

what do you want to achieve with posting this code?

again:
change your global CSmPlayer[] array WhoPickupedArtefact into an Id[] array and add the player Ids instead of the player objects when they pick up the artefact

Re: array (when player leave game)

Posted: 17 Aug 2013, 10:36
by alividerci
steeffeen wrote:i know what you want to do even though i didn't understand your english

what do you want to achieve with posting this code?

again:
change your global CSmPlayer[] array WhoPickupedArtefact into an Id[] array and add the player Ids instead of the player objects when they pick up the artefact
I want the player who picked up the artifact was removed it from an array when disconnecting...
i can do it without id?