1. Hello,

    I was tinkering with sphere collider to find the codelocks around the player but I can't get it right.

    Even if I find a codelock object, when it returns target it comes back as door.hinge instead of lock.code.

    I can get it to find all the existing codelocks, but its too laggy if server has thousands of them.

    Thx in advance for any ideas or suggestions

    This is what I got so far:
    Code:
            private object Sphere(Vector3 Pos, int radius)
            {
                var hits = Physics.OverlapSphere(Pos, 30);
                var codeLocks = UnityEngine.Object.FindObjectsOfType<CodeLock>();
                object target = null;
                int i = 0;
                foreach (var hit in hits)
                {
                    //"hits" dont find codelock, "codeLocks" dont work in sphere colider
                    if (hit.GetComponentInParent<CodeLock>() != null )
                    {
                            target = hit.GetComponentInParent<CodeLock>();
                            PrintWarning("target found: " +target.ToString());
                            PrintWarning("hit found: " +hit.ToString());
                            PrintWarning("Objecs found: " +i.ToString());
                            i++;
                            return target;
                    }
                }
                return null;
            }
     
  2. I think you have to get the Door component and then get the codelock from the door?

    Maybe try that
     
  3. Hi Ryan, big fan of Rustoria, I'm basically copying rustoria's plugins cos I think your servers got it just right, I have /cupboard and /turret working exactly like your servers do, now just stuck at codelocks ;D
     
  4. I would prefer you not to copy, but I can't stop you :p

    Get the door component and then get the codelock from the door component :D You should release it after completing it :p
     
  5. Releasing it would not be beneficial for both of us xD, so lets just keep it to ourselves ;D. But I get what u mean, finding all the doors in radius and then find codelocks attached to the doors that have been found ?
     
  6. Yup. Get the slots of the doors, I guess you can do the same with other entities that have codelocks on them.
     
  7. Good idea, will try to get this to work on chests, tcs and lockers :}
    [DOUBLEPOST=1496855196][/DOUBLEPOST]Oh, and I got a question, did extrimity pushed the idea for turret authorisation? Cos your plugin appeared in your servers while I was in the middle of making mine and I was playing with him from time to time ^^. Feels like my idea was leaked trough extrimity xD
     
  8. I was asked to add turret authorisation into the plugin by the Owner (Tyran), not sure where he got the idea from. I know a lot of players had requested it though.
     
  9. Yeah, I had cupboard plugin working first so making it work for turrets was super easy, I wonder why u didn't have it earlier ^^
     
  10. Alright, I got past the problem of finding codelocks, but yet again they work different from Turrets and Cupboards, or I just make a mistake somewhere...

    I want to check if player can open the door before passing priviledge to anyone else


    Code:
                    if (!(CanUseDoor(player, entity as codeLock))) 
                    {
                        SendReply(player, msg("noOwner"));
                        return;
                    }
    and the CanUseDoor below:
    Code:
            bool CanUseDoor(BasePlayer player, BaseLock codeLock)
            {
                if (codeLock is CodeLock)
                {
                    List<ulong> whitelist = (List<ulong>)whitelistPlayers.GetValue(codeLock);                if (whitelist.Contains(player.userID))
                    {  
                        PrintWarning("Yes he can!");
                        return true;
                    }
                }            return false;
            }
     
  11. What I found in AssemblyCSharp.dll - BaseLock: HasLockPermission(BasePlayer player):bool
    by, find: Usage, I found this:
    Code:
      public override bool OnTryToOpen(BasePlayer player)
      {
        object obj = Interface.CallHook("CanUseLockedEntity", (object) player, (object) this);
        if (obj is bool)
          return (bool) obj;
        if (this.HasLockPermission(player))
          return true;
        return !this.IsLocked();
      }
    CanUseLockedEntity is actually OxideHook: "CanUseLockedEntity" "object [Oxide.Core]Oxide.Core.Interface::CallHook(string, object[])"
    But I think more important for you is this.HasLockPermission(player) and this.IsLocked()
     
  12. Epic find mate ! Gonna test it out a bit later ;) Thanks !
     
  13. Didn't read all of it, but you should setup Visual Studio so you can see all the methods. Manually allowing people on doors isn't the greatest idea. I asked Ryan a day or two ago if I could copy his and release it and he said yes, so you can just wait for that if you'd like. :)
     
  14. I got visual studio, but sometimes forum people give me straight up answer instead of me snooping trough a bunch of files in hopes to find the right method ;D On top of that I get suggestions of making things in different ways :}, hopefully I get my codelock plugin working today, but if yours works better just gonna switch to yours ;)
     
  15. Hello,

    I'd like to use this method for my plugin, but I've got an issue.

    Code:
                    if (CanUseDoor(player, entity as CodeLock))
                    {
                        SendReply(player, msg("noOwner"));
                        return;
                    }
    entity is returned as "lock.code[562630]"

    but when it gets to the "whitelist" in CanUseDoor , I get (NullReferenceException: Object reference not set to an instance of an object)
     
  16. Wulf

    Wulf Community Admin

    Without seeing all of your code, we can't really help. If you used the old examples from other threads, then you are likely using it wrong as it has changed and reflection is not needed anymore.
     
  17. Hey guys, still stuck, but the error persists in this line:

    List<ulong> whitelist = (List<ulong>)whitelistPlayers.GetValue(codeLock);

    Reflection used:

    System.Reflection.FieldInfo whitelistPlayers = typeof(CodeLock).GetField("whitelistPlayers", BindingFlags.NonPublic | BindingFlags.Instance);

    Ideas ?
     
  18. Wulf

    Wulf Community Admin

    You do not need to use reflection for that.
     
  19. how should I declare the whitelistPlayers then ?
    [DOUBLEPOST=1497281658][/DOUBLEPOST]Oh, nwm, used the whitelist check from friends plugin, I was overthinking it, while it was so simple xD... Cheers for the help !
     
  20. Ummm, another tiny annoying issue, hopefully the final one ^^... For some reason my code finds same codelock twice or more, I tried to filter it out every way I could but, to no avail... Also, even if im looking for codelocks on doors specifically and yet it still finds the tc's codelock, tried to "If" it out, but it still screws up the whole search.

    Code:
                        case "addfriends":
                            if (Friends)
                            {
                                int b = 0;
                                var bhits = Physics.OverlapSphere(player.transform.position, 30);
                                var prev = "nothing";                            var next = "nothing";
                              
                                foreach (var hit in bhits)
                                {
                                    Door door = hit.GetComponentInParent<Door>();
                                    BoxStorage box = hit.GetComponentInParent<BoxStorage>();
                                    Locker locker = hit.GetComponentInParent<Locker>();
                                    BuildingPrivlidge cupboard = hit.GetComponentInParent<BuildingPrivlidge>();
                                    if (hit.GetComponentInParent<Door>() != null && door.GetSlot(BaseEntity.Slot.Lock) is CodeLock && !(hit.GetComponentInParent<BuildingPrivlidge>()))
                                    {
                                        var target = door.GetSlot(BaseEntity.Slot.Lock);
                                        //PrintWarning("Target: " + target);
                                        prev = target.ToString();
                                        if (!(prev == next))
                                        {
                                            RegisterFriends(player, target);
                                            //PrintWarning("PreviousDoor: " + prev + " NextDoor: " + next);
                                            PrintWarning("Added to: " + target.ToString());
                                            b++;
                                        }
                                        next = prev;
                                    }
                                }
                            }
    Any other, more elegant ways to remodel this ?