From b7bab11c3b4a619b1ebd27245375a1aea4183bcf Mon Sep 17 00:00:00 2001 From: Anand S Date: Sun, 18 Nov 2018 18:45:32 +0530 Subject: [PATCH] Add medkits, remove apples --- mods/ctf/ctf_inventory/init.lua | 2 +- mods/ctf/ctf_treasure/init.lua | 2 +- mods/mtg/default/aliases.lua | 3 +- mods/mtg/default/mapgen.lua | 1 - mods/mtg/default/nodes.lua | 57 +-------- mods/other/random_messages/init.lua | 3 +- mods/other/sprint/depends.txt | 1 + mods/other/sprint/init.lua | 9 +- mods/pvp/medkits/init.lua | 121 ++++++++++++++++++++ mods/pvp/medkits/textures/medkit_hud.png | Bin 0 -> 1196 bytes mods/pvp/medkits/textures/medkit_medkit.png | Bin 0 -> 582 bytes 11 files changed, 134 insertions(+), 65 deletions(-) create mode 100644 mods/pvp/medkits/init.lua create mode 100644 mods/pvp/medkits/textures/medkit_hud.png create mode 100644 mods/pvp/medkits/textures/medkit_medkit.png diff --git a/mods/ctf/ctf_inventory/init.lua b/mods/ctf/ctf_inventory/init.lua index 662eb43..2a346cf 100644 --- a/mods/ctf/ctf_inventory/init.lua +++ b/mods/ctf/ctf_inventory/init.lua @@ -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", diff --git a/mods/ctf/ctf_treasure/init.lua b/mods/ctf/ctf_treasure/init.lua index 7a5c1c5..c432995 100644 --- a/mods/ctf/ctf_treasure/init.lua +++ b/mods/ctf/ctf_treasure/init.lua @@ -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 diff --git a/mods/mtg/default/aliases.lua b/mods/mtg/default/aliases.lua index 6db3fc8..14d6879 100644 --- a/mods/mtg/default/aliases.lua +++ b/mods/mtg/default/aliases.lua @@ -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") diff --git a/mods/mtg/default/mapgen.lua b/mods/mtg/default/mapgen.lua index 6e0a4d8..dd713ad 100644 --- a/mods/mtg/default/mapgen.lua +++ b/mods/mtg/default/mapgen.lua @@ -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") diff --git a/mods/mtg/default/nodes.lua b/mods/mtg/default/nodes.lua index 85893d5..e1b7b15 100644 --- a/mods/mtg/default/nodes.lua +++ b/mods/mtg/default/nodes.lua @@ -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, }) diff --git a/mods/other/random_messages/init.lua b/mods/other/random_messages/init.lua index 8d88b4c..972bffa 100644 --- a/mods/other/random_messages/init.lua +++ b/mods/other/random_messages/init.lua @@ -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.", diff --git a/mods/other/sprint/depends.txt b/mods/other/sprint/depends.txt index 3e1d5c2..9f63eba 100644 --- a/mods/other/sprint/depends.txt +++ b/mods/other/sprint/depends.txt @@ -1 +1,2 @@ +medkits hudbars? diff --git a/mods/other/sprint/init.lua b/mods/other/sprint/init.lua index de4cadb..10f6bc9 100644 --- a/mods/other/sprint/init.lua +++ b/mods/other/sprint/init.lua @@ -28,8 +28,8 @@ local players = {} local function setSprinting(player, info, sprinting) if info.sprinting ~= sprinting then player:set_physics_override(SPRINT_MODIFIERS[sprinting]) + info.sprinting = sprinting end - info.sprinting = sprinting end minetest.register_globalstep(function(dtime) @@ -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 diff --git a/mods/pvp/medkits/init.lua b/mods/pvp/medkits/init.lua new file mode 100644 index 0000000..4d1c364 --- /dev/null +++ b/mods/pvp/medkits/init.lua @@ -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 +}) diff --git a/mods/pvp/medkits/textures/medkit_hud.png b/mods/pvp/medkits/textures/medkit_hud.png new file mode 100644 index 0000000000000000000000000000000000000000..e677630ac1db6a90042c64c38eca533ff9e2a76f GIT binary patch literal 1196 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!6#=yXs@#Xw?AcrO0(btiIVPik{pF~z5pDoGT z-G#x2;Sd9t*uJIgKoQOYkH}&M20djEW~^9hUj`IpFY)wsWq-uU%C4``U%*lUG)U9a z#WBP}kWr51;crHlwEyxzWeiLp0tE1gKolUUg$cm*zy#o?5ifvY223lA#xN5m0i!8b zFc{oGxi2U;fnYemf*co3&>{ifkP}!aUjOMWFU8GbZ8()Nlj2>E@cM*00F8=L_t(I%dL|!ZWKWf zMPK#I&LGydgb;}(4uC{xgouEv00}p6z&crH7DwR%WY~9bMubCTiN#`Px4Y^S^fJ3b zmJ{f#t5yI1`o9|f@z`y}b}psOi#9b0%FOIefbLY9BzW~$nAIj1)C-(nK@P|twm`Pq z{Prn?D(68DT>=LNH-0W*U=m!TaaNepj3ONo72K2}3a!gZOwMAjWt`4@wx>Aykol6P z@2J2Geib-7ugwR&n7uY6as1i2UW$-mA=YJQXP~n74Gh`1S-~=c?;As@#$GSQw}og- z^k%HXh}{u9jN(?e^R`u