trying to add permissions to instant research plugin:
but on research starts i am getting this:Code:void OnItemResearchStart(ResearchTable table, BaseEntity target) { if (permission.UserHasPermission(target.OwnerID.ToString(), "instantresearch.use")) {table.researchDuration = 0f;} else {table.researchDuration = 10f;} }any advice if it's possible to add such perm?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
Permissions for Research Table
Discussion in 'Rust Development' started by Artasan, May 21, 2017.
-
Wulf Community Admin
I wouldn't assume that the player is always there, so add a null check.
-
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 -
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;} }
it works if permission set for the group and i check for it, but it's pointless. it should work with player permissions.. -
Wulf Community Admin
You can't just add new arguments to hooks either, you need to use what the hook provides. -
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;} } } }
-
Wulf Community Admin
Also, remove the PermissionExists check, that is unnecessary.