mIRC Homepage
Posted By: Matrix301 Save to a text file ? - 19/07/05 05:11 PM
hey, hmm im trying to make register command where people can register for a tournament by typing command, -register <user> <nick> but i cant use variables since there will be 16 to 32 registration per tournament, i dont want too much elseif, i thought i could save it to a text file, which i can read too on -list players and read how many lines are in the text file so if there is 16 or 32 players registered, it says, error tournament full, hmm neway, the problem is that i dont know how to save to a text file, or i could save it into another user lsit ? can we have more than 1 user lsit ? eh ty for your help/idea
Posted By: DaveC Re: Save to a text file ? - 19/07/05 05:22 PM
//write textfilename.txt your text to write
Posted By: Matrix301 Re: Save to a text file ? - 19/07/05 05:55 PM
ok, thx it works fine, but can i read and delete from this file ? so i can list
and make he 16 or 32 players limit (you receive an error if there is 16 or 32 lines in the txt file
Posted By: MikeChat Re: Save to a text file ? - 19/07/05 06:19 PM
if ($lines(file.txt) < 16) { write to file stuff }
else msg #gamechan game is full $nick please wait for an opening
Posted By: Matrix301 Re: Save to a text file ? - 19/07/05 06:48 PM
oh cool, and to delete ?
to see if text match i guess i can do:

Code:
if ($lines(file.txt) == $2) { User isn't in game }  right ? or line ?
Posted By: MikeChat Re: Save to a text file ? - 19/07/05 06:56 PM
/help $read

Quote:

//echo $read(info.txt, s, mirc)

Scans the file info.txt for a line beginning with the word mirc and returns the text following the match value.

$readn
Returns the line number that was matched in a previous call to $read(). If no match was found, $readn is set to zero.



you might also consider using an ini file so you can track a user and their score, a little more complicated maybe, but more usefull overall

/help writeini
/help $readini
/help $ini
Posted By: Riamus2 Re: Save to a text file ? - 19/07/05 06:57 PM
READ:
$read(file.txt,s,nick)
$read(file.txt,w,*nick*)

/help $read

DELETE:
/write -dl# file.txt

/help /write
Posted By: MikeChat Re: Save to a text file ? - 19/07/05 06:59 PM
cool
Posted By: Riamus2 Re: Save to a text file ? - 19/07/05 07:01 PM
You beat me!!! mad

LOL!! grin
Posted By: Matrix301 Re: Save to a text file ? - 19/07/05 07:34 PM
oh ok, i tried to use help but couldnt find it :P thx now i know more but eh i still got a problem, when someone register, i want it to check if user is already registered, if yes then it says user is already registered, so i should use:

Code:
if ( $read(file.txt, w,  $3 ) {
blahblah
}


im not sure about this one, $3 is the username, -<game> register <user> <pass>
Posted By: Riamus2 Re: Save to a text file ? - 19/07/05 07:51 PM
First of all, "w" is for a wildcard search, so you need wildcards in the search parameters. If you don't want a wildcard search, use "s" instead, as the help file shows.

If your text file starts with the nick and then a space and $3 == the nick, you can use:

Code:
if ($read(file.txt,s,$3 $+ $chr(32)) {
  do whatever
}


Note that I include the space -- $chr(32) -- in that because otherwise it will run into problems with two nicks that are similar (such as Super and Superman... if you look for Super, and Superman is first in the text file, it would stop there... with the space, it won't stop at the wrong one).
Posted By: Matrix301 Re: Save to a text file ? - 19/07/05 09:04 PM
ew i cant get it to works, can you help me and look at my code plz ?:

Code:
########## Register

on *:TEXT:-tanklin register *:?: {
  if ( $lines(tanklinplayers.ini) &lt; %tanklinplayers &amp;&amp; $read(tanklinplayers.ini,s,$3 $+ $chr(32) $+ $4) {
    write tanklinplayers.ini $3 $+ $chr(32) $+ $4
    msg $nick 0,1[14««7« 7R0egistration 7S0uccessful ! 7U0ser:7 $3 7P0assword:7 $4 7»14»»0]
  }
  elseif ( $lines(tanklinplayers.ini) &lt; %tanklinplayers &amp;&amp; $cantread(tanklinplayers.ini,s,$3 $+ $chr(32) $+ $4) { ;i want this check if user is already in list
    msg $nick 0,1[14««7« 0You already registered ! 7»14»»0]
}
elseif ( $lines(tanklinplayers.ini) &gt;= %tanklinplayers ) {
    msg $nick 0,1[14««7« 0Sorry, the tournament is full ! 7»14»»0]
  }
}


%tanklinplayers is a variable to set the number of players in tournament (16 or 32)
tanklinplayers.ini is my players file (i asked for to save for a file but .ini looked sexier lmao
$3 and $4 are <user> and <pass> need pass to avoid being unregistered by someone else without authorization
Posted By: MikeChat Re: Save to a text file ? - 19/07/05 11:43 PM
if you want to use an .ini file, try this out
Code:
on *:TEXT:-tanklin register *:?: {
  if ($isfile(tanklinplayers.ini) == $false) { write -c tanklinplayers.ini }
  if ($readini(tanklinplayers.ini,players,$nick)) {
    msg $nick 0,1[14««7« 0You already registered ! 7»14»»0]
    halt
  }
  var %inicount = $ini(tanklinplayers.ini,players,0)
  if (%inicount &lt;= %tanklinplayers) {
    if ($readini(tanklinplayers.ini,players,$nick) == $null) {
      writeini tanklinplayers.ini players $nick $3
      msg $nick 0,1[14««7« 7R0egistration 7S0uccessful ! 7U0ser:7 $nick 7P0assword:7 $3 7»14»»0]
    }
  }

  if (%inicount &gt; %tanklinplayers) {
    msg $nick 0,1[14««7« 0Sorry, the tournament is full ! 7»14»»0]
  }
}


the user would msg you with -tanklin register <password>

the script picks up their nick so they dont have to post that
Posted By: Matrix301 Re: Save to a text file ? - 20/07/05 12:07 AM
oh cool i guess ini are better :P it works fine, your the pro lol, now i have a question i hope it wont scrap it all, i want to list all the user in the tournament, the command ist -list, can i list only user in the .ini file or it will list the password too ? :s

i also need -tanklin unregister <pass> ;it need to verify password, if true then it remove, otherwise then Bad password, im working on this one but not sure if i should wait becuz of list.. if you still there, help would be appreciated :P im kinda a noob, and i never scripted using files and all so im a lil loss but i learn alot :P


Edit: Ok I got the unregister thing working but I don't have any idea on how to see if password match.. im looking how i could list the file but i think i will have problems listing user only without password
Posted By: MikeChat Re: Save to a text file ? - 20/07/05 01:54 AM
Code:
on *:TEXT:-tanklin register *:?: {
  if ($isfile(tanklinplayers.ini) == $false) { write -c tanklinplayers.ini }
  if ($readini(tanklinplayers.ini,players,$nick)) {
    msg $nick 0,1[14««7« 0You already registered ! 7»14»»0]
    halt
  }
  var %inicount = $ini(tanklinplayers.ini,players,0)
  if (%inicount &lt;= %tanklinplayers) {
    if ($readini(tanklinplayers.ini,players,$nick) == $null) {
      writeini tanklinplayers.ini players $nick $3
      msg $nick 0,1[14««7« 7R0egistration 7S0uccessful ! 7U0ser:7 $nick 7P0assword:7 $3 7»14»»0]
    }
  }

  if (%inicount &gt; %tanklinplayers) {
    msg $nick 0,1[14««7« 0Sorry, the tournament is full ! 7»14»»0]
  }
}
on *:TEXT:-list:#: {
  var %inicount = $ini(tanklinplayers.ini,players,0)
  var %i = 1, %users
  while (%i &lt;= %inicount) {
    var %users = %users $ini(tanklinplayers.ini,players,%i)
    inc %i
  }
  msg $chan Current Players: %users
}
on *:TEXT:-tanklin unregister *:?: {
  var %checkID = $readini(tanklinplayers.ini,players,$nick)
  if (%checkID == $3) {
    remini tanklinplayers.ini players $nick
    msg $nick Your Nick $+(",$nick,") has been removed from the players list.
  }
  else { 
    msg $nick 04,01 ERROR! Your password does not match entry for $nick $+ ! Unregister denied!
  }
}

try that
Posted By: Matrix301 Re: Save to a text file ? - 20/07/05 04:30 AM
alright, but i need 2 more thing, i used:

########## Player Lists

Code:
on *:TEXT:-tanklin list:?: {
  var %inicount = $ini(tanklinplayers.ini,players,0)
  var %i = 1, %users
  while (%i &lt;= %inicount) {
    var %users = %users $ini(tanklinplayers.ini,players,%i)
    inc %i
  }
  msg #contests 0,1[14««7« 7T0anklin 7P0layers 7L0ist (7 $lines(tanklinplayers.ini) 0) 7»14»»0]
  msg #contests %users
  msg #contests 0,1[14««7« 7E0nd 7o0f 7P0layers 7L0ist 7»14»»0]
}


i used: $lines(tanklinplayers.ini) to show how many lines are in the files (so how many user but with the [player] it add an extra line, is there anyway to substract 1 to the number eh or make a count without [player]

also, i need a message that say: you aren't registered if user try to unregister when not in the list

Edit: oh nice i fixed teh total user in the list by changing the code to the following:

Code:
########## Lists

on *:TEXT:-tanklin list:?: {
  var %inicount = $ini(tanklinplayers.ini,players,0)
  var %i = 1, %users
  while (%i &lt;= %inicount) {
    var %users = %users $ini(tanklinplayers.ini,players,%i)
    inc %i
[color:red]    var %totaltanklinplayers = $lines(tanklinplayers.ini)
    dec %totaltanklinplayers 1[/color]
  }
  msg #contests 0,1[14««7« 7T0anklin 7P0layers 7L0ist[color:red] (7 %totaltanklinplayers 0)[/color] 7»14»»0]
  msg #contests %users
  msg #contests 0,1[14««7« 7E0nd 7o0f 7P0layers 7L0ist 7»14»»0]
}


this post is getting LONG and the thread too lol, ew neway, im checking for the message that say user isnt registered

thx to everybody who tooks few mins of their time to help me ! its really appreciated
Posted By: MikeChat Re: Save to a text file ? - 20/07/05 05:13 AM
$lines isn't the right way to do it.

//say $ini(tanklinplayers.ini,players,0)

$lines is counting the [topic] line as well and is why you got 1 more thanthere are users

you may want to use the ini to do more later and as other data is stored in it $lines would be increasing while the actual user count may not.
Quote:

also, i need a message that say: you aren't registered if user try to unregister when not in the list


take some time to look at the code and read the help file.
/help $readini
Posted By: Matrix301 Re: Save to a text file ? - 20/07/05 06:23 AM
hehe i know, but i made a var for the total user, and i just did dec 1, so it get the right number :P it works fine, everything works fine now except the unregistration, i fixed the thing to say not register but if someone type: -tanklin unregister (a space after unregister) it says unregister user but it doesnt becuz it dont exist eh :P

also, i was wondering, when i list, it list user like this:

User1, User2, User 3

is there anyway to list them like this:
User1
User2
User3
Posted By: Riamus2 Re: Save to a text file ? - 20/07/05 12:37 PM
Try:
on *:TEXT:-tanklin unregister &:?: {
Posted By: MikeChat Re: Save to a text file ? - 20/07/05 02:47 PM
yup
Code:
on *:TEXT:-tanklin register *:?: {
  if ($isfile(tanklinplayers.ini) == $false) { write -c tanklinplayers.ini }
  if ($readini(tanklinplayers.ini,players,$nick)) {
    msg $nick 0,1[14««7« 0You already registered ! 7»14»»0]
    halt
  }
  var %inicount = $ini(tanklinplayers.ini,players,0)
  if (%inicount &lt;= %tanklinplayers) {
    if ($readini(tanklinplayers.ini,players,$nick) == $null) {
      writeini tanklinplayers.ini players $nick $3
      msg $nick 0,1[14««7« 7R0egistration 7S0uccessful ! 7U0ser:7 $nick 7P0assword:7 $3 7»14»»0]
    }
  }
  if (%inicount &gt; %tanklinplayers) {
    msg $nick 0,1[14««7« 0Sorry, the tournament is full ! 7»14»»0]
  }
  close -m $nick
}

on *:TEXT:-tanklin unregister *:?: {
  var %checkID = $readini(tanklinplayers.ini,players,$nick)
  if (%checkID == $null) {
    msg $nick 04,01 ERROR! $+(",$nick,") Not in database.
    halt
  }
  if (%checkID == $3) {
    remini tanklinplayers.ini players $nick
    msg $nick Your Nick $+(",$nick,") has been removed from the players list.
  }
  else { 
    msg $nick 04,01 ERROR! Your password does not match entry for $nick $+ ! Unregister denied!
  }
  close -m $nick
}


on *:TEXT:-list:#: {
  write -c tanklinplayers.txt
  write tanklinplayers.txt 0,1[14««7« 7T0anklin 7P0layers 7L0ist (7 $ini(tanklinplayers.ini,players,0) 0) 7»14»»0]
  var %inicount = $ini(tanklinplayers.ini,players,0)
  var %i = 1, %users
  while (%i &lt;= %inicount) {
    write tanklinplayers.txt $ini(tanklinplayers.ini,players,%i)
    inc %i
  }
  write tanklinplayers.txt 0,1[14««7« 7E0nd 7o0f 7P0layers 7L0ist 7»14»»0]
  .play # tanklinplayers.txt
}
Posted By: Matrix301 Re: Save to a text file ? - 20/07/05 05:16 PM
wow awesome eh, everything works extremly fine now smile and i noticied the bot dont flood all the user lsit at the same time, he send one every sec (to avoid flood) thats excellent, because i have lots of other command for my bot, and people keep sending command and my bot keep disconnecting (Excess Flood) becuz my script send all commands at the same time (not every sec) this is very annoying, how could i make it send a line every sec like with the list, do i need to use timer lol ?
Posted By: MikeChat Re: Save to a text file ? - 20/07/05 05:36 PM
you have the bot msg somewhere (channel is my guess) the players action and/or result.
change the way it posts the text from just msg to writing/playing a text

mIRC will queue the texts to be played thereby delaying the replys to the order in which they were received, one reply at a time.

you might have now something like:
on *:text:-action *:#channel: {
do stuff
msg #channel stuff
}

instead do it:

on *:text:-action *:#channel: {
; create or clear a text for that user
write -c $+($nick,.txt)
do stuff
write $+($nick,.txt) stuff
;play the text to channel
.play #channel $+($nick,.txt)
}
Posted By: Matrix301 Re: Save to a text file ? - 20/07/05 07:51 PM
or so basicly, it write a file called the person $nick.. and write stuff to say in the text file and play it, but lol wont it make alot of files ? i think it would be better if it delete the file at the end no ?
Posted By: MikeChat Re: Save to a text file ? - 20/07/05 08:00 PM
I am guessing that you have users log in and out for the game, when they log out .remove $+($nick,.txt)
cool
Posted By: Matrix301 Re: Save to a text file ? - 20/07/05 08:33 PM
oh well no i dont have log, the game is outside irc, and hmm i mean, i have alot of other commands for other use than my tanklin game, or for example when an admin type -help, he receive all commands and it flood like 20 lines lol, i wish the bot send 1 ines every secs to avoid flood or maybe not 1 secs but hmm enuf to avoid excess flood, becuz its annoying lol, but for the script you made tis perfect
Posted By: MikeChat Re: Save to a text file ? - 20/07/05 08:41 PM
since you did not post your code, I will guess you have it message the -help to whoever one line at a time rather than having the help as a text file that would be played to that nick


played in a message window
on *:TEXT:-help:*:{
.play $nick -help.txt 1500
}
Posted By: Matrix301 Re: Save to a text file ? - 20/07/05 10:08 PM
good idea ! i can even set the delay ! woot thx
© mIRC Discussion Forums