array (when player leave game)

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

User avatar
alividerci
Posts: 363
Joined: 11 Feb 2012, 07:03

array (when player leave game)

Post 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]
User avatar
steeffeen
Translator
Translator
Posts: 2463
Joined: 14 Oct 2012, 16:22
Location: Germany

Re: array (when player leave game)

Post 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)
    Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

    ManiaControl, FancyManiaLinks
    User avatar
    alividerci
    Posts: 363
    Joined: 11 Feb 2012, 07:03

    Re: array (when player leave game)

    Post by alividerci »

    i have not ids :!:
    User avatar
    steeffeen
    Translator
    Translator
    Posts: 2463
    Joined: 14 Oct 2012, 16:22
    Location: Germany

    Re: array (when player leave game)

    Post by steeffeen »

    and? you have the players, so you can save the ids

    Code: Select all

    MyPlayerIds.add(Player.Id);
      Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

      ManiaControl, FancyManiaLinks
      User avatar
      alividerci
      Posts: 363
      Joined: 11 Feb 2012, 07:03

      Re: array (when player leave game)

      Post 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
      User avatar
      alividerci
      Posts: 363
      Joined: 11 Feb 2012, 07:03

      Re: array (when player leave game)

      Post 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
      User avatar
      steeffeen
      Translator
      Translator
      Posts: 2463
      Joined: 14 Oct 2012, 16:22
      Location: Germany

      Re: array (when player leave game)

      Post 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
        Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

        ManiaControl, FancyManiaLinks
        User avatar
        alividerci
        Posts: 363
        Joined: 11 Feb 2012, 07:03

        Re: array (when player leave game)

        Post 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;
        }
        :)
        Last edited by alividerci on 21 Aug 2013, 12:09, edited 1 time in total.
        User avatar
        steeffeen
        Translator
        Translator
        Posts: 2463
        Joined: 14 Oct 2012, 16:22
        Location: Germany

        Re: array (when player leave game)

        Post 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
          Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

          ManiaControl, FancyManiaLinks
          User avatar
          alividerci
          Posts: 363
          Joined: 11 Feb 2012, 07:03

          Re: array (when player leave game)

          Post 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?
          Post Reply

          Return to “ManiaScript”

          Who is online

          Users browsing this forum: No registered users and 1 guest