Faui

Clientsided Spam

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 :-)

Share this post


Link to post
Share on other sites
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);
        }
    }

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.