diff --git a/README.md b/README.md index eeee287..39bf73e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ Note: features are subject to change. This mod is WIP and may not be useable in it's current state. Intructions on use will come further in development. +if you wish to help with this project please let me know. Planned features: diff --git a/body.lua b/body.lua index 581a4bf..4803479 100644 --- a/body.lua +++ b/body.lua @@ -12,18 +12,18 @@ minetest.register_entity("medical:body", { on_activate = function(self, staticdata, dtime_s) self.object:set_animation({x=162,y=167}, 1) self.object:set_armor_groups({immortal = 1}) - self.object:set_yaw(math.random(math.pi*-1, math.pi)) + self.object:set_yaw(math.random(-math.pi, math.pi)) end, --[[get_staticdata = function(self) - --return minetest.serialize({owner = self.owner, sleeping = self.sleeping, expiretime = self.time, mesh = self.mesh, textures = self.textures, yaw = self.yaw, inv = serializeContents(self.inv)}) + --return end,--]] on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir) if not puncher:is_player() then return end local wielditem = puncher:get_wielded_item() local wieldname = wielditem:get_name() - local hitloc = medical.gethitloc(self, puncher, tool_capabilities, dir) + local hitloc, local_hitloc = medical.gethitloc(self.object, puncher, tool_capabilities, dir) if medical.attachedtools[wieldname] then - medical.usedtools[wieldname](self, puncher, wielditem, hitloc) + medical.attachedtools[wieldname](self, puncher, wielditem, hitloc, local_hitloc) end -- attach things end, @@ -31,9 +31,9 @@ minetest.register_entity("medical:body", { if not clicker:is_player() then return end local wielditem = clicker:get_wielded_item() local wieldname = wielditem:get_name() - local hitloc = medical.gethitloc(self, clicker, nil, nil) - if medical.attachedtools[wieldname] then - medical.usedtools[wieldname](self, clicker, wielditem, hitloc) + local hitloc, local_hitloc = medical.gethitloc(self.object, clicker, nil, nil) + if medical.usedtools[wieldname] then + medical.usedtools[wieldname](self, clicker, wielditem, hitloc, local_hitloc) end -- use things end diff --git a/controls.lua b/controls.lua new file mode 100644 index 0000000..e3a230a --- /dev/null +++ b/controls.lua @@ -0,0 +1,23 @@ + +medical.lookingplayer = {} + +medical.registered_on_lookaway = {} +function medical.register_on_lookaway(func) + medical.registered_on_lookaway[#medical.registered_on_lookaway+1] = func +end +minetest.register_globalstep(function(dtime) + for name, table in pairs(medical.lookingplayer) do + originaldir = table.dir + originalpos = table.pos + local player = minetest.get_player_by_name(name) + if not player then medical.lookingplayer[name] = nil return end + local dir = player:get_look_dir() + local pos = player:get_pos() + if vector.distance(originalpos, pos) > .1 or vector.distance(originaldir, dir) > .05 then --gives just a little bit of room that player can look around + for _, func in pairs(medical.registered_on_lookaway) do + func(player, name) + end + medical.lookingplayer[name] = nil + end + end +end) \ No newline at end of file diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..0fb92fb --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +controls \ No newline at end of file diff --git a/hitloc.lua b/hitloc.lua index 55ba629..7fcdf76 100644 --- a/hitloc.lua +++ b/hitloc.lua @@ -76,6 +76,15 @@ function medical.gethitloc(player, hitter, tool_capabilities, dir) hitpos = pointed.intersection_point end end + local playeryaw + if player:is_player() then + playeryaw = player:get_look_horizontal() + else + playeryaw = player:get_yaw() + end + local loc = vector.subtract(hitpos, playerpos) + local x, z = rotateVector(loc.x, loc.z, -playeryaw) + local local_hitpos = {x=x,y=loc.y,z=z} if DEBUG_WAYPOINT then local marker = hitter:hud_add({ hud_elem_type = "waypoint", @@ -85,7 +94,24 @@ function medical.gethitloc(player, hitter, tool_capabilities, dir) }) minetest.after(10, function() hitter:hud_remove(marker) end, hitter, marker) end - return hitpos + return hitpos, local_hitpos +end + +function medical.getclosest(table, local_hitpos) + local distance + local closest + for name, loc in pairs (table) do + if not distance then + distance = vector.distance(loc, local_hitpos) + closest = name + else + if vector.distance(loc, local_hitpos) < distance then + distance = vector.distance(loc, local_hitpos) + closest = name + end + end + end + return distance, closest end function medical.getlimb(player, hitter, tool_capabilities, dir, hitloc) diff --git a/init.lua b/init.lua index 498c60a..6285c74 100644 --- a/init.lua +++ b/init.lua @@ -10,6 +10,9 @@ if not medical.data.injuries then medical.data.injuries = {} end local modpath = minetest.get_modpath(minetest.get_current_modname()) +dofile(modpath.."/timers.lua") +dofile(modpath.."/controls.lua") dofile(modpath.."/vitals.lua") dofile(modpath.."/hitloc.lua") -dofile(modpath.."/body.lua") \ No newline at end of file +dofile(modpath.."/body.lua") +dofile(modpath.."/tools.lua") \ No newline at end of file diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..2e98d1c --- /dev/null +++ b/license.txt @@ -0,0 +1,5 @@ +sounds: + human-heartbeat-daniel_simon: License: Attribution 3.0 Recorded by Daniel Simion + +code: CC-BY-SA +textures: CC-BY-SA \ No newline at end of file diff --git a/sounds/human-heartbeat-daniel_simon.ogg b/sounds/human-heartbeat-daniel_simon.ogg new file mode 100644 index 0000000..7c01bae Binary files /dev/null and b/sounds/human-heartbeat-daniel_simon.ogg differ diff --git a/textures/foundpulse.png b/textures/foundpulse.png new file mode 100644 index 0000000..c13c74e Binary files /dev/null and b/textures/foundpulse.png differ diff --git a/textures/nopulse.png b/textures/nopulse.png new file mode 100644 index 0000000..079e247 Binary files /dev/null and b/textures/nopulse.png differ diff --git a/timers.lua b/timers.lua new file mode 100644 index 0000000..6d7c84a --- /dev/null +++ b/timers.lua @@ -0,0 +1,46 @@ +medical.timers = {} + +function medical.start_timer(name, length, loop, arg, func) + local index + if name then + index = name + else + local i = 0 + while true do + if not medical.timers[i] then + index = i + break + end + i = i + 1 + end + end + medical.timers[index] = {} + medical.timers[index].length = length + medical.timers[index].timeleft = length + medical.timers[index].loop = loop + medical.timers[index].arg = arg + medical.timers[index].func = func + return index +end + +function medical.stop_timer(name, runonce) + local timer = medical.timers[name] + if runonce then + timer.func(timer.arg) + end + medical.timers[name] = nil +end + +minetest.register_globalstep(function(dtime) + for index, timer in pairs (medical.timers) do + timer.timeleft = timer.timeleft - dtime + if timer.timeleft <= 0 then + timer.func(timer.arg) + if timer.loop then + medical.start_timer(index, timer.length, timer.loop, timer.arg, timer.func) + else + medical.stoptimer(name) + end + end + end +end) \ No newline at end of file diff --git a/tools.lua b/tools.lua new file mode 100644 index 0000000..d7f9530 --- /dev/null +++ b/tools.lua @@ -0,0 +1,63 @@ +medical.hud = {} + +medical.usedtools[""] = function(self, clicker, wielditem, hitloc, local_hitloc) + local vitalpoints = {} + local playerpos = self.object:get_pos() + vitalpoints.cartoid = {x=0,y=.1,z=-.425} + vitalpoints.radialright = {x=.5,y=.1,z=-.05} + vitalpoints.radialleft = {x=-.5,y=.1,z=-.05} + vitalpoints.pedalright = {x=.20,y=.1,z=.7} + vitalpoints.pedalleft = {x=-.20,y=.1,z=.7} + local distance, hitpart = medical.getclosest(vitalpoints, local_hitloc) + if distance > .15 then return end + local cname = clicker:get_player_name() + if medical.hud[cname] then clicker:hud_remove(medical.hud[cname]) medical.hud[cname] = nil end + if not medical.lookingplayer[cname] then medical.lookingplayer[cname] = {dir = clicker:get_look_dir(), pos = clicker:get_pos()} end + medical.hud[cname] = clicker:hud_add({ + hud_elem_type = "image", + position = {x = 0.5, y = 0.55}, + offset = {x = 0, y = 0}, + text = "nopulse.png", + scale = { x = 10, y = 10}, + alignment = { x = 0, y = 0 }, + }) + medical.start_timer(cname.."pulsecheck", 60/medical.data.vitals[cname].pulse, true, cname, --todo: change this to give the patient's pulse instead of yours + function(arg) + minetest.sound_play("human-heartbeat-daniel_simon", { + pos = hitloc, + to_player = arg, + }) + local circle = clicker:hud_add({ + hud_elem_type = "image", + position = {x = 0.5, y = 0.55}, + offset = {x = 0, y = 0}, + text = "foundpulse.png", + scale = { x = 10, y = 10}, + alignment = { x = 0, y = 0 }, + }) + minetest.after(.15, function() + local hitter = minetest.get_player_by_name(cname) + if hitter then + hitter:hud_remove(circle) + end + end) + end + ) +end + +controls.register_on_release(function(player, key, time) + local name = player:get_player_name() + if key == "RMB" and medical.hud[name] then + player:hud_remove(medical.hud[name]) medical.hud[name] = nil + medical.lookingplayer[name] = nil + medical.stop_timer(name.."pulsecheck", false) + end +end) +medical.register_on_lookaway(function(player, name) + if medical.hud[name] then + player:hud_remove(medical.hud[name]) + medical.hud[name] = nil + medical.lookingplayer[name] = nil + medical.stop_timer(name.."pulsecheck", false) + end +end) \ No newline at end of file