Hi. This is my code
Error: Failed to run a 10.00 timer in 'Testing v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)Code:using System; using UnityEngine; using System.Linq; using System.Collections.Generic;namespace Oxide.Plugins { [Info("Testing", "Testing", 1.0)] [Description("Testing")] class Testing : RustPlugin { void OnServerInitialized(BasePlayer player, PlayerInventory inventory) { timer.Repeat(10, 0, () => { if (player.inventory.GetAmount(498591726) > 2000) { PrintToChat("It works!"); } }); } } }
I have no idea what is wrong. If I remove the timer, it works.
Thank you!!!!!!
@Wulf
Timers and if problem
Discussion in 'Rust Development' started by Reynostrum, Nov 26, 2015.
-
OnServerInitialized does not have any parameters. remove the parameters and just loop through the players inside the timer.
-
Can you explain me a little more?
Thank you for helping me!! -
So you will need to loop through players instead.
Code:using System; using System.Collections.Generic;namespace Oxide.Plugins { [Info("C4 Count Checker", "Reynostrum", 1.0)] [Description("Checks if somebody has more than 2k C4")] class Testing : RustPlugin { void Loaded() { timer.Repeat(10, 0, () => { foreach(BasePlayer player in BasePlayer.activePlayerList) { if (player.inventory.GetAmount(498591726) > 2000) { Puts("Player " + player.displayName + " has more than 2000 C4!"); } } }); } } }
I'd also use Loaded() instead of OnServerInitialized -
Wulf Community Admin
-
Thanks for helping me.
Wulf, you may help me.
I am getting this error:
[Error] Failed to run a 10.00 timer in 'Dupetest v1.0.0' (InvalidOperationException: Collection was modified; enumeration operation may not execute.)
It works excellent after 1 loop. But then it stop working.Attached Files:
-
-
Wulf Community Admin
-
I apologize for my ignorance. -
Wulf Community Admin
-
I think i solved it:
I changed: foreach(BasePlayer player in BasePlayer.activePlayerList)
To: foreach(BasePlayer player in BasePlayer.activePlayerList.ToList())
I tried it like 10 times and looks like its ok.