Hello all, im creating a timer that works using the every 1 second timer and giving of a non-existing item. My code is below: the error is that it doesent take into account multiple people using this. IF anyone has any ideas i beg of you to post them! Thanks in advanced
every second it increments the timer by one BTW
Code:#region GiveTimer Oxide.Plugins.Timer GiveTimer; private void GivePlayerTime(BasePlayer player) { float time = 0; GiveTimer = timer.Repeat(1f, 0, () => { if (currentPlayers.ContainsKey(player.UserIDString)) { time++; player.SendConsoleCommand("note.inv", -1565095136, time, "Time"); } }); } #endregionCode:GivePlayerTime(player); GiveTimer.Destroy();
Using give item command as a timer
Discussion in 'Rust Development' started by Sonny-Boi, Feb 5, 2018.
-
Wulf Community Admin
If you want to have a timer per player that is later destroyed, you’d need to add each timer usage to a dictionary by something unique to that player.
-
Could you possibly give an example on what that would look like
-
Basically something like this
Code:[OnlinePlayers] private readonly Hash<BasePlayer, OnlinePlayer> _onlinePlayers = new Hash<BasePlayer, OnlinePlayer>(); // You can find the current online player using `var curPlayer = _onlinePlayers[basePlayer]` private class OnlinePlayer{ // -- All custom elements of a player -- // Add timer in here, a new instance of a timer will be created for each player }
-
The userid, either as string or ulong, is much more consistent.Last edited by a moderator: Feb 5, 2018 -
I don't think anyone will learn by blatantly giving them the answer (Unless the premise of stack overflow is wrong). What I gave was a step toward a right direction, not the right direction. Also, no, it's not the worst decision one could make. The list is there already, use it.
If you're still interested in how a person gets a hint and does research off of it, please PM me, I'm open to discuss. -