-
-
Save Andrey2470T/b675bd69ac4069fe993a1c6008eb7aed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
misc = {} | |
saved_players_properties = {textures = {}, meshes = {}} | |
minetest.register_craftitem('medicine:alcohol_bottle', { | |
description = 'Alcohol Bottle', | |
inventory_image = 'alcohol_bottle.png', | |
stack_max = 99, | |
}) | |
minetest.register_craftitem("medicine:bandage", { | |
description = "Bandage", | |
inventory_image = "bandage.png", | |
on_use = function (itemstack, user, pointed_thing) | |
for _, texturename in ipairs(minetest.deserialize(user:get_meta():get_string("textures_list"))) do | |
if texturename == "^character_with_broken_hand.png" then | |
texture = texturename | |
return itemstack | |
end | |
end | |
if texture ~= "^character_with_broken_hand.png" then | |
return itemstack | |
else | |
misc.replace_player_texture(user, texture) | |
end | |
end | |
}) | |
minetest.register_craftitem("medicine:antiemetic_powder", { | |
description = "Antiemetic Powder", | |
inventory_image = "antiemetic_powder.png" | |
}) | |
minetest.register_craftitem('medicine:mask', { | |
description = 'Mask', | |
inventory_image = 'mask.png', | |
stack_max = 99, | |
}) | |
minetest.register_craftitem('medicine:headphones', { | |
description = 'Headphones', | |
inventory_image = 'headphones.png', | |
stack_max = 99, | |
}) | |
minetest.register_craftitem('medicine:pinceps', { | |
description = 'Pinceps', | |
inventory_image = 'pinceps.png', | |
stack_max = 99, | |
}) | |
minetest.register_craftitem('medicine:plaster', { | |
description = 'Plaster', | |
inventory_image = 'plaster.png', | |
stack_max = 99, | |
--on_use = function (itemstack, user, pointed_thing) | |
}) | |
function misc.replace_player_texture(player, texturename) | |
local player_textures_list = minetest.deserialize(player:get_meta():get_string("textures_list")) | |
if player_textures_list ~= {} or player_textures_list ~= nil then | |
if texturename == nil then | |
player_textures_list[#player_textures_list] = nil | |
elseif type(texturename) == "string" then | |
for texture_ind, texture_name in pairs(player_textures_list) do | |
if texture_name == texturename then | |
player_textures_list[texture_ind] = nil | |
end | |
end | |
else | |
return | |
end | |
player:get_meta():set_string("textures_list", player_textures_list) | |
local texture = player:get_meta():get_string("texture") | |
local textures = "" | |
for _, texture_name in ipairs(player_textures_list) do | |
textures = textures .. texture_name | |
end | |
player:get_meta():set_string("texture", textures) | |
player:set_properties({textures = {textures}}) | |
return textures | |
else | |
return | |
end | |
end | |
function misc.hurt_player_of_any_reasons(player, max_damage, reason) | |
local chance_to_make_damage_on_punchnode_table = { | |
[1] = "true", | |
[2] = "true", | |
[3] = "false", | |
[4] = "true" | |
} | |
if reason == "punchnode" then | |
local random_table_value = math.random(table.maxn(chance_to_make_damage_on_punchnode_table)) | |
if random_table_value == "true" then | |
minetest.chat_send_player(player:get_player_name(), "You have broken your hand!") | |
player:set_hp(player:get_hp() - math.random(max_damage)) | |
local texture = player:get_meta():get_string("texture") | |
player:get_meta():set_string("texture", texture .. "^character_with_broken_hand.png") | |
local textures_list = player:get_meta():get_string("textures_list") | |
textures_list[#textures_list+1] = "^character_with_broken_hand.png" | |
player:get_meta():set_string("textures_list", textures_list) | |
player:set_properties({texture = player:get_properties().textures[1] .. "^character_with_broken_hand.png"}) | |
else | |
return | |
end | |
elseif reason == "falling" and max_damage == nil then | |
minetest.chat_send_player(player:get_player_name(), "You have broken your leg!") | |
local texture = player:get_meta():get_string("texture") | |
player:get_meta():set_string("texture", texture .. "^character_with_broken_leg") | |
local textures_list = player:get_meta():get_string("textures_list") | |
textures_list[#textures_list+1] = "^character_with_broken_leg.png" | |
player:get_meta():set_string("textures_list", textures_list) | |
player:set_properties({texture = player:get_properties().textures[1] .. "^character_with_broken_leg.png"}) | |
end | |
end | |
local punches_amount = 0 | |
minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) | |
if minetest.get_item_group(node.name, "group:oddly_breakable_by_hand") ~= 0 then | |
if punches_amount == 0 then | |
local punches_amount_to_damage_player = math.random(1, 10) | |
end | |
punches_amount = punches_amount + 1 | |
if punches_amount == punches_amount_to_damage_player then | |
misc.hurt_player_of_any_reasons(puncher, 4, "punchnode") | |
punches_amount = 0 | |
end | |
else | |
return | |
end | |
end) | |
local players_in_airnode = {} | |
minetest.register_globalstep(function(dtime) | |
for _, player in ipairs(minetest.get_connected_players()) do | |
local node = minetest.get_node({x = player:get_pos(), y = player:get_pos().y - 1, z = player:get_pos()}) | |
if node == "air" and not minetest.settings:get_bool("fly") then | |
players_in_airnode[player:get_player_name()] = true | |
end | |
if node ~= "air" and not minetest.settings:get_bool("fly") and players_in_airnode[player:get_player_name()] then | |
misc.hurt_player_of_any_reasons(player, "falling") | |
players_in_airnode[player:get_player_name()] = false | |
end | |
end | |
end) | |
function misc.max_table_value(input) | |
local max_number = 0 | |
--minetest.debug(dump(assert(type(input) == "table", "This function expects table but got " .. type(input)))) | |
for index, value in pairs(input) do | |
if type(value) == "number" then | |
if max_number < value then | |
max_number = max_number + value | |
end | |
end | |
end | |
return max_number | |
end | |
function misc.create_particle_spawner(particlespawners_amount, player, particles_spawners_def, particlespawner_id) | |
if type(particlespawners_amount) == "number" and particlespawners_amount > 0 then -- If particlespawners_amount is number and over of 0 create particles_spawner_def table and the loop is running on each particles_spawner | |
math.abs(math.ceil(particlespawners_amount)) | |
local particles_spawner_def = {} | |
local playermeta = player:get_meta() | |
if misc.is_player_has_the_particlespawner(player, particlespawner_id) then | |
error("Can not add particlespawner with same id!", 1) | |
return | |
else | |
playermeta:set_string("active_particlespawners[" .. particlespawner_id.. "]", minetest.serialize({mode = "active", | |
particles_amount = particlespawners_amount, | |
particles_def = particles_spawners_def, | |
particles_time = {start = 0, end_ = misc.max_table_value(particles_spawners_def[2])}, | |
standard_particles_list = {}})) | |
minetest.debug(dump(minetest.deserialize(playermeta:get_string("active_particlespawners["..particlespawner_id.."]")))) | |
--[[playermeta:set_string("active_particlespawners[" .. particlespawner_id.. "]".."[particlespawner_mode]", "active") | |
playermeta:set_string("active_particlespawners[" .. particlespawner_id.. "][particlespawners_amount]", tostring(particlespawners_amount)) | |
playermeta:set_string("active_particlespawners[" .. particlespawner_id.. "][particles_spawners_def]", minetest.serialize(particles_spawners_def)) | |
playermeta:set_string("active_particlespawners[" .. particlespawner_id.. "][standard_particlespawners_list]", minetest.serialize({}))]] | |
local max_table_index = table.maxn(particles_spawners_def) | |
for table_index = 1, max_table_index do | |
particles_spawner_def[table_index] = {} | |
if table_index >=3 and table_index <= 7 then | |
particles_spawner_def[table_index][1] = {} | |
particles_spawner_def[table_index][2] = {} | |
end | |
end | |
for particles_spawner = 1, particlespawners_amount do | |
for particles_spawner_param = 1, max_table_index do | |
if particles_spawner_param >= 3 and particles_spawner_param <= 5 then | |
for min_or_max_param = 1, 2 do | |
particles_spawner_def[particles_spawner_param][min_or_max_param][particles_spawner] = {} | |
for point = 1, 3 do | |
particles_spawner_def[particles_spawner_param][min_or_max_param][particles_spawner][point] = particles_spawners_def[particles_spawner_param][min_or_max_param][particles_spawner][point] | |
end | |
end | |
elseif particles_spawner_param < 3 or particles_spawner_param > 7 then | |
particles_spawner_def[particles_spawner_param][particles_spawner] = particles_spawners_def[particles_spawner_param][particles_spawner] | |
if particles_spawner_param == 2 then | |
time = particles_spawner_def[particles_spawner_param][particles_spawner] | |
end | |
elseif particles_spawner_param == 5 or particles_spawner_param == 6 then | |
for min_or_maxparam = 1, 2 do | |
particles_spawner_def[particles_spawner_param][min_or_maxparam][particles_spawner] = particles_spawners_def[particles_spawner_param][min_or_maxparam][particles_spawner] | |
end | |
end | |
end | |
local meta = minetest.deserialize(playermeta:get_string("active_particlespawners["..particlespawner_id.."]")) | |
meta.standard_particles_list.particlespawner_id = minetest.add_particlespawner({ | |
amount = particles_spawner_def[1][particles_spawner], | |
time = particles_spawner_def[2][particles_spawner], | |
minpos = {x = particles_spawner_def[3][1][particles_spawner][1], y = particles_spawner_def[3][1][particles_spawner][2], z = particles_spawner_def[3][1][particles_spawner][3]}, | |
maxpos = {x = particles_spawner_def[3][2][particles_spawner][1], y = particles_spawner_def[3][2][particles_spawner][2], z = particles_spawner_def[3][2][particles_spawner][3]}, | |
minvel = {x = particles_spawner_def[4][1][particles_spawner][1], y = particles_spawner_def[4][1][particles_spawner][2], z = particles_spawner_def[4][1][particles_spawner][3]}, | |
maxvel = {x = particles_spawner_def[4][2][particles_spawner][1], y = particles_spawner_def[4][2][particles_spawner][2], z = particles_spawner_def[4][2][particles_spawner][3]}, | |
minacc = {x = particles_spawner_def[5][1][particles_spawner][1], y = particles_spawner_def[5][1][particles_spawner][2], z = particles_spawner_def[5][1][particles_spawner][3]}, | |
maxacc = {x = particles_spawner_def[5][2][particles_spawner][1], y = particles_spawner_def[5][2][particles_spawner][2], z = particles_spawner_def[5][2][particles_spawner][3]}, | |
minexptime = particles_spawner_def[6][1][particles_spawner], | |
maxexptime = particles_spawner_def[6][2][particles_spawner], | |
minsize = particles_spawner_def[7][1][particles_spawner], | |
maxsize = particles_spawner_def[7][2][particles_spawner], | |
collisiondetection = particles_spawner_def[8][particles_spawner], | |
vertical = particles_spawner_def[9][particles_spawner], | |
texture = particles_spawner_def[10][particles_spawner], | |
playername = particles_spawner_def[11][particles_spawner] | |
}) | |
playermeta:set_string("active_particlespawners["..particlespawner_id.."]", minetest.serialize(meta)) | |
end | |
--[[local particlespawner_def = playermeta:get_string("active_particlespawners["..particlespawner_id.."]") | |
particlespawner_def.particles_time.start = | |
playermeta:set_string("active_particlespawners["..particlespawner_id.."][time]", minetest.serialize({start = 0, end_ = particles_spawners_def[2][1]}))]] | |
minetest.register_globalstep(function (dtime) | |
local particlespawner_mode = minetest.deserialize(player:get_meta():get_string("active_particlespawners["..particlespawner_id.."]")).mode | |
if player:get_hp() > 0 and player:is_player_connected(player:get_player_name()) and particlespawner_mode == "active" then | |
local particlespawner_def = minetest.deserialize(playermeta:get_string("active_particlespawners["..particlespawner_id.."]")) | |
particlespawner_def.particles_time.start = particlespawner_def.particles_time.start + dtime | |
for particlespawner_index, particlespawner_time in ipairs(particlespawner_def.particles_def.time) do | |
particlespawner_def.time.particlespawner_index = particlespawner_def.time.particlespawner_index - dtime | |
playermeta:set_string("active_particlespawners["..particlespawner_id.."]", particlespawner_def) | |
end | |
playermeta:set_string("active_particlespawners["..particlespawner_id.."]", minetest.serialize(particlespawner_def)) | |
--^^ playermeta:get_string("active_particlespawners["..particlespawner_id.."][time][start]") gets a nil value!!! | |
end | |
end) | |
minetest.after(misc.max_table_value(particles_spawners_def[2]), function (playermeta) | |
misc.remove_particle_spawner(player, particlespawner_id) | |
end, playermeta) | |
end | |
else | |
return | |
end | |
end | |
function misc.is_player_has_any_particlespawners (player) | |
local current_player_particlespawners = minetest.deserialize(player:get_meta():get_string("active_particlespawners")) | |
if table.maxn(current_player_particlespawners) ~= 0 then | |
return true | |
else | |
return false | |
end | |
end | |
function misc.is_player_has_the_particlespawner (player, particlespawner_id) | |
local current_player_particlespawners = minetest.deserialize(player:get_meta():get_string("active_particlespawners")) | |
local max_particlespawners_index = 0 | |
for search_particlespawner, particlespawner_table in pairs(current_player_particlespawners) do | |
max_particlespawners_index = max_particlespawners_index + 1 | |
if search_particlespawner == particlespawner_id then | |
return true | |
end | |
if max_particlespawners_index == table.maxn(current_player_particlespawners) then | |
return false | |
end | |
end | |
end | |
function misc.stop_particle_spawner(player, particlespawner_id) | |
if misc.is_player_has_the_particlespawner(player, particlespawner_id) then | |
local particlespawner_def = minetest.deserialize(player:get_meta():get_string("active_particlespawners["..particlespawner_id.."]")) | |
if particlespawner_def.mode == "active" then | |
particlespawner_def.mode = "stopped" | |
player:get_meta():set_string("active_particlespawners["..particlespawner_id.."]", minetest.serialize(particlespawner_def)) | |
misc.remove_particle_spawner(player, particlespawner_id) | |
end | |
else | |
return | |
end | |
end | |
function misc.remove_particle_spawner (player, particlespawner_id) | |
local particlespawner_def = minetest.deserialize(player:get_meta():get_string("active_particlespawners["..particlespawner_id.."]")) | |
if misc.is_player_has_the_particlespawner(player, particlespawner_id) then | |
for standard_spawner_index, remove_standard_spawner in pairs(particlespawner_def.standard_particles_list) do | |
minetest.delete_particlespawner(remove_standard_spawner, player) | |
end | |
player:get_meta():set_string("active_particlespawners[" .. particlespawner_id.."]", minetest.deserialize({})) | |
end | |
end | |
function misc.continue_particle_spawner (player, particlespawner_id) | |
if misc.is_player_has_the_particlespawner(player, particlespawner_id) then | |
local particlespawner_def = minetest.deserialize(player:get_meta():get_string("active_particlespawners["..particlespawner_id.."]")) | |
if particlespawner_def.mode == "stopped" then | |
particlespawner_def.mode = "active" | |
player:get_meta():set_string("active_particlespawners["..particlespawner_id.."]", minetest.serialize(particlespawner_def)) | |
misc.create_particle_spawner(particlespawner_def.particles_amount, player, particlespawner_def.particles_def, particlespawner_id) | |
else | |
return | |
end | |
else | |
return | |
end | |
end | |
function misc.return_player_properties(player) | |
local playername = player:get_player_name() | |
if player:is_player_connected(playername) then | |
local playertexture = player:get_meta():get_string("texture") or false | |
if playertexture then | |
player:set_properties({textures = playertexture}) | |
else | |
return | |
end | |
local playermesh = player:get_meta():get_string("mesh") or false | |
if playermesh then | |
player:set_properties({mesh = playermesh}) | |
else | |
return | |
end | |
else | |
return | |
end | |
end | |
minetest.register_on_leaveplayer(function (player) | |
local current_player_particlespawners = minetest.deserialize(player:get_meta():get_string("active_particlespawners")) -- HERE! To write correct player meta data in register_on_leaveplayer and register_on_joinplayer | |
if misc.is_player_has_any_particlespawners(player) then | |
for particlespawner_id, particlespawner_table in pairs(current_player_particlespawners) do | |
if particlespawner_table.mode == "active" then | |
local particlespawners_time = current_player_particlespawners.particlespawner_id.particles_time | |
current_player_particlespawners.particlespawner_id.particles_time = {start = 0, end_ = particlespawners_time.end_ - particlespawners_time.start} | |
local playermeta = player:get_meta() | |
playermeta:set_string("active_particlespawners["..particlespawner_id.."]", minetest.serialize(current_player_particlespawners.particlespawner_id)) | |
end | |
end | |
else | |
return | |
end | |
end) | |
minetest.register_on_joinplayer(function (player) | |
if not player:get_meta():get_string("texture") then | |
player:get_meta():set_string("texture", player:get_properties().textures[1]) | |
end | |
if not player:get_meta():get_string("mesh") then | |
player:get_meta():set_string("mesh", player:get_properties().mesh) | |
end | |
minetest.debug(player:get_properties().mesh) | |
--[[minetest.debug(player:get_meta():get_string("texture")) | |
minetest.debug(player:get_meta():get_string("mesh"))]] | |
misc.return_player_properties(player) | |
if not minetest.deserialize(player:get_meta():get_string("textures_list")) then | |
player:get_meta():set_string("textures_list", minetest.serialize({[1] = player:get_properties().textures[1]})) | |
end | |
if not minetest.deserialize(player:get_meta():get_string("active_particlespawners")) then | |
player:get_meta():set_string("active_particlespawners", minetest.serialize({})) | |
end | |
if misc.is_player_has_any_particlespawners(player) then | |
local current_player_particlespawners = minetest.deserialize(player:get_meta():get_string("active_particlespawners")) | |
for particlespawner_id, particlespawner_table in pairs(current_player_particlespawners) do | |
if particlespawner_table.mode == "active" then | |
misc.create_particle_spawner(current_player_particlespawners.particlespawner_id.particles_amount, | |
player, | |
current_player_particlespawners.particlespawner_id.particles_def, | |
particlespawner_id) | |
--[[for time_index, time_search in ipairs(get_particlespawner_def) do | |
if time_index == 2 then | |
for time_index2, time_change in ipairs(time_search) do | |
time_search[time_index2] = get_particlespawner_time | |
end | |
elseif time_index == 6 then | |
local min_exptime = time_search[time_index][1] | |
local max_exptime = time_search[time_index][2] | |
for time_change_num = 1, get_particlespawner_amount do | |
min_exptime[time_change_num] = get_particlespawner_time | |
max_exptime[time_change_num] = get_particlespawner_time | |
end | |
end | |
end | |
misc.create_particle_spawner(get_particlespawner_amount, player, particlespawner_table[2], particlespawner_id)]] | |
end | |
end | |
end | |
end) | |
minetest.register_on_dieplayer(function (player) | |
if misc.is_player_has_any_particlespawners(player) then | |
local current_player_particlespawners = minetest.deserialize(player:get_meta():get_string("active_particlespawners")) | |
for particlespawner_id, particlespawner_table in pairs(current_player_particlespawners) do | |
player:get_meta():set_string("active_particlespawners".. "["..particlespawner_id.."]", "") | |
end | |
else | |
return | |
end | |
end) | |
minetest.register_on_newplayer(function (player) | |
local playermeta = player:get_meta() | |
playermeta:set_string("texture", player:get_properties().textures[1]) | |
playermeta:set_string("mesh", player:get_properties().mesh) | |
playermeta:set_string("active_particlespawners", minetest.serialize({})) | |
playermeta:set_string("textures_list", minetest.serialize({[1] = player:get_properties().textures[1]})) | |
end) | |
--[[local playername = player:get_player_name() | |
if saved_players_properties[textures] ~= {} then | |
saved_player_properties[textures][playername] = player:get_properties().textures | |
misc.return_player_properties(player) | |
end | |
if saved_players_properties[meshes] ~= {} then | |
saved_player_properties[meshes][playername] = player:get_properties().mesh | |
misc.return_player_properties(player) | |
end | |
end)]] | |
effects.register_healing_effect(user, "healing_effect", 15, 5, 2, 4, 4, { | |
{1, 1, 1, 1}, | |
{2, 2, 2, 2}, -- This field has index 2 | |
{{{user:get_pos().x + 0.2, user:get_pos().y + 1.5, user:get_pos().z + 0.2}, | |
{user:get_pos().x - 0.2, user:get_pos().y + 1.5, user:get_pos().z - 0.2}, | |
{user:get_pos().x - 0.2, user:get_pos().y + 1.5, user:get_pos().z + 0.2}, | |
{user:get_pos().x + 0.2, user:get_pos().y + 1.5, user:get_pos().z - 0.2} | |
}, | |
{{user:get_pos().x + 0.5, user:get_pos().y + 1.5, user:get_pos().z + 0.5}, | |
{user:get_pos().x - 0.5, user:get_pos().y + 1.5, user:get_pos().z - 0.5}, | |
{user:get_pos().x - 0.5, user:get_pos().y + 1.5, user:get_pos().z + 0.5}, | |
{user:get_pos().x + 0.5, user:get_pos().y + 1.5, user:get_pos().z - 0.5} | |
} | |
}, | |
{{{0, 0.2, 0}, | |
{0, 0.2, 0}, | |
{0, 0.2, 0}, | |
{0, 0.2, 0} | |
}, | |
{{0, 0.4, 0}, | |
{0, 0.4, 0}, | |
{0, 0.4, 0}, | |
{0, 0.4, 0} | |
} | |
}, | |
{{{0, 0.2, 0}, | |
{0, 0.2, 0}, | |
{0, 0.2, 0}, | |
{0, 0.2, 0} | |
}, | |
{{0, 0.4, 0}, | |
{0, 0.4, 0}, | |
{0, 0.4, 0}, | |
{0, 0.4, 0} | |
} | |
}, | |
{{2, 2, 2, 2}, | |
{2, 2, 2, 2} | |
}, | |
{{10, 10, 10, 10}, | |
{12, 12, 12, 12} | |
}, | |
{true, true, true, true}, | |
{true, true, true, true}, | |
{"poisonous_effect.png", "poisonous_effect.png", "poisonous_effect.png", "poisonous_effect.png"}, | |
{user:get_player_name(), user:get_player_name(), user:get_player_name(), user:get_player_name()} | |
}, "healing_particlespawner") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2018-08-20 20:25:47: WARNING[Server]: Assignment to undeclared global "time" inside a function at ...home/user/opt/minetest/bin/../mods/medicine/misc.lua:235.
2018-08-20 20:25:47: ERROR[Main]: ServerError: AsyncErr: environment_Step: Runtime error from mod '??' in callback environment_Step(): ...home/user/opt/minetest/bin/../mods/medicine/misc.lua:173: bad argument #1 to 'pairs' (table expected, got nil)
2018-08-20 20:25:47: ERROR[Main]: stack traceback:
2018-08-20 20:25:47: ERROR[Main]: [C]: in function 'pairs'
2018-08-20 20:25:47: ERROR[Main]: ...home/user/opt/minetest/bin/../mods/medicine/misc.lua:173: in function 'max_table_value'
2018-08-20 20:25:47: ERROR[Main]: ...home/user/opt/minetest/bin/../mods/medicine/misc.lua:288: in function 'create_particle_spawner'
2018-08-20 20:25:47: ERROR[Main]: .../user/opt/minetest/bin/../mods/medicine/diseases.lua:449: in function '?'
2018-08-20 20:25:47: ERROR[Main]: ...e/user/opt/minetest/bin/../builtin/game/register.lua:419: in function <...e/user/opt/minetest/bin/../builtin/game/register.lua:399>
2018-08-20 20:25:47: ERROR[Main]: stack traceback: