auto doors

maughanorama

Member
Member
Nov 27, 2014
181
10
18
50
hi i have a request
a really pathetic one really.
people are moaning that they are getting raided and people are hacking because theres no way in. actually turns out the lazy gits cant be bothered to shut their doors.

is there a way to have the doors auto shut ?


thanks
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
Yeah. There were discussions about this in Magma. I think with the latest methods we are able to do It.

Sent from my Samsung Galaxy S4
 

maughanorama

Member
Member
Nov 27, 2014
181
10
18
50
im sure there was a mod for this i have been on a server where the doors auto shut and there was an option for everyone to choose if their doors auto shut or not... dunno if it was magma or oxide server though
 

maughanorama

Member
Member
Nov 27, 2014
181
10
18
50
If I was more competant at python I would convert or try to the oxide plugon but alas I'm rubbish at coding :(
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
I remember that we couldn't transfer the door into a timer. Think we can do that. Convert the object to string or we also have two methods in the Util class that I made. GetDooratCoors

Sent from my Samsung Galaxy S4
 
Last edited:

maughanorama

Member
Member
Nov 27, 2014
181
10
18
50
Whoever put the door there... there's a magma pluging that shoWs who owns the door when u walk up to it
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
This works, But the door doesn't close.
Python:
__author__ = 'DreTaX'
__version__ = '1.0'
import clr

clr.AddReferenceByPartialName("Fougerite")
import Fougerite
import re

"""
    Class
"""

DStable = "DoorCloser"
class AutoDoorCloser:

    bd = None

    def On_PluginInit(self):
        self.bd = Util.TryFindReturnType("BasicDoor")
        if self.bd is None:
            Plugin.Log("Error", "Couldn't find return type.")

    def Stringify(self, List):
        s = re.sub("[[\]\'\ ]", '', str(List))
        return str(s)

    def Parse(self, String):
        return String.split(',')

    def ReplaceToDot(self, String):
        str = re.sub('[(\)]', '', String)
        return str.split(':')

    """
        Timer Functions
    """

    def addJob(self, id, xtime, x, y, z):
        epoch = Plugin.GetTimestamp()
        exectime = int(epoch) + int(xtime)
        # ID, EXECTIME : Location : CallBack number  : Player's Last Location | Requires to be splited
        List = []
        List.append(str(exectime))
        List.append(str(x))#.replace(',', ':'))
        List.append(str(y))
        List.append(str(z))
        DataStore.Add(DStable, id, self.Stringify(List))
        self.startTimer()

    def killJob(self, id):
        DataStore.Remove(DStable, id)

    def startTimer(self):
        gfjfhg = 100
        try:
            if not Plugin.GetTimer("AutoCloser"):
                Plugin.CreateTimer("AutoCloser", gfjfhg).Start()
        except:
            pass

    def stopTimer(self):
        timer = Plugin.GetTimer("AutoCloser")
        if timer is None:
            return
        timer.Stop()
        Plugin.Timers.Remove("AutoCloser")

    def getPlayer(self, d):
        try:
            id = str(d)
            pl = Server.FindPlayer(id)
            return pl
        except:
            return None

    def clearTimers(self):
        DataStore.Flush(DStable)
        self.stopTimer()

    def On_DoorUse(self, Player, DoorUseEvent):
        if DoorUseEvent.Open:
            x = DoorUseEvent.Entity.X
            y = DoorUseEvent.Entity.Y
            z = DoorUseEvent.Entity.Z
            self.addJob(Player.SteamID, 2, x, y, z)

    def AutoCloserCallback(self):
        epoch = int(Plugin.GetTimestamp())
        if DataStore.Count(DStable) >= 1:
            pending = DataStore.Keys(DStable)
            for id in pending:
                if DataStore.Get(DStable, id) is None:
                    DataStore.Remove(DStable, id)
                    continue
                params = self.Parse(str(DataStore.Get(DStable, id)))
                if epoch >= int(params[0]):
                    self.killJob(id)
                    #xto = self.ReplaceToDot(params[1])
                    Server.Broadcast(params[1])
                    Server.Broadcast(params[2])
                    Server.Broadcast(params[3])
                    door = Util.GetDooratCoords(int(params[1]), int(params[2]), int(params[3]))#float(xto[0]), float(xto[1]), float(xto[2]))
                    if door is None:
                        continue
                    if self.bd is not None:
                        # Praise baluerino
                        self.bd.InvokeMember("ToggleStateServer", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, None, door, System.Linq.Enumerable.ToArray([None, Plugin.GetTimestamp().As[System.UInt64], None]))
        else:
            self.stopTimer()
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
This works, But the door doesn't close.
Python:
__author__ = 'DreTaX'
__version__ = '1.0'
import clr

clr.AddReferenceByPartialName("Fougerite")
import Fougerite
import re

"""
    Class
"""

DStable = "DoorCloser"
class AutoDoorCloser:

    bd = None

    def On_PluginInit(self):
        self.bd = Util.TryFindReturnType("BasicDoor")
        if self.bd is None:
            Plugin.Log("Error", "Couldn't find return type.")

    def Stringify(self, List):
        s = re.sub("[[\]\'\ ]", '', str(List))
        return str(s)

    def Parse(self, String):
        return String.split(',')

    def ReplaceToDot(self, String):
        str = re.sub('[(\)]', '', String)
        return str.split(':')

    """
        Timer Functions
    """

    def addJob(self, id, xtime, x, y, z):
        epoch = Plugin.GetTimestamp()
        exectime = int(epoch) + int(xtime)
        # ID, EXECTIME : Location : CallBack number  : Player's Last Location | Requires to be splited
        List = []
        List.append(str(exectime))
        List.append(str(x))#.replace(',', ':'))
        List.append(str(y))
        List.append(str(z))
        DataStore.Add(DStable, id, self.Stringify(List))
        self.startTimer()

    def killJob(self, id):
        DataStore.Remove(DStable, id)

    def startTimer(self):
        gfjfhg = 100
        try:
            if not Plugin.GetTimer("AutoCloser"):
                Plugin.CreateTimer("AutoCloser", gfjfhg).Start()
        except:
            pass

    def stopTimer(self):
        timer = Plugin.GetTimer("AutoCloser")
        if timer is None:
            return
        timer.Stop()
        Plugin.Timers.Remove("AutoCloser")

    def getPlayer(self, d):
        try:
            id = str(d)
            pl = Server.FindPlayer(id)
            return pl
        except:
            return None

    def clearTimers(self):
        DataStore.Flush(DStable)
        self.stopTimer()

    def On_DoorUse(self, Player, DoorUseEvent):
        if DoorUseEvent.Open:
            x = DoorUseEvent.Entity.X
            y = DoorUseEvent.Entity.Y
            z = DoorUseEvent.Entity.Z
            self.addJob(Player.SteamID, 2, x, y, z)

    def AutoCloserCallback(self):
        epoch = int(Plugin.GetTimestamp())
        if DataStore.Count(DStable) >= 1:
            pending = DataStore.Keys(DStable)
            for id in pending:
                if DataStore.Get(DStable, id) is None:
                    DataStore.Remove(DStable, id)
                    continue
                params = self.Parse(str(DataStore.Get(DStable, id)))
                if epoch >= int(params[0]):
                    self.killJob(id)
                    #xto = self.ReplaceToDot(params[1])
                    Server.Broadcast(params[1])
                    Server.Broadcast(params[2])
                    Server.Broadcast(params[3])
                    door = Util.GetDooratCoords(int(params[1]), int(params[2]), int(params[3]))#float(xto[0]), float(xto[1]), float(xto[2]))
                    if door is None:
                        continue
                    if self.bd is not None:
                        # Praise baluerino
                        self.bd.InvokeMember("ToggleStateServer", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, None, door, System.Linq.Enumerable.ToArray([None, Plugin.GetTimestamp().As[System.UInt64], None]))
        else:
            self.stopTimer()
https://github.com/dretax/Python-Plugins/blob/master/AutoDoorCloser/AutoDoorCloser.py#L80 Well yeah thats a fail over there.
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
This works, But the door doesn't close.
Python:
__author__ = 'DreTaX'
__version__ = '1.0'
import clr

clr.AddReferenceByPartialName("Fougerite")
import Fougerite
import re

"""
    Class
"""

DStable = "DoorCloser"
class AutoDoorCloser:

    bd = None

    def On_PluginInit(self):
        self.bd = Util.TryFindReturnType("BasicDoor")
        if self.bd is None:
            Plugin.Log("Error", "Couldn't find return type.")

    def Stringify(self, List):
        s = re.sub("[[\]\'\ ]", '', str(List))
        return str(s)

    def Parse(self, String):
        return String.split(',')

    def ReplaceToDot(self, String):
        str = re.sub('[(\)]', '', String)
        return str.split(':')

    """
        Timer Functions
    """

    def addJob(self, id, xtime, x, y, z):
        epoch = Plugin.GetTimestamp()
        exectime = int(epoch) + int(xtime)
        # ID, EXECTIME : Location : CallBack number  : Player's Last Location | Requires to be splited
        List = []
        List.append(str(exectime))
        List.append(str(x))#.replace(',', ':'))
        List.append(str(y))
        List.append(str(z))
        DataStore.Add(DStable, id, self.Stringify(List))
        self.startTimer()

    def killJob(self, id):
        DataStore.Remove(DStable, id)

    def startTimer(self):
        gfjfhg = 100
        try:
            if not Plugin.GetTimer("AutoCloser"):
                Plugin.CreateTimer("AutoCloser", gfjfhg).Start()
        except:
            pass

    def stopTimer(self):
        timer = Plugin.GetTimer("AutoCloser")
        if timer is None:
            return
        timer.Stop()
        Plugin.Timers.Remove("AutoCloser")

    def getPlayer(self, d):
        try:
            id = str(d)
            pl = Server.FindPlayer(id)
            return pl
        except:
            return None

    def clearTimers(self):
        DataStore.Flush(DStable)
        self.stopTimer()

    def On_DoorUse(self, Player, DoorUseEvent):
        if DoorUseEvent.Open:
            x = DoorUseEvent.Entity.X
            y = DoorUseEvent.Entity.Y
            z = DoorUseEvent.Entity.Z
            self.addJob(Player.SteamID, 2, x, y, z)

    def AutoCloserCallback(self):
        epoch = int(Plugin.GetTimestamp())
        if DataStore.Count(DStable) >= 1:
            pending = DataStore.Keys(DStable)
            for id in pending:
                if DataStore.Get(DStable, id) is None:
                    DataStore.Remove(DStable, id)
                    continue
                params = self.Parse(str(DataStore.Get(DStable, id)))
                if epoch >= int(params[0]):
                    self.killJob(id)
                    #xto = self.ReplaceToDot(params[1])
                    Server.Broadcast(params[1])
                    Server.Broadcast(params[2])
                    Server.Broadcast(params[3])
                    door = Util.GetDooratCoords(int(params[1]), int(params[2]), int(params[3]))#float(xto[0]), float(xto[1]), float(xto[2]))
                    if door is None:
                        continue
                    if self.bd is not None:
                        # Praise baluerino
                        self.bd.InvokeMember("ToggleStateServer", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, None, door, System.Linq.Enumerable.ToArray([None, Plugin.GetTimestamp().As[System.UInt64], None]))
        else:
            self.stopTimer()
Ohh no that's not how the location thingy goes.
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
This doesn't matter right now, But when closing a door it will start the timer