Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved How can I freeze a player?

Comments in 'Plugin Development' started by Legoboy0215, Jul 5, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    I have a simple Minigame plugin called BlockRun. I want to freeze a player before they start. They get in by tapping a sign then they are in on their spawns. How can I freeze them? I know PlayerMoveEvent, but how do I add a player to an array (Maybe...) and check if they are in-game then when the game starts they unfreeze all the players. I think basicly the problem is the arrays. IDK how to use them XD.
    How can I acheive that???
    Last edited: Jul 5, 2015
    RekkuzaRage likes this.
  2. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    so create a array using
    PHP:
    $arrayname = array();
    you can then add players to the array by array_push i recomend names
    PHP:
    array_push($arrayname$player)
    and then to check if player is in array use in_array
    PHP:
    if (in_array($player$arrayname)){
    //DO something here
    }
    to remove player
    PHP:
    if (($key array_search($player$arrayname)) !== false) {
        unset(
    $array[$key]);
    }
    other array stuff i would suggest google ;)
    Legoboy0215 likes this.
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Um... $player = $event->getPlayer() or $player = $event->getPlayer()->getName()?
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    How do you unset every thing in an array?
  5. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    reset array just set it again
    PHP:
    $arrayname =  array();
    and just $event->getPlayer() should be good
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Thanks! SO if my var $thegameisstarted = true then after that just $arrayname = array();?
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    I thought you need to put text in arrays. Isn't that names?
  8. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    First question yea i think i dont get what your asking to well. And for the second one the way i did was easier so later you can get a player from array and sendmessage or teleport directly from the item in array if ($item instanceof Player) of course. Hope that makes sense?
    Legoboy0215 likes this.
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    PHP:
    if (($key array_search($player$arrayname)) !== false) {
           unset(
    $array[$key]);
        }
    Should the $array be changed to $arrayname?
    BalAnce likes this.
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Yes!
  11. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    yea and also $event->getPlayer() also returns player name just for a fyi (at least for me it does)
    so the list of player in the array would be by name
    Legoboy0215 likes this.
  12. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    How do I make the frozen player able to see around?
    PHP:
        public function onFrozenMove(PlayerMoveEvent $event){
        if (
    in_array($event->getPlayer()->getName(), $this->plugin->freeze)){
        
    $event->setCancelled(true);
        }else{
        
    $event->setCancelled(false);
        }
    }
    ??? I saw GrabBag but IDK how to implent it in my plugin...
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If x y and z of from and to are the same, don't cancel event.
  14. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    PHP:
    $event->getPlayer();
    returns player id! like: Player(1), not a name !
    To get name do
    PHP:
    $event->getPlayer()->getName();
    now it will return a name!
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    BalAnce likes this.
  16. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Um... Same x y z? Their xyz wi always be the same to their own xyz.
  17. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Can you give me an example of letting the players look around but not move?

Share This Page

Advertisement