Comments (9)
Ok I think I have a fix for teleporting to the lobby and dropping all your items at the lobby right before you die. I made a new function in GameManager.php called removePlayerWithoutTeleport()
that is the exact same thing as removePlayer()
except it doesn't teleport. I implemented this function into the EventListener.php playerDeathEvent()
function, replacing the old removePlayer()
function with the new removePlayerWithoutTeleport()
.
Below is a copy of both the original removePlayer()
function and my added removePlayerWithoutTeleport()
function:
/**
* Removes player from game
*
* @param Player $p
* @param bool $message
*/
public function removePlayer(Player $p, $message = false){
$this->HGApi->getStorage()->removePlayer($p);
$p->teleport($this->getGame()->getLobbyPosition());
foreach($this->HGApi->getScriptManager()->getScripts() as $script){
if(!$script->isEnabled()) continue;
$script->onPlayerQuitGame($p, $this->getGame());
}
if($message){
$this->sendGameMessage(Msg::color(str_replace(["%player%", "%game%"], [$p->getName(), $this->getGame()->getName()], Msg::getHGMessage("hg.message.quit"))));
}
}
/**
* Removes player from game without teleporting them
*
* @param Player $p
* @param bool $message
*/
public function removePlayerWithoutTeleport(Player $p, $message = false){
$this->HGApi->getStorage()->removePlayer($p);
foreach($this->HGApi->getScriptManager()->getScripts() as $script){
if(!$script->isEnabled()) continue;
$script->onPlayerQuitGame($p, $this->getGame());
}
if($message){
$this->sendGameMessage(Msg::color(str_replace(["%player%", "%game%"], [$p->getName(), $this->getGame()->getName()], Msg::getHGMessage("hg.message.quit"))));
}
}
Once you've added the new removePlayerWithoutTeleport()
function to the GameManager.php file, change the playerDeathEvent()
function in the EventListener.php file to include removePlayerWithoutTeleport()
in place of removePlayer()
:
Old:
public function playerDeathEvent(PlayerDeathEvent $e){
$p = $e->getEntity();
if($this->HGApi->getStorage()->isPlayerSet($p)){
$game = $this->HGApi->getStorage()->getPlayerGame($p);
if($game !== null){
$this->HGApi->getGlobalManager()->getGameManager($game)->removePlayer($p);
}
$count = $this->HGApi->getStorage()->getPlayersInGameCount($game);
if($count > 1){
$msg = Msg::getHGMessage("hg.message.death");
$msg = str_replace(["%player%", "%game%", "%left%"], [$p->getName(), $game->getName(), $count], $msg);
$this->HGApi->getGlobalManager()->getGameManager($game)->sendGameMessage(Msg::color($msg));
}
}
}
New:
public function playerDeathEvent(PlayerDeathEvent $e){
$p = $e->getEntity();
if($this->HGApi->getStorage()->isPlayerSet($p)){
$game = $this->HGApi->getStorage()->getPlayerGame($p);
if($game !== null){
$this->HGApi->getGlobalManager()->getGameManager($game)->removePlayerWithoutTeleport($p);
}
$count = $this->HGApi->getStorage()->getPlayersInGameCount($game);
if($count > 1){
$msg = Msg::getHGMessage("hg.message.death");
$msg = str_replace(["%player%", "%game%", "%left%"], [$p->getName(), $game->getName(), $count], $msg);
$this->HGApi->getGlobalManager()->getGameManager($game)->sendGameMessage(Msg::color($msg));
}
}
}
In my testing, this will solve the problem of players teleporting to the lobby right before they die causing them to drop their items in the lobby. It also adds the benefit of dead players dropping their items in the arena, rather than the lobby, so their killer(s) can loot them during a match. There is one catch; you can death glitch. Since the player is never teleported, if they tap "main menu" after dying, then log back in, they will spawn where they died. I think you should be able to prevent this using the AlwaysSpawn plugin, which should force players to the set /spawnpoint when they login. https://poggit.pmmp.io/p/AlwaysSpawn/2.2
Let me know if you think this is a good solution to preventing tournament players from dropping their items at the lobby upon death.
from hungergames-updated.
I think it's a good idea. You can make a pull request and I think you should also add it for PlayerQuitEvent because it might be the reason that is freezes when a players quits. Thanks :D
from hungergames-updated.
It doesn't appear that I have permission to make pull requests, it keeps saying "Authentication Failed: You may not have permission to access HungerGames-UPDATED. Check Preferences to make sure youβre still logged in." Maybe I'm doing it wrong.
Regarding adding removePlayerWithoutTeleport()
to playerQuitEvent()
, it doesn't seem to do anything differently than removePlayer()
in my testing. But also in my testing, the game isn't freezing when a player quits the match. Can you elaborate on this?
from hungergames-updated.
I believe it was when the match is ticking while waiting to start. If you quit it freezes, might be related to the removePlayer() method.
from hungergames-updated.
Ah, I'll test that later tonight. Any word I why I can't submit pull requests?
from hungergames-updated.
Did you commit to the master branch?
from hungergames-updated.
from hungergames-updated.
Hmm, I don't know. I think it's something on your side.
from hungergames-updated.
xBeastMode said, "I believe it was when the match is ticking while waiting to start. If you quit it freezes..."
I still can't seem to reproduce this.
from hungergames-updated.
Related Issues (20)
- Help!!! HOT 7
- request HOT 2
- Inventory issues HOT 1
- Map Reset Doesn't work, no matter what HOT 3
- Adding Items to each game. HOT 2
- please update HOT 1
- EXCEPTION HOT 1
- Update to 3.0.0+ HOT 1
- client crash
- improvement suggestion
- Player Move issue
- Crash!
- Joining world causes server crash HOT 1
- Game stopping after gametime has passed. HOT 1
- Support for Plugin HOT 3
- The Server crashes after the death match!!! HOT 4
- Crash /hg add HOT 1
- SUGGESTION
- Question HOT 6
- Hunger games
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hungergames-updated.