1
0
Fork 0

Harden a number of minetest.after player checks

This commit is contained in:
Wuzzy 2018-06-03 16:44:37 +02:00
parent 2132cdacc5
commit f022b747b0
8 changed files with 42 additions and 23 deletions

View File

@ -85,11 +85,12 @@ function boat.on_rightclick(self, clicker)
{x = 0, y = 3.75, z = -1}, {x = 0, y = 0, z = 0})
clicker:set_properties({ visual_size = driver_visual_size })
mcl_player.player_attached[name] = true
minetest.after(0.2, function(clicker)
if clicker:is_player() then
mcl_player.player_set_animation(clicker, "sit" , 30)
minetest.after(0.2, function(name)
local player = minetest.get_player_by_name(name)
if player then
mcl_player.player_set_animation(player, "sit" , 30)
end
end, clicker)
end, name)
clicker:set_look_horizontal(self.object:getyaw())
end
end

View File

@ -115,7 +115,8 @@ minetest.register_globalstep(function(dtime)
if object:get_luaentity().init ~= true then
object:get_luaentity().init = true
minetest.after(1, function(args)
local player = args[1]
local playername = args[1]
local player = minetest.get_player_by_name(playername)
local object = args[2]
local lua = object:get_luaentity()
if player == nil or not player:is_player() or object == nil or lua == nil or lua.itemstring == nil then
@ -136,7 +137,7 @@ minetest.register_globalstep(function(dtime)
else
enable_physics(object, object:get_luaentity())
end
end, {player, object})
end, {player:get_player_name(), object})
end
end
end

View File

@ -570,7 +570,8 @@ if c("totem") then
scale = { x=17, y=17 },
offset = { x=0, y=-178 },
})
minetest.after(3, function(player)
minetest.after(3, function(name)
local player = minetest.get_player_by_name(name)
if player and player:is_player() then
local name = player:get_player_name()
if hud_totem[name] then
@ -578,7 +579,7 @@ if c("totem") then
hud_totem[name] = nil
end
end
end, player)
end, player:get_player_name())
end
-- Set HP to exactly 1

View File

@ -338,12 +338,16 @@ function awards.unlock(name, award)
alignment = {x = 0, y = 0},
direction = 0,
})
minetest.after(3, function()
minetest.after(3, function(name)
local player = minetest.get_player_by_name(name)
if not player then
return
end
player:hud_remove(one)
player:hud_remove(two)
player:hud_remove(three)
player:hud_remove(four)
end)
end, player:get_player_name())
end
end

View File

@ -72,8 +72,8 @@ local function now_playing(player, track_id)
active_huds[playername] = id
end
minetest.after(5, function(tab)
local player = tab[1]
local playername = player:get_player_name()
local playername = tab[1]
local player = minetest.get_player_by_name(playername)
local id = tab[2]
local seq = tab[3]
if not player or not player:is_player() or not active_huds[playername] or not hud_sequence_numbers[playername] or seq ~= hud_sequence_numbers[playername] then
@ -83,7 +83,7 @@ local function now_playing(player, track_id)
player:hud_remove(active_huds[playername])
active_huds[playername] = nil
end
end, {player, id, hud_sequence_numbers[playername]})
end, {playername, id, hud_sequence_numbers[playername]})
end

View File

@ -404,6 +404,9 @@ minetest.register_abm({
end
-- teleport the object
minetest.after(3, function(obj, pos, target)
if not obj:get_luaentity() then
return
end
-- Prevent quick back-and-forth teleportation
if portal_cooloff[obj] then
return

View File

@ -292,11 +292,15 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
for field, _ in pairs(fields) do
if string.find(field, "skins_set") then
minetest.after(0, function(player)
minetest.after(0, function(name)
local player = minetest.get_player_by_name(name)
if not player then
return
end
local skin = armor:get_player_skin(name)
armor.textures[name].skin = skin..".png"
armor:set_player_armor(player)
end, player)
end, player:get_player_name())
end
end
end)
@ -406,9 +410,13 @@ minetest.register_on_joinplayer(function(player)
end
end
for i=1, ARMOR_INIT_TIMES do
minetest.after(ARMOR_INIT_DELAY * i, function(player)
minetest.after(ARMOR_INIT_DELAY * i, function(name)
local player = minetest.get_player_by_name(name)
if not player then
return
end
armor:set_player_armor(player)
end, player)
end, player:get_player_name())
end
end)
@ -435,7 +443,7 @@ if ARMOR_DROP == true or ARMOR_DESTROY == true then
end
armor:set_player_armor(player)
if ARMOR_DESTROY == false then
minetest.after(ARMOR_BONES_DELAY, function()
minetest.after(ARMOR_BONES_DELAY, function(pos, drop)
local node = minetest.get_node(vector.round(pos))
if node then
if node.name ~= "bones:bones" then
@ -461,7 +469,7 @@ if ARMOR_DROP == true or ARMOR_DESTROY == true then
armor.drop_armor(pos, stack)
end
end
end)
end, pos, drop)
end
end)
end

View File

@ -85,9 +85,10 @@ local function reset_bars_poison_hunger(player)
end
-- Poison player
local function poisonp(tick, time, time_left, damage, exhaustion, player)
local function poisonp(tick, time, time_left, damage, exhaustion, name)
local player = minetest.get_player_by_name(name)
-- First check if player is still there
if not player:is_player() then
if not player then
return
end
local name = player:get_player_name()
@ -97,7 +98,7 @@ local function poisonp(tick, time, time_left, damage, exhaustion, player)
end
time_left = time_left + tick
if time_left < time then
minetest.after(tick, poisonp, tick, time, time_left, damage, exhaustion, player)
minetest.after(tick, poisonp, tick, time, time_left, damage, exhaustion, name)
else
if damage > 0 then
mcl_hunger.poison_damage[name] = mcl_hunger.poison_damage[name] - 1
@ -236,7 +237,7 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poiso
end
mcl_hunger.poison_hunger[name] = mcl_hunger.poison_hunger[name] + 1
end
poisonp(1, poisontime, 0, poison, exhaust, user)
poisonp(1, poisontime, 0, poison, exhaust, user:get_player_name())
end
end