2020-08-12 22:37:11 -07:00
|
|
|
local player_data = pvp_revamped.player_data
|
|
|
|
local player_persistent_data = pvp_revamped.player_persistent_data
|
|
|
|
local drop = pvp_revamped.drop
|
2020-08-15 14:02:57 -07:00
|
|
|
local get_player_by_name = minetest.get_player_by_name
|
2020-08-12 22:37:11 -07:00
|
|
|
|
|
|
|
-- Create an empty data sheet for the player.
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
player_persistent_data[player:get_player_name()] = {damage_texture_modifier = player:get_properties().damage_texture_modifier}
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Clear up memory if the player leaves.
|
|
|
|
-- Drop any item the player is about to throw on leave.
|
2020-08-13 14:29:19 -07:00
|
|
|
-- Remove the shield entity.
|
2020-08-12 22:37:11 -07:00
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
2020-08-13 14:29:19 -07:00
|
|
|
local pdata = player_data[name]
|
2020-08-12 22:37:11 -07:00
|
|
|
|
2020-08-13 14:29:19 -07:00
|
|
|
if not pdata then
|
2020-08-12 22:37:11 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-08-13 14:29:19 -07:00
|
|
|
local throw_data = pdata.throw
|
2020-08-12 22:37:11 -07:00
|
|
|
|
|
|
|
if throw_data then
|
|
|
|
drop(player, throw_data.item)
|
|
|
|
end
|
|
|
|
|
2020-08-13 14:29:19 -07:00
|
|
|
local entity = pdata.entity
|
|
|
|
|
|
|
|
if entity then
|
|
|
|
entity:remove()
|
|
|
|
end
|
|
|
|
|
2020-08-12 22:37:11 -07:00
|
|
|
player_data[name] = nil
|
|
|
|
player_persistent_data[name] = nil
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Drop any item the player is about to throw on death.
|
2020-08-13 14:29:19 -07:00
|
|
|
-- Remove the shield entity.
|
2020-08-12 22:37:11 -07:00
|
|
|
minetest.register_on_dieplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
2020-08-13 14:29:19 -07:00
|
|
|
local pdata = player_data[name]
|
2020-08-12 22:37:11 -07:00
|
|
|
|
2020-08-13 14:29:19 -07:00
|
|
|
if not pdata then
|
2020-08-12 22:37:11 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-08-13 14:29:19 -07:00
|
|
|
local throw_data = pdata.throw
|
2020-08-12 22:37:11 -07:00
|
|
|
|
|
|
|
if throw_data then
|
|
|
|
drop(player, throw_data.item)
|
|
|
|
|
2020-08-13 14:29:19 -07:00
|
|
|
pdata.throw = nil
|
2020-08-12 22:37:11 -07:00
|
|
|
end
|
2020-08-13 14:29:19 -07:00
|
|
|
|
|
|
|
local entity = pdata.entity
|
|
|
|
|
|
|
|
if entity then
|
|
|
|
entity:remove()
|
|
|
|
|
|
|
|
pdata.entity = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
player_data[name] = pdata
|
2020-08-12 22:37:11 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- Drop any item the player is about to throw on shutdown.
|
2020-08-13 14:29:19 -07:00
|
|
|
-- Remove the shield entity.
|
2020-08-12 22:37:11 -07:00
|
|
|
minetest.register_on_shutdown(function()
|
|
|
|
for k, v in pairs(player_data) do
|
|
|
|
local throw_data = v.throw
|
|
|
|
|
|
|
|
if throw_data then
|
2020-08-15 14:02:57 -07:00
|
|
|
drop(get_player_by_name(k), throw_data.item)
|
2020-08-12 22:37:11 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|