Move player at his original position when he leaves the game
This commit is contained in:
parent
6fb3c509bc
commit
bd6487a055
1
depends.txt
Normal file
1
depends.txt
Normal file
@ -0,0 +1 @@
|
||||
default
|
88
init.lua
88
init.lua
@ -23,8 +23,10 @@ minetest.register_chatcommand("watch", {
|
||||
watcher:set_nametag_attributes({color = {a=0}})
|
||||
|
||||
watcher:hud_set_flags({
|
||||
hotbar = false, healthbar = false,
|
||||
crosshair = false, wielditem = false
|
||||
hotbar = false,
|
||||
healthbar = false,
|
||||
crosshair = false,
|
||||
wielditem = false
|
||||
})
|
||||
|
||||
watcher:set_properties({
|
||||
@ -43,55 +45,53 @@ minetest.register_chatcommand("watch", {
|
||||
end
|
||||
})
|
||||
|
||||
local function unwatching(name)
|
||||
local watcher = nil
|
||||
watcher = minetest.get_player_by_name(name)
|
||||
local privs = minetest.get_player_privs(name)
|
||||
|
||||
if watcher and default.player_attached[name] == true then
|
||||
watcher:set_detach()
|
||||
default.player_attached[name] = false
|
||||
watcher:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
|
||||
watcher:set_nametag_attributes({color = {a=255, r=255, g=255, b=255}})
|
||||
|
||||
watcher:hud_set_flags({
|
||||
hotbar = true,
|
||||
healthbar = true,
|
||||
crosshair = true,
|
||||
wielditem = true
|
||||
})
|
||||
|
||||
watcher:set_properties({
|
||||
visual_size = {x=1, y=1},
|
||||
makes_footstep_sound = true,
|
||||
collisionbox = {-0.3, -1, -0.3, 0.3, 1, 0.3}
|
||||
})
|
||||
|
||||
if not privs.interact and privs.watch == true then
|
||||
privs.interact = true
|
||||
minetest.set_player_privs(name, privs)
|
||||
end
|
||||
|
||||
if original_pos[watcher] then
|
||||
watcher:setpos(original_pos[watcher])
|
||||
end
|
||||
|
||||
original_pos[watcher] = {}
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("unwatch", {
|
||||
description = "unwatch a player",
|
||||
privs = {watch=true},
|
||||
func = function(name, param)
|
||||
local watcher = nil
|
||||
watcher = minetest.get_player_by_name(name)
|
||||
local privs = minetest.get_player_privs(name)
|
||||
|
||||
if watcher and default.player_attached[name] == true then
|
||||
watcher:set_detach()
|
||||
default.player_attached[name] = false
|
||||
watcher:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
|
||||
watcher:set_nametag_attributes({color = {a=255, r=255, g=255, b=255}})
|
||||
|
||||
watcher:hud_set_flags({
|
||||
hotbar = true, healthbar = true,
|
||||
crosshair = true, wielditem = true
|
||||
})
|
||||
|
||||
watcher:set_properties({
|
||||
visual_size = {x=1, y=1},
|
||||
makes_footstep_sound = true,
|
||||
collisionbox = {-0.3, -1, -0.3, 0.3, 1, 0.3}
|
||||
})
|
||||
|
||||
privs.interact = true
|
||||
minetest.set_player_privs(name, privs)
|
||||
|
||||
minetest.after(0.1, function()
|
||||
watcher:setpos(original_pos[watcher])
|
||||
end)
|
||||
|
||||
minetest.after(0.2, function()
|
||||
original_pos[watcher] = {}
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
return false, "You're not watching a player currently."
|
||||
func = function(name, param)
|
||||
unwatching(name)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local privs = minetest.get_player_privs(name)
|
||||
|
||||
if not privs.interact and privs.watch == true then
|
||||
privs.interact = true
|
||||
minetest.set_player_privs(name, privs)
|
||||
end
|
||||
unwatching(name)
|
||||
end)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user