Code:object OnXpEarn(BasePlayer player, float amount, string source) { if (HasPermission(player, "XP2")) { //SendReply(player, source); return null; } else { return null; } }
There is something wrong or I am doing something wrong?Code:Object reference not set to an instance of an object
NullReferenceException with my code
Discussion in 'Rust Development' started by Reynostrum, Jul 7, 2016.
-
Wulf Community Admin
Sounds like you're trying to use something that doesn't exist. Does your HasPermission take a player or a Steam ID?
-
Same.Code:
object OnXpEarn(BasePlayer player, float amount, string source) { return null; } -
Wulf Community Admin
There's no way you'd get an NRE from just that. -
You are right. My bad.
But this
Still NRE.Code:object OnXpEarn(BasePlayer player, float amount, string source) { if (player.IsAdmin()) { SendReply(player, source); return null; } return null; } -
Wulf Community Admin
Add some null checks, but there's nothing in there that would be null. -
Sorry Wulf, what do you mean by null checks?
-
Wulf Community Admin
Checking if a variable is null or not, printing, == checks, etc. -
It's fine now. But I have another question.
Since I am making a personal plugin, I also want to boost xp, but for that I need to use the hook just in one plugin, so I have this problem:
That does not work. I can't find what I am doing wrong.Code:object OnXpEarn(BasePlayer player, float amount, string source) { amount * 10f; //stolen from your plugin :P // some other code that works fine return null; } -
Wulf Community Admin
You have to return the amount, not null. -
Can't make it work.Code:
amount = amount * 10f; return amount;
Sorry Wulf, I'm giving you a headache. -
Wulf Community Admin
You're likely not on the latest Oxide version then. -
You're right. Thanks Wulf. You're amazing.
