How to check if a player is going out of an area and if out kick him, because there are many hack clients which can enable no clip and they can go outside an area where they are not supposed to go..
since i am feeling generous, here's an example this is inside a task under onrun Code: $areas // @var $areas area[] foreach players as player foreach areas as area if $area->isInside($player) continue 2//skips the kick code and look for next player end foreach $player->tpToSpawn() //also set them to spawn or they will be kicked forever $player->disconnect() //dont let them know i kicked them to emulate some unknow network issue, just because i can end foreach may not be the most ideal lag free but logic certainly works as an example you can improve upon
it only lags when there's a lot of players online + there's a lot of areas if there's 50 players 3 areas it's only about 150 loops at worst since again they have a 33% to be in 1 or 2nd or just put the most popular one on first increasing the odds and reducing the iteration needed and players out of areas creates more lagg than players IN the areas also you dont need to run this task every tick, save your self some cpu and run it every 60 ticks+ there's other method like foreaching players and distance them to vector points but it's ultimately same
Incomplete but thats pretty much it, then just kinda schedule a task PHP: $y = $p->getY(); $z = $p->getZ(); $xx = [214, 210]; $yy = [74, 69]; $zz = [1, 4]; if($x >= min($xx) and $x <= max($xx) and $y >= min($yy) and $y <= max($yy) and $z >= min($zz) and $z <= max($zz)){ $p->sendmessage("In Region"); }else{ $p->sendmessage("Not In Region"); }
In a termux command on an Android phone released 3 years ago and bought 2 years ago, executing 6 object field comparisons for 88 players for 11 times takes 0.001234 second, using PHP 7.1.2 (the version where stuff started getting slow). On a server supporting 80 players, you definitely have much better hardware than my phone. With PHP 7.0 running, it should take much less than the 2% of a tick as if from my phone. Spoiler