|
@@ -51,11 +51,6 @@ bandages.delay_from_level = function(level)
|
|
|
return 0
|
|
|
end
|
|
|
|
|
|
-bandages.target_not_player = function(pname)
|
|
|
- minetest.chat_send_player(pname, "# Server: Target is not a player.")
|
|
|
- --easyvend.sound_error(pname)
|
|
|
-end
|
|
|
-
|
|
|
bandages.target_not_hurt = function(pname, tname)
|
|
|
minetest.chat_send_player(pname, "# Server: Player <" .. rename.gpn(tname) .. "> is not wounded.")
|
|
|
--easyvend.sound_error(pname)
|
|
@@ -163,92 +158,105 @@ end
|
|
|
|
|
|
|
|
|
|
|
|
+function bandages.heal_target(itemstack, user, target, level)
|
|
|
+ local pname = user:get_player_name()
|
|
|
+ local tname = target:get_player_name()
|
|
|
+ local hp = target:get_hp()
|
|
|
+ local hp_max = target:get_properties().hp_max
|
|
|
+
|
|
|
+ if hp >= hp_max then
|
|
|
+ return bandages.target_not_hurt(pname, tname)
|
|
|
+ end
|
|
|
+ if hp <= 0 then
|
|
|
+ return bandages.target_is_dead(pname, tname)
|
|
|
+ end
|
|
|
+ if hp < bandages.get_max_damage_for_level(level, hp, hp_max) then
|
|
|
+ return bandages.target_too_hurt(pname, tname, level)
|
|
|
+ end
|
|
|
+ if bandages.players[pname] or bandages.players[tname] then
|
|
|
+ return bandages.medkit_already_in_use(pname)
|
|
|
+ end
|
|
|
+
|
|
|
+ bandages.play_sound_effects(target:get_pos(), level)
|
|
|
+
|
|
|
+ bandages.players[tname] = {pos=target:get_pos()}
|
|
|
+ bandages.players[pname] = {pos=user:get_pos()}
|
|
|
+ minetest.after(bandages.delay_from_level(level), function()
|
|
|
+ local pos = bandages.players[tname].pos
|
|
|
+ bandages.players[tname] = nil
|
|
|
+ bandages.players[pname] = nil
|
|
|
+ local target = minetest.get_player_by_name(tname)
|
|
|
+ if not target or not target:is_player() then return end
|
|
|
+ if vector_distance(target:get_pos(), pos) > bandages.movement_limit_from_level(level) then
|
|
|
+ return bandages.target_moved_too_much(pname, tname)
|
|
|
+ end
|
|
|
+ -- Don't heal target if already dead.
|
|
|
+ -- This solves an exploit people have found.
|
|
|
+ if target:get_hp() == 0 then return end
|
|
|
+ target:set_hp(hp + bandages.hp_from_level(level))
|
|
|
+ bandages.player_bandages_target(pname, tname, target:get_hp(), hp_max)
|
|
|
+ end)
|
|
|
+
|
|
|
+ itemstack:take_item()
|
|
|
+ return itemstack
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function bandages.heal_self(itemstack, user, level)
|
|
|
+ local pname = user:get_player_name()
|
|
|
+ local hp = user:get_hp()
|
|
|
+ local hp_max = user:get_properties().hp_max
|
|
|
+
|
|
|
+ if hp >= hp_max then
|
|
|
+ return bandages.player_not_hurt(pname)
|
|
|
+ end
|
|
|
+ if hp <= 0 then
|
|
|
+ return bandages.player_is_dead(pname)
|
|
|
+ end
|
|
|
+ if hp < bandages.get_max_damage_for_level(level, hp, hp_max) then
|
|
|
+ return bandages.player_too_hurt(pname, level)
|
|
|
+ end
|
|
|
+ if bandages.players[pname] then
|
|
|
+ return bandages.medkit_already_in_use(pname)
|
|
|
+ end
|
|
|
+
|
|
|
+ bandages.play_sound_effects(user:get_pos(), level)
|
|
|
+
|
|
|
+ bandages.players[pname] = {pos=user:get_pos()}
|
|
|
+ minetest.after(bandages.delay_from_level(level), function()
|
|
|
+ local pos = bandages.players[pname].pos
|
|
|
+ bandages.players[pname] = nil
|
|
|
+ local user = minetest.get_player_by_name(pname)
|
|
|
+ if not user or not user:is_player() then return end
|
|
|
+ if vector_distance(user:get_pos(), pos) > bandages.movement_limit_from_level(level) then
|
|
|
+ return bandages.player_moved_too_much(pname)
|
|
|
+ end
|
|
|
+ -- Don't heal user if already dead.
|
|
|
+ -- This solves an exploit people have found.
|
|
|
+ if user:get_hp() == 0 then return end
|
|
|
+ user:set_hp(hp + bandages.hp_from_level(level))
|
|
|
+ bandages.player_bandages_self(pname, user:get_hp(), hp_max)
|
|
|
+ end)
|
|
|
+
|
|
|
+ itemstack:take_item()
|
|
|
+ return itemstack
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
bandages.use_bandage = function(itemstack, user, pointed_thing, level)
|
|
|
if not user or not user:is_player() then return end
|
|
|
- local pname = user:get_player_name()
|
|
|
|
|
|
if pointed_thing.type == "object" then
|
|
|
local target = pointed_thing.ref
|
|
|
if not target or not target:is_player() then
|
|
|
- return bandages.target_not_player(pname)
|
|
|
- end
|
|
|
- local tname = target:get_player_name()
|
|
|
- local hp = target:get_hp()
|
|
|
- local hp_max = target:get_properties().hp_max
|
|
|
-
|
|
|
- if hp >= hp_max then
|
|
|
- return bandages.target_not_hurt(pname, tname)
|
|
|
+ return bandages.heal_self(itemstack, user, level)
|
|
|
end
|
|
|
- if hp <= 0 then
|
|
|
- return bandages.target_is_dead(pname, tname)
|
|
|
- end
|
|
|
- if hp < bandages.get_max_damage_for_level(level, hp, hp_max) then
|
|
|
- return bandages.target_too_hurt(pname, tname, level)
|
|
|
- end
|
|
|
- if bandages.players[pname] or bandages.players[tname] then
|
|
|
- return bandages.medkit_already_in_use(pname)
|
|
|
- end
|
|
|
-
|
|
|
- bandages.play_sound_effects(target:get_pos(), level)
|
|
|
-
|
|
|
- bandages.players[tname] = {pos=target:get_pos()}
|
|
|
- bandages.players[pname] = {pos=user:get_pos()}
|
|
|
- minetest.after(bandages.delay_from_level(level), function()
|
|
|
- local pos = bandages.players[tname].pos
|
|
|
- bandages.players[tname] = nil
|
|
|
- bandages.players[pname] = nil
|
|
|
- local target = minetest.get_player_by_name(tname)
|
|
|
- if not target or not target:is_player() then return end
|
|
|
- if vector_distance(target:get_pos(), pos) > bandages.movement_limit_from_level(level) then
|
|
|
- return bandages.target_moved_too_much(pname, tname)
|
|
|
- end
|
|
|
- -- Don't heal target if already dead.
|
|
|
- -- This solves an exploit people have found.
|
|
|
- if target:get_hp() == 0 then return end
|
|
|
- target:set_hp(hp + bandages.hp_from_level(level))
|
|
|
- bandages.player_bandages_target(pname, tname, target:get_hp(), hp_max)
|
|
|
- end)
|
|
|
-
|
|
|
- itemstack:take_item()
|
|
|
- return itemstack
|
|
|
- else
|
|
|
- -- Otherwise, try to heal self.
|
|
|
- local hp = user:get_hp()
|
|
|
- local hp_max = user:get_properties().hp_max
|
|
|
|
|
|
- if hp >= hp_max then
|
|
|
- return bandages.player_not_hurt(pname)
|
|
|
- end
|
|
|
- if hp <= 0 then
|
|
|
- return bandages.player_is_dead(pname)
|
|
|
- end
|
|
|
- if hp < bandages.get_max_damage_for_level(level, hp, hp_max) then
|
|
|
- return bandages.player_too_hurt(pname, level)
|
|
|
- end
|
|
|
- if bandages.players[pname] then
|
|
|
- return bandages.medkit_already_in_use(pname)
|
|
|
- end
|
|
|
-
|
|
|
- bandages.play_sound_effects(user:get_pos(), level)
|
|
|
-
|
|
|
- bandages.players[pname] = {pos=user:get_pos()}
|
|
|
- minetest.after(bandages.delay_from_level(level), function()
|
|
|
- local pos = bandages.players[pname].pos
|
|
|
- bandages.players[pname] = nil
|
|
|
- local user = minetest.get_player_by_name(pname)
|
|
|
- if not user or not user:is_player() then return end
|
|
|
- if vector_distance(user:get_pos(), pos) > bandages.movement_limit_from_level(level) then
|
|
|
- return bandages.player_moved_too_much(pname)
|
|
|
- end
|
|
|
- -- Don't heal user if already dead.
|
|
|
- -- This solves an exploit people have found.
|
|
|
- if user:get_hp() == 0 then return end
|
|
|
- user:set_hp(hp + bandages.hp_from_level(level))
|
|
|
- bandages.player_bandages_self(pname, user:get_hp(), hp_max)
|
|
|
- end)
|
|
|
-
|
|
|
- itemstack:take_item()
|
|
|
- return itemstack
|
|
|
+ return bandages.heal_target(itemstack, user, target, level)
|
|
|
+ else
|
|
|
+ return bandages.heal_self(itemstack, user, level)
|
|
|
end
|
|
|
end
|
|
|
|