Skip to content

Commit ec3142a

Browse files
Wuzzy2ClobberXD
authored andcommittedAug 1, 2019
Group "immortal" also protects players from damage
Document new meaning of immortal=1 for players Disable breathing if player is immortal Hide builtin statbars if player immortal (delayed) Co-authored-by: ClobberXD <ClobberXD@gmail.com>
1 parent 3296952 commit ec3142a

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed
 

‎builtin/game/statbars.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ local function update_builtin_statbars(player)
5050
end
5151
local hud = hud_ids[name]
5252

53-
if flags.healthbar and enable_damage then
53+
local immortal = player:get_armor_groups().immortal == 1
54+
if flags.healthbar and enable_damage and not immortal then
5455
local number = scaleToDefault(player, "hp")
5556
if hud.id_healthbar == nil then
5657
local hud_def = table.copy(health_bar_definition)
@@ -65,7 +66,7 @@ local function update_builtin_statbars(player)
6566
end
6667

6768
local breath_max = player:get_properties().breath_max
68-
if flags.breathbar and enable_damage and
69+
if flags.breathbar and enable_damage and not immortal and
6970
player:get_breath() < breath_max then
7071
local number = 2 * scaleToDefault(player, "breath")
7172
if hud.id_breathbar == nil then
@@ -116,7 +117,7 @@ local function player_event_handler(player,eventname)
116117
end
117118
end
118119

119-
if eventname == "hud_changed" then
120+
if eventname == "hud_changed" or eventname == "properties_changed" then
120121
update_builtin_statbars(player)
121122
return true
122123
end

‎doc/lua_api.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,9 @@ Another example: Make red wool from white wool and red dye:
15331533
Special groups
15341534
--------------
15351535

1536-
* `immortal`: Disables the group damage system for an entity
1536+
* `immortal`: Skips all damage and breath handling for an object. This group
1537+
will also hide the integrated HUD status bars for players, and is
1538+
automatically set to all players when damage is disabled on the server.
15371539
* `punch_operable`: For entities; disables the regular damage mechanism for
15381540
players punching it by hand or a non-tool item, so that it can do something
15391541
else than take damage.

‎src/content_sao.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void UnitSAO::setArmorGroups(const ItemGroupList &armor_groups)
134134
m_armor_groups_sent = false;
135135
}
136136

137-
const ItemGroupList &UnitSAO::getArmorGroups()
137+
const ItemGroupList &UnitSAO::getArmorGroups() const
138138
{
139139
return m_armor_groups;
140140
}
@@ -1015,14 +1015,14 @@ void PlayerSAO::step(float dtime, bool send_recommended)
10151015
}
10161016
}
10171017

1018-
if (m_breathing_interval.step(dtime, 0.5f)) {
1018+
if (m_breathing_interval.step(dtime, 0.5f) && !isImmortal()) {
10191019
// Get nose/mouth position, approximate with eye position
10201020
v3s16 p = floatToInt(getEyePosition(), BS);
10211021
MapNode n = m_env->getMap().getNodeNoEx(p);
10221022
const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n);
1023-
// If player is alive & no drowning & not in ignore, breathe
1024-
if (m_breath < m_prop.breath_max &&
1025-
c.drowning == 0 && n.getContent() != CONTENT_IGNORE && m_hp > 0)
1023+
// If player is alive & not drowning & not in ignore & not immortal, breathe
1024+
if (m_breath < m_prop.breath_max && c.drowning == 0 &&
1025+
n.getContent() != CONTENT_IGNORE && m_hp > 0)
10261026
setBreath(m_breath + 1);
10271027
}
10281028

@@ -1069,6 +1069,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
10691069
// create message and add to list
10701070
ActiveObjectMessage aom(getId(), true, str);
10711071
m_messages_out.push(aom);
1072+
m_env->getScriptIface()->player_event(this, "properties_changed");
10721073
}
10731074

10741075
// If attached, check that our parent is still there. If it isn't, detach.
@@ -1287,8 +1288,8 @@ int PlayerSAO::punch(v3f dir,
12871288

12881289
FATAL_ERROR_IF(!puncher, "Punch action called without SAO");
12891290

1290-
// No effect if PvP disabled
1291-
if (!g_settings->getBool("enable_pvp")) {
1291+
// No effect if PvP disabled or if immortal
1292+
if (isImmortal() || !g_settings->getBool("enable_pvp")) {
12921293
if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
12931294
std::string str = gob_cmd_punched(getHP());
12941295
// create message and add to list

‎src/content_sao.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ class UnitSAO: public ServerActiveObject
4545

4646
inline bool isAttached() const
4747
{ return getParent(); }
48+
4849
inline bool isImmortal() const
49-
{ return itemgroup_get(m_armor_groups, "immortal"); }
50+
{ return itemgroup_get(getArmorGroups(), "immortal"); }
5051

5152
void setArmorGroups(const ItemGroupList &armor_groups);
52-
const ItemGroupList &getArmorGroups();
53+
const ItemGroupList &getArmorGroups() const;
5354
void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop);
5455
void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop);
5556
void setAnimationSpeed(float frame_speed);
@@ -107,31 +108,32 @@ class LuaEntitySAO : public UnitSAO
107108
{
108109
public:
109110
LuaEntitySAO(ServerEnvironment *env, v3f pos,
110-
const std::string &name, const std::string &state);
111+
const std::string &name, const std::string &state);
111112
~LuaEntitySAO();
112113
ActiveObjectType getType() const
113114
{ return ACTIVEOBJECT_TYPE_LUAENTITY; }
114115
ActiveObjectType getSendType() const
115116
{ return ACTIVEOBJECT_TYPE_GENERIC; }
116117
virtual void addedToEnvironment(u32 dtime_s);
117118
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
118-
const std::string &data);
119+
const std::string &data);
119120
void step(float dtime, bool send_recommended);
120121
std::string getClientInitializationData(u16 protocol_version);
121122
bool isStaticAllowed() const
122123
{ return m_prop.static_save; }
123124
void getStaticData(std::string *result) const;
124125
int punch(v3f dir,
125-
const ToolCapabilities *toolcap=NULL,
126-
ServerActiveObject *puncher=NULL,
127-
float time_from_last_punch=1000000);
126+
const ToolCapabilities *toolcap = nullptr,
127+
ServerActiveObject *puncher = nullptr,
128+
float time_from_last_punch = 1000000);
128129
void rightClick(ServerActiveObject *clicker);
129130
void setPos(const v3f &pos);
130131
void moveTo(v3f pos, bool continuous);
131132
float getMinimumSavedMovement();
132133
std::string getDescription();
133134
void setHP(s32 hp, const PlayerHPChangeReason &reason);
134135
u16 getHP() const;
136+
135137
/* LuaEntitySAO-specific */
136138
void setVelocity(v3f velocity);
137139
void addVelocity(v3f velocity)

‎src/server.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ void Server::SendPlayerHPOrDie(PlayerSAO *playersao, const PlayerHPChangeReason
14291429
if (playersao->isImmortal())
14301430
return;
14311431

1432-
session_t peer_id = playersao->getPeerID();
1432+
session_t peer_id = playersao->getPeerID();
14331433
bool is_alive = playersao->getHP() > 0;
14341434

14351435
if (is_alive)

0 commit comments

Comments
 (0)
Please sign in to comment.