1. trying to add permissions to instant research plugin:
    Code:
    void OnItemResearchStart(ResearchTable table, BaseEntity target)
    {
    if (permission.UserHasPermission(target.OwnerID.ToString(), "instantresearch.use")) {table.researchDuration = 0f;} else {table.researchDuration = 10f;}
    }
    but on research starts i am getting this:
    Code:
    [Error] Failed to call hook 'OnItemResearchStart' on plugin 'InstantResearch v1.1.0' (NullReferenceException: Object reference not set to an instance of an object)
    [Stacktrace]   at Oxide.Plugins.InstantResearch.OnItemResearchStart (.ResearchTable table, .BaseEntity target) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.InstantResearch.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.CSharpPlugin.InvokeMethod (HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00000] in <filename unknown>:0
    any advice if it's possible to add such perm?
     
  2. Wulf

    Wulf Community Admin

    I wouldn't assume that the player is always there, so add a null check.
     
  3. something like this:
    Code:
    void OnItemResearchStart(ResearchTable table, BaseEntity target, BasePlayer player)
    {
    if (player != null && permission.UserHasPermission(target.OwnerID.ToString(), "instantresearch.use")) {table.researchDuration = 0f;} else {table.researchDuration = 10f;}
    }
    ?
     
    Last edited by a moderator: May 24, 2017
  4. i got rid of the error with null check:
    Code:
    void OnItemResearchStart(ResearchTable table, BasePlayer player)
    {
    if (player != null && permission.UserHasPermission(player.ToString(), "instantresearch.use")) {table.researchDuration = 0f;} else {table.researchDuration = 10f;}
    }
    but there still is no effect of insta research. don't get what i am doing wrong.. еxcept that i am noob in coding =]
    it works if permission set for the group and i check for it, but it's pointless. it should work with player permissions..
     
  5. Wulf

    Wulf Community Admin

    player.ToString() is not the ID. Also, formatting. ;)

    You can't just add new arguments to hooks either, you need to use what the hook provides.
     
  6. Code:
    namespace Oxide.Plugins
    {
        [Info("Instant Research", "Artasan", "1.1.0", ResourceId = 1318)]
        [Description("Instant research in research table")]
        public class InstantResearch : RustPlugin
        {
            string perm = "instantresearch.use";
            float insta = 0f;
            float dur = 10f;        void Init()
            {
                if (!permission.PermissionExists(perm)) permission.RegisterPermission(perm, this);
            }        void OnItemResearchStart(ResearchTable t, BasePlayer p)
            {
                if (p == null) return;
                if (permission.UserHasPermission(p.UserIDString, perm)) {t.researchDuration = insta;} else {t.researchDuration = dur;}
            }
        }
    }
    and still nothing.. can u point me please with more details? =\
     
  7. Wulf

    Wulf Community Admin

    There is no BasePlayer argument for OnItemResearchStart, you can't just add new arguments. You'd have to get the player form the ResearchTable.

    Also, remove the PermissionExists check, that is unnecessary.