Skip to content

Commit

Permalink
embed /spawn command in custom mod (pandorabox-io/pandorabox-mods#1)
Browse files Browse the repository at this point in the history
21 lines of duplicated code
  • Loading branch information
NatureFreshMilk committed Aug 19, 2019
1 parent d374ad8 commit 002460c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ if minetest.get_modpath("loot") then
dofile(MP.."/loot.lua")
end

-- /spawn command
dofile(MP.."/spawn.lua")

-- custom privs
dofile(MP.."/privs.lua")

Expand Down
21 changes: 21 additions & 0 deletions spawn.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
spawn_command = {}
spawn_command.pos = {x=0, y=3, z=0}

if minetest.setting_get_pos("static_spawnpoint") then
spawn_command.pos = minetest.setting_get_pos("static_spawnpoint")
end

function teleport_to_spawn(name)
local player = minetest.get_player_by_name(name)
if player == nil then
-- just a check to prevent the server crashing
return false
end
player:setpos(spawn_command.pos)
minetest.chat_send_player(name, "Teleported to spawn!")
end

minetest.register_chatcommand("spawn", {
description = "Teleport you to spawn point.",
func = teleport_to_spawn,
})

0 comments on commit 002460c

Please sign in to comment.