Jump to content
  • 0

How do I add 20 seconds before I can send a message again in this code?


Question

Posted

How can I add 20 seconds before I can send a message again in this code?

-    script    map    -1,{

OnWhisperglobal:
if( getgroupid() < 5 ) end;
announce ""+strcharinfo(0)+": "+@whispervar0$,bc_map;

end;

}

-    script    global    -1,{

OnWhisperglobal:
if( getgroupid() < 5 ) end;
announce ""+strcharinfo(0)+": "+@whispervar0$,bc_all;

end;

}

 

1 answer to this question

Recommended Posts

  • 0
Posted

Add gettimetick(2)

Try the code below

-    script    global    -1,{
    
OnInit:
    setarray .@LastWhisperTime[0], 0; // Initialize an array to store the last whisper time

OnWhisperglobal:
    if (getgroupid() < 5) end; // Allow only players with group ID 5 and above to use this command
    if (.@LastWhisperTime[getcharid(0)] + 20 > gettimetick(2)) {
        // If the time since the last whisper is less than 20 seconds, prevent another whisper
        dispbottom "You need to wait " + (.@LastWhisperTime[getcharid(0)] + 20 - gettimetick(2)) + " seconds before sending another message.";
        end;
    }
    // Update the last whisper time to the current time
    .@LastWhisperTime[getcharid(0)] = gettimetick(2);
    // Announce the message
    announce ""+strcharinfo(0)+": "+@whispervar0$,bc_all;

end;

}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...