mIRC Home    About    Download    Register    News    Help

Page 1 of 2 1 2 >
Topic Options
#125584 - 19/07/05 06:11 PM Save to a text file ?
Matrix301 Offline
Ameglian cow

Registered: 30/06/05
Posts: 47
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

Top
#125585 - 19/07/05 06:22 PM Re: Save to a text file ?
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
//write textfilename.txt your text to write

Top
#125586 - 19/07/05 06:55 PM Re: Save to a text file ?
Matrix301 Offline
Ameglian cow

Registered: 30/06/05
Posts: 47
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


Edited by Matrix301 (19/07/05 06:56 PM)

Top
#125587 - 19/07/05 07:19 PM Re: Save to a text file ?
MikeChat Offline
Hoopy frood

Registered: 12/12/02
Posts: 1245
Loc: California, doooood
if ($lines(file.txt) < 16) { write to file stuff }
else msg #gamechan game is full $nick please wait for an opening

Top
#125588 - 19/07/05 07:48 PM Re: Save to a text file ?
Matrix301 Offline
Ameglian cow

Registered: 30/06/05
Posts: 47
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 ?


Edited by Matrix301 (19/07/05 07:49 PM)

Top
#125589 - 19/07/05 07:56 PM Re: Save to a text file ?
MikeChat Offline
Hoopy frood

Registered: 12/12/02
Posts: 1245
Loc: California, doooood
/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

Top
#125590 - 19/07/05 07:57 PM Re: Save to a text file ?
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
READ:
$read(file.txt,s,nick)
$read(file.txt,w,*nick*)

/help $read

DELETE:
/write -dl# file.txt

/help /write
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#125591 - 19/07/05 07:59 PM Re: Save to a text file ?
MikeChat Offline
Hoopy frood

Registered: 12/12/02
Posts: 1245
Loc: California, doooood
cool

Top
#125592 - 19/07/05 08:01 PM Re: Save to a text file ?
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
You beat me!!! mad

LOL!! grin
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#125593 - 19/07/05 08:34 PM Re: Save to a text file ?
Matrix301 Offline
Ameglian cow

Registered: 30/06/05
Posts: 47
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>

Top
#125594 - 19/07/05 08:51 PM Re: Save to a text file ?
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
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).
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#125595 - 19/07/05 10:04 PM Re: Save to a text file ?
Matrix301 Offline
Ameglian cow

Registered: 30/06/05
Posts: 47
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[147 7R0egistration 7S0uccessful ! 7U0ser:7 $3 7P0assword:7 $4 7140]
  }
  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[147 0You already registered ! 7140]
}
elseif ( $lines(tanklinplayers.ini) &gt;= %tanklinplayers ) {
    msg $nick 0,1[147 0Sorry, the tournament is full ! 7140]
  }
}


%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


Edited by Matrix301 (19/07/05 10:06 PM)

Top
#125596 - 20/07/05 12:43 AM Re: Save to a text file ?
MikeChat Offline
Hoopy frood

Registered: 12/12/02
Posts: 1245
Loc: California, doooood
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[147 0You already registered ! 7140]
    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[147 7R0egistration 7S0uccessful ! 7U0ser:7 $nick 7P0assword:7 $3 7140]
    }
  }

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


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

the script picks up their nick so they dont have to post that

Top
#125597 - 20/07/05 01:07 AM Re: Save to a text file ?
Matrix301 Offline
Ameglian cow

Registered: 30/06/05
Posts: 47
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


Edited by Matrix301 (20/07/05 02:47 AM)

Top
#125598 - 20/07/05 02:54 AM Re: Save to a text file ?
MikeChat Offline
Hoopy frood

Registered: 12/12/02
Posts: 1245
Loc: California, doooood
Code:
on *:TEXT:-tanklin register *:?: {
  if ($isfile(tanklinplayers.ini) == $false) { write -c tanklinplayers.ini }
  if ($readini(tanklinplayers.ini,players,$nick)) {
    msg $nick 0,1[147 0You already registered ! 7140]
    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[147 7R0egistration 7S0uccessful ! 7U0ser:7 $nick 7P0assword:7 $3 7140]
    }
  }

  if (%inicount &gt; %tanklinplayers) {
    msg $nick 0,1[147 0Sorry, the tournament is full ! 7140]
  }
}
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

Top
#125599 - 20/07/05 05:30 AM Re: Save to a text file ?
Matrix301 Offline
Ameglian cow

Registered: 30/06/05
Posts: 47
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[147 7T0anklin 7P0layers 7L0ist (7 $lines(tanklinplayers.ini) 0) 7140]
  msg #contests %users
  msg #contests 0,1[147 7E0nd 7o0f 7P0layers 7L0ist 7140]
}


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[147 7T0anklin 7P0layers 7L0ist[color:red] (7 %totaltanklinplayers 0)[/color] 7140]
  msg #contests %users
  msg #contests 0,1[147 7E0nd 7o0f 7P0layers 7L0ist 7140]
}


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


Edited by Matrix301 (20/07/05 05:45 AM)

Top
#125600 - 20/07/05 06:13 AM Re: Save to a text file ?
MikeChat Offline
Hoopy frood

Registered: 12/12/02
Posts: 1245
Loc: California, doooood
$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

Top
#125601 - 20/07/05 07:23 AM Re: Save to a text file ?
Matrix301 Offline
Ameglian cow

Registered: 30/06/05
Posts: 47
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

Top
#125602 - 20/07/05 01:37 PM Re: Save to a text file ?
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
Try:
on *:TEXT:-tanklin unregister &:?: {
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#125603 - 20/07/05 03:47 PM Re: Save to a text file ?
MikeChat Offline
Hoopy frood

Registered: 12/12/02
Posts: 1245
Loc: California, doooood
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[147 0You already registered ! 7140]
    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[147 7R0egistration 7S0uccessful ! 7U0ser:7 $nick 7P0assword:7 $3 7140]
    }
  }
  if (%inicount &gt; %tanklinplayers) {
    msg $nick 0,1[147 0Sorry, the tournament is full ! 7140]
  }
  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[147 7T0anklin 7P0layers 7L0ist (7 $ini(tanklinplayers.ini,players,0) 0) 7140]
  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[147 7E0nd 7o0f 7P0layers 7L0ist 7140]
  .play # tanklinplayers.txt
}

Top
Page 1 of 2 1 2 >