[DONE] Changing max. player health
- Wuzzy
- Member
- Posts: 4803
- Joined: Mon Sep 24, 2012 15:01
- GitHub: Wuzzy2
- IRC: Wuzzy
- In-game: Wuzzy
- Contact:
[DONE] Changing max. player health
Hi.
I’m suggesting a Lua API feature which allows the modder to change the maximum health for players.
I’m suggesting a Lua API feature which allows the modder to change the maximum health for players.
Last edited by Wuzzy on Tue Aug 27, 2019 18:44, edited 1 time in total.
Re: Changing max. player health
I think it's possible to change the HP to be over the max (20) directly (i think player.hp )
- Wuzzy
- Member
- Posts: 4803
- Joined: Mon Sep 24, 2012 15:01
- GitHub: Wuzzy2
- IRC: Wuzzy
- In-game: Wuzzy
- Contact:
Re: Changing max. player health
No, this doesn’t work. There is no field “hp” in a player object; I checked it.
- Calinou
- Moderator
- Posts: 3169
- Joined: Mon Aug 01, 2011 14:26
- GitHub: Calinou
- IRC: Calinou
- In-game: Calinou
- Location: Troyes, France
- Contact:
Re: Changing max. player health
Reported here on GitHub.
- Wuzzy
- Member
- Posts: 4803
- Joined: Mon Sep 24, 2012 15:01
- GitHub: Wuzzy2
- IRC: Wuzzy
- In-game: Wuzzy
- Contact:
Re: Changing max. player health
It seems that there is no need for new Lua code. Instead, the old one should just be fixed. Actually, I found this in lua_api.txt:
object:set_properties(object_properties_table)
Players are objects. The object properties table includes a field called “hp_max”. So I would expect that
sets the max HP to 5. But nothing happens. :/ If I have 1 HP, I can still heal myself up to full 20 HP.
I also noticed that
does not change anything.
is_visible=false does not work either. Yeah, it seems that some object properties can not be changed for players. Bug?
Actually, using a call like player:set_properties is not uncommon, it used serveral times in minetest_game/default/player.lua. But it is only used to set models and textures and stuff like that.
object:set_properties(object_properties_table)
Players are objects. The object properties table includes a field called “hp_max”. So I would expect that
Code: Select all
player:set_properties({hp_max=5})
I also noticed that
Code: Select all
player:set_properties({makes_footstep_sound=false})
is_visible=false does not work either. Yeah, it seems that some object properties can not be changed for players. Bug?
Actually, using a call like player:set_properties is not uncommon, it used serveral times in minetest_game/default/player.lua. But it is only used to set models and textures and stuff like that.
- DeepGaze
- Member
- Posts: 332
- Joined: Fri May 10, 2013 00:49
- GitHub: DeepGaze
- IRC: DeepGaze
- In-game: DeepGaze
- Location: Take your best guess
Re: Changing max. player health
@Wuzzy the heart issue is AFAIK where the engine edits "player.txt" if you shut down and edit the file in notepad/gedit the 100 hearts are listed as your health but if you heal at 99 it sets it to 20.
the sounds I have no idea towards, this is just experience and not where i understand the code(I don't understand C)
the sounds I have no idea towards, this is just experience and not where i understand the code(I don't understand C)
-
- Member
- Posts: 647
- Joined: Thu Feb 21, 2013 23:54
Re: Changing max. player health
Poking around in the source code, it appears you can set the "hp_max" property on any object, whether it is a player or not. However, the only time the "hp_max" property is actually used is when a new non-player object is first added to the environment. You can even set such an object's HPs above this "maximum" without any kind of checks at all. It's not really a maximum, it is an initial/default value. It should have been called "initial_hp" or something. In fact, seeing as there is apparently no way to get properties (what kind of API is this anyway?), not even Lua can use the "hp_max" property to do bounds checking.
As for player objects, they have a compile-time constant (#define'd even) PLAYER_MAX_HP with a value of 20 that serves as both an initial value for HPs and as an absolute maximum. The "hp_max" property exists for player objects, but isn't used at all (other than being initialized to PLAYER_MAX_HP when the object is created). The somewhat good news, I guess, is that it appears clients will respect whatever value is set on the server, so if you wanted to build a custom server with a new value for PLAYER_MAX_HP, or one that used the "hp_max" property instead even, existing clients should work fine. You're just out of luck trying to do anything from mod code.
By the way, changing the server code to use something more dynamic like the "hp_max" object property appears like it would be pretty darned trivial, for anyone who wants to try to get a pull request past the dev team (hint: PlayerSAO::setHP(s16) in content_sao.cpp and Server::RespawnPlayer(u16) in server.cpp).
As for player objects, they have a compile-time constant (#define'd even) PLAYER_MAX_HP with a value of 20 that serves as both an initial value for HPs and as an absolute maximum. The "hp_max" property exists for player objects, but isn't used at all (other than being initialized to PLAYER_MAX_HP when the object is created). The somewhat good news, I guess, is that it appears clients will respect whatever value is set on the server, so if you wanted to build a custom server with a new value for PLAYER_MAX_HP, or one that used the "hp_max" property instead even, existing clients should work fine. You're just out of luck trying to do anything from mod code.
By the way, changing the server code to use something more dynamic like the "hp_max" object property appears like it would be pretty darned trivial, for anyone who wants to try to get a pull request past the dev team (hint: PlayerSAO::setHP(s16) in content_sao.cpp and Server::RespawnPlayer(u16) in server.cpp).
- Wuzzy
- Member
- Posts: 4803
- Joined: Mon Sep 24, 2012 15:01
- GitHub: Wuzzy2
- IRC: Wuzzy
- In-game: Wuzzy
- Contact:
Re: Changing max. player health
Prestidigitator, I thank you for your insights. So, first of all, I stick to my initial suggestion, of course. :=)
Using name “hp_max” for something which isn’t actually the maximum HP is pretty stupid. Also putting initial HP and maximum HP into the same bucket is not the smartest move either. It’s annoying but not really serious, because it can be worked around by immediately calling set_hp after creating the object.
If I understood correctly, the problem here is that the max HP can not be changed after creation. But then the question arises why hp_max is even in set_properties then. It looks like some API cleanup is needed. The tricky part is the question how to do it without breaking anything.
As for your complaint about get_properties being not existant. I filed an issue on GitHub. I noticed that there are quite some missing getter functions.
Using name “hp_max” for something which isn’t actually the maximum HP is pretty stupid. Also putting initial HP and maximum HP into the same bucket is not the smartest move either. It’s annoying but not really serious, because it can be worked around by immediately calling set_hp after creating the object.
If I understood correctly, the problem here is that the max HP can not be changed after creation. But then the question arises why hp_max is even in set_properties then. It looks like some API cleanup is needed. The tricky part is the question how to do it without breaking anything.
Obviously an unfinished one. ;-)prestidigitator wrote:what kind of API is this anyway?
As for your complaint about get_properties being not existant. I filed an issue on GitHub. I noticed that there are quite some missing getter functions.
-
- New member
- Posts: 1
- Joined: Tue Aug 27, 2019 18:14
- GitHub: Blue-Tech-PS
- IRC: Blue0Tech
- In-game: Blue0Tech
Re: Changing max. player health
Guys, I've got half the solution.
~/minetest means the minetest folder
I found PLAYER_MAX_HP_DEFAULT = 20 in ~/minetest/builtin/game/constants.lua
However, the file is Read-Only, and I cannot find out how to change permissions, even when I launch nautilus as root with sudo from gnome-terminal (I am on Ubuntu 18.04.3lts x64). Can anyone help me change permissions? Or do I have to copy the rest of the program and make another minetest folder with slight changes to increase maximum health?
Edit: Not the minetest folder in /Home/user/snap/minetest, but the /snap/minetest in the filesystem root. On Windows, there is just 1 minetest directory, so there is not a problem finding the builtin directory there.
Another edit: Wrong folder, the folder is in ~/minetest/builtin/share/minetest/game/constants.lua or something like that, I'll will edit later today to get the correct folder.
~/minetest means the minetest folder
I found PLAYER_MAX_HP_DEFAULT = 20 in ~/minetest/builtin/game/constants.lua
However, the file is Read-Only, and I cannot find out how to change permissions, even when I launch nautilus as root with sudo from gnome-terminal (I am on Ubuntu 18.04.3lts x64). Can anyone help me change permissions? Or do I have to copy the rest of the program and make another minetest folder with slight changes to increase maximum health?
Edit: Not the minetest folder in /Home/user/snap/minetest, but the /snap/minetest in the filesystem root. On Windows, there is just 1 minetest directory, so there is not a problem finding the builtin directory there.
Another edit: Wrong folder, the folder is in ~/minetest/builtin/share/minetest/game/constants.lua or something like that, I'll will edit later today to get the correct folder.
Last edited by Blue0Tech on Wed Aug 28, 2019 08:08, edited 1 time in total.
- Wuzzy
- Member
- Posts: 4803
- Joined: Mon Sep 24, 2012 15:01
- GitHub: Wuzzy2
- IRC: Wuzzy
- In-game: Wuzzy
- Contact:
Re: [DONE] Changing max. player health
This feature is implemented in version 5.0.0.
Who is online
Users browsing this forum: No registered users and 6 guests