home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 February
/
chip_20022115.iso
/
amiga
/
chiputil
/
amiquiz.lha
/
amiquiz_eng.rexx
next >
Wrap
OS/2 REXX Batch file
|
2001-12-17
|
12KB
|
447 lines
/*
NAME: amiquiz.rexx
AUTHOR: Emers/Appendix (emers@px.pl)
VER: 1.0 (eng, col, WinUAE trojan free)
DATE: 17.12.2001
USAGE: /rx amirc.rexx in AmIRC window or rx amiquiz.rexx in CLI (recommended)
*/
/****************************************************************/
/*C O N F I G U R A T I O N*/
series=20
stats_every=10
ircnick='AmiQuiz'
questfile='pytania.amiga'
chan='#amiquiz'
amircport='AMIRC.2'
viamsg=0
/****************************************************************/
/*DONT EDIT LINES BELOW*/
OPTIONS RESULTS
IF ~SHOW( 'P', amircport ) THEN DO
ADDRESS COMMAND 'echo 'amircport' is not active!'
EXIT 10
END
ADDRESS (amircport)
plridx=0
running=1
game=0
podpow=0
answersize=0
seekquestion=0
text='/join' chan
CALL ToChannelInit
text='/nick' ircnick
CALL ToChannelInit
text='/topic /msg' ircnick '!pomoc'
CALL ToChannelInit
CALL Pause
text=D2C(3)'4,1Welcome to 'D2C(3)'8,1amiquiz.rexx 'D2C(3)'11,1(Amiga)'
CALL ToChannel
text=D2C(3)'4,1Type 'D2C(3)'8,1!start 'D2C(3)'4,1to start the quiz or 'D2C(3)'8,1!help 'D2C(3)'4,1to get help'
CALL ToChannel
CALL Pause
GETMYNICK
ircnick=result
GETSERVERNAME
serv=result
say
say 'My nick is' ircnick' and I am connected to 'serv
say 'Quiz channel is:' chan
say
DO WHILE running=1
DO WHILE game=0
GetLine
PARSE VAR line.prefix nick '!' something
PARSE VAR line.rest ':!' comnd argument
IF UPPER(comnd)='QUIT' THEN CALL QuitQuiz
IF UPPER(comnd)='HELP' THEN CALL PrintHelp
IF UPPER(comnd)='INFO' THEN CALL ShowInfo
IF UPPER(comnd)='START' THEN DO
CALL OPEN('questions',questfile,'R')
text=D2C(3)'4,1Counting questions in database...'
CALL ToChannel
CALL CountQuestions
text=D2C(3)'4,1Number of questions:'D2C(3)'11,1 ' numofquest||'.'
CALL ToChannel
game=1
END
END
text=D2C(3)'4,1I am starting a new game with'D2C(3)'11,1 'series D2C(3)'4,1questions. Statistics every'D2C(3)'11,1 ' stats_every D2C(3)'4,1questions.'
CALL ToChannel
CALL NextQuestions
result.=0
players=0
DO quest_index=1 TO series
CALL ClearPlayers
CALL GetQuestion
seekquestion=seekquestion+1
PARSE VAR line_ question ':' answer
text=D2C(3)'4,8Queston' quest_index||':'
CALL Pause
CALL ToChannel
text=D2C(2)D2C(3)'12'||question
CALL ToChannel
Say 'Question was asked'
hint=0
good_answer=0
DO WHILE good_answer=0
GetLastLine
rawline=RESULT
IF rawline~=oldline THEN DO
oldline=rawline
ParseLine rawline
PARSE VAR line.prefix nickstat '!' something
PARSE VAR line.rest ':!' comndstat
IF UPPER(comndstat)='TOPTEN' THEN CALL DisplayResults
IF UPPER(comndstat)='STAT' THEN CALL DisplayStats
PARSE VAR line.prefix nick '!' something
IF UPPER(line.dest)=UPPER(chan) | nick=ircnick THEN DO
Say 'Message from' nick
/* check for commands */
PARSE VAR line.rest ':!' comndmsg argument1
IF UPPER(comndmsg)='HELP' THEN CALL PrintHelp
IF UPPER(comndmsg)='RELOAD' THEN CALL ReloadQuestions
IF UPPER(comndmsg)='STOP' THEN CALL EndQuiz
IF UPPER(comndmsg)='INFO' then CALL ShowInfo
IF UPPER(comndmsg)='QUIT' THEN CALL QuitQuiz
IF UPPER(comndmsg)='NICK' then CALL ChangeNick
IF UPPER(comndmsg)='NEXT' then CALL SkipQuestion
IF UPPER(comndmsg)='HINT' then CALL HintAnswer
IF COMPRESS(UPPER(line.rest),': ')=COMPRESS(UPPER(answer)) THEN DO
/* find player index */
DO plridx=1 TO players
IF result.plridx.nickname==nick THEN LEAVE plridx
END
/* check for new players */
Say 'index:' plridx 'nick:' nick 'table:' result.plridx.nickname
IF result.plridx.nickname~=nick THEN DO
players=players+1
plridx=players
result.plridx.nickname=nick
Say 'New player' result.plridx.nickname 'nr' plridx
END
IF result.plridx.correct=0 THEN DO
result.plridx.correct=1
result.plridx.good=result.plridx.good+1
DO sst=1 TO players
IF result.sst.nickname==nick THEN DO
text=D2C(2)D2C(3)'11,1'nick': 'D2C(3)'6,1GOOD! 'D2C(3)'4,1You already have'D2C(3)'8,1 'result.sst.good' 'D2C(3)'4,1pts.'
CALL ToChannel
END
END
Say 'Good answer by 'nick
good_answer=1
CALL SortTable
END
END
END
END
END
text=D2C(2)D2C(3)'12The right answer is' D2C(3)'4 '||answer||D2C(2)||'.'
CALL ToChannel
IF quest_index//stats_every=0 THEN CALL DisplayResults
END
text=D2C(3)'4,1The game has ended,'D2C(3)'11,1 'result.1.nickname' 'D2C(3)'4,1won.'
CALL ToChannel
IF quest_index//stats_every~=0 THEN CALL DisplayResults
CALL Pause
CALL ClearPlayers
CALL CLOSE('questions')
plridx=0
hint=0
answersize=0
numofquest=0
players=0
game=0
END
exit 0
/*===========================================================================*/
ClearPlayers:
DO i=1 TO players
result.i.correct=0
END
RETURN
/*===========================================================================*/
CountQuestions:
numofquest=0
DO WHILE EOF('questions')=0
trash=READLN('questions')
IF trash="" THEN LEAVE
numofquest=numofquest+1
END
CALL SEEK('questions',0,'B')
RETURN
/*===========================================================================*/
ChangeNick:
IF argument1="" THEN DO
say 'Nick cannot be changed'
header='/msg' nick
text=header 'Bad arguments! Type !NICK oldnick'
CALL ToChannel
END
ELSE DO
DO i=1 TO players
IF UPPER(result.i.nickname)=UPPER(argument1) THEN result.i.nickname=nick
END
text=D2C(3)'8,1'argument1||D2C(3)'4,1 is now known as 'D2C(3)'11,1'nick
CALL ToChannel
say 'Nick changed 'argument1 '->' nick
END
RETURN
/*===========================================================================*/
SortTable:
Say 'Sorting table'
DO i=1 TO players-1
ii=i+1
IF result.i.good<result.ii.good THEN DO
temp=result.ii.nickname
result.ii.nickname=result.i.nickname
result.i.nickname=temp
temp=result.ii.good
result.ii.good=result.i.good
result.i.good=temp
temp=result.ii.correct
result.ii.correct=result.i.correct
result.i.correct=temp
END
END
RETURN
/*===========================================================================*/
DisplayResults:
text=D2C(3)'12,7The best players:'
CALL ToChannel
z=10
IF players<10 THEN z=players
DO i=1 TO z
text=D2C(2)D2C(3)'6,1 'i||'.' D2C(3)'8,1 'result.i.nickname||':' D2C(3)'11,1 'result.i.good' 'D2C(3)'4,1pts.'
CALL ToChannel
END
RETURN
/*===========================================================================*/
DisplayStats:
say nick 'asked for statistics'
IF players>0 THEN DO
DO st=1 TO players
IF result.st.nickname==nickstat THEN DO
text=D2C(2)D2C(3)'6,1 'st||'.'D2C(3)'8,1 'result.st.nickname||':'D2C(3)'11,1 'result.st.good' 'D2C(3)'4,1pts.'
CALL ToChannel
END
END
END
RETURN
/*===========================================================================*/
Pause:
ADDRESS COMMAND
Wait 6
ADDRESS (amircport)
RETURN
/*===========================================================================*/
ToChannel:
if viamsg=1 then do
'say /msg' chan text
END
else do
'Say' text
END
RETURN
/*===========================================================================*/
ToChannelInit:
'Say' text
RETURN
/*===========================================================================*/
PrintHelp:
header='/msg' nick
text=header 'Answers are given at the channel. Who answers correctly as first, gets a point'
CALL ToChannelInit
text=header 'Available commands: !start, !help, !stat, !topten, !hint, !info, !nick <old> (changing old nick to actual on the list)'
CALL ToChannelInit
RETURN
/*===========================================================================*/
EndQuiz:
GETMYNICK
ircnick=result
IF nick=ircnick THEN DO
text=D2C(2)D2C(3)'11,1The quiz has ended.'
CALL ToChannel
CALL ClearPlayers
good_answer=1
game=0
quest_index=series
CALL CLOSE('questions')
END
ELSE DO
say 'Unauthorized ending by' nick
END
RETURN
/*===========================================================================*/
QuitQuiz:
GETMYNICK
ircnick=result
IF nick=ircnick THEN DO
text=D2C(2)D2C(3)'11,1The quiz has been switched off.'
CALL ToChannel
CALL CLOSE('questions')
running=0
exit 0
END
ELSE DO
say 'Unauthorized quiting by' nick
END
RETURN
/*===========================================================================*/
ReloadQuestions:
GETMYNICK
ircnick=result
IF nick=ircnick THEN DO
CALL CLOSE('questions')
ADDRESS COMMAND
'Rename 'questfile' 'questfile'.old'
'Rename 'questfile'.new 'questfile
ADDRESS (amircport)
CALL OPEN('questions','questions','R')
CALL CountQuestions
say 'Questions was reloaded'
END
ELSE DO
say 'Unauthorized reload by' nick
END
RETURN
/*===========================================================================*/
NextQuestions:
IF seekquestion=numofquest THEN DO
seekquestion=0
CALL CLOSE('questions')
CALL OPEN('questions',questfile,'R')
say 'Questions back to begin'
END
DO ii=1 TO seekquestion
IF EOF('questions')=1 THEN DO
CALL SEEK('questions',0,'B')
END
trash=READLN('questions')
END
RETURN
/*===========================================================================*/
ShowInfo:
header='/msg' nick
text=header 'amiquiz.rexx v1.0 by Emers/Appendix (emers@px.pl)'
CALL ToChannelInit
RETURN
/*===========================================================================*/
SkipQuestion:
GETMYNICK
ircnick=result
IF nick=ircnick THEN DO
good_answer=1
say 'Question skipped'
text=D2C(2)D2C(3)'4,1The answer has been canceled'
CALL ToChannel
END
ELSE DO
say 'Unauthorized skipping by' nick
END
RETURN
/*===========================================================================*/
GetQuestion:
IF seekquestion=numofquest THEN DO
seekquestion=0
CALL CLOSE('questions')
CALL OPEN('questions',questfile,'R')
say 'Questions back to begin'
END
line_ = READLN('questions')
RETURN
/*===========================================================================*/
HintAnswer:
answersize=length(answer)
hint=hint+1
if hint<answersize then do
text=D2C(3)'8,12Hint:'D2C(3)'11,1 'left(answer,hint)
DO dots=1+hint TO answersize
lettertmp=left(answer,dots)
letter=right(lettertmp,1)
IF letter~=' ' THEN letter='.'
text=text||letter
END
CALL ToChannel
say 'Hinted the answer'
END
RETURN
/*===========================================================================*/
exit 0