Add medkits, remove apples

This commit is contained in:
Anand S 2018-11-18 18:45:32 +05:30 committed by rubenwardy
parent 3e57880520
commit b7bab11c3b
11 changed files with 134 additions and 65 deletions

View file

@ -5,7 +5,7 @@ local items = {
" running and punching your team's flag.",
"* Look for weapons and other resources in chests, or mine and use furnaces to make swords.",
"* Good swords do more damage than guns, but need to be used at close range.",
"* Use apples to replenish health quickly.",
"* Use medkits to replenish health gradually.",
"* Gain more score by killing more than you die, or by capturing the flag.",
"* Players are immune for 10 seconds after they respawn.",
"* Access the pro section of the chest by achieving a 2k+ score and",

View file

@ -4,7 +4,6 @@ function ctf_treasure.register_default_treasures()
treasurer.register_treasure("default:ladder",0.3,5,{1,20})
treasurer.register_treasure("default:torch",0.3,5,{1,20})
treasurer.register_treasure("default:cobble",0.4,5,{45,99})
treasurer.register_treasure("default:apple",0.3,5,{1,8})
treasurer.register_treasure("default:wood",0.3,5,{30,60})
treasurer.register_treasure("doors:door_steel",0.3,5,{1,3})
@ -24,4 +23,5 @@ function ctf_treasure.register_default_treasures()
treasurer.register_treasure("shooter:arrow_white",0.5,2,{2,18})
treasurer.register_treasure("ctf_bandages:bandage",0.3,5,{1,6})
treasurer.register_treasure("medkits:medkit",0.8,5,{2,4})
end

View file

@ -40,7 +40,6 @@ minetest.register_alias("cobble", "default:cobble")
minetest.register_alias("mossycobble", "default:mossycobble")
minetest.register_alias("steelblock", "default:steelblock")
minetest.register_alias("sapling", "default:sapling")
minetest.register_alias("apple", "default:apple")
minetest.register_alias("WPick", "default:pick_wood")
minetest.register_alias("STPick", "default:pick_stone")
@ -75,3 +74,5 @@ minetest.register_alias("default:pinewood", "default:pine_wood")
minetest.register_alias("default:ladder", "default:ladder_wood")
minetest.register_alias("default:sign_wall", "default:sign_wall_wood")
minetest.register_alias("default:apple", "air")

View file

@ -22,7 +22,6 @@ minetest.register_alias("mapgen_sandstone", "default:sandstone")
minetest.register_alias("mapgen_tree", "default:tree")
minetest.register_alias("mapgen_leaves", "default:leaves")
minetest.register_alias("mapgen_apple", "default:apple")
minetest.register_alias("mapgen_jungletree", "default:jungletree")
minetest.register_alias("mapgen_jungleleaves", "default:jungleleaves")
minetest.register_alias("mapgen_junglegrass", "default:junglegrass")

View file

@ -78,7 +78,6 @@ default:tree
default:wood
default:leaves
default:sapling
default:apple
default:jungletree
default:junglewood
@ -728,58 +727,6 @@ minetest.register_node("default:leaves", {
after_place_node = default.after_place_leaves,
})
minetest.register_node("default:apple", {
description = "Apple",
drawtype = "plantlike",
tiles = {"default_apple.png"},
inventory_image = "default_apple.png",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
is_ground_content = false,
selection_box = {
type = "fixed",
fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
},
groups = {fleshy = 3, dig_immediate = 3, flammable = 2,
leafdecay = 3, leafdecay_drop = 1, food_apple = 1},
on_use = minetest.item_eat(2),
sounds = default.node_sound_leaves_defaults(),
after_place_node = function(pos, placer, itemstack)
minetest.set_node(pos, {name = "default:apple", param2 = 1})
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if oldnode.param2 == 0 then
minetest.set_node(pos, {name = "default:apple_mark"})
minetest.get_node_timer(pos):start(math.random(300, 1500))
end
end,
})
minetest.register_node("default:apple_mark", {
description = "Apple Marker",
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
groups = {not_in_creative_inventory = 1},
on_timer = function(pos, elapsed)
if not minetest.find_node_near(pos, 1, "default:leaves") then
minetest.remove_node(pos)
elseif minetest.get_node_light(pos) < 11 then
minetest.get_node_timer(pos):start(200)
else
minetest.set_node(pos, {name = "default:apple"})
end
end
})
minetest.register_node("default:jungletree", {
description = "Jungle Tree",
@ -2849,7 +2796,7 @@ minetest.register_node("default:cloud", {
if minetest.get_mapgen_setting("mg_name") == "v6" then
default.register_leafdecay({
trunks = {"default:tree"},
leaves = {"default:apple", "default:leaves"},
leaves = {"default:leaves"},
radius = 2,
})
@ -2861,7 +2808,7 @@ if minetest.get_mapgen_setting("mg_name") == "v6" then
else
default.register_leafdecay({
trunks = {"default:tree"},
leaves = {"default:apple", "default:leaves"},
leaves = {"default:leaves"},
radius = 3,
})

View file

@ -48,7 +48,8 @@ end
function random_messages.read_messages()
random_messages.messages = {
"To talk to only your team, start your messages with /t. For example, /t Hello team!",
"Eat apples to restore health quickly.",
"Use medkits to gradually restore your health.",
"Moving or fighting while healing will interrupt the healing process.",
"Steel swords do more damage than guns, but you need to be up close.",
"Gain more score by killing more than you die, or by capturing the flag.",
"You gain more score the better the opponent you defeat.",

View file

@ -1 +1,2 @@
medkits
hudbars?

View file

@ -28,9 +28,9 @@ local players = {}
local function setSprinting(player, info, sprinting)
if info.sprinting ~= sprinting then
player:set_physics_override(SPRINT_MODIFIERS[sprinting])
end
info.sprinting = sprinting
end
end
minetest.register_globalstep(function(dtime)
for name, info in pairs(players) do
@ -46,11 +46,10 @@ minetest.register_globalstep(function(dtime)
local sprintRequested = controls.aux1 and controls.up
-- ##1## replace info.sprintRequested with info.sprinting
if sprintRequested ~= info.sprintRequested then
if sprintRequested and info.stamina > MIN_SPRINT then
if sprintRequested and info.stamina > MIN_SPRINT
and not is_healing(player:get_player_name()) then
setSprinting(player, info, true)
end
if not sprintRequested then
elseif not sprintRequested then
setSprinting(player, info, false)
end
end

121
mods/pvp/medkits/init.lua Normal file
View file

@ -0,0 +1,121 @@
-- Table of tables indexed by player names, each having three fields:
-- * HP at time of left-click + regen_max,
-- * Max HP of player (generally 20)
-- * ID of "healing effect" HUD element
local players = {}
local regen_max = 6 -- Max HP provided by one medkit
local regen_interval = 0.5 -- Time in seconds between each iteration
local regen_timer = 0 -- Timer to keep track of regen_interval
local regen_step = 1 -- Number of HP added every iteration
-- Boolean function for use by other mods to check if a player is healing
function is_healing(name)
return players[name] and true or false
end
-- Called when player uses a medkit
-- Aborts if player is already healing
local function start_healing(stack, player)
if not player then
return stack
end
local name = player:get_player_name()
if players[name] or player:get_hp() >= 20 then
return stack
end
players[name] = {
pos = player:get_pos(),
target = player:get_hp() + regen_max,
hud = player:hud_add({
hud_elem_type = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -100, y = -100},
text = "medkit_hud.png"
})
}
stack:take_item()
return stack
end
-- Called after regen is complete. Remove additional effects
-- If interrupted == true, revert to original HP and give back one medkit.
local function stop_healing(player, interrupted)
local name = player:get_player_name()
local info = players[name]
players[name] = nil
if interrupted then
minetest.chat_send_player(name, minetest.colorize("#FF4444",
"Your healing was interrupted!"))
player:set_hp(info.target - regen_max)
player:get_inventory():add_item("main", ItemStack("medkits:medkit 1"))
end
player:hud_remove(info.hud)
end
-- Called after left-click every n seconds (determined by regen_interval)
-- heals player for a total of regen_max, limited by player's max hp
minetest.register_globalstep(function(dtime)
regen_timer = regen_timer + dtime
if regen_timer < regen_interval then
return
end
for name, info in pairs(players) do
local player = minetest.get_player_by_name(name)
if not player then
players[name] = nil
else
-- Abort if player moves more than 1m in any direction to
-- allow players to manually interrupt healing if necessary
local pos = player:get_pos()
if vector.distance(pos, info.pos) >= 1 then
stop_healing(player, true)
end
-- Stop healing if target reached
local hp = player:get_hp()
if hp < info.target and hp < 20 then
player:set_hp(hp + regen_step)
else
stop_healing(player)
end
end
end
regen_timer = 0
end)
-- If player takes damage while healing,
-- stop regen and revert back to original state
minetest.register_on_player_hpchange(function(player, hp, reason)
if hp < 0 then
if players[player:get_player_name()] then
stop_healing(player, true)
end
if reason and reason.type == "punch" then
local hitter = reason.object
if hitter and players[hitter:get_player_name()] then
stop_healing(hitter, true)
end
end
end
return hp
end, true)
minetest.register_on_leaveplayer(function(player)
players[player:get_player_name()] = nil
end)
minetest.register_craftitem("medkits:medkit", {
description = "Medkit",
inventory_image = "medkit_medkit.png",
wield_image = "medkit_medkit.png",
stack_max = 10,
on_use = start_healing
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B