-
-
Save SmallJoker/0bfddbd1b9616572e964 to your computer and use it in GitHub Desktop.
Jail function for minetest
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
-- Created by Krock | |
-- License: WTFPL, with credits if possible | |
-- PLAYERS WITHOUT "FAST" PRIVILEGE GET TELEPORTED TO JAIL | |
-- CHANGE THIS PRIVILEGE NAME IF YOU DON'T HAVE "FAST" AS DEFAULT PRIVILEGEE | |
jail = {} | |
jail.time = 0 | |
-- minimal, maximal position which a player can go to without teleporting back | |
jail.min = {x=17,y=13,z=33} | |
jail.max = {x=31,y=21,z=45} | |
-- where the player gets teleported into jail | |
jail.join = {x=22,y=17,z=40} | |
-- where the player gets teleported when released | |
jail.leave = {x=26,y=11,z=38} | |
-- wait X seconds until check again for guys which broke out of jail | |
jail.check = 8 | |
minetest.register_chatcommand("gojail", { | |
params = "<name>", | |
description = "Lets someone go to jail.", | |
privs = {ban=true}, | |
func = function(name, param) | |
if not minetest.auth_table[param] then | |
minetest.chat_send_player(name, "Player "..param.." does not exist.") | |
return | |
end | |
local priv = minetest.get_player_privs(param) | |
if not priv.fast then | |
minetest.chat_send_player(name, "'"..param.."' is already in the jail.") | |
return | |
end | |
if priv.ban or priv.landrush then | |
minetest.chat_send_player(name, "'"..param.."' can not go to jail.") | |
return | |
end | |
priv["fast"] = nil | |
minetest.set_player_privs(param, priv) | |
minetest.chat_send_player(param, "You are a prisoner now. Think about the things you did wrong!", true) | |
print("Jail: + "..param.." (by "..name..")") | |
local player = minetest.get_player_by_name(param) | |
if(player ~= nil) then | |
if(player:get_hp() > 0) then | |
player:setpos(jail.join) | |
end | |
end | |
minetest.chat_send_player(name, "Sent '"..param.."' to jail.", true) | |
end, | |
}) | |
minetest.register_chatcommand("leavejail", { | |
params = "<name>", | |
description = "Lets someone leave the jail.", | |
privs = {ban=true}, | |
func = function(name, param) | |
if not minetest.auth_table[param] then | |
minetest.chat_send_player(name, "Player "..param.." does not exist.") | |
return | |
end | |
local priv = minetest.get_player_privs(param) | |
if priv.fast and priv.interact then | |
minetest.chat_send_player(name, "'"..param.."' is not in the jail.") | |
return | |
end | |
priv["fast"] = true | |
minetest.set_player_privs(param, priv) | |
minetest.chat_send_player(param, "You are now a free person. I hope we will never see us again.", true) | |
print("Jail: - "..param.." (by "..name..")") | |
local player = minetest.get_player_by_name(param) | |
if(player ~= nil) then | |
if(player:get_hp() > 0) then | |
player:setpos(jail.leave) | |
end | |
end | |
minetest.chat_send_player(name, "'"..param.."' is free now.", true) | |
end, | |
}) | |
minetest.register_on_respawnplayer(function(obj) | |
local priv = minetest.get_player_privs(obj:get_player_name()) | |
if priv.fast then | |
if(not priv.interact) then | |
priv["interact"] = true | |
minetest.set_player_privs(obj:get_player_name(), priv) | |
end | |
return false | |
end | |
obj:setpos(jail.join) | |
return true | |
end) | |
minetest.register_globalstep(function(dtime) | |
jail.time = jail.time + dtime | |
if jail.time < 8 then | |
return | |
end | |
jail.time = 0 | |
for _,player in ipairs(minetest.get_connected_players()) do | |
local name = player:get_player_name() | |
if not minetest.get_player_privs(name).fast then | |
local plpos = player:getpos() | |
if( plpos.x > jail.max.x or plpos.x < jail.min.x or | |
plpos.y > jail.max.y or plpos.y < jail.min.y or | |
plpos.z > jail.max.z or plpos.z < jail.min.z) then | |
minetest.chat_send_player(name, "Gotcha! Go back to jail!") | |
player:setpos(jail.join) | |
print(name.." tried to break out of the jail.") | |
end | |
end | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment