mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
Merge pull request #771 from MihailRis/fix-player-suspend
player-related fixes
This commit is contained in:
commit
ea25b51485
8 changed files with 22 additions and 12 deletions
|
|
@ -117,6 +117,7 @@ player.set_suspended(pid: int, suspended: bool)
|
|||
Setter and getter for the player's suspended status.
|
||||
|
||||
When suspended, the entity is deleted and the player is disabled from the world simulation.
|
||||
When resumed, a new entity will be created with a different ID.
|
||||
|
||||
```lua
|
||||
player.set_name(playerid: int, name: str)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ player.get_name(playerid: int) -> string
|
|||
|
||||
|
||||
-- Сеттер и геттер статуса "заморозки" игрока.
|
||||
-- При заморозке сущность игрока удаляется. При последующей разморозке будет создана новая, с другим id.
|
||||
player.set_suspended(pid: int, suspended: boolean)
|
||||
player.is_suspended(pid: int) -> boolean
|
||||
```
|
||||
|
|
@ -125,4 +126,4 @@ player.get_all() -> table<int>
|
|||
|
||||
-- Возвращает id ближайшего к указанной позиции игрока, либо nil если игроков нет.
|
||||
player.get_nearest(position: vec3) -> int / nil
|
||||
```
|
||||
```
|
||||
|
|
|
|||
|
|
@ -58,7 +58,15 @@ local function process_player_inputs(pid, rot, delta)
|
|||
end
|
||||
end
|
||||
|
||||
local prepared = false
|
||||
body:set_enabled(false)
|
||||
|
||||
function on_physics_update(delta)
|
||||
if not prepared then
|
||||
prepared = true
|
||||
body:set_enabled(true)
|
||||
end
|
||||
|
||||
local pid = entity:get_player()
|
||||
if pid == -1 then
|
||||
return
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ Decorator::Decorator(
|
|||
addParticles(def, pos);
|
||||
}
|
||||
});
|
||||
playerNamePreset.deserialize(engine.getResPaths().readCombinedObject(
|
||||
"presets/text3d/player_name.toml"
|
||||
));
|
||||
for (const auto& [id, player] : *level.players) {
|
||||
if (id == this->player.getId()) {
|
||||
continue;
|
||||
|
|
@ -63,9 +66,6 @@ Decorator::Decorator(
|
|||
player->getPosition()
|
||||
));
|
||||
}
|
||||
playerNamePreset.deserialize(engine.getResPaths().readCombinedObject(
|
||||
"presets/text3d/player_name.toml"
|
||||
));
|
||||
}
|
||||
|
||||
void Decorator::addParticles(const Block& def, const glm::ivec3& pos) {
|
||||
|
|
|
|||
|
|
@ -324,8 +324,10 @@ static int l_is_suspended(lua::State* L) {
|
|||
}
|
||||
|
||||
static int l_set_suspended(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
player->setSuspended(lua::toboolean(L, 2));
|
||||
if (lua::toboolean(L, 2)) {
|
||||
level->players->suspend(lua::tointeger(L, 1));
|
||||
} else {
|
||||
level->players->resume(lua::tointeger(L, 1));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,10 +105,8 @@ void Player::postUpdate() {
|
|||
if (flight && hitbox.grounded && !noclip) {
|
||||
flight = false;
|
||||
}
|
||||
if (spawnpoint.y <= 0.1) {
|
||||
for (int i = 0; i < SPAWN_ATTEMPTS_PER_UPDATE; i++) {
|
||||
attemptToFindSpawnpoint();
|
||||
}
|
||||
for (int i = 0; i < SPAWN_ATTEMPTS_PER_UPDATE && std::isnan(spawnpoint.x); i++) {
|
||||
attemptToFindSpawnpoint();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class Player : public Serializable {
|
|||
|
||||
int chosenSlot;
|
||||
glm::vec3 position;
|
||||
glm::vec3 spawnpoint {};
|
||||
glm::vec3 spawnpoint {std::nanf(""), std::nanf(""), std::nanf("")};
|
||||
std::shared_ptr<Inventory> inventory;
|
||||
bool suspended = false;
|
||||
bool flight = false;
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ void Players::suspend(int64_t id) {
|
|||
}
|
||||
player->setSuspended(true);
|
||||
level.entities->despawn(player->getEntity());
|
||||
player->setEntity(0);
|
||||
player->setEntity(ENTITY_AUTO);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue