So what i'm trying to do is if you take a look at the code at the bottom, i'm trying to make a command that when said /grind weed , if you stand still for 60 seconds it will give you 1 weed in your amount variable, take a look:
So in the if statement how would i make the player stand still for 60 seconds to gain + 1 in their WeedAmountCode:private float WeedGrindTimer = 60; private float WeedAmount;[ChatCommand("grind")] void cmdGrind(BasePlayer player, String Command, String[] arg) { switch (arg.Length) { case 0: PrintToChat("/grind help - for commands"); break; case 1: if(arg[0] == "weed") { } break; } }
Solved Giving amount of time over time?
Discussion in 'Rust Development' started by Captain Zip, Aug 7, 2017.
-
Code:
private Dictionary<ulong, Vector3> SavedPositions = new Dictionary<ulong, Vector3>(); [ChatCommand("grind")] void cmdGrind(BasePlayer player, String Command, String[] arg) { switch (arg.Length) { case 0: { PrintToChat("/grind help - for commands"); break; } case 1: { if (arg[0].ToLower() == "weed") { if (!SavedPositions.ContainsKey(player.userID)) SavedPositions.Add(player.userID, player.transform.position); else { PrintToChat(player, "You're already grinding weed"); return; } var repeatCount = 0; timer.Repeat(1f, 60, () => { if (SavedPositions[player.userID] != player.transform.position) { PrintToChat(player, "It looks like you've moved, you need to stand still to grind weed."); SavedPositions.Remove(player.userID); return; } if (repeatCount == 59) { PrintToChat(player, "You've sucessfully grinded your weed"); SavedPositions.Remove(player.userID); // rest of your code here return; } repeatCount++; }); } break; } } }
-
-
Yea the timer also needs destroying inside of the callback
-
-
Well showing the error would help, I assume it's because you need to add a "using UnityEngine;" though.
-
-
Vector3.Distance would be better I thing =)
-