I am trying to write a function that sets poisoning effect for my Medicine mod. I have some questions for it.
1. How to set time of how long effect will be last?
2.How to change standard heart bar to poisoned heart one? I assume i need to use minetest.hud_change(), but i don`t know what first arguement has to be.
3. How to change color of the screen while the effect is on?
Creating an effect in Minetest.
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
- Pyrollo
- Developer
- Posts: 385
- Joined: Mon Jan 08, 2018 15:14
- GitHub: pyrollo
- In-game: Naj
- Location: Paris
Re: Creating an effect in Minetest.
Try to use "player effects" mod that you can find on this forum
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Re: Creating an effect in Minetest.
I know this mod, but i would like to try to write the function myself. Do you know how to set time of how long will poison effect be last, how to change standard heart bar onto poison bar? (I want to change only textures, no creating new bar) and how to change screen color while the effect is on?Pyrollo wrote:Try to use "player effects" mod that you can find on this forum
- Krock
- Developer
- Posts: 4649
- Joined: Thu Oct 03, 2013 07:48
- GitHub: SmallJoker
- Location: Switzerland
- Contact:
Re: Creating an effect in Minetest.
You can either use "minetest.after" or register a globalstep. Here's a sample code how you can have effects that last multiple times, limited by time and/or by count. How you register the effects is up to you.Andrey01 wrote:Do you know how to set time of how long will poison effect be last
Code: Select all
-- Code entirely untested.
local effects = {}
--[[ Effects format
effects[player_name] = {
effect_name = "hurt",
count = 10, -- effect occurs 10 times (nil to disable)
max_time = 10, -- for how long maximal (nil to disable)
interval = 2.0, -- seconds
time = 0, -- "time = interval" to trigger instantly, then each 2s
data = {}, -- is passed as reference to trigger_effect
}
]]
local function trigger_effect(player_name, effect_name, effect_data)
-- if effect_name == "hurt" then ....
end
minetest.register_globalstep(function(dtime)
for name, def in pairs(effects) do
def.time = def.time + dtime
if def.time >= def.interval then
trigger_effect(name, def.effect_name, def.data)
def.time = def.time - def.interval
if def.count then -- limit by trigger count
def.count = def.count - 1
if def.count <= 0 then
-- Delete effect
effects[name] = nil
def = nil -- For later checks
end
end
end
if def and def.max_time then -- limit by time
def.max_time = def.max_time - dtime
if def.max_time <= 0 then
-- Delete effect
effects[name] = nil
def = nil -- For later checks
end
end
end -- for loop
end)
https://github.com/minetest/minetest/bl ... .txt#L3693Andrey01 wrote:how to change standard heart bar onto poison bar? (I want to change only textures, no creating new bar)
Code: Select all
minetest.hud_replace_builtin("health", {
-- Table def from here https://github.com/minetest/minetest/blob/master/builtin/game/statbars.lua#L6-L12
hud_elem_type = "statbar",
position = { x=0.5, y=1 },
text = "mymod_heart_unhealthy.png",
number = minetest.PLAYER_MAX_HP_DEFAULT or 20,
direction = 0,
size = { x=24, y=24 },
offset = { x=(-10*24)-25, y=-(48+24+16)},
})
With the current API you can only cause a red flashing screen when the player HP decreases.Andrey01 wrote:and how to change screen color while the effect is on?
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Re: Creating an effect in Minetest.
Thanks, Krock.
Who is online
Users browsing this forum: No registered users and 5 guests