add player.is_instant_destruction, .set_instant_destruction

This commit is contained in:
MihailRis 2024-11-21 05:02:45 +03:00
parent 005bcfb436
commit 2ba90625ce
5 changed files with 44 additions and 0 deletions

View File

@ -63,6 +63,13 @@ player.set_infinite_items(bool)
Getter and setter for infinite items (not removed from inventory after use) Getter and setter for infinite items (not removed from inventory after use)
```lua
player.is_instant_destruction() -> bool
player.set_instant_destruction(bool)
```
Getter and setter for instant destruction of blocks when the `player.destroy` binding is activated.
``` lua ``` lua
player.set_spawnpoint(playerid: int, x: number, y: number, z: number) player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
player.get_spawnpoint(playerid: int) -> number, number, number player.get_spawnpoint(playerid: int) -> number, number, number

View File

@ -63,6 +63,13 @@ player.set_infinite_items(bool)
Геттер и сеттер бесконечных предметов (не удаляются из инвентаря при использовании) Геттер и сеттер бесконечных предметов (не удаляются из инвентаря при использовании)
```lua
player.is_instant_destruction() -> bool
player.set_instant_destruction(bool)
```
Геттер и сеттер мнгновенного разрушения блоков при активации привязки `player.destroy`.
```lua ```lua
player.set_spawnpoint(playerid: int, x: number, y: number, z: number) player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
player.get_spawnpoint(playerid: int) -> number, number, number player.get_spawnpoint(playerid: int) -> number, number, number

View File

@ -142,6 +142,20 @@ static int l_set_infinite_items(lua::State* L) {
return 0; return 0;
} }
static int l_is_instant_destruction(lua::State* L) {
if (auto player = get_player(L, 1)) {
return lua::pushboolean(L, player->isInstantDestruction());
}
return 0;
}
static int l_set_instant_destruction(lua::State* L) {
if (auto player = get_player(L, 1)) {
player->setInstantDestruction(lua::toboolean(L, 2));
}
return 0;
}
static int l_get_selected_block(lua::State* L) { static int l_get_selected_block(lua::State* L) {
if (auto player = get_player(L, 1)) { if (auto player = get_player(L, 1)) {
if (player->selection.vox.id == BLOCK_VOID) { if (player->selection.vox.id == BLOCK_VOID) {
@ -236,6 +250,8 @@ const luaL_Reg playerlib[] = {
{"set_noclip", lua::wrap<l_set_noclip>}, {"set_noclip", lua::wrap<l_set_noclip>},
{"is_infinite_items", lua::wrap<l_is_infinite_items>}, {"is_infinite_items", lua::wrap<l_is_infinite_items>},
{"set_infinite_items", lua::wrap<l_set_infinite_items>}, {"set_infinite_items", lua::wrap<l_set_infinite_items>},
{"is_instant_destruction", lua::wrap<l_is_instant_destruction>},
{"set_instant_destruction", lua::wrap<l_set_instant_destruction>},
{"get_selected_block", lua::wrap<l_get_selected_block>}, {"get_selected_block", lua::wrap<l_get_selected_block>},
{"get_selected_entity", lua::wrap<l_get_selected_entity>}, {"get_selected_entity", lua::wrap<l_get_selected_entity>},
{"set_spawnpoint", lua::wrap<l_set_spawnpoint>}, {"set_spawnpoint", lua::wrap<l_set_spawnpoint>},

View File

@ -248,6 +248,14 @@ void Player::setInfiniteItems(bool flag) {
infiniteItems = flag; infiniteItems = flag;
} }
bool Player::isInstantDestruction() const {
return instantDestruction;
}
void Player::setInstantDestruction(bool flag) {
instantDestruction = flag;
}
entityid_t Player::getEntity() const { entityid_t Player::getEntity() const {
return eid; return eid;
} }
@ -282,6 +290,7 @@ dv::value Player::serialize() const {
root["flight"] = flight; root["flight"] = flight;
root["noclip"] = noclip; root["noclip"] = noclip;
root["infinite-items"] = infiniteItems; root["infinite-items"] = infiniteItems;
root["instant-destruction"] = instantDestruction;
root["chosen-slot"] = chosenSlot; root["chosen-slot"] = chosenSlot;
root["entity"] = eid; root["entity"] = eid;
root["inventory"] = inventory->serialize(); root["inventory"] = inventory->serialize();
@ -310,6 +319,7 @@ void Player::deserialize(const dv::value& src) {
flight = src["flight"].asBoolean(); flight = src["flight"].asBoolean();
noclip = src["noclip"].asBoolean(); noclip = src["noclip"].asBoolean();
src.at("infinite-items").get(infiniteItems); src.at("infinite-items").get(infiniteItems);
src.at("instant-destruction").get(instantDestruction);
setChosenSlot(src["chosen-slot"].asInteger()); setChosenSlot(src["chosen-slot"].asInteger());
eid = src["entity"].asNumber(); eid = src["entity"].asNumber();

View File

@ -50,6 +50,7 @@ class Player : public Object, public Serializable {
bool flight = false; bool flight = false;
bool noclip = false; bool noclip = false;
bool infiniteItems = true; bool infiniteItems = true;
bool instantDestruction = true;
entityid_t eid; entityid_t eid;
entityid_t selectedEid; entityid_t selectedEid;
public: public:
@ -90,6 +91,9 @@ public:
bool isInfiniteItems() const; bool isInfiniteItems() const;
void setInfiniteItems(bool flag); void setInfiniteItems(bool flag);
bool isInstantDestruction() const;
void setInstantDestruction(bool flag);
entityid_t getEntity() const; entityid_t getEntity() const;
void setEntity(entityid_t eid); void setEntity(entityid_t eid);