Changing max. player health

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Changing max. player health

by Wuzzy » Fri Jul 11, 2014 04:18

Hi.
I’m suggesting a Lua API feature which allows the modder to change the maximum health for players.
 

Ragnar
Member
 
Posts: 850
Joined: Thu Oct 25, 2012 15:19

Re: Changing max. player health

by Ragnar » Fri Jul 11, 2014 06:59

I think it's possible to change the HP to be over the max (20) directly (i think player.hp )
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: Changing max. player health

by Wuzzy » Fri Jul 11, 2014 12:42

No, this doesn’t work. There is no field “hp” in a player object; I checked it.
 

User avatar
Calinou
Member
 
Posts: 3124
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou

Re: Changing max. player health

by Calinou » Fri Jul 11, 2014 18:45

Reported here on GitHub.
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: Changing max. player health

by Wuzzy » Mon Jul 14, 2014 20:26

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

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
player:set_properties({hp_max=5})


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
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
player:set_properties({makes_footstep_sound=false})

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.
 

User avatar
DeepGaze
Member
 
Posts: 332
Joined: Fri May 10, 2013 00:49
GitHub: DeepGaze
IRC: DeepGaze
In-game: DeepGaze

Re: Changing max. player health

by DeepGaze » Mon Jul 14, 2014 21:24

@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)
there's no place like 127.0.0.1
The deep life Minetest text page
minetest cards
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

Re: Changing max. player health

by prestidigitator » Tue Jul 15, 2014 21:41

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).
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: Changing max. player health

by Wuzzy » Wed Jul 16, 2014 20:59

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.

prestidigitator wrote:what kind of API is this anyway?

Obviously an unfinished one. ;-)
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.
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 10 guests

cron