Strange situation. I have hook in my plugin:
Calling it from other plugin:Code:[HookMethod("HasFriend")] private bool HasFriend(ulong playerId, ulong friendId) { if (!knownPlayers.Contains(playerId) || !knownPlayers.Contains(friendId)) { return false; } if (!playerInfo.ContainsKey(playerId)) { var kvp = LoadData(playerId); playerInfo.Add(kvp); } PlayerInfo p = null; if (playerInfo.TryGetValue(playerId, out p)) { var friend = p.friends.FirstOrDefault(f => f.Id == friendId); if (friend != null) { return true; } } return false; }
Before last Rust and Oxide update it was working fine? but now I'm getting:Code:return (bool)Players?.Call("HasFriend", new object[] { playerId, friendId });
Hmm, trying other method:Code:[FriendlyFire] FriendlyFire: OnPlayerAttack failed: Object reference not set to an instance of an object
same error.Code:return (bool)Players?.CallHook("HasFriend", playerId, friendId );
Wtf?
Solved Calling hook throws a NullReferenceException
Discussion in 'Rust Development' started by Rizzok, Oct 6, 2017.
-
I'd recommend better null checking. It's hard to say without having the full plugin code, but with that snippet it looks like any of knownPlayers, playerInfo, or p.friends could be null.
-
no, all vars is initializing correctly and plugin worked like a charm almost 2 years...
-
-
Wulf Community Admin
Please test the latest Oxide snapshot here: AppVeyor
Should fix plugins using the wrong hook arguments in the plugin they are relying on (ie. Economics) by sending new object[ "blah", blah ] instead of the actual hook's args in the plugin they are calling or sending an int when the target plugin expects a double.
I've tested it personally and it resolved the issue you were having, so please test for yourself as able. -
Code:> version Protocol: 2022.152.1 Build Date: 10/06/2017 05:24:20 Unity Version: 2017.1.1f1 Changeset: 23156 Branch: main Oxide Version: 2.0.3519
Code:return (bool)Players?.Call("HasFriend", new object[] { playerId, friendId });
Code:return (bool)Players?.CallHook("HasFriend", playerId, friendId );
-
Wulf Community Admin
-
Code:
private bool HasFriend(string playerId, string friendId) { if (Players == null) return false; return (bool)Players?.CallHook("HasFriend", playerId, friendId ); }
-
Wulf Community Admin
-
-
Wulf Community Admin
-