Pong v1.0 — File Browser

Pongv1.0v1.0 / Pongv1.0v1.0 / pong1.0 / pong.txt

pong.txt — 21.88 KB — Download this file

; pong v1.0 - entropy dalnet - entropy12345@yahoo.com

menu menubar,status,channel {
  -
  Pong v1.0
  .Client { pong 1 }
  .Server { pong 2 }
  -
}
on *:load:{
  if ($version < 6.2) { beep | echo -ta * [ERROR] You need mIRC version 6.2+ to play this game! | .unload -rs $script }
  else { echo -ta * Pong v1.0 - by entropy dalnet - loaded! (check status window popups) }
}
alias pong {
  if ($1 == 2 && !$portfree(3000)) { beep | echo -at * [ERROR] Port 3000 not free! | return }
  if ($window(@pong)) { 
    window -c @pong
    window -c @pong.buf
    if ($hget(pong)) { hsave pong $+(",$scriptdir,pong.dat") | hfree pong }
  }
  window -pk0e +d @pong -1 -1 500 549
  window -pk0he +d @pong.buf -1 -1 500 549
  hmake pong 100
  sockclose pong*
  if ($exists($+(",$scriptdir,pong.dat"))) { hload pong $+(",$scriptdir,pong.dat") }
  if ($1 == 1) {
    sockclose pong
    hdel pong text
    hadd pong method client
    hdel pong paddle2.y
    hdel pong paddle2.x
    hdel pong paddle2.w
    hdel pong paddle2.h
    hdel pong paddle2.s
    hdel pong player2.points
    hadd pong paddle.y 475
    hadd pong ball.control player1
    hadd pong ball.x 275
    hadd pong ball.y 465
    hadd pong ball.s 10
    hadd pong ball.direction up

    hadd pong ball.angle straight
    hadd pong paddle.x 200
    hadd pong paddle.w 100
    hadd pong paddle.h 20
    hadd pong paddle.s 20
    hdel pong text
    hdel pong scoreboard
    output Single Player
    .timerping -o 0 3 ping
  }
  if ($1 == 2) {
    hadd pong method server
    socklisten pong 3000
    hdel pong paddle.y
    hdel pong paddle.x
    hdel pong paddle.w
    hdel pong paddle.h
    hdel pong paddle.s
    hdel pong ball.x 
    hdel pong ball.y 
    hdel pong ball.s 
    hdel pong lag

    hadd pong player2.points 0
    hdel pong ball.control
    hadd pong ball.direction up
    if (!$hget(pong,ball.s)) { hadd pong ball.s 10 }
    hadd pong paddle2.y 12
    hadd pong paddle2.x 200
    hadd pong paddle2.w 100
    hadd pong paddle2.h 20
    hadd pong paddle2.s 20
    hdel pong text
    hdel pong scoreboard
    hdel pong chat
    output Listening...
    if ($hget(pong.ball.sp2)) { hadd pong ball.sp $ifmatch }
    removeball
  }
  hadd pong players 1
  hadd pong player1.points 0
  if (!$hget(pong,ball.color) && $hget(pong,ball.color) != 0) { hadd pong ball.color 00 }
  if (!$hget(pong,paddle.color) && $hget(pong,paddle.color) != 0) { hadd pong paddle.color 00 }
  if (!$hget(pong,background.color) && $hget(pong,background.color) != 0) { hadd pong background.color 01 }
  if (!$hget(pong,ball.size)) { hadd pong ball.size 12 }
  if (!$hget(pong,ball.sp)) { hadd pong ball.sp 10 }
  .timerpong -om 0 20 update

}
on *:socklisten:pong:{
  var %a = $+(pong,$r(1,99))
  sockaccept %a
  sockclose pong
  hadd pong paddle.y 475
  hadd pong paddle.x 200
  hadd pong paddle.w 100
  hadd pong paddle.h 20
  hadd pong paddle.s 20
  hadd pong player2.points 0
  hadd pong ball.control player1
  hadd pong ball.direction up
  hadd pong ball.x 275
  hadd pong ball.y 465
  hadd pong ball.s 10
  hadd pong ball.angle straight
  hinc pong players
  sockwrite -n %a AVATAR $iif($hget(pong,avatar),$ifmatch,avatar1)
  hadd pong player2.avatar $iif($hget(pong,avatar),$ifmatch,avatar1)
}
alias -l ping {
  if ($sock(pong*,1)) {
    sockwrite -n pong* PING $ticks
  }
} 
alias -l implantball {
  if (!$hget(pong)) { return }
  hadd pong ball.y $1
  hadd pong ball.angle straight
  hadd pong ball.control $2
  hadd pong ball.direction $iif($1 == 465,up,down)
  hinc pong $+($2,.points)
  if ($hget(pong,players) == 2) {
    scoreboard $hget(pong,player1.points) / $hget(pong,player2.points)
  }
  else {
    output $calc($hget(pong,player1.points) - 1) Score!
    if (!$hget(pong,top) || $calc($hget(pong,player1.points) - 1) > $hget(pong,top)) { hadd pong top $calc($hget(pong,player1.points) - 1) | splay -wq $+(",$scriptdir,top.wav") }
    hdel pong player1.points
    hadd pong ball.sp 10
  }
  if ($sock(pong*,1)) {
    sockwrite -n pong* DIRECTION $iif($1 == 465,up,down)
    sockwrite -n pong* BALL 275 $1
    sockwrite -n pong* CONTROL $2
    sockwrite -n pong* ANGLE straight
    sockwrite -n pong* SCOREBOARD $hget(pong,player1.points) / $hget(pong,player2.points)
    sockwrite -n pong* SOUND score.wav
    sockwrite -n pong* SCORE $2
  }
  splay -wq $+(",$scriptdir,score.wav")
}
alias -l removeball {
  if (!$hget(pong)) { return }
  hdel pong ball.x
  hdel pong ball.y
}
on *:sockread:pong*:{
  if ($sockerr > 0) { return }
  var %a, %p = $iif($hget(pong,method) == client,paddle2,paddle), %p2 = $iif($hget(pong,method) == client,Player2,Player1)
  sockread -f %a
  tokenize 32 %a
  if ($1 == PADDLEX) { hadd pong $+(%p,.x) $2 }
  if ($1 == BALL) { hadd pong ball.x $2 | hadd pong ball.y $3 }
  if ($1 == OUTPUT) { output $2- }
  if ($1 == SCOREBOARD) { scoreboard $2- }
  if ($1 == CONTROL) { hadd pong ball.control $2 }
  if ($1 == NOCONTROL) { hdel pong ball.control }
  if ($1 == DIRECTION) { hadd pong ball.direction $2 }
  if ($1 == REMBALL) { removeball }
  if ($1 == ANGLE) { hadd pong ball.angle $2 }
  if ($1 == SOUND) { splay -w $+(",$scriptdir,$2,") }
  if ($1 == SPEED) { hadd pong ball.sp $2 }
  if ($1 == PING) { hadd pong lag $left($calc($ticks - $2),3) | sockwrite -n pong* LAG $hget(pong,lag) }
  if ($1 == LAG) { hadd pong lag $2 }
  if ($1 == SCORE) { hinc pong $+($2,.points) }
  if ($1 == INPUT) { chat $2- }
  if ($1 == NAME) { hadd pong $+(%p2,.name) $2- }
  if ($1 == AVATAR) { hadd pong $+(%p2,.avatar) $2- }
}

on *:sockopen:pongx:{
  if ($sockerr > 0) { return }
  output Connected.
  sockwrite -n $sockname output Connected.
  hadd pong paddle2.y 12
  hadd pong paddle2.x 200
  hadd pong paddle2.w 100
  hadd pong paddle2.h 20
  hadd pong paddle2.s 100
  hadd pong player2.points 0
  hadd pong player1.points 0
  hadd pong ball.control player1
  hadd pong ball.angle straight
  hinc pong players
  sockwrite -n $sockname AVATAR $iif($hget(pong,avatar),$ifmatch,avatar1)
  hadd pong player1.avatar $iif($hget(pong,avatar),$ifmatch,avatar1)
  if ($hget(pong,name)) { sockwrite -n $sockname NAME $hget(pong,name) }
}
on *:sockclose:pong*:{
  output Disconnected.
  if ($sock(pong*,1)) { sockwrite -n pong* OUTPUT Disconnected. }
  hdec pong players
  hdel pong lag
  if ($hget(pong,method) == server) {
    hdel pong ball.control
    hdel pong ball.x
    hdel pong ball.y
    hdel pong ball.s
    hdel pong ball.sp
    hdel pong ball.angle
    hdel pong paddle.y
    hdel pong paddle.x
    hdel pong paddle.w
    hdel pong paddle.h
    hdel pong paddle.s
    hdel pong player1.points
    hdel pong player2.points
    hdel pong player1.avatar
    hdel pong player1.name
    socklisten pong 3000
  }
  else {
    hdel pong paddle2.y
    hdel pong paddle2.x
    hdel pong paddle2.w
    hdel pong paddle2.h
    hdel pong paddle2.s
    hdel pong player1.points
    hdel pong player2.points
    hdel pong player1.avatar
    hdel pong player1.name
    hdel pong player2.avatar
    hdel pong player2.name
  }
}

alias -l update {
  if (!$window(@pong)) { .timerpong off | .timertext off | .timerping off | if ($hget(pong)) { hfree pong } | sockclose pong* | return }
  var %p = $iif($hget(pong,method) == server,paddle2,paddle), %p2 = $iif($hget(pong,method) == server,Player1,Player2)
  hadd pong prev.paddle $hget(pong,$+(%p,.x))

  ;background
  drawrect -fr @pong.buf $rgb(255,255,255) 10 0 0 500 505
  if ($hget(pong,background.image)) { drawpic -hsc @pong.buf 2 2 494 536 $ifmatch }
  else { drawrect -f @pong.buf $hget(pong,background.color) 10 2 2 494 520 }

  ;paddle movement
  movepaddle

  ;paddle image
  if ($hget(pong,players) == 2 || $hget(pong,method) == server) { if ($hget(pong,image)) { drawpic -hsc @pong.buf $hget(pong,paddle2.x) $hget(pong,paddle2.y) $pic($ifmatch).width $pic($ifmatch).height $ifmatch } | else { drawrect -f @pong.buf $hget(pong,paddle.color) 10 $hget(pong,paddle2.x) $hget(pong,paddle2.y) $hget(pong,paddle2.w) 10 } }
  if ($hget(pong,paddle.x)) { if ($hget(pong,image)) { drawpic -hsc @pong.buf $hget(pong,paddle.x) $hget(pong,paddle.y) $pic($ifmatch).width $pic($ifmatch).height $ifmatch } | else { drawrect -f @pong.buf $hget(pong,paddle.color) 10 $hget(pong,paddle.x) $hget(pong,paddle.y) $hget(pong,paddle.w) 10 } }

  ;move ball
  if ($hget(pong,method) == server || $hget(pong,players) == 1) { move | collide }

  ;ball
  if ($hget(pong,ball.x) && $hget(pong,ball.y) && $hget(pong,ball.y) != 0 && $hget(pong,ball.s)) { 
    if ($hget(pong,ball.image)) { drawpic -htsc @pong.buf $rgb(0,0,0) $calc($hget(pong,ball.x) - 10) $calc($hget(pong,ball.y) - 10) 20 20 $+(",$scriptdir,ball.bmp") }
    else { drawdot -h @pong.buf $hget(pong,ball.color) $hget(pong,ball.s) $hget(pong,ball.x) $hget(pong,ball.y) }
  }

  ;navbar
  if ($hget(pong,method) == server || $hget(pong,players) == 2) {
    drawpic -htsc @pong.buf $rgb(0,0,0) 0 502 500 22 $+(",$scriptdir,bottom.bmp")
    drawtext -hpr @pong.buf $rgb(85,170,255) Tahoma 12 38 505  $+ $iif($hget(pong,lag) && $left($hget(pong,lag),1) != -,$hget(pong,lag),0)
    drawtext -hpr @pong.buf $rgb(85,170,255) Tahoma 12 150 505  $+ $iif($hget(pong,player1.points),$ifmatch,0)
    drawtext -hpr @pong.buf $rgb(85,170,255) Tahoma 12 265 505  $+ $iif($hget(pong,player2.points),$ifmatch,0)
  }
  else {
    drawpic -htsc @pong.buf $rgb(0,0,0) 0 502 500 22 $+(",$scriptdir,bottom2.bmp")
    drawtext -hpr @pong.buf $rgb(85,170,255) Tahoma 12 63 505  $+ $iif($hget(pong,player1.points),$ifmatch,0)
    drawtext -hpr @pong.buf $rgb(85,170,255) Tahoma 12 166 505  $+ $iif($hget(pong,ball.sp),$ifmatch,0)
    drawtext -hpr @pong.buf $rgb(85,170,255) Tahoma 12 243 505  $+ $iif($hget(pong,top),$ifmatch,0)
  }

  ;chat
  if ($hget(pong,chat)) {
    var %n = $replace(%p,paddle2,player2,paddle,player1), %txt = $gettok($ifmatch,2-,32)
    drawpic -ht @pong.buf $rgb(0,0,0) 300 200 $+(",$scriptdir,chat.bmp")
    drawpic -mht @pong.buf $rgb(255,255,255) 310 210 $+(",$scriptdir,$hget(pong,$eval($+(%p2,.avatar),2)),.bmp")
    drawtext -hpc @pong.buf 01 Tahoma 09 360 215 116 20  $+ $gettok($hget(pong,chat),1,32) says:
    if ($mid(%txt,1,24)) { drawtext -hpc @pong.buf 01 Tahoma 09 360 225 120 20 $ifmatch }
    if ($mid(%txt,25,49)) { drawtext -hpc @pong.buf 01 Tahoma 09 360 235 120 20 $ifmatch }
    if ($mid(%txt,50,75)) { drawtext -hpc @pong.buf 01 Tahoma 09 360 245 120 20 $ifmatch }
  }

  ;scoreboard text
  if ($hget(pong,scoreboard)) {
    drawpic -ht @pong.buf $rgb(0,0,0) 150 200 $+(",$scriptdir,scoreboard.bmp")
    drawtext -hp @pong.buf 01 Tahoma 22 190 215  $+ $gettok($ifmatch,1,32)
    drawtext -hp @pong.buf 01 Tahoma 22 275 215  $+ $gettok($ifmatch,3,32)
  }
  ;regular text
  elseif ($hget(pong,text)) {
    drawpic -ht @pong.buf $rgb(0,0,0) 150 200 $+(",$scriptdir,scoreboard_blank.bmp")
    drawtext -h @pong.buf 01 Tahoma 22 175 215 $ifmatch
  }

  ;idle ball
  if ($hget(pong,method) == server || $hget(pong,players) == 1) {
    if ($hget(pong,ball.control)) {
      var %h = $replace($ifmatch,player1,paddle,player2,paddle2)
      hadd pong ball.y $replace(%h,paddle2,35,paddle,465)
      hadd pong ball.x $calc($hget(pong,$+(%h,.x)) + ($hget(pong,$+(%h,.w)) / 2))
    }
  }
  ;finishing up
  if ($hget(pong,method) == server || $hget(pong,players) == 1) {
    if ($hget(pong,ball.y) < 0 || $hget(pong,ball.y) > 500) { hdel pong ball.y }
  }

  ;sending data to socket
  var %x = $hget(pong,ball.x), %y = $hget(pong,ball.y)
  if ($hget(pong,method) == server || $hget(pong,players) == 1) {
    if ($sock(pong*,1)) {
      if (%x && %y) { sockwrite -n pong* BALL %x %y }
    }
  }
  if ($sock(pong*,1)) {
    sockwrite -n pong* PADDLEX $hget(pong,$+(%p,.x))
  }

  ;copying
  drawcopy @pong.buf 0 0 500 522 @pong 0 0 500 528

}
alias -l move {
  if (!$hget(pong,ball.x) && $hget(pong,ball.x) != 0) { return }
  elseif (!$hget(pong,ball.y) && $hget(pong,ball.y) != 0) { return }
  :begin
  var %x = $hget(pong,ball.x), %y = $hget(pong,ball.y)
  if (!$hget(pong,ball.control)) {
    if ($hget(pong,ball.angle) == left) { dec %x $hget(pong,ball.sp) }
    elseif ($hget(pong,ball.angle) == tightleft) { dec %x $calc($hget(pong,ball.sp) - ($hget(pong,ball.sp) / 2 - 5)) }
    elseif ($hget(pong,ball.angle) == right) { inc %x $hget(pong,ball.sp) }
    elseif ($hget(pong,ball.angle) == tightright) { inc %x $calc($hget(pong,ball.sp) + ($hget(pong,ball.sp) / 2 + 5)) }
    if ($hget(pong,ball.direction) == up) { dec %y $hget(pong,ball.sp) }
    elseif ($hget(pong,ball.direction) == down) { inc %y $hget(pong,ball.sp) }

    ;checked
    if (%x > 500) { 
      %x = 495
      if ($sock(pong*,1)) { sockwrite -n pong* ANGLE $replace($hget(pong,ball.angle),right,left) | sockwrite -n pong* SOUND wallhit.wav }
      hadd pong ball.angle $replace($hget(pong,ball.angle),right,left)
      splay -w $+(",$scriptdir,wallhit.wav")
    }
    elseif (%x < 0) {
      %x = 5
      if ($sock(pong*,1)) { sockwrite -n pong* ANGLE $replace($hget(pong,ball.angle),left,right) | sockwrite -n pong* SOUND wallhit.wav }
      hadd pong ball.angle $replace($hget(pong,ball.angle),left,right)
      splay -w $+(",$scriptdir,wallhit.wav")
    }

    ;checked
    if (%y < 0 || !%y) {
      if ($hget(pong,players) == 1) {
        hinc pong player1.points
        hadd pong ball.direction down
        var %s = $hget(pong,ball.sp)
        inc %s 0.1
        hadd pong ball.sp %s
        splay -w $+(",$scriptdir,wallhit.wav")
        goto begin
      }
      else {
        removeball
        if ($sock(pong*,1)) { sockwrite -n pong* REMBALL }
        .timerimplant -om 1 600 implantball 465 player1
        goto end
      }
    }

    ;checked
    elseif (%y > 500) {
      if ($hget(pong,players) == 1) {
        hadd pong ball.direction up
        removeball
        .timerimplant -om 1 600 implantball 465 player1
        goto end
      }
      else { 
        removeball
        if ($sock(pong*,1)) { sockwrite -n pong* REMBALL }
        .timerimplant -om 1 600 implantball 35 player2
        goto end
      }
    }
    hadd pong ball.x %x
    hadd pong ball.y %y
  }
  :end
}
alias -l collide {
  if (!$hget(pong,ball.x) && $hget(pong,ball.x) != 0) { return }
  var %x = $hget(pong,ball.x), %y = $hget(pong,ball.y)
  ;Collision TOP paddle
  if (%y isnum 0-35 && %x isnum $+($hget(pong,paddle2.x),-,$calc($hget(pong,paddle2.x) + $hget(pong,paddle2.w)))) {
    var %1 = $+($hget(pong,paddle2.x),-,$calc($hget(pong,paddle2.x) + 19))
    var %2 = $+($calc($hget(pong,paddle2.x) + 20),-,$calc($hget(pong,paddle2.x) + 39))
    var %3 = $+($calc($hget(pong,paddle2.x) + 40),-,$calc($hget(pong,paddle2.x) + 59))
    var %4 = $+($calc($hget(pong,paddle2.x) + 60),-,$calc($hget(pong,paddle2.x) + 79))
    var %5 = $+($calc($hget(pong,paddle2.x) + 80),-,$calc($hget(pong,paddle2.x) + 100))

    if (%x isnum %1) { hadd pong ball.angle tightleft }
    if (%x isnum %2) { hadd pong ball.angle left }
    if (%x isnum %3) { hadd pong ball.angle straight }
    if (%x isnum %4) { hadd pong ball.angle right }
    if (%x isnum %5) { hadd pong ball.angle tightright }

    hadd pong ball.direction down
    if ($sock(pong*,1)) { sockwrite -n pong* ANGLE $hget(pong,ball.angle) }
    if ($sock(pong*,1)) { sockwrite -n pong* DIRECTION down }
    if (!$hget(pong,ball.control)) {
      splay -w $+(",$scriptdir,paddle.wav")
      if ($sock(pong*,1)) { sockwrite -n pong* SOUND paddle.wav }
    }
  }
  ;Collision BOTTOM paddle
  elseif (%y isnum 475-500 && %x isnum $+($hget(pong,paddle.x),-,$calc($hget(pong,paddle.x) + $hget(pong,paddle.w)))) {
    var %1 = $+($hget(pong,paddle.x),-,$calc($hget(pong,paddle.x) + 19))
    var %2 = $+($calc($hget(pong,paddle.x) + 20),-,$calc($hget(pong,paddle.x) + 39))
    var %3 = $+($calc($hget(pong,paddle.x) + 40),-,$calc($hget(pong,paddle.x) + 59))
    var %4 = $+($calc($hget(pong,paddle.x) + 60),-,$calc($hget(pong,paddle.x) + 79))
    var %5 = $+($calc($hget(pong,paddle.x) + 80),-,$calc($hget(pong,paddle.x) + 100))

    if (%x isnum %1) { hadd pong ball.angle tightleft }
    if (%x isnum %2) { hadd pong ball.angle left }
    if (%x isnum %3) { hadd pong ball.angle straight }
    if (%x isnum %4) { hadd pong ball.angle right }
    if (%x isnum %5) { hadd pong ball.angle tightright }

    hadd pong ball.direction up
    if ($sock(pong*,1)) { sockwrite -n pong* ANGLE $hget(pong,ball.angle) }
    if ($sock(pong*,1)) { sockwrite -n pong* DIRECTION up }
    if (!$hget(pong,ball.control)) {
      splay -w $+(",$scriptdir,paddle.wav")
      if ($sock(pong*,1)) { sockwrite -n pong* SOUND paddle.wav }
    }
  }
}
menu @pong {
  $iif($hget(pong,method) == client && $hget(pong,players) < 2,Multiplayer) { var %a = $input(IP address?,5) | if (%a) { sockclose pongx | sockopen pongx %a 3000 } }
  -
  Options
  .Background
  ..Color $chr(9) $hget(pong,background.color) { var %a = $input(Double digit color?,5) | if (%a || %a == 00) { hadd pong background.color %a | hdel pong background.image | drawrect -f @pong %a 10 0 0 500 500 } }
  ..Image $chr(9) $hget(pong,background.image) { var %a = $sfile($mircdir*.bmp,Select a background bmp:) | if (%a) { hadd pong background.image $+(",%a,") } | else { hdel pong background.image } }
  .Ball
  ..$iif($hget(pong,method) == server,Speed $chr(9) $hget(pong,ball.sp)) { var %a = $input(Speed? 10 is normal.,5) | if (%a || %a == 0) { hadd pong ball.sp %a | hadd pong ball.sp2 %a | if ($sock(pong*,1)) { sockwrite pong* SPEED %a } } }
  ..-
  ..Color $chr(9) $hget(pong,ball.color) { var %a = $input(Double digit color?,5) | if (%a || %a == 00) { hadd pong ball.color %a | hdel pong ball.image } } 
  ..Image $chr(9) $hget(pong,ball.image) { hadd pong ball.image Yes }
  .Paddle
  ..Color $chr(9) $hget(pong,paddle.color) { var %a = $input(Double digit color?,5) | if (%a || %a == 00) { hadd pong paddle.color %a | hdel pong image } } 
  ..Image $chr(9) $hget(pong,image) { var %a = $sfile($mircdir*.bmp,Select File:) | if (%a) { hadd pong image %a } }
  .-
  .Name $chr(9) $hget(pong,name) { var %a = $input(Your name?,5) | if (%a) { hadd pong name %a | if ($sock(pong*,1)) { sockwrite -n pong* NAME %a } } }
  .Avatar $chr(9) $hget(pong,avatar)
  ..Avatar1 { hadd pong avatar avatar1 | if ($sock(pong*,1)) { sockwrite -n pong* AVATAR avatar1 } | hadd pong $iif($hget(pong,method) == server,player2.avatar,player1.avatar) avatar1 }
  ..Avatar2 { hadd pong avatar avatar2 | if ($sock(pong*,1)) { sockwrite -n pong* AVATAR avatar2 } | hadd pong $iif($hget(pong,method) == server,player2.avatar,player1.avatar) avatar2 }
  ..Avatar3 { hadd pong avatar avatar3 | if ($sock(pong*,1)) { sockwrite -n pong* AVATAR avatar3 } | hadd pong $iif($hget(pong,method) == server,player2.avatar,player1.avatar) avatar3 }
  ..Avatar4 { hadd pong avatar avatar4 | if ($sock(pong*,1)) { sockwrite -n pong* AVATAR avatar4 } | hadd pong $iif($hget(pong,method) == server,player2.avatar,player1.avatar) avatar4 }
  ..Avatar5 { hadd pong avatar avatar5 | if ($sock(pong*,1)) { sockwrite -n pong* AVATAR avatar5 } | hadd pong $iif($hget(pong,method) == server,player2.avatar,player1.avatar) avatar5 }
  ..Avatar6 { hadd pong avatar avatar6 | if ($sock(pong*,1)) { sockwrite -n pong* AVATAR avatar6 } | hadd pong $iif($hget(pong,method) == server,player2.avatar,player1.avatar) avatar6 }
  -
  Help { return $input(Welcome to pong v1.0 by entropy! $crlf $+ <- arrow to go left and -> arrow to go right - hit [ctrl] to launch the ball! $crlf $+ Have fun :P $crlf,4,Pong v1.0 Help) }
  -
  Close { if ($sock(pong*,1)) { sockwrite -n pong* OUTPUT Disconnected. } | sockclose pong* | .timertext off | .timerpong off | .timerping off | window -c @pong | window -c @pong.buf | hsave pong $+(",$scriptdir,pong.dat") | hfree pong }
}
on *:input:@pong:{
  if (/* !iswm $1) {
    if (!$hget(pong,ball.control) || $hget(pong,players) < 2) { splay -w $+(",$scriptdir,oops.wav") | return }
    if ($sock(pong*,1)) { splay -w $+(",$scriptdir,chat2.wav") | var %nick = $iif($hget(pong,name),$ifmatch,$iif($hget(pong,method) == server,Player2,Player1)) | sockwrite -n pong* INPUT %nick $1- }
    haltdef
  }
}
on *:keydown:@pong:17:{
  ;control
  if (!$hget(pong,ball.control) || !$hget(pong,ball.y)) { return }
  if ($hget(pong,method) == server && $hget(pong,ball.control) == player2) {
    hdel pong ball.control
    if ($sock(pong*,1)) { sockwrite -n pong* NOCONTROL }
  }
  if ($hget(pong,method) == client && $hget(pong,ball.control) == player1) {
    hdel pong ball.control
    if ($sock(pong*,1)) { sockwrite -n pong* NOCONTROL }
  }
}
on *:keydown:@pong:37:{
  var %p = $iif($hget(pong,method) == server,paddle2,paddle)
  ;left
  hadd pong $+(%p,.pos) $addtok($hget(pong,$+(%p,.pos)),left,32)
}
on *:keyup:@pong:37:{
  var %p = $iif($hget(pong,method) == server,paddle2,paddle)
  hadd pong $+(%p,.pos) $remtok($hget(pong,$+(%p,.pos)),left,1,32)
}
on *:keydown:@pong:39:{
  var %p = $iif($hget(pong,method) == server,paddle2,paddle)
  ;right
  hadd pong $+(%p,.pos) $addtok($hget(pong,$+(%p,.pos)),right,32)
}
on *:keyup:@pong:39:{
  var %p = $iif($hget(pong,method) == server,paddle2,paddle)
  hadd pong $+(%p,.pos) $remtok($hget(pong,$+(%p,.pos)),right,1,32)
}
alias -l movepaddle {
  var %p = $iif($hget(pong,method) == server,paddle2,paddle)
  var %a = $hget(pong,$+(%p,.x)), %b = $hget(pong,ball.x), %c = $hget(pong,ball.y)
  if ($istok($hget(pong,$+(%p,.pos)),left,32)) {
    dec %a $hget(pong,$+(%p,.s))
    if (%a < 1) { %a = 1 }
  }
  elseif ($istok($hget(pong,$+(%p,.pos)),right,32)) {
    inc %a $hget(pong,$+(%p,.s))
    var %t = $calc(500 - $hget(pong,$+(%p,.w)))
    if (%a > %t) { %a = %t }
  }
  hadd pong $+(%p,.x) %a
  hadd pong prev.paddle $hget(pong,$+(%p,.x))
}
alias -l scoreboard {
  hadd pong scoreboard $1-
  .timerscoreboard -o 1 3 hdel pong scoreboard
}
alias -l output {
  hadd pong text $1-
  .timertext -o 1 3 hdel pong text
}
alias -l chat {
  splay -w $+(",$scriptdir,chat.wav")
  hadd pong chat $1-
  .timerchat -o 1 5 hdel pong chat
}