Faui Posted August 14, 2018 Posted August 14, 2018 Hello Someone can help me? I have a Tablet with apps and when the user is clicking on the app its triggering C# Server-event. But user can spam button even when i set the called function in a timer. Does someone have a good and easy idea how to disable for example getting commands by the player for 5 seconds? Thx
notsosmart Posted August 14, 2018 Posted August 14, 2018 First create a timer system that runs on [ServerEvent(Event.Update)] and invokes an Action when the time is up. That way you can do SetEntityData("cooldown", true) on the player if they execute the command and if they execute it again and the player HasEntityData("cooldown") just return out. If they don't have the data, SetEntityData("cooldown") again, execute your command code, then create a timer CreateTimer(() => { ResetEntityData("cooldown"); }, 5000) which in 5 seconds removes the entity data. I'm not home at the moment but if you are struggling to make a timer system I can give you mine later.
Faui Posted August 14, 2018 Author Posted August 14, 2018 It would be sick if you could send me yours my friend - Awesome!!! I done many timers with c# but is not working as i want it - So i would really celebrate it!!! Write me a PN :-)
notsosmart Posted August 15, 2018 Posted August 15, 2018 10 hours ago, Faui said: It would be sick if you could send me yours my friend - Awesome!!! I done many timers with c# but is not working as i want it - So i would really celebrate it!!! Write me a PN 🙂 I just realized this was implemented long ago into the actual bridge API and serves your needs perfectly fine. public class Example : Script { [Command("cooldown")] public void CCExample(Client player) { if (player.HasData("cooldown")) return; player.SetData("cooldown", true); player.SendChatMessage("Triggered!"); NAPI.Task.Run(() => { player.ResetData("cooldown"); }, 5000); } }
Faui Posted August 15, 2018 Author Posted August 15, 2018 Some little changes and worked perfect :--)))
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now