[Mod]No Escape ![For PvP][0.2]

[Mod]No Escape ![For PvP][0.2]

Postby Sirvoid » Sun Dec 25, 2016 11:08 pm

NO ESCAPE

This simple mod prevent people to do /spawn or /home during a Fight with another player. There is no Escape !!!

Feature:
-You can't do /spawn & /home during a Fight
-You can do it again after X seconds (You can set the seconds in the init file (15 by default))
-There is No Escape !
-Seriously there is No Escape don't try to run ...

GitHub
Download

Code: Select all
------V0.2-------
-All the known bugs have been resolved.
-The code has been cleaned Big thanks to Taikedz!
-----------------


Code: Select all
Licence: WTFPL

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE

Version 2, December 2004

Copyright (C) 2004 Sam Hocevar sam@hocevar.net

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
Sirvoid
Member
 
Posts: 47
Joined: Thu Feb 04, 2016 10:12 pm
GitHub: Sirvoid
In-game: Sirvoid

Re: [Mod]No Escape ![For PvP][0.1]

Postby taikedz » Mon Dec 26, 2016 2:25 pm

Nice one.

Really hate these hit-and-run people who try you then realize they could kick their butts and /spawn out .... This'll be good :-D
taikedz
Member
 
Posts: 676
Joined: Sun May 15, 2016 11:11 am
GitHub: taikedz
In-game: DuCake

Re: [Mod]No Escape ![For PvP][0.1]

Postby taikedz » Mon Dec 26, 2016 2:43 pm

Naj wrote:Does it work for mobs also ?


What, so that if you are hit by a mob you can't escape? That would be plain mean :D

That being said, a mob that removes your home and spawn privs when you attack it could be interesting ;-)
taikedz
Member
 
Posts: 676
Joined: Sun May 15, 2016 11:11 am
GitHub: taikedz
In-game: DuCake

Re: [Mod]No Escape ![For PvP][0.2]

Postby ManElevation » Thu Dec 29, 2016 7:50 am

this is pretty nice, I might put this my server is up
ManElevation
Member
 
Posts: 896
Joined: Tue Aug 02, 2016 10:04 pm
GitHub: ManElevation
In-game: ManElevation

Re: [Mod]No Escape ![For PvP][0.2]

Postby Sirvoid » Fri Dec 30, 2016 10:14 pm

Naj wrote:Does it work for mobs also ?


That is not a bad idea. Maybe I could make something optional for that ^^

ManElevation wrote:this is pretty nice, I might put this my server is up


Sure ! I would not say no to see the mod running on a server with some players.
Sirvoid
Member
 
Posts: 47
Joined: Thu Feb 04, 2016 10:12 pm
GitHub: Sirvoid
In-game: Sirvoid

Re: [Mod]No Escape ![For PvP][0.2]

Postby Fixer » Sun Jan 01, 2017 11:47 pm

Thanks. Very needed for survival.
Fixer
Member
 
Posts: 891
Joined: Sun Jul 31, 2011 11:23 am
In-game: Fixer

Re: [Mod]No Escape ![For PvP][0.2]

Postby RWЯ » Thu Jan 11, 2018 6:01 am

What if player start to log off?
RWЯ
Member
 
Posts: 111
Joined: Thu Jun 29, 2017 11:21 am
GitHub: DreamCrusher
In-game: Hood

Re: [Mod]No Escape ![For PvP][0.2]

Postby ChimneySwift » Thu Jan 11, 2018 1:03 pm

Now we just need a mod which prevents people teleport requesting you into lava :rolling_eyes:
ChimneySwift
Member
 
Posts: 320
Joined: Fri Sep 22, 2017 6:46 am
GitHub: ChimneySwift
In-game: ChimneySwift

Re: [Mod]No Escape ![For PvP][0.2]

Postby Fixer » Fri Apr 19, 2019 9:45 pm

Original repo no longer available, full mod code (create a folder for it and paste into new init.lua file):
Code: Select all
-----------------------------------------------------------
-- This mod remove the home and spawn privileges during a fight.
-- Thanks to Taikedz for cleaning the code--
-------------configuration---------------------------------

-- Other player cannot escape
-- false if the player being hit can't teleport when someone hits them.
local OPCE = false

-- How long in seconds until a battle ends (times since last hit)
local battletimeout = 15

-- Fight start message
local FightMessage = "You entered a Fight !"

-- Fight end message
local EndFightMessage = "The Fight is Over !"

---------------------------------------------

-- Get default privs at server level
local default_privs = minetest.setting_get("default_privs") or ""
default_privs = default_privs:split(",")

local dprivs = {}
for _,v in pairs(default_privs) do
   dprivs[v] = true
end

local playerinpvp = {}

local function limit_privs(playername)
   local privs = minetest.get_player_privs(playername)
   privs.home = nil
   privs.spawn = nil
   minetest.set_player_privs(playername, privs)
end

local function setplayerpvp(playername, isvictim)
   if isvictim and OPCE == true then return end

   if not playerinpvp[playername] then
      playerinpvp[playername] = 0
      minetest.chat_send_player(playername, FightMessage)
      limit_privs(playername)
   end
end

local function resettime(playername)
   if playerinpvp[playername] ~= nil then
      playerinpvp[playername] = 0
   end
end

local function restoreprivs(fighter)
   local privs = minetest.get_player_privs(fighter)
   privs.home = dprivs.home
   privs.spawn = dprivs.spawn

   minetest.set_player_privs(fighter, privs)

   playerinpvp[fighter] = nil
end

minetest.register_on_punchplayer(function(player, hitter)
   if not (player:is_player() and hitter:is_player() ) then
      return
   end
   
   local hittername = hitter:get_player_name()
   local victimname = player:get_player_name()

   setplayerpvp(hittername)
   setplayerpvp(victimname, true) -- moved OPCE check

   resettime(hittername)
   resettime(victimname) -- won't affect non-registered victims
end)

minetest.register_globalstep(function(dtime)
   for fighter,oldtime in pairs(playerinpvp) do
      local newtime = oldtime + dtime
      playerinpvp[fighter] = newtime
   
      if newtime >= battletimeout then
         restoreprivs(fighter)
         minetest.chat_send_player(fighter, EndFightMessage)
      end
   end
end)

minetest.register_on_joinplayer(function(player)
   restoreprivs( player:get_player_name() )
end)
Fixer
Member
 
Posts: 891
Joined: Sun Jul 31, 2011 11:23 am
In-game: Fixer



Return to WIP Mods



Who is online

Users browsing this forum: Bing Bot [Bot] and 0 guests