SimpleGather

From Scriptwiki
Revision as of 00:06, 17 July 2007 by Vliedel (talk | contribs) (fixed damn spaces)

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 "%SG.channel" to your gather channel;
  • Change "%SG.maxplayers" to the amount of players (defaults to 10);
  • Change "%SG.serverinfo" 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 SG.hash }

;; Return gather channel name.
alias -l gatherchannel { return %SG.channel }

alias -l maxplayers { return %SG.maxplayers }

alias -l serverinfo { return %SG.serverinfo }

alias -l resetgather {
  if ($hget($htname)) { hfree $htname }
  .timer 1 1 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:{
  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:{
  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:{
  ;; 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,$mask($fulladdress,1),1).data) { .notice $nick Clones are not allowed to join a gather. | return }
  
  ;; if we get here, add the player
  hadd $htname $nick $mask($fulladdress,1)
  .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)) { var %teamA = $addtok(%teamA,$chr(32) $+ $hget($htname,%i).item,44) }
      else { var %teamB = $addtok(%teamB,$chr(32) $+ $hget($htname,%i).item,44) }
      dec %i
    }
    msg # Team A: %teamA
    msg # Team B: %teamB
    .msg $remove(%teamA,$chr(32)) Team: A > %teamA -- Server: $serverinfo
    .msg $remove(%teamB,$chr(32)) Team: B > %teamB -- Server: $serverinfo
    .enable #numplayers-afeb-6ac1-6b3a-7606-20070710103913
    .timer 1 30 resetgather
  }
}

;; !remove
;; Removes a player from a running gather. Everyone can remove themselves.
on *:TEXT:!remove:$gatherchannel:{
  ;; 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:{
  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:{
  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:{
  ;; first arg has to be a number
  if ($2 !isnum 1-) { .notice $nick Wrong usage of trigger. | return }
  
  if ($calc($2 % 2)) { .notice $nick Number of players must be even. | return }
  
  
  set %SG.maxplayers $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
    .msg $remove(%teamA,$chr(32)) :Team: A > %teamA -- Server: $serverinfo
    .msg $remove(%teamB,$chr(32)) :Team: B > %teamB -- Server: $serverinfo
    .enable #numplayers-afeb-6ac1-6b3a-7606-20070710103913
    .timer 1 30 resetgather
  }
}
#numplayers-afeb-6ac1-6b3a-7606-20070710103913 end

;; !gatherchan
;; Changes gather channel to a new one
on *:TEXT:!gatherchan &:$gatherchannel:{
  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 %SG.channel $2
  .notice $nick Gather channel set to $2
}

;; !serverinfo
;; Changes the server info. Only a channel operator can use this.
on *:TEXT:!serverinfo *:$gatherchannel:{
  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 %SG.serverinfo $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:{ if ($hget($htname,$knick)) { hdel $htname $knick } }
on *:PART:$gatherchannel:{ if ($hget($htname,$nick)) { hdel $htname $nick } }
on *:QUIT: {
  if ($nick == $me) && ($hget($htname)) { hfree $htname }
  elseif ($hget($htname,$nick)) { hdel $htname $nick }
}
on *:DISCONNECT:{ if ($hget($htname)) { hfree $htname } }

on *:NICK:{
  if ($nick == $me) || ($nick == $newnick) { return }
  if ($hget($htname,$nick)) {
    hadd $htname $newnick $v1
    hdel $htname $nick
  }
}

on *:LOAD:{
  set %SG.channel #channel
  set %SG.maxplayers 10
  set %SG.serverinfo cs.someserver.com:12345
}