1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to give only the player in the event the variable

Discussion in 'Development' started by rektpixel, Jan 22, 2018.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    Ok this title might be slightly wrong but I didn't know what to call this.
    Anyways I have this code:
    PHP:
        public function onInteract(PlayerInteractEvent $event){
            
    $player $event->getPlayer();
            
    $block $event->getBlock();
            
    $level $this->getServer()->getDefaultLevel();
            
    $this->mode 0;
            if(
    $block->getId() == 46) {
                if(
    $this->mode>=0&&$this->mode<=1000) {
                    
    $this->mode++;
                    
    $this->text->setText("§aYour score: §e" $this->mode "");
                    
    $level->addParticle($this->text);
                    
    $player->sendPopup("score:" $this->mode "");
                }
            }
        }
    }
    So atm if a player taps TNT(46) it will make $this->mode increase everytime it is tapped. However this is the problem: if a player taps the tnt it will become 1 and then if another player comes along it becomes 2. I want each player to have their own seperate. so what I'm wanting to do is make $this->mode per player.
    hope that was understandable :)
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Use an integer array instead of a single integer. Use the player entity ID ($player->getId()) as the index, and make sure you clear them when player quits to prevent memory leak.
     
    rektpixel likes this.
  3. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    I don't quite understand. Is there a plugin which uses this, I need to see a working example :D
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    rektpixel likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.