It's a simple game that counts down (in seconds)
Commands are:
!countdown (number can't be over 500000) (id can be set)
!countstarted (id) (shows who started it what number it is counting down from and how much time has passed)
!viewcount (id) (shows what the countdown number is at)
!countstop (id) (stops the count only the person who started it can stop it, it shows who stopped it, what is was counting down from and how much time had passed)
!countpause (id) (pauses the countdown)
!countrestart (id) (starts the countdown again)
!viewid (id) (Status on the id)
on *:TEXT:*:#: {
tokenize 32 $strip($1-)
if ( %flood [ $+ [ $nick ] ] == $null ) {
set -u4 %flood [ $+ [ $nick ] ] 1
if (!countdown == $1) {
if ($3) && ($3 >= 5) { goto count2 }
if (!$2) { msg $chan Useage: !countdown (second), are you can set a Id to it Useage: !countdown (number) (Id) | halt }
elseif ($2) && ($2 >= 500001) { msg $chan Sorry number is to big | halt }
else { goto count }
:count
if (%count5) && (%count4) && (%count3) && (%count2) && (%count) && ($2) { msg $chan There is already 5 counts going | halt }
if (!%count) { .timer 1 2 set -z %count $2 | set %countp1.1 $2 | set %countp2.1 $nick | msg $chan It will now count down from $2 (Count Id 1) | halt }
elseif (!%count2) { .timer 1 2 set -z %count2 $2 | set %countp1.2 $2 | set %countp2.2 $nick | msg $chan It will now count down from $2 (Count Id 2) | halt }
elseif (!%count3) { .timer 1 2 set -z %count3 $2 | set %countp1.3 $2 | set %countp2.3 $nick | msg $chan It will now count down from $2 (Count Id 3) | halt }
elseif (!%count4) { .timer 1 2 set -z %count4 $2 | set %countp1.4 $2 | set %countp2.4 $nick | msg $chan It will now count down from $2 (Count Id 4) | halt }
elseif (!%count5) { .timer 1 2 set -z %count5 $2 | set %countp1.5 $2 | set %countp2.5 $nick | msg $chan It will now count down from $2 (Count Id 5) | halt }
:count2
if ($3 == 1) && (!%count) { .timer 1 2 set -z %count $2 | set %countp1.1 $2 | set %countp2.1 $nick | msg $chan It will now count down from $2 (Count Id 1) | halt }
elseif ($3 == 2) && (!%count2) { .timer 1 2 set -z %count2 $2 | set %countp1.2 $2 | set %countp2.2 $nick | msg $chan It will now count down from $2 (Count Id 2) | halt }
elseif ($3 == 3) && (!%count3) { .timer 1 2 set -z %count3 $2 | set %countp1.3 $2 | set %countp2.3 $nick | msg $chan It will now count down from $2 (Count Id 3) | halt }
elseif ($3 == 4) && (!%count4) { .timer 1 2 set -z %count3 $2 | set %countp1.3 $2 | set %countp2.3 $nick | msg $chan It will now count down from $2 (Count Id 3) | halt }
elseif ($3 == 5) && (!%count5) { .timer 1 2 set -z %count5 $2 | set %countp1.5 $2 | set %countp2.5 $nick | msg $chan It will now count down from $2 (Count Id 5) | halt }
else { msg $chan Error Entering Infomation }
}
if (!viewcount == $1) {
if (!$2) { msg $chan You need to type a count Id ranging from 1 to 5 | halt }
if ($2 == 1) && (%count) { msg $chan $calc(%countp1.1 - %count) has gone by. Count has been running for $duration($calc(%countp1.1 - %count)) }
elseif ($2 == 2) && (%count2) { msg $chan $calc(%countp1.2 - %count2) has gone by. Count has been running for $duration($calc(%countp1.2 - %count2)) }
elseif ($2 == 3) && (%count3) { msg $chan $calc(%countp1.3 - %count3) has gone by. Count has been running for $duration($calc(%countp1.3 - %count3)) }
elseif ($2 == 4) && (%count4) { msg $chan $calc(%countp1.4 - %count4) has gone by. Count has been running for $duration($calc(%countp1.4 - %count4)) }
elseif ($2 == 5) && (%count5) { msg $chan $calc(%countp1.5 - %count5) has gone by. Count has been running for $duration($calc(%countp1.5 - %count5)) }
elseif ($2 == 1) && (%count.pause1) { msg $chan That count has been stopped by %countp2.1 }
elseif ($2 == 2) && (%count.pause2) { msg $chan That count has been stopped by %countp2.2 }
elseif ($2 == 3) && (%count.pause3) { msg $chan That count has been stopped by %countp2.3 }
elseif ($2 == 4) && (%count.pause4) { msg $chan That count has been stopped by %countp2.4 }
elseif ($2 == 5) && (%count.pause5) { msg $chan That count has been stopped by %countp2.5 }
else { msg $chan Count Id doesn't exist }
}
if (!countstarted == $1) {
if (!$2) { msg $chan You need to type a count Id ranging from 1 to 5 | halt }
if ($nick isop $chan) || ($nick == %countp2.1) && ($2 == 1) { msg $chan $calc(%countp1.1 - %count) has gone by. Count has been running for $duration($calc(%countp1.1 - %count)), Count stated by %countp2.1 it was set to countdown from %countp1.1 }
elseif ($nick isop $chan) || ($nick == %countp2.2) && ($2 == 2) { msg $chan $calc(%countp1.2 - %count2) has gone by. Count has been running for $duration($calc(%countp1.2 - %count2)), Count stated by %countp2.2 it was set to countdown from %countp1.2 }
elseif ($nick isop $chan) || ($nick == %countp2.3) && ($2 == 3) { msg $chan $calc(%countp1.3 - %count3) has gone by. Count has been running for $duration($calc(%countp1.3 - %count3)), Count stated by %countp2.3 it was set to countdown from %countp1.3 }
elseif ($nick isop $chan) || ($nick == %countp2.4) && ($2 == 4) { msg $chan $calc(%countp1.4 - %count4) has gone by. Count has been running for $duration($calc(%countp1.4 - %count4)), Count stated by %countp2.4 it was set to countdown from %countp1.4 }
elseif ($nick isop $chan) || ($nick == %countp2.5) && ($2 == 5) { msg $chan $calc(%countp1.5 - %count5) has gone by. Count has been running for $duration($calc(%countp1.5 - %count5)), Count stated by %countp2.5 it was set to countdown from %countp1.5 }
else { msg $chan Count Id doesn't exist }
}
if (!countstop == $1) {
if (!$2) { msg $chan No count Id typed | halt }
if ($nick isop $chan) || ($nick == %countp2.1) && ($2 == 1) && (%count) { unset %count %countp1.1 %countp2.1 | msg $chan $nick stopped the count number 1 }
elseif ($nick isop $chan) || ($nick == %countp2.2) && ($2 == 2) && (%count2) { unset %count2 %countp1.2 %countp2.2 | msg $chan $nick stopped the count number 2 }
elseif ($nick isop $chan) || ($nick == %countp2.3) && ($2 == 3) && (%count3) { unset %count3 %countp1.3 %countp2.3 | msg $chan $nick stopped the count number 3 }
elseif ($nick isop $chan) || ($nick == %countp2.4) && ($2 == 4) && (%count4) { unset %count4 %countp1.4 %countp2.4 | msg $chan $nick stopped the count number 4 }
elseif ($nick isop $chan) || ($nick == %countp2.5) && ($2 == 5) && (%count5) { unset %count5 %countp1.5 %countp2.5 | msg $chan $nick stopped the count number 5 }
else { msg $chan Count Id doesn't exist }
}
if (!countpause == $1) {
if (!$2) { msg $chan No count Id typed | halt }
if ($nick isop $chan) || ($nick == %countp2.1) && ($2 == 1) && (%count) { set %count.pause1 $calc(%countp1.1 - %count) | unset %count | msg $chan Count 1 was paused by $nick }
elseif ($nick isop $chan) || ($nick == %countp2.2) && ($2 == 2) && (%count2) { set %count.pause2 $calc(%countp1.2 - %count2) | unset %count2 | msg $chan Count 2 was paused by $nick }
elseif ($nick isop $chan) || ($nick == %countp2.3) && ($2 == 3) && (%count3) { set %count.pause3 $calc(%countp1.3 - %count3) | unset %count3 | msg $chan Count 3 was paused by $nick }
elseif ($nick isop $chan) || ($nick == %countp2.4) && ($2 == 4) && (%count4) { set %count.pause4 $calc(%countp1.4 - %count4) | unset %count4 | msg $chan Count 4 was paused by $nick }
elseif ($nick isop $chan) || ($nick == %countp2.5) && ($2 == 5) && (%count5) { set %count.pause5 $calc(%countp1.5 - %count5) | unset %count5 | msg $chan Count 5 was paused by $nick }
else { msg $chan Count Id doesn't exist }
}
if (!countrestart == $1) {
if (!$2) { msg $chan No count Id typed | halt }
if ($nick isop $chan) || ($nick == %countp2.1) && ($2 == 1) && (%count.pause1) { set -z %count %count.pause1 | unset %count.pause1 | msg $chan Count 1 restarted by $nick }
elseif ($nick isop $chan) || ($nick == %countp2.2) && ($2 == 2) && (%count.pause2) { set -z %count %count.pause2 | unset %count.pause2 | msg $chan Count 2 restarted by $nick }
elseif ($nick isop $chan) || ($nick == %countp2.3) && ($2 == 3) && (%count.pause3) { set -z %count %count.pause3 | unset %count.pause3 | msg $chan Count 3 restarted by $nick }
elseif ($nick isop $chan) || ($nick == %countp2.4) && ($2 == 4) && (%count.pause4) { set -z %count %count.pause4 | unset %count.pause4 | msg $chan Count 4 restarted by $nick }
elseif ($nick isop $chan) || ($nick == %countp2.5) && ($2 == 5) && (%count.pause5) { set -z %count %count.pause5 | unset %count.pause5 | msg $chan Count 5 restarted by $nick }
else { msg $chan Count Id doesn't exist }
}
if (!viewid == $1) {
if ($2 == 1) && (%count) { msg $chan Id in use }
elseif ($2 == 2) && (%count2) { msg $chan Id in use }
elseif ($2 == 3) && (%count3) { msg $chan Id in use }
elseif ($2 == 4) && (%count4) { msg $chan Id in use }
elseif ($2 == 5) && (%count5) { msg $chan Id in use }
else { msg $chan Id not in use }
}
}
}
very nice, your coding is coming along nicely, keeptin it neat using elseif's etc.
gd work m8
Am I to understand that this means that you are not a good script writer if you don't use /elseif ? The reason i use Else { then /if is that it makes it easier for me to see and understand. (I'm not nagging or complaining or trying to start anything) I just like to code that way. ^_^
No, the %var is faster. The main reason is because instead of having to reference $[N/I] over and over, and mIRC re-calculates it everytime, static %variables never change and are in your code, itself, rather than referencing back to parsing out the identifiers through calculations.
However, if you're seeing no lag, I wouldn't see the need, so awesome! :)
Just a quick hint: You can DRASTICALLY improve speed in the event by setting a variable to common used identifiers that don't require dynamic-values. ie: $chan will always be $chan, as well as $1 and $2.
At the beginning of the event, try setting a temporary variable to the commonly used identifiers. ie:
var %1 = $1, %2 = $2, %3 = $3, %c = $chan
While usage of the halt statement will prevent the extra processing of the if statements that follow the if statement that matches, Aucun's usage of if/elseif is not completely misused, however, I admit, it could be better coded.
As I have stated before, the only way to tell for sure which is faster, is to time test each of the codes, ensuring that the timing was set and relayed from the same general locations in both scripts... Ideally the timings should be done between exactly the same locations, however, due to the difference in the number of ON TEXT events in the two scripts, this is not possible.\
The $gettok is necessary for all of the modifications to be accurate.
You're right, however, about having to process multiple if's rather than if/elseif/else being slower.
As to the actual overall speed, it's difficult to say if Korvin's corrected code would be faster or slower than your original code, Aucun50, due to the fact that your code uses multiple ON TEXT events, which, in reality, do a built in if (the event has to check if the matchtext section matches the entry or not).
Additionally, a true speed test would have to be checked between the same two points in the two scripts, which is difficult to do, based on the fact that one uses a single event, and the other multiple events.
i really hate your style =/ soooooo i decided to edit your code in my style. look over it.
on *:TEXT:*:#: {
tokenize 32 $strip($1-)
var %w = !countdown,!viewcount,!countstarted,!countstop,!countpause,!countrestart
if ( %flood $+ $nick == $null ) {
set -u2 %flood $+ $nick 1
if ($1 == $gettok(%w,1,44)) {
if (%count) { msg $chan There is a game going already | halt }
if ($2 >= 100001) { msg $chan Sorry number is to big | halt }
if (!$2) { msg $chan Usage: !countdown (second) | halt }
set -z %count $2 | msg $chan It will now count down from $2, to view it type !viewcount | set %count2 $2 | set %count3 $nick
}
if (!%count) {
if ($1 == $gettok(%w,1,44)) {
if ($v1 = 1) { msg $chan Countdown is now over from %count2 | unset %count2 | unset %count3 | halt }
msg $chan %count | var %t $calc(%count2 - %count) | var %t2 $duration(%t) | msg $chan I have been running for %t2
}
if ($1 == $gettok(%w,1,44)) {
msg $chan The count was set to %count2 and $calc(%count2 - %count) seconds has gone by so far, the count was started by %count3 | var %t $calc(%count2 - %count) | var %t2 $duration(%t) | msg $chan Count can be stopped by %count3 with !stopcount, i have been running for %t2
}
if ($1 == $gettok(%w,1,44)) {
if ($nick !== %count3) { msg $chan You didn't start the count | halt }
msg $chan Count stopped by $nick it was set to %count2 and $calc(%count2 - %count) seconds had passed | unset %count %count2 %count3 %countpause
}
if ($1 == $gettok(%w,1,44)) {
if ($nick !== %count3) { msg $chan You didn't start the count | halt }
set %countpause %count | msg $chan Count is now paused, to start is again tpye !countrestart | unset %count
}
if ($1 == $gettok(%w,1,44)) {
if (%countpause) {
if ($nick !== %count3) { msg $chan You didn't pause or start the count | halt }
msg $chan Count started after stop | set -z %count %countpause
halt
}
msg $chan The count was never paused
}
}
msg $chan No countdown started
}
}
What reason, if any, did you pick a maximum time of 100000 seconds (aka 1day 3hrs 46mins 40secs)?
Suggestions for improvements:
1) Allowing multiple timers to run.
2) Make game multi-channel and multi-network ready.
3) Allow channel op to be able to stop the game if the person that started it leaves the room for any reason. Especially if the person is kicked and/or banned.
4) Change your unset line to read unset %count* (noting as how all of your variables start with %count)
All in all, a nice idea, and good scripting. 7/10 from me.