Solved Subscribing to a hook?

Discussion in 'Rust Development' started by deusprox, Feb 16, 2017.

  1. I want to utilize the "OnItemDeployed" Hook to detect when a codelock is set and then change the OwnerID of the entity(door|chest|ladder hatch|...possible future thing...)

    But I also would like to make it configurable for the server admin to decide if this hook should be used or if the entity keeps it's OwnerID. I could simply wrap it my code inside an "if-clause" but i would like to save the performance when this functionality is unwanted. Instead I would like to register it similiar to "AddChatCommand()". Is there maybe some functionality I have overlooked for achieving this?
     
  2. Here's an example from Vanish:
    Code:
    Subscribe(nameof(CanNetworkTo));
    Unsubscribe(nameof(CanNetworkTo));
    
    Where "CanNetworkTo" is your hook.
    I'm not really sure what the point of this is since the performance difference will be less than a single millisecond if it's not calling something that's slow for the if (which is why I question it's use in Vanish as well), but it should work for what you're asking.
     
    Last edited by a moderator: Feb 16, 2017
  3. Great! Thank you! Yeah it probably won't be a big perfomance influence checking it with an if-clause everytime but it's kinda my habit to strip off everything unneeded. Every milliseconds counts :D