The functions don`t work.
- Andrey01
- Member
- Posts: 2577
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
The functions don`t work.
Why do minetest.hud_replace_builtin and player:set_physics_override() not work to me? When i tried to call first function it just removed current healthbar and did not add new one. Second function doesn`t work at all.
- Tmanyo
- Member
- Posts: 196
- Joined: Mon Sep 29, 2014 01:20
- GitHub: Tmanyo
- IRC: Tmanyo
- In-game: tmanyo
- Location: United States
- Contact:
Re: The functions don`t work.
For the set_physics_override function did you look in the API for how it is to be done? player:set_physics_override
I was able to get this to work:
The "player" needs to be userdata, not a name.
Did you provide a valid replacement HUD definition for this function? minetest.hud_replace_builtin
I was able to get this to work:
Code: Select all
player:set_physics_override({speed=2,jump=2})
Did you provide a valid replacement HUD definition for this function? minetest.hud_replace_builtin
Tmanyo
http://www.rrhmsservers.ml
Servers I Host:
Tmanyo-Realism
Mods of mine that I don't totally hate:
Bank Accounts
T-Rating
Tmusic Player
http://www.rrhmsservers.ml
Servers I Host:
Tmanyo-Realism
Mods of mine that I don't totally hate:
Bank Accounts
T-Rating
Tmusic Player
- Andrey01
- Member
- Posts: 2577
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Re: The functions don`t work.
Here is how i wrote:Tmanyo wrote:For the set_physics_override function did you look in the API for how it is to be done? player:set_physics_override
I was able to get this to work:The "player" needs to be userdata, not a name.Code: Select all
player:set_physics_override({speed=2,jump=2})
Did you provide a valid replacement HUD definition for this function? minetest.hud_replace_builtin
Code: Select all
local player = minetest.get_player_by_name(playername)
player:set_physics_override({speed = 0.4,
jump = 0.4})
Replacement HUD definition is valid exactly, because one member suggested correct example (Krock, kinda) to me and I just added new field "text = "poisonous_heart.png".
- Tmanyo
- Member
- Posts: 196
- Joined: Mon Sep 29, 2014 01:20
- GitHub: Tmanyo
- IRC: Tmanyo
- In-game: tmanyo
- Location: United States
- Contact:
Re: The functions don`t work.
Is the playername in the function minetest.get_player_by_name() a correct player name? How are you calling this function? What is the trigger?Andrey01 wrote:Here is how i wrote:Tmanyo wrote:For the set_physics_override function did you look in the API for how it is to be done? player:set_physics_override
I was able to get this to work:The "player" needs to be userdata, not a name.Code: Select all
player:set_physics_override({speed=2,jump=2})
Did you provide a valid replacement HUD definition for this function? minetest.hud_replace_builtinBut it did not work.Code: Select all
local player = minetest.get_player_by_name(playername) player:set_physics_override({speed = 0.4, jump = 0.4})
Replacement HUD definition is valid exactly, because one member suggested correct example (Krock, kinda) to me and I just added new field "text = "poisonous_heart.png".
Tmanyo
http://www.rrhmsservers.ml
Servers I Host:
Tmanyo-Realism
Mods of mine that I don't totally hate:
Bank Accounts
T-Rating
Tmusic Player
http://www.rrhmsservers.ml
Servers I Host:
Tmanyo-Realism
Mods of mine that I don't totally hate:
Bank Accounts
T-Rating
Tmusic Player
- Andrey01
- Member
- Posts: 2577
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Re: The functions don`t work.
Here is a part of the code where it is shown how i call the function:Tmanyo wrote:Is the playername in the function minetest.get_player_by_name() a correct player name? How are you calling this function? What is the trigger?Andrey01 wrote:Here is how i wrote:Tmanyo wrote:For the set_physics_override function did you look in the API for how it is to be done? player:set_physics_override
I was able to get this to work:The "player" needs to be userdata, not a name.Code: Select all
player:set_physics_override({speed=2,jump=2})
Did you provide a valid replacement HUD definition for this function? minetest.hud_replace_builtinBut it did not work.Code: Select all
local player = minetest.get_player_by_name(playername) player:set_physics_override({speed = 0.4, jump = 0.4})
Replacement HUD definition is valid exactly, because one member suggested correct example (Krock, kinda) to me and I just added new field "text = "poisonous_heart.png".
Code: Select all
function effects.create_poisoning_effect(playername, effect_time) -- Not whole function definition
active_effects["poisoning_effect"] = true
local player = minetest.get_player_by_name(playername)
minetest.hud_replace_builtin("health", {
hud_elem_type = "statbar",
position = {x = 0.5, y = 1},
text = "poisonous_heart.png",
number = core.PLAYER_MAX_HP_DEFAULT,
direction = 0,
size = {x = 24, y = 24},
offset = {x = (-10*24) - 25, y = -(48 + 24 + 16)}
})
player:set_physics_override({
speed = 0.4,
jump = 0.4,
gravity = 1.0,
sneak = true,
sneak_glitch = false
})
end
minetest.register_craftitem("medicine:toxic_apple", {
description = "Toxic Apple",
inventory_image = "toxic_apple.png",
on_use = function (itemstack, user, pointed_thing)
itemstack:take_item()
return itemstack, effects.create_poisoning_effect(user:get_player_name(), 10)
end
})
Re: The functions don`t work.
I do something similar (sorry, bad indentation due to copy/paste):
But one day I installed a mod and it stopped working. This mod was using set_physics_override() like me in global_step(), but it wasn't immediately obvious it would do that sort of thing.
Code: Select all
minetest.register_globalstep(function(dtime)
--Loop through all connected players
for playerName,playerInfo in pairs(players) do
local player = minetest.get_player_by_name(playerName)
if player ~= nil then
local physics=player:get_physics_override()
if (player:get_player_control_bits()%32>=16) and playerInfo.energy>dtime then
physics.gravity=0
playerInfo.energy=math.max(playerInfo.energy-dtime*2, 0)
else
physics.gravity=1 -- math.min(0.8, physics.gravity+0.2)
if playerInfo.energy < MAX_ENERGY then
playerInfo.energy=math.min(playerInfo.energy+dtime/2, MAX_ENERGY)
end
end
player:set_physics_override(physics)
--Update the players's hud energy
hb.change_hudbar(player, "energy", math.max(0,playerInfo.energy))
end
end
end
- Tmanyo
- Member
- Posts: 196
- Joined: Mon Sep 29, 2014 01:20
- GitHub: Tmanyo
- IRC: Tmanyo
- In-game: tmanyo
- Location: United States
- Contact:
Re: The functions don`t work.
I suggest removing the ":get_player_name()" from when you call the function in "minetest.register_craftitem". Also remove the line where you get the player from a name. It is an unneeded step. Maybe you should try just returning the itemstack. Then call the function before you return the itemstack.Here is a part of the code where it is shown how i call the function:Code: Select all
function effects.create_poisoning_effect(playername, effect_time) -- Not whole function definition active_effects["poisoning_effect"] = true local player = minetest.get_player_by_name(playername) minetest.hud_replace_builtin("health", { hud_elem_type = "statbar", position = {x = 0.5, y = 1}, text = "poisonous_heart.png", number = core.PLAYER_MAX_HP_DEFAULT, direction = 0, size = {x = 24, y = 24}, offset = {x = (-10*24) - 25, y = -(48 + 24 + 16)} }) player:set_physics_override({ speed = 0.4, jump = 0.4, gravity = 1.0, sneak = true, sneak_glitch = false }) end minetest.register_craftitem("medicine:toxic_apple", { description = "Toxic Apple", inventory_image = "toxic_apple.png", on_use = function (itemstack, user, pointed_thing) itemstack:take_item() return itemstack, effects.create_poisoning_effect(user:get_player_name(), 10) end })
Tmanyo
http://www.rrhmsservers.ml
Servers I Host:
Tmanyo-Realism
Mods of mine that I don't totally hate:
Bank Accounts
T-Rating
Tmusic Player
http://www.rrhmsservers.ml
Servers I Host:
Tmanyo-Realism
Mods of mine that I don't totally hate:
Bank Accounts
T-Rating
Tmusic Player
- Andrey01
- Member
- Posts: 2577
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Re: The functions don`t work.
But why? Then player:set_physics_override() won`t work. And why do i need to return just the itemstack?Tmanyo wrote:I suggest removing the ":get_player_name()" from when you call the function in "minetest.register_craftitem". Also remove the line where you get the player from a name. It is an unneeded step. Maybe you should try just returning the itemstack. Then call the function before you return the itemstack.Here is a part of the code where it is shown how i call the function:Code: Select all
function effects.create_poisoning_effect(playername, effect_time) -- Not whole function definition active_effects["poisoning_effect"] = true local player = minetest.get_player_by_name(playername) minetest.hud_replace_builtin("health", { hud_elem_type = "statbar", position = {x = 0.5, y = 1}, text = "poisonous_heart.png", number = core.PLAYER_MAX_HP_DEFAULT, direction = 0, size = {x = 24, y = 24}, offset = {x = (-10*24) - 25, y = -(48 + 24 + 16)} }) player:set_physics_override({ speed = 0.4, jump = 0.4, gravity = 1.0, sneak = true, sneak_glitch = false }) end minetest.register_craftitem("medicine:toxic_apple", { description = "Toxic Apple", inventory_image = "toxic_apple.png", on_use = function (itemstack, user, pointed_thing) itemstack:take_item() return itemstack, effects.create_poisoning_effect(user:get_player_name(), 10) end })
- Tmanyo
- Member
- Posts: 196
- Joined: Mon Sep 29, 2014 01:20
- GitHub: Tmanyo
- IRC: Tmanyo
- In-game: tmanyo
- Location: United States
- Contact:
Re: The functions don`t work.
I know for a fact that player:set_physics_override() does work. Maybe instead of returning the function alongside the itemstack, you should try calling the function before you return the itemstack. Do what you want. I am just experimenting to try to help.Andrey01 wrote:But why? Then player:set_physics_override() won`t work. And why do i need to return just the itemstack?
Tmanyo
http://www.rrhmsservers.ml
Servers I Host:
Tmanyo-Realism
Mods of mine that I don't totally hate:
Bank Accounts
T-Rating
Tmusic Player
http://www.rrhmsservers.ml
Servers I Host:
Tmanyo-Realism
Mods of mine that I don't totally hate:
Bank Accounts
T-Rating
Tmusic Player
- Andrey01
- Member
- Posts: 2577
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Re: The functions don`t work.
How will this code look like then? Write soTmanyo wrote:I know for a fact that player:set_physics_override() does work. Maybe instead of returning the function alongside the itemstack, you should try calling the function before you return the itemstack. Do what you want. I am just experimenting to try to help.Andrey01 wrote:But why? Then player:set_physics_override() won`t work. And why do i need to return just the itemstack?
Code: Select all
return effects.create_poisoning_effect(user:get_player_name(), 10), itemstack
- Tmanyo
- Member
- Posts: 196
- Joined: Mon Sep 29, 2014 01:20
- GitHub: Tmanyo
- IRC: Tmanyo
- In-game: tmanyo
- Location: United States
- Contact:
Re: The functions don`t work.
I have already recommended just returning the itemstack. If you call the functionAndrey01 wrote:/quote]
How will this code look like then? Write so?Code: Select all
return effects.create_poisoning_effect(user:get_player_name(), 10), itemstack
Code: Select all
effects.create_poisoning_effect(user:get_player_name(), 10)
Tmanyo
http://www.rrhmsservers.ml
Servers I Host:
Tmanyo-Realism
Mods of mine that I don't totally hate:
Bank Accounts
T-Rating
Tmusic Player
http://www.rrhmsservers.ml
Servers I Host:
Tmanyo-Realism
Mods of mine that I don't totally hate:
Bank Accounts
T-Rating
Tmusic Player
Who is online
Users browsing this forum: Bing [Bot] and 10 guests