SimpleGather

From Scriptwiki
Revision as of 12:22, 10 July 2007 by Shenghi (talk | contribs) (Simple gather script)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

SimpleGather is a fairly basic gather script mainly created because so many beginners are trying to make one, while even a very basic gather script is not that simple. The aim of SimpleGather is simplicity: it can run only one gather at a time, works only on a single channel, and multiple servers is out of the question. Setting it up is easy:

  • Copy and paste the script into a new script file, load it and make sure you run the initialization commands;
  • Go to the variables tab in the script editor;
  • Change "%gatherchannel-1172-df51-b4b6-313e-20070710100156" to your gather channel;
  • Change "%gatherplayercount-e7ab-d273-a5f9-6ae2-20070710094110" to the amount of players (defaults to 10);
  • Change "%serverinfo-da91-c1fb-b6c7-8f8b-20070710105309" to your server IP/Port.

The triggers

  •  !start - Starts a new gather. Only available to channel ops.
  •  !stop - Stops an ongoing gather. Only available to channel ops.
  •  !add - Adds the typer to the gather. Available to everyone.
  •  !remove - Removes the typer from the gather. Available to everyone.
  •  !remove <nick> - Removes the specified player from the gather. Only available to channel ops.
  •  !numplayers <num> - Sets the amount of participating players to <num>. If a gather is already past this amount then it will be flagged as full right away. Only available to channel ops.
  •  !gatherchan <chan> - Sets the gatherchan to <chan>. Cannot be used while gathering is in progress. Only available to channel ops on both the current and the new channel.
  •  !serverinfo <info> - Sets the server information to <info>. Cannot be used while gathering is in progress. Only available to channel ops.

The code

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;;  SimpleGather 1.0 by Shenghi 
;;  #help.script @ irc.quakenet.org 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
 
;;;;;;;;;;;;;;;;;;;; PRIVATE ALIASES ;;;;;;;;;;;;;;;;;;;; 
 
;; Return hash table name. Crazy name to prevent interferance with other scripts 
alias -l htname !return htGather-e064-e6ac-679f-c8b3-20070710073819 
 
;; Return gather channel name. 
alias -l gatherchannel !return %gatherchannel-1172-df51-b4b6-313e-20070710100156 
 
alias -l maxplayers !return %gatherplayercount-e7ab-d273-a5f9-6ae2-20070710094110 
 
alias -l serverinfo !return %serverinfo-da91-c1fb-b6c7-8f8b-20070710105309 
 
alias -l resetgather {  
  .timer 1 30 if ($!hget($!htname)) !hfree $htname  
  .timer 1 31 msg $!gatherchannel A new gather can be started now. 
} 
 
 
;;;;;;;;;;;;;;;;;;;; TRIGGERS ;;;;;;;;;;;;;;;;;;;; 
 
;; !start 
;; Starts a gather. Only a channel op can start a gather. 
on *:TEXT:!start:%gatherchannel-1172-df51-b4b6-313e-20070710100156: { 
  if ($nick !isop #) { .notice $nick You are not allowed to start a gather. | !return } 
 
  ;; check to see if we are already gathering (the hashtable will exist if we are) 
  if ($hget($htname)) { .notice $nick A gather is already going on. | !return } 
 
  ;; if we get here, start the gather. 
  !hmake $htname 
  msg # Starting a gather with $maxplayers players. Type !add to add yourself to the list of players or !remove to quit. 
} 
 
;; !stop 
;; Stops a gather. Only a channel op can stop a gather. 
on *:TEXT:!stop:%gatherchannel-1172-df51-b4b6-313e-20070710100156: { 
  if ($nick !isop #) { .notice $nick You are not allowed to stop a gather. | !return } 
 
  ;; check to see if there is a gather we can stop 
  if (!$hget($htname)) { .notice $nick There is currently no gather going on. | !return } 
 
  ;; if we get here we have to stop what's going on! 
  !hfree $htname 
  msg # Gather stopped. Type !start to start a new gather. 
} 
 
;; !add 
;; Adds a player to a running gather. Everyone can enter, but never more than 10 players. 
on *:TEXT:!add:%gatherchannel-1172-df51-b4b6-313e-20070710100156: { 
  ;; if there's no gathering going on, we can hardly add the player 
  if (!$hget($htname)) { .notice $nick There is no gather going on at the moment. | !return } 
 
  ;; up to 10 players can add themselves, never more. 
  if ($hget($htname,0).item == $maxplayers) { .notice $nick This gather is already full. | !return } 
 
  ;; if the player is already part of the gather, there's no point in adding them again. 
  if ($hget($htname,$nick)) { .notice $nick You are already taking part in this gather. | !return } 
 
  ;; clones can't join... 
  ;;if ($hfind($htname,$gettok($fulladdress,2,33)).data) { .notice $nick Clones are not allowed to join a gather. | !return } 
 
  ;; if we get here, add the player 
  !hadd $htname $nick $gettok($fulladdress,2,33) 
  .notice $nick You have been added to the gather. 
 
  ;; if the player who just joined was the 10th we end the gathering 
  ;; and notify the players of the information 
  if ($hget($htname,0).item == $maxplayers) { 
    .disable #numplayers-afeb-6ac1-6b3a-7606-20070710103913 
    msg # Gather full. If you joined this gather, please do not change your name until you received server information. 
    msg # Please wait until teams are generated and information is sent to players. 
 
    var %i = $maxplayers, %teamA, %teamB 
    while %i {  
      if (($rand(0,1)) && ($numtok(%teamA,44) < $calc($maxplayers / 2))) || ($numtok(%teamB,44) >= $calc($maxplayers / 2)) %teamA = $addtok(%teamA,$chr(32) $+ $hget($htname,%i).item,44) 
      else %teamB = $addtok(%teamB,$chr(32) $+ $hget($htname,%i).item,44) 
      dec %i 
    } 
    msg # Team A: %teamA 
    msg # Team B: %teamB 
    .raw PRIVMSG $remove(%teamA,$chr(32)) :Team: A > %teamA -- Server: $serverinfo 
    .raw PRIVMSG $remove(%teamB,$chr(32)) :Team: B > %teamB -- Server: $serverinfo 
    .enable #numplayers-afeb-6ac1-6b3a-7606-20070710103913 
    resetgather 
  } 
} 
 
;; !remove 
;; Removes a player from a running gather. Everyone can remove themselves. 
on *:TEXT:!remove:%gatherchannel-1172-df51-b4b6-313e-20070710100156:{ 
  ;; if there's no gathering going on, we can hardly remove the player 
  if (!$hget($htname)) { .notice $nick There is no gather going on at the moment. | !return } 
 
  ;; if the player was no part of this gather, we can't remove him either 
  if (!$hget($htname,$nick)) { .notice $nick You are not taking part in this gather. | !return } 
 
  ;; if we get here, remove the player from the gather 
  !hdel $htname $nick 
  .notice $nick You have been removed from the gather. 
} 
 
;; !remove <player> 
;; Removes a player from a running gather. Only a channel op can remove another player. 
on *:TEXT:!remove &:%gatherchannel-1172-df51-b4b6-313e-20070710100156:{ 
  if ($nick !isop #) { .notice $nick You are not allowed to remove another player. | !return } 
 
  ;; if there's no gathering going on, we can hardly remove the player 
  if (!$hget($htname)) { .notice $nick There is no gather going on at the moment. | !return } 
 
  ;; if the player was no part of this gather, we can't remove him either 
  if (!$hget($htname,$2)) { .notice $nick That player is not taking part in this gather. | !return } 
 
  ;; if we get here, remove the player from the gather 
  !hdel $htname $2 
  .notice $nick $2 has been removed from the gather. 
} 
 
;; !players 
;; Shows the current players in a running gather. Only channel operators can use this trigger 
on *:TEXT:!players:%gatherchannel-1172-df51-b4b6-313e-20070710100156:{ 
  if ($nick !isop #) { .notice $nick You are not allowed to dump the playerlist. | !return } 
 
  ;; if there is no gather going on, there is no list of players to dump. 
  if (!$hget($htname)) { msg # There is no gather going on at this moment. Use !start to start one. | !return } 
  var %i = $hget($htname,0).item 
  if (!%i) { msg # There are currently no players participating in this gather. | !return } 
  var %players 
  while %i {  
    %players = $addtok(%players,$chr(32) $+ $hget($htname,%i).item,44) 
    dec %i  
  } 
  msg # Current players: %players 
} 
 
#numplayers-afeb-6ac1-6b3a-7606-20070710103913 on 
;; !numplayers 
;; Sets the amount of players. 
on *:TEXT:!numplayers &:%gatherchannel-1172-df51-b4b6-313e-20070710100156:{ 
  ;; first arg has to be a number 
  if ($2 !isnum) { .notice $nick Wrong usage of trigger. | !return } 
 
  if ($calc($2 % 2)) { .notice $nick Number of players must be even. | !return } 
 
 
  !set %gatherplayercount-e7ab-d273-a5f9-6ae2-20070710094110 $2 
  msg # Amount of players for gather set to $2 $+ . 
 
  if ($hget($htname,0).item >= $maxplayers) { 
    ;; form teams and start... 
    .disable #numplayers-afeb-6ac1-6b3a-7606-20070710103913 
    msg # Gather full. If you joined this gather, please do not change your name until you received server information. 
    msg # Please wait until teams are generated and information is sent to players. 
 
    var %i = $maxplayers, %teamA, %teamB 
    while %i {  
      if (($rand(0,1)) && ($numtok(%teamA,44) < $calc($maxplayers / 2))) || ($numtok(%teamB,44) >= $calc($maxplayers / 2)) %teamA = $addtok(%teamA,$chr(32) $+ $hget($htname,%i).item,44) 
      else %teamB = $addtok(%teamB,$chr(32) $+ $hget($htname,%i).item,44) 
      dec %i 
    } 
    msg # Team A: %teamA 
    msg # Team B: %teamB 
    .raw PRIVMSG $remove(%teamA,$chr(32)) :Team: A > %teamA -- Server: $serverinfo 
    .raw PRIVMSG $remove(%teamB,$chr(32)) :Team: B > %teamB -- Server: $serverinfo 
    .enable #numplayers-afeb-6ac1-6b3a-7606-20070710103913 
    resetgather 
  } 
} 
#numplayers-afeb-6ac1-6b3a-7606-20070710103913 end 
 
;; !gatherchan 
;; Changes gather channel to a new one 
on *:TEXT:!gatherchan &:%gatherchannel-1172-df51-b4b6-313e-20070710100156:{ 
  if ($nick !isop #) { .notice $nick Only a channel operator on both old and new channel can change the channel. | !return } 
  if ($hget($htname)) { .notice $nick Cannot change gather channel while a gather is running. | !return } 
  if ($left($2,1) !isin $chantypes) { .notice $nick Not a valid channelname. | !return } 
  if ($me !ison $2) { .notice $nick Cannot change the gather channel to a channel I am not on. | !return } 
  if ($nick !isop $2) { .notice $nick Only a channel operator on both old and new channel can change the channel. | !return } 
 
  !set %gatherchannel-1172-df51-b4b6-313e-20070710100156 $2 
  .notice $nick Gather channel set to $2 
} 
 
;; !serverinfo 
;; Changes the server info. Only a channel operator can use this. 
on *:TEXT:!serverinfo *:%gatherchannel-1172-df51-b4b6-313e-20070710100156:{ 
  if ($nick !isop #) { .notice $nick You are not allowed to change the server info | !return } 
  if ($hget($htname)) { .notice $nick Server info cannot be changed during a gather. | !return } 
 
  !set %serverinfo-da91-c1fb-b6c7-8f8b-20070710105309 $2- 
  .notice $nick Server information changed. 
} 
 
;;;;; Some overhead. When a player quits, parts or is kicked they are removed from the gather. 
;;;;; When the bot quits or is disconnected the gather is terminated. 
;;;;; When a user changes his nick it's automatically updated 
on *:KICK:%gatherchannel-1172-df51-b4b6-313e-20070710100156: if ($hget($htname,$nick)) !hdel $htname $nick 
on *:PART:%gatherchannel-1172-df51-b4b6-313e-20070710100156: if ($hget($htname,$nick)) !hdel $htname $nick 
on *:QUIT: { 
  if ($nick == $me) && ($hget($htname)) !hfree $htname 
  else if ($hget($htname,$nick)) !hdel $htname $nick 
} 
on *:DISCONNECT: if ($hget($htname)) !hfree $htname 
 
on *:NICK:{ 
  if ($nick != $me) && ($nick != $newnick) { 
    if ($hget($htname,$nick)) { 
      !hadd $htname $newnick $v1 
      !hdel $htname $nick 
    } 
  } 
} 
 
on *:LOAD:{ 
  !set %gatherchannel-1172-df51-b4b6-313e-20070710100156 #channel 
  !set %gatherplayercount-e7ab-d273-a5f9-6ae2-20070710094110 10 
  !set %serverinfo-da91-c1fb-b6c7-8f8b-20070710105309 cs.someserver.com:12345 
}