Author Topic: ServerCmd Delay  (Read 1379 times)

How would I go about putting a delay between commands to prevent spamming? I am very clueless on how to do so. Simplest way please.

How would I go about putting a delay between commands to prevent spamming? I am very clueless on how to do so. Simplest way please.

What he meant was that if someone say /stuff they have to wait 5 sec or more before they can do it again.


It should look something like this

Code: [Select]
function serverCmdSomeCommand(%client)
{
     %time = getSimTime();
     if(%client.lastTimeSomeCommand $= "" || %time - %client.lastTimeSomeCommand > 5000)
     {
          //your code here

          %client.lastTimeSomeCommand = %time;
     }
     else
     {
          messageClient(%client,'',"You can't use this command right now.");
     }

}

This should work..

Code: [Select]
function serverCmdDoSomething(%client)
{
  if(%client.somethingCooldown)
    return;
  //stuff
  %client.somethingCooldown = 1;
  schedule(5000,0,cooledDown,%client);
}

function cooledDown(%obj)
{
   %obj.somethingCooldown = 0;
}

something like that but there's probably a better way to do it, i don't know if that works or not

Warning - while you were typing a new reply has been posted. You may wish to review your post.
ah i see

It should look something like this

Code: [Select]
function serverCmdSomeCommand(%client)
{
     %time = getSimTime();
     if(%client.lastTimeSomeCommand $= "")
     {
          %client.lastTimeSomeCommand = %time;
     }
     if(%time - %client.lastTimeSomeCommand > 5000)
     {
          //your code here

          %client.lastTimeSomeCommand = %time;
     }
     else
     {
          messageClient(%client,'',"You can't use this command right now.");
     }

}

This should work..
Code: [Select]
function servercmdstuff(%client)
{
if(%client.lastcommand <= $Sim::Time+10)
{
messageclient(%client,'',"You must wait 10 seconds before using this command again.");
%client.lastcommand = $Sim::Time;
}
}
Would that work too?

Code: [Select]
function serverCmdDoSomething(%client)
{
  if(%client.somethingCooldown)
    return;
  //stuff
  %client.somethingCooldown = 1;
  schedule(5000,0,cooledDown,%client);
}

function cooledDown(%obj)
{
   %obj.somethingCooldown = 0;
}

something like that but there's probably a better way to do it, i don't know if that works or not

Warning - while you were typing a new reply has been posted. You may wish to review your post.
ah i see

Yes, this is another way to do it.

Code: [Select]
function servercmdstuff(%client)
{
if(%client.lastcommand <= $Sim::Time+10)
{
messageclient(%client,'',"You must wait 10 seconds before using this command again.");
%client.lastcommand = $Sim::Time;
}
}
Would that work too?

No, sime time isn't actual seconds.. It is milliseconds

I actually made a support script a while ago, where you just added a single function call with arguments of the function name, number of arguments in the function, number of times allowed to be used, reset time, and an optional callback, a function that would execute (with the proper %client passed to it, of course) if the client has used the function too many times.

For example, the following code (if you have the script, of course) would make suiciding not be able to be used more than 5 times a minute, and it would tell the user "You can't Self Delete that often!" if they try to do it more

Code: [Select]
registerTimeRestrictedCommand("Self Delete",5,60,0,"handleSelf DeleteSpam");

function handleSelf DeleteSpam(%client)
{
    messageClient(%client,'','You can't Self Delete that often!');
}
« Last Edit: July 27, 2011, 07:31:37 PM by Headcrab Zombie »

Code: [Select]
function servercmdstuff(%client)
{
if(%client.lastcommand < $Sim::Time-10000)
{
//Dostuff
%client.lastcommand = $Sim::Time;
}
else
{
messageclient(%client,'',"You must wait 10 seconds before using this command again.");
}
}
Would that work? If not tell me what's wrong

no it wouldn't

look at the script infiniteloop gave again

It should look something like this

-snip-

This should work..

Code: [Select]
function serverCmdSomeCommand(%client) {
if(%client.lastTimeSomeCommand $= "" || (%time = getSimTime()) - %client.lastTimeSomeCommand > 5000) {
//your code here
%client.lastTimeSomeCommand = %time;
}
else
messageClient(%client, '', "You can't use this command right now.");
}

I shortened it a little. :D I'm God of suck.

Code: [Select]
function serverCmdSomeCommand(%client) {
if(%client.lastTimeSomeCommand $= "" || (%time = getSimTime()) - %client.lastTimeSomeCommand > 5000) {
//your code here
%client.lastTimeSomeCommand = %time;
}
else
messageClient(%client, '', "You can't use this command right now.");
}

I shortened it a little. :D I'm God of suck.

Yes, yes you are.

I shortened it a little. :D I'm God of suck.
Not worth it. It just makes the code harder to understand for new users.

I tried the following and it did not work.
Code: [Select]
package chatbot
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{

if(%client.lastTimeChatMessage $= "" || (%time = getSimTime()) - %client.lastTimeChatMessage > 5000) {

parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
                switch$(%msg)
                {
                        case "Testing":
                               commandToServer('messageSent',"This was a triumph!");
                        case "Hi":
                              commandToServer('messageSent',"Hello");
                        case "Bye":
                                commandtoserver('messagesent',"Goodbye.");
                        case "Goodbye":
                                commandtoserver('messagesent',"Goodbye.");
                }
}

};


%client.lastTimeChatMessage = %time;
}
else
messageClient(%client, '', "You can't use this command right now.");

activatePackage(chatbot);