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

Solved Prevent players to exit areas

Comments in 'Plugin Development' started by Tim // robske Büba, Mar 2, 2016.

  1. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Any Idea how to do this?
    I searched everywhere, but couldn't find an idea.
    I don't need full code, but some concepts would be useful
    Skullex likes this.
  2. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    If a player isn't in the area, teleport he back...
  3. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Ok, that is the obvious part
    But should i do it on an task? And how to check if something is in an area? (Ok, I'll probaly look at iProtector)
  4. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Why you need read iProtector source?
    Use your mind... And ">", "<" comparison operators.
  5. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I would go for PlayerMoveEvent and if player's coordinate is not in the area (Compare their coordinate to certain area), cancel it.
  6. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    No need for a task. It can be done with PlayerMoveEvent
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You don't need to do that every tick. Using a task that is run less frequently can improve performance.
  8. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Ok, I'll try to use my mind ;)
    And if I'm too stupid for it I will just look at iProtector
  9. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Sorry, I worked hard on an FloatingText plugin the last days!
    (Offtopic: I HATE THE OFFSET and USING SPRINTF TO GET POSITION NORMALISED)
    But my mind came up with this:
    PHP:
        public function isInArea(Player $player,array $pos1, array $pos2) : bool //Will this cause crash in PHP5?
        
    {
            
    $posPlayer['X'] = $player->getX();
            
    $posPlayer['Y'] = $player->getY();
            
    $posPlayer['Z'] = $player->getZ();
            if (
    $posPlayer['X'] => $pos1['X'] && $posPlayer['Y'] <= $pos2['X']){
                if (
    $posPlayer['Y'] => $pos1['Y'] && $posPlayer['Z'] <= $pos2['Y']){
                    if (
    $posPlayer['Z'] => $pos1['Z'] && $posPlayer['X'] <= $pos2['Z']){
                        return 
    true;
                    }else{
                        return 
    false;
                    }
                }
            }
        }
    And can anyone answer the question in the code? (That : bool)
  10. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Hello?
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why are you creating an array? You could just have used the values directly, or declared three separate variables. Why must you create an array for the player's current position?

    About the PHP 5 thing, yes, but PHP 5 is no longer supported by PocketMine anyway.
  12. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I don't know :p
    But the code itself does not work :(
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Tim // robske Büba likes this.
  14. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Thanks, got it to work, done with an repeating task every 20 ticks

Share This Page

Advertisement