auto doors

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
INI:
[1/30/2015 8:41:58 PM] [Debug] [IronPython] An error occurred in: AutoDoorCloser plugin while calling method: AutoCloserCallback
[1/30/2015 8:41:58 PM] [Exception] [ IPPlugin->Invoke | IPPlugin->OnTimerCB | IPTimedEvent->_timer_Elapsed | Timer->Callback | ]
System.InvalidCastException: Cannot cast from source type to destination type.
  at Fougerite.Util.GetDooratCoords (Vector3 givenPosition) [0x00000] in <filename unknown>:0
  at Fougerite.Util.GetDooratCoords (Single x, Single y, Single z) [0x00000] in <filename unknown>:0
  at (wrapper delegate-invoke) System.Func`5<Fougerite.Util, single, single, single, Fougerite.Entity>:invoke_Entity__this___Util_single_single_single (Fougerite.Util,single,single,single)
  at Microsoft.Scripting.Interpreter.FuncCallInstruction`5[Fougerite.Util,System.Single,System.Single,System.Single,Fougerite.Entity].Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in <filename unknown>:0
  at Microsoft.Scripting.Interpreter.Interpreter.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in <filename unknown>:0
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
INI:
[1/30/2015 8:41:58 PM] [Debug] [IronPython] An error occurred in: AutoDoorCloser plugin while calling method: AutoCloserCallback
[1/30/2015 8:41:58 PM] [Exception] [ IPPlugin->Invoke | IPPlugin->OnTimerCB | IPTimedEvent->_timer_Elapsed | Timer->Callback | ]
System.InvalidCastException: Cannot cast from source type to destination type.
  at Fougerite.Util.GetDooratCoords (Vector3 givenPosition) [0x00000] in <filename unknown>:0
  at Fougerite.Util.GetDooratCoords (Single x, Single y, Single z) [0x00000] in <filename unknown>:0
  at (wrapper delegate-invoke) System.Func`5<Fougerite.Util, single, single, single, Fougerite.Entity>:invoke_Entity__this___Util_single_single_single (Fougerite.Util,single,single,single)
  at Microsoft.Scripting.Interpreter.FuncCallInstruction`5[Fougerite.Util,System.Single,System.Single,System.Single,Fougerite.Entity].Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in <filename unknown>:0
  at Microsoft.Scripting.Interpreter.Interpreter.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in <filename unknown>:0
Wuuu, thats ugly.
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
As I see the method changed since I created It. Mike did It. I will edit It, for now we can only for cycle through structures. Lemme push one.
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
You forgot to import UnityEngine.
also with UnityEngine imported, it finds the door. The bad news, it finds the door as None.
https://github.com/dretax/Python-Plugins/blob/master/AutoDoorCloser/AutoDoorCloser.py#L104

This is what I had for testing.
Python:
if door is None:
    Server.Broadcast("Door is none")
    continue
And in chat it broadcasts the message
I was able to get It, but System.MissingMemberException: attribute 'Linq' of 'namespace#' object is read-only..... ASD
 
  • Funny
Reactions: Jakkee

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
I guys rule... is this for autoshutting doors and door owner display?
Super simple door owner lookup, If you try to open a door it will tell you the owners name unless you are the owner.
Python:
__author__ = 'DreTaX'
__version__ = '1.0'
import clr

clr.AddReferenceByPartialName("Fougerite")
clr.AddReferenceByPartialName("UnityEngine")
clr.AddReferenceByPartialName("System.Core")
import Fougerite
import re
import UnityEngine
from UnityEngine import *
import System
from System import Reflection

"""
    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, location):
        epoch = Plugin.GetTimestamp()
        exectime = int(epoch) + int(xtime)
        # ID, EXECTIME : Location | Requires to be splited
        List = []
        List.append(str(exectime))
        List.append(str(location).replace(',', ':'))
        DataStore.Add(DStable, id, self.Stringify(List))
        self.startTimer()

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

    def startTimer(self):
        gfjfhg = 1700
        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 Find(self, x, y, z):
        objects = UnityEngine.Resources.FindObjectsOfTypeAll(self.bd)
        loc = Util.CreateVector(x, y, z)
        for door in objects:
            Distance = Util.GetVectorsDistance(loc, door.transform.position)
            if Distance < 1.5:
            #if door.transform.position == loc:
                return door
        return None

    def On_DoorUse(self, Player, DoorUseEvent):
        #if DoorUseEvent.Open:
        if DoorUseEvent.Entity.Owner is not Player:
            Player.Message(DoorUseEvent.Entity.Owner.Name + " owns this door")
        loc = Util.CreateVector(float(DoorUseEvent.Entity.X), float(DoorUseEvent.Entity.Y), float(DoorUseEvent.Entity.Z))
        self.addJob(Player.SteamID, 2, loc)

    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])
                    door = self.Find(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()