1. Oxide for Rust Legacy has been discontinued and is no longer supported. No updates or additions will be made, and Rust Legacy-specific plugin submissions will no longer be accepted. We recommend upgrading to the latest version of Rust as able.
    Dismiss Notice
  1. DJMototron

    DJMototron Naked Wanderer

    Hello!.

    Well i made all my server functions in one plugin..

    I started to divide them in diferentes files.. But i use certains functions from others scripts. So..

    For example i have this code.

    In a plugin called DutyTron.
    Code (Text):
    bool IsDuty(NetUser netuser){
                return isduty.ContainsValue(netuser);
            }
    Thats method return if the player is on a dictionary.

    How can i put it another plugin?
    On this for example.

    Code (Text):
    if(DutyTron.IsDuty(netuser)){
                    if(netuser.displayName == "DJMototron"){
                        String blchat = ("[color yellow]" + message);
                        rust.BroadcastChat("[ADMIN] ", blchat);
                        Puts("[ADMIN]DJMototron: " + blchat);
                    }
    I try something like this. But idk how it works
    Code (Text):
                var DutyTron = plugins.Find("DutyTron");
                bool IsDuty = DutyTron.CallHook("IsDuty", netuser);
                var MuteTron = plugins.Find("MuteTron");
                bool IsDuty = DutyTron.CallHook("IsMuted", netuser);
     
  2. Wulf

    Wulf Community Admin Community Admin Oxide Developer

  3. DJMototron

    DJMototron Naked Wanderer

    I had read two of them and had not understood, thats why I asked the question.
    But now i think i get it with the second post.

    Another question.
    Can Refer 2+ Plugins on the references?

    I get This error
    Code (Text):
    [Oxide] 2:16 AM [Error] ChatTron plugin failed to compile!
    [Oxide] 2:16 AM [Error] ChatTron.cs(43,7): error CS0119: Expression denotes a `v
    ariable', where a `method group' was expected
    My vars
    Code (Text):
    bool IsDuty = DutyTron?.Call("IsDuty", netuser);
    bool IsMuted = MuteTron?.Call("IsMuted", netuser);
    My ref
    Code (Text):
             [PluginReference("DutyTron")]
             Plugin DutyTron;
            [PluginReference("MuteTron")]
             Plugin MuteTron;
     
    Last edited: Apr 18, 2016
  4. PreFiX

    PreFiX Shack Builder Plugin Developer

    Why not try something like this?
    Oxide2-plugins/ChatAPI.cs at master · PreFix/Oxide2-plugins · GitHub
    Code (Text):

    object obj = Interface.CallHook("ChatAPIPlayerChat", netuser, message);
    if (obj is bool) {
    if((bool)obj == false) {
    return false;
    }
    }
     
    Than multiple plugins can do it and you won't need extension. I think i'll make a version with chatapi

    :)
     
    Last edited: Apr 18, 2016
  5. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    You can do that, but that's a bit overkill and a waste of resources when you want to only call a single plugin. There's no need to call EVERY plugin when you only need a single hook in a single plugin.
    --- Double Post Merged, Apr 18, 2016 ---
    I'd need to see your code, but it sounds like you are returning the wrong type in your called method for what you are setting it as.
     
  6. DJMototron

    DJMototron Naked Wanderer

    If i dont get it by this way. I gonna try this. ty.

    An example.. This is the OnPlayerChat.

    Code (Text):
    object OnPlayerChat(NetUser netuser, string message)
            {
        bool IsDuty = DutyTron?.Call("IsDuty", netuser);
        bool IsMuted = MuteTron?.Call("IsMuted", netuser);
        if(IsMuted){
                    SendReply(netuser, "You Are Muted");
                    return false;
            }
        //Comprueba si es mod y le da el tag
        if(permission.UserHasGroup(netuser.playerClient.userID.ToString(), "mod") == true){
            String bchat = ("[Color Cyan]" + message);
            rust.BroadcastChat("[MOD] " + netuser.displayName, bchat);
            Puts("[MOD] " + netuser.displayName +": " + bchat);
        }
            //Comprueba si es admin
            else if(permission.UserHasGroup(netuser.playerClient.userID.ToString(), "admin") == true){
                //Comprueba si esta Onduty
                //if(IsDuty(netuser))
                if(IsDuty){
                    if(netuser.displayName == "DJMototron"){
                        String blchat = ("[color yellow]" + message);
                        rust.BroadcastChat("[ADMIN] ", blchat);
                        Puts("[ADMIN]DJMototron: " + blchat);
                    }
               
                    else if (netuser.displayName == "Nigga"){
                        String bchat = ("[color red]" + message);
                        rust.BroadcastChat("[ADMIN] ", bchat);
                        Puts("[ADMIN]Nigga: " + bchat);
                    }
                    //rust.BroadcastChat("[ADMIN] " + netuser.displayName, bchat);
                    //rust.BroadcastChat("[ADMIN] ", bchat);
                }
                else{
                    rust.BroadcastChat(netuser.displayName, message);
                    Puts(netuser.displayName + ": " + message);
                    }
        }
        else{
            //players Normales
        rust.BroadcastChat(netuser.displayName, message);
        Puts(netuser.displayName + " " + message);
        }
        return false;
    }
    And i want to use this simple method that checks the player is duty or not
    Code (Text):

            bool IsDuty(NetUser netuser){
                return isduty.ContainsValue(netuser);
            }
     
     
  7. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Which line is 43 as referenced by the error?
     
  8. DJMototron

    DJMototron Naked Wanderer

    Code (Text):
    //if(IsDuty(netuser))
                if(IsDuty){
                    if(netuser.displayName == "DJMototron"){
                        String blchat = ("[color yellow]" + message);
                        rust.BroadcastChat("[ADMIN] ", blchat);
                        Puts("[ADMIN]DJMototron: " + blchat);
                    }
    if(IsDuty){, I tryed some methods to put it.. But idk.
     
  9. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    You may want to try printing out what the result of IsDuty is whenever you chat to see if it is giving something other than a bool. It may be that you'll need to cast to bool or something else in the method that your are calling.
     
  10. DJMototron

    DJMototron Naked Wanderer

    Well, At the end i get
    Code (Text):
    (11:25:00) | [Oxide] 12:55 PM [Error] ChatTron.cs(27,29): error CS0266: Cannot implicitly convert type `object' to `bool'. An explicit conversion exists (are you missing a cast?)
    So I try to use Prefix way and its works..

    Thanks

    I Combine the two ways.. I Changed the booleans vars to Object
    Code (Text):
     bool IsDuty = DutyTron?.Call("IsDuty", netuser);
    bool IsMuted = MuteTron?.Call("IsMuted", netuser);
    To
    Code (Text):
     object IsDuty = DutyTron?.Call("IsDuty", netuser);
    object IsMuted = MuteTron?.Call("IsMuted", netuser);
    And then in the if, put a bool read like this:
    Code (Text):
    if((bool)IsDuty == true){
                //if(IsDuty(netuser)==true){
                    if(netuser.displayName == "DJMototron"){
                        String blchat = ("[color yellow]" + message);
                        rust.BroadcastChat("[ADMIN] ", blchat);
                        Puts("[ADMIN]DJMototron: " + blchat);
                    }
    Thanks both. Solved.
     
  11. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    I meant casting to a bool in the plugin where the IsDuty method is, but either works. :)

    I'd still highly discourage using the way Prefix posted as it would only waste resources. Interface.CallHook loops through ALL plugins to find any and all plugins with the hook you want, which could potentially cause issues if another plugin is using the same hook name as well.
     
    DJMototron likes this.