mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2004
Posts: 175
R
Vogon poet
OP Offline
Vogon poet
R
Joined: Mar 2004
Posts: 175
TCG Script. For this script, it is supposed to delete the card from their deck (decks\ $+ $nick $+ .txt. When they type !del <card> nothing happens. Everything from "Else { carddelete }" to the end of the loop doesn't work. Even if the $2- is in the .txt file, it doesn't delete it. It might have been an bad idea to use loop, im not sure. The reason why I used -dl and not write -ds $+ $2- decks\ $+ $nick $+ .txt is because the -ds only supports searching 1 word. Since $2- is more than 1, it won't work. Help me plz, ill appreciate it.
Code:
on *:text:!del*:?: {
  closemsg $nick
  If (!$readini(registered.txt, n, Password, $nick)) { msg $nick You are not registered! Please type !register password | halt }
  If (!$readini(registered.txt, n, Login, $nick)) { msg $nick You have not logged into your account! Please type !login password | halt }
  ElseIf (!$2-) { msg $nick You need to put the name of the card you want to delete from your deck! | halt }
  ElseIf (%player1 == $nick) { msg $nick You cannot delete cards from your deck while you are dueling! | halt }
  ElseIf (%player2 == $nick) { msg $nick You cannot delete cards from your deck while you are dueling! | halt } 
  ElseIf ($2 == all) {
    msg $nick You have now deleted your Whole Deck!
    remove decks\ $+ $nick $+ .txt
    remove decks\ $+ $nick $+ .Fusion.txt
    remove decks\ $+ $nick $+ .Sidedeck.txt
  }
  Elseif ($2 == deck) {
    msg $nick You have now deleted your Normal Deck!
    remove decks\ $+ $nick $+ .txt
  }
  Elseif ($2 == fusion) {
    msg $nick You have now deleted your Fusion Deck!
    remove decks\ $+ $nick $+ .Fusion.txt
  }
  Elseif ($2 == sidedeck) {
    msg $nick You have now deleted your Side Deck!
    remove ecks\ $+ $nick $+ .Sidedeck.txt
  }
Else { carddelete }
}
Alias carddelete {
  Set %Counts 0
  :Start
  Inc %Counts
  if (!$Read(decks\ $+ $nick $+ .txt, %Counts)) &amp;&amp; (!$Read(decks\ $+ $nick $+ .Fusion.txt, %Counts)) &amp;&amp; (!$Read(decks\ $+ $nick $+ .Sidedeck.txt, %Counts)) { Goto Finish }
  Elseif ($Read(decks\ $+ $nick $+ .txt, %Counts) == $2-) { write -dl $+ %Counts decks\ $+ $nick $+ .txt | unset %Counts | halt }
  Elseif ($Read(decks\ $+ $nick $+ .Fusion.txt, %Counts) == $2-) { write -dl $+ %Counts decks\ $+ $nick $+ .Fusion.txt | unset %Counts | halt }
  Elseif ($Read(decks\ $+ $nick $+ .Sidedeck.txt, %Counts) == $2-) { write -dl $+ %Counts decks\ $+ $nick $+ .Sidedeck.txt | unset %Counts | halt }
  Goto Start
  :Finish
  msg $nick You do not have this card in your deck! Please check spelling!
  unset %Counts
  halt
}
 

Last edited by Relinsquish; 29/03/04 10:29 PM.
M
MIMP
MIMP
M
Try this, obviously I haven't tested it but I think it should be a lot easier and faster.

Code:
on ^*:text:!del*:?: {
  If (!$readini(registered.txt, n, Password, $nick)) msg $nick You are not registered! Please type !register password
  ElseIf (!$readini(registered.txt, n, Login, $nick)) msg $nick You have not logged into your account! Please type !login password
  ElseIf (!$2-) msg $nick You need to put the name of the card you want to delete from your deck!
  ElseIf (%player1 == $nick) || (%player2 == $nick) msg $nick You cannot delete cards from your deck while you are dueling!
  ElseIf ($2 == all) {
    msg $nick You have now deleted your Whole Deck!
    remove decks\ $+ $nick $+ .txt
    remove decks\ $+ $nick $+ .Fusion.txt
    remove decks\ $+ $nick $+ .Sidedeck.txt
  }
  Elseif ($2 == deck) {
    msg $nick You have now deleted your Normal Deck!
    remove decks\ $+ $nick $+ .txt
  }
  Elseif ($2 == fusion) {
    msg $nick You have now deleted your Fusion Deck!
    remove decks\ $+ $nick $+ .Fusion.txt
  }
  Elseif ($2 == sidedeck) {
    msg $nick You have now deleted your Side Deck!
    remove decks\ $+ $nick $+ .Sidedeck.txt
  }
  Else {
    ;
    ; Store the number of lines prior to removing any.
    ;
    var %Total = $lines($+(decks\,$nick,.txt))
    ;
    ; Filter through the file and put back all the lines EXCEPT those that have $2- in them.
    ; This could be bad if you have say: Green Wizard and Green Wizard's Dog as card names 
    ; as it'll be greedy when matching.
    ;
    filter -ffx $+(decks\,$nick,.txt) @Temp $+(*,$2-,*)
    ;
    ; Compare the number that stayed in the file to the original total to see if any were removed.
    ;
    If ($filtered == %Total) msg $nick You do not have any cards matching: $+(",$2-,") in your deck! Please check spelling!
    Else msg $nick Removed $calc(%Total - $filtered) card(s) matching: $+(",$2-,") from your deck!
  }
  Haltdef
}

Joined: Mar 2004
Posts: 175
R
Vogon poet
OP Offline
Vogon poet
R
Joined: Mar 2004
Posts: 175
As much as I want that to work, it don't :P, anybody else could help me?

M
MIMP
MIMP
M
Are you getting an error? If so what is it? Is the text file for each deck just a plain text listing or is it an .ini or other structured plain text file?

Also, after you've added all the code, hit the {} button to make sure all the brackets line up normally. Don't just hit it, but scroll through and double check that the end of each routine is up against the edge normally.

M
MIMP
MIMP
M
D'oh! I think I tracked it down, was late when I wrote that.

/filter requires us to use the -c switch to clear the file before rewriting it. Also, I left a @Temp in there, where it should be the filename again (was originally going to do it differently.)

So, end result, change the one line:
filter -ffx $+(decks\,$nick,.txt) @Temp $+(*,$2-,*)

to this:
filter -ffxc $+(decks\,$nick,.txt) $+(decks\,$nick,.txt) $+(*,$2-,*)

Also I assume here that you're using the latest version of mIRC. If it still doesn't work let me know exactly which parts are failing. E.G.: here the remote seemed to be working but the entry wasn't being removed from the file.

Joined: Mar 2004
Posts: 175
R
Vogon poet
OP Offline
Vogon poet
R
Joined: Mar 2004
Posts: 175
thx, that works. 1 thing, so there are flaws to this script correct? if $2- is equal to "Jinzo" and in the txt file, theres a "Jinzo" and a "Jinzo #7", those 2 will get deleted. meh, better than nothing.

M
MIMP
MIMP
M
Indeed, if you wanted you could first /filter the lines to a custom window. Check $filtered and if it's more than one don't do it. Or have it message the user telling them which ones would be deleted and require them to select which if any it should delete. Doing so would obviously require further exchanges of information between your script and the user but it can be done.

Joined: Mar 2004
Posts: 175
R
Vogon poet
OP Offline
Vogon poet
R
Joined: Mar 2004
Posts: 175
hmmm, how would I make it so that it deletes only 1 from the .txt file?

T
theRat
theRat
T
change $+(*,$2-,*) to $2- ?

M
MIMP
MIMP
M
I changed a couple things. First off it won't default to using wild cards, however it will accept them if you specify them. If wildcards are used and multiple matches (less then 5, which you can change if you like but may flood yourself off if you do,) are found the user is presented with a list and can use: !confirm <#> to specify which item in the list to delete. The final item is always "all of the above" and can be selected as well.

Code:
on ^*:text:!del *:?:{
  If (!$readini(registered.txt, n, Password, $nick)) msg $nick You are not registered! Please type !register password
  ElseIf (!$readini(registered.txt, n, Login, $nick)) msg $nick You have not logged into your account! Please type !login password
  ElseIf (!$2-) msg $nick You need to put the name of the card you want to delete from your deck!
  ElseIf (%player1 == $nick) || (%player2 == $nick) msg $nick You cannot delete cards from your deck while you are dueling!
  ElseIf ($2 == all) {
    msg $nick You have now deleted your Whole Deck!
    remove decks\ $+ $nick $+ .txt
    remove decks\ $+ $nick $+ .Fusion.txt
    remove decks\ $+ $nick $+ .Sidedeck.txt
  }
  ElseIf ($2 == deck) {
    msg $nick You have now deleted your Normal Deck!
    remove decks\ $+ $nick $+ .txt
  }
  ElseIf ($2 == fusion) {
    msg $nick You have now deleted your Fusion Deck!
    remove decks\ $+ $nick $+ .Fusion.txt
  }
  ElseIf ($2 == sidedeck) {
    msg $nick You have now deleted your Side Deck!
    remove decks\ $+ $nick $+ .Sidedeck.txt
  }
  Else {
    var %Total = $lines($+(decks\,$nick,.txt))
    If ($window($+(@Temp.,$nick))) clear $+(@Temp.,$nick)
    Else window -h $+(@Temp.,$nick)
    filter -fw $+(decks\,$nick,.txt) $+(@Temp.,$nick) $2-
    titlebar $+(@Temp.,$nick) $2-
    If ($filtered &gt; 5) {
      msg $nick Too many matches found, please refine your request or use: !del deck/fusion/sidedeck to delete the entire deck.
      window -c $+(@Temp.,$nick)
    }
    ElseIf ($filtered == 1) {
      msg $nick Deleted: $line($+(@Temp.,$nick),1)
      window -c $+(@Temp.,$nick)
    }
    ElseIf ($filtered == 0) {
      msg $nick No matches found for: $2-
      window -c $+(@Temp.,$nick)
    }
    Else {
      var %i = 1
      msg $nick Multiple matches found, please clarify which of the following you would like deleted:
      While (%i &lt;= $line($+(@Temp.,$nick),0)) {
        msg $nick $+($chr(3),4) %i $+($chr(15),$line($+(@Temp.,$nick),%i)))
        inc %i
      }
      msg $nick $+($chr(3),4) %i $+($chr(15),All) of the above.
      msg $nick Type: /msg $me !confirm &lt;#&gt;
      .timer 1 300 window -c $+(@Temp.,$nick)
  } }
  Haltdef
}
on ^*:text:!confirm *:?:{
  if ($window($+(@Temp.,$nick))) {
    if ($2 isnum) {
      if ($2 == $calc($line($+(@Temp.,$nick),0) + 1)) {
        filter -ffxc $+(decks\,$nick,.txt) $+(decks\,$nick,.txt) $window($+(@Temp.,$nick)).titlebar
        msg $nick Deleted $line($+(@Temp.,$nick),0) items matching: $window($+(@Temp.,$nick)).titlebar
      }
      else {
        msg $nick Deleted: $read($+(decks\,$nick,.txt),w,$line($+(@Temp.,$nick),$2))
        write $+(-dl,$readn) $+(decks\,$nick,.txt)
    } }
    window -c $+(@Temp.,$nick)
} }


Link Copied to Clipboard