Random Naruto Character

By Xain on Jun 12, 2011

This is just a random Naruto Character snippet. It generates randomly and sets it as a variable or something.
Please tell me if there are any errors or if I can make an improvement.

Eg:
(12:59:30) &RecruitX: +naruto
(12:59:31) ~Cop: «ø» NARUTO «ø» RecruitX is Killer Bee.

on *:load:loading
on *:start:loading
on *:connect:loading
on me:*:join:#:loading
alias -l loading { 
  if !$exists($qt($scriptdirnaruto.txt)) {
    var %load 7Uzumaki Naruto^13Haruno Sakura^12Uchiha Sasuke^5Inuzuka Kiba^$&
      11Hyuuga Hinata^14Aburame Shino^3Nara Shikamaru^4Akimichi Chouji^$&
      6Yamanaka Ino^11Hyuuga Neji^9Rock Lee^13Tenten^5Gaara^$&
      5Kankuro^13Temari^12Uchiha Obito^10Umino Iruka^10Hatake Kakashi^$&
      10Maito Gai^10Sarutobi Asuma^4Mitarashi Anko^4Yuhi Kurenei^10Baki^$&
      6Orochimaru^4Jiraiya^9Tsunade^4Sandaime Hokage^5Shodai Hokage^$&
      12Nidaime Hokage^11Hoshikage Kisame^4Uchiha Itachi^14Sai^5Yamato^$&
      4Inuzuka Tsume^4Akimichi Chouza^6Yamanaka Inoichi^2Morino Ibiki^$&
      8Killer Bee^14Yakushi Kabuto^6Hozuki Suijetsu^13Karin^7Juugo^8Deidara$&
      4Sasori^5Hidan^3Kakuzu^11Konan^4Pein^4Madara - Tobi 
    tokenize 94 %load | write naruto.txt $*
  }
}

on *:TEXT:+naruto:#: {
  if (!$var(%flood)) {
    if !$exists($qt($scriptdirnaruto.hsh)) { hload Naruto $qt($scriptdirNaruto.hsh) | hmake naruto 100  }
    if ($hget(Naruto,$wildsite)) { 
      msg $chan %stamp NARUTO %stamp $nick is  $hget(Naruto,$wildsite) $+ . 
      set -u3 %flood 1.
    } { halt }
    set %stamp 11«ø»14
    %narutotest = $read(naruto.txt)
    hadd -m Naruto $wildsite %narutotest
    msg $chan %stamp NARUTO %stamp $nick is  $hget(Naruto,$wildsite) $+ .
    hsave Naruto Naruto.hsh
    set -u3 %flood 1.
  }
}

Comments

Sign in to comment.
blackvenomm666   -  Jun 15, 2011

yea the laptop im normally running only has 192 mb of ram:(

 Respond  
Jethro   -  Jun 15, 2011

blackvenomm666, I did say 4000 with a + sign! The actual, specific amount the variables can include is unbeknownst to me, since the latest versions have updated its capability to include more storage limits over the years. And as jaytea has mentioned, the variable size is bounded by your RAM, so I suppose our concern over the maximum capacity of variables can hold should not be too big a worry...especially the modern computers come with an ample amount of RAM these days.

 Respond  
jaytea   -  Jun 15, 2011

No.. I'm saying that I didn't know that .ini's and Vars had a limit of storage.. my bad..

they're not significantly limited. variables are limited by the size of your RAM, and INI files (just as with any data that resides on disk) are limited by the size of your hard disk. these limits are, on any modern computer, very very high and judging by the nature of your data, not something you need to worry about right now.

does this mean you SHOULD be setting tens of thousands of global variables for this kind of script? of course not! why? because it's simply not the right tool for the job. global variables are 1-dimensional and shared across all scripts: use them sparingly! don't use them to save a continuously growing amount of data over a long period of time, especially if this data is only relevant to a single script. do use them to store data that is relevant to the client eg. global settings in a full mIRC script that control the behaviour of all its addons, and that a user may want to edit manually (you can add comments to a variables file, so this is often a worthwhile approach).

and 'hash files' is a misnomer, call them 'hash tables' :P a hash table is essentially a collection of variables, thus it's a good idea to use them when you have many related name&value associations. don't go out of your way to use them though; INI files are well handled by mIRC. an INI section can even be loaded into a hash table for when you need to perform operations with $hfind() or such. if you have a task that involves long-term maintenance of structured data in mIRC, ask yourself "why shouldn't i use an INI file?".

 Respond  
blackvenomm666   -  Jun 15, 2011

ok well out of boredom jethro_ i tested that 4000 variable limit and it stopped at 56646 for me

 Respond  
Xain   -  Jun 15, 2011

No.. I'm saying that I didn't know that .ini's and Vars had a limit of storage.. my bad..
And your tips taught(however you spell it) me how to make .hsh files.. Thankyou :)

 Respond  
napa182   -  Jun 15, 2011

we are just giving you tips nothing more. You say you are just starting out so shouldn't you want tips on how to do things a little better so you can learn better coding habits?
in my rewrites i said these are nothing more then working examples. I never said you need to do it like this.

 Respond  
Xain   -  Jun 15, 2011

I just started out, so I'm a little new to this =\

 Respond  
Xain   -  Jun 15, 2011

Eh... I'll make them into hash files then and use $wildsite

 Respond  
Jethro   -  Jun 14, 2011

After a review of this snippet, I find it annoyingly flustering that all the global variables were used when they weren't necessary. Wouldn't it be a lot simpler if you did:

on *:load:loading
on *:start:loading
on *:connect:loading
on me:*:join:#:loading
alias -l loading { 
  if !$exists($qt($scriptdirnaruto.txt)) {
    var %load 7Uzumaki Naruto^13Haruno Sakura^12Uchiha Sasuke^5Inuzuka Kiba^$&
      11Hyuuga Hinata^14Aburame Shino^3Nara Shikamaru^4Akimichi Chouji^$&
      6Yamanaka Ino^11Hyuuga Neji^9Rock Lee^13Tenten^5Gaara^$&
      5Kankuro^13Temari^12Uchiha Obito^10Umino Iruka^10Hatake Kakashi^$&
      10Maito Gai^10Sarutobi Asuma^4Mitarashi Anko^4Yuhi Kurenei^10Baki^$&
      6Orochimaru^4Jiraiya^9Tsunade^4Sandaime Hokage^5Shodai Hokage^$&
      12Nidaime Hokage^11Hoshikage Kisame^4Uchiha Itachi^14Sai^5Yamato^$&
      4Inuzuka Tsume^4Akimichi Chouza^6Yamanaka Inoichi^2Morino Ibiki^$&
      8Killer Bee^14Yakushi Kabuto^6Hozuki Suijetsu^13Karin^7Juugo^8Deidara$&
      4Sasori^5Hidan^3Kakuzu^11Konan^4Pein^4Madara - Tobi 
    tokenize 94 %load | write naruto.txt $*
  }
}
on *:text:$($iif(+naruto == $strip($1),$1)):*:{
  if !%flood { set -u3 %flood 1. | var %stamp 11«ø»14
    .msg $iif(#,#,$nick) %stamp NARUTO %stamp $nick is $read($scriptdirnaruto.txt) $+ .
  }
}

One thing to note that if a newbie installs your code without loading it, the naurato characters won't be there when the code triggers. It's best to include the start, connect and on me join event just in case.

 Respond  
Jethro   -  Jun 14, 2011

Someone rated this snippet a 10. :| What has our world turned into?

 Respond  
napa182   -  Jun 14, 2011

Xain, ini will fill up as well, and you can run into a problem if the nick is like [name]more or just [nick] [N]nick. also you are still using $nick so they can just change nicks an add more lines in ur file

 Respond  
Xain   -  Jun 14, 2011

oh.. I didn't know that it could not store more than 4000 entries... Well I put them into .ini

 Respond  
Jethro   -  Jun 14, 2011

jaytea, again, you have a valid point. ^^

 Respond  
jaytea   -  Jun 13, 2011
if (!$isfile($qt($file(naruto.txt).shortfn))) {

=

if (!$isfile(naruto.txt)) {

which checks for naruto.txt inside $mircdir.

napa has the right idea with $scriptdir, since scripts should try to keep supplementary files out of the main mIRC directory unless absolutely necessary, but in order for it to be consistent with the rest of the original script, naruto.txt would need to be changed to $scriptdirnaruto.txt in all cases.

relative paths in script files are always relative to $mircdir.

 Respond  
Jethro   -  Jun 13, 2011

nap182, you can also use

if (!$isfile($qt($file(naruto.txt).shortfn))) {

but it's the same difference. :p

 Respond  
Jethro   -  Jun 13, 2011

napa's right on the issue at hand. Using $nick is not a good idea because people tend to change their nicknames, and they do from time to time.

In general, using dynamic global variables is fine if you know for certain that your variable entries won't exceed 4000 plus. If you still fancy the use of $nick instead of $wildsite, you may think about implementing a nick event to track the nickname changes and then have the existing variable reset to reflect that matter.

While hash table is considered a wise choice, it has to be saved to retain the information stored if your mIRC gets exited or closed for any reason. But if you don't know what hash table is, you're suggested to read up on that so you understand what I'm saying here.

 Respond  
napa182   -  Jun 13, 2011

Xain, The only thing about using a global var an the way you have it set the global var to store that info, is if someone uses this in a channel with a lot of people or if they change nicks repeatedly they would end up filling your var list.
It would just be better to use a hash file instead of a global var along with $wildsite instead of $nick.

Xain, I only made them snippets, and posted them as comments to show you different examples/ways to make that nothing more.
But what ever to each their own...

another thing no need to set a global var to do this check:

if (%loaded.naruto == $null) {
    set %loaded.naruto on

you can just use

if (!$exists($qt($scriptdirnaruto.txt))) {
 Respond  
Jethro   -  Jun 13, 2011

Is there a reason why you set various dynamic global variables?

When you use a local or global variable, the local one is for a temporary value to be referred to. The global one is to be evaluated when its value needs to be used later on.

What you have done here is pretty much the same without using a global variable:

I'll quote this section of your code:

var %narutotest = $read(naruto.txt)

  ;you set a local variable to refer to the random value from naruto.txt

 **set %naruto. [ $+ [ $nick ] ] %narutotest**

  ; you then set a dynamic global variable to identify each nickname who triggers the command.

  **msg $chan %stamp NARUTO %stamp $nick is  %naruto. [ $+ [ $nick ] ] $+ .**

 ; finally you have the output messaged in the channel.You seem to have missed the fact that every time the same user who triggers the command, the dynamic variable's value for him or her will still be changed to a random value because of this line you made:> var %narutotest = $read(naruto.txt)You use many dynamic global variables in your code unnecessarily, and your script is going to run into a problem in the future when your mIRC variable stores more than 4000+ entries. It won't store more variables after that. 

I don't see you have your global variables unset at the end of script routine, so they'll get stored and clogged up in your variables on account of other nicknames involve using the script eventually.

 Respond  
Xain   -  Jun 13, 2011

.. I was referring to the one you posted along with the sockets:

on *:TEXT:*:#: {
  tokenize 32 $Strip($1-)
  if ($1 = +naruto && !%flood) { inc -u3 %flood
    msg # 11«ø»14NARUTO11«ø»14 $nick is  $read(naruto.txt) $+ .
  }
} 

It outputs a random Character every time they type +naruto..
But I had it set a variable..

on *:TEXT:+naruto:#: {
  if (!$var(%flood)) {
    if (%naruto. [ $+ [ $nick ] ] == $null) { 
      set %stamp 11«ø»14
      %narutotest = $read(naruto.txt)
      set %naruto. [ $+ [ $nick ] ] %narutotest 
      msg $chan %stamp NARUTO %stamp $nick is  %naruto. [ $+ [ $nick ] ] $+ .
    } { Halt }
    msg $chan %stamp NARUTO %stamp $nick is  %naruto. [ $+ [ $nick ] ] $+ .
    set -u3 %flood 1.
  }
}

On the other hand, that socket one looks good too...

 Respond  
napa182   -  Jun 13, 2011

Xain, what is the reason you want a global var for? I am a little fuzzy on what you said. Making what random every time? What is it that people keep typing every time? ah wait i think i understand you want, you want them to get the same name every time they trigger the snippet. hmm kinda odd but what ever
not hard to do

here is an example of it:

on $*:text:/^\+naruto$/iS:#:{
  if (!%f) { inc -u3 %f
    if ($hget(Naruto,$wildsite)) { msg # $nick $+ , you already have a Naruto name it is $v1 }
    else {
      if ($sock(naruto)) sockclose naruto
      sockopen naruto pastebin.com 80
      sockmark naruto $r(1,623) $wildsite msg # $+($chr(3),$&
        11«ø»,$chr(3),14NARUTO,$chr(3),11«ø»,$chr(3),$&
        14,$chr(32),$nick is,$chr(32),$chr(3),$base($r(2,15),10,10,2))
    }
  }
}
on *:sockopen:naruto: {
  sockwrite -n naruto GET /LpfeWEUL HTTP/1.1
  sockwrite -n naruto Host: $+($sock(naruto).addr,$str($crlf,2))
}
on *:sockread:naruto: {
  var %naruto | sockread %naruto
  if ($regex(%naruto,/<div class="de\d">(.+?)<\/div>/)) {  
    hinc -mu3 n c 1 
    if ($hget(n,c) = $gettok($sock(naruto).mark,1,32)) { 
      hadd -m Naruto $gettok($sock(naruto).mark,2,32) $regml(1)
      $+($gettok($sock(naruto).mark,3-,32),$regml(1),.) 
      sockclose naruto
    } 
  }
}
on *:connect:SarutoLoad
on *:start:SarutoLoad
on *:exit:NarutoSave
on *:disconnect:NarutoSave
alias -l NarutoSave hsave Naruto $qt($scriptdirNaruto.hsh) 
alias -l NarutoLoad $iif($exists($qt($scriptdirNaruto.hsh)),hload Naruto $qt($scriptdirNaruto.hsh),hmake Naruto 100)

So now the output would be this:

+naruto <~One> «ø»NARUTO«ø» napa182 is Meizu. +naruto <~One> napa182, you already have a Naruto name it is Meizu

Xain you can also do that with the other ones I left as comments.

 Respond  
Xain   -  Jun 13, 2011

and yeah.. sockets are much better.. but I don't really understand them... And Napa.. I like to have a perm Variable other than making it random everytime.. I hate it when people keep typing the same thing over and over again..

 Respond  
Xain   -  Jun 13, 2011

I only added the main characters :... most of the people don't know side story characters...

 Respond  
napa182   -  Jun 12, 2011

Yeah, but 623 is not that bad to start with. ;x

 Respond  
Jethro   -  Jun 12, 2011

Good deal, napa182. But then the exact list of characters is not definitive. I read it somewhere that there are approximately 771 naruto characters available.

 Respond  
napa182   -  Jun 12, 2011

well in the socket i made in the comment, i used what the author had posted in this snippet.
i can update the list. um idk about how stable that site you posted is if it has a lot of uptime or if it drops a lot, but i used pastebin to socket to an that site is good on not dropping. Also that site seems to double a few of the names.

anyways here is the socket using those other names . it does give you 574 more names.
this is nothing more then a working example:

on $*:text:/^\+naruto$/iS:#:{
  if (!$hget(n,c)) {
    if ($sock(naruto)) sockclose naruto
    sockopen naruto pastebin.com 80
    sockmark naruto $r(1,623) msg # $+($chr(3),$&
      11«ø»,$chr(3),14NARUTO,$chr(3),11«ø»,$chr(3),$&
      14,$chr(32),$nick is,$chr(32),$chr(3),$base($r(2,15),10,10,2))
  }
}
on *:sockopen:naruto: {
  sockwrite -n naruto GET /LpfeWEUL HTTP/1.1
  sockwrite -n naruto Host: $+($sock(naruto).addr,$str($crlf,2))
}
on *:sockread:naruto: {
  var %naruto | sockread %naruto
  if ($regex(%naruto,/<div class="de\d">(.+?)<\/div>/)) {  
    hinc -mu3 n c 1 
    if ($hget(n,c) = $gettok($sock(naruto).mark,1,32)) { 
      $+($gettok($sock(naruto).mark,2-,32),$regml(1),.) 
      sockclose naruto
    } 
  }
}

i had to use $chr(3) instead of the color block cuz when i posted the socket as a comment it was taking out the color block

But if you want to keep it the same kind of set up you can do this..

on *:load: {
  echo 04 -a Naruto Random Character Generator Loaded! Script by Xain - irc.rizon.net #maxacre 
  if (!%loaded.naruto) {
    set %loaded.naruto on
    var %lold = write naruto.txt
    %lold 7Uzumaki Naruto
    %lold 13Haruno Sakura
    %lold 12Uchiha Sasuke
    %lold 5Inuzuka Kiba
    %lold 11Hyuuga Hinata
    %lold 14Aburame Shino
    %lold 3Nara Shikamaru
    %lold 4Akimichi Chouji
    %lold 6Yamanaka Ino
    %lold 11Hyuuga Neji
    %lold 9Rock Lee
    %lold 13Tenten
    %lold 5Gaara
    %lold 5Kankuro
    %lold 13Temari
    %lold 12Uchiha Obito
    %lold 10Umino Iruka
    %lold 10Hatake Kakashi
    %lold 10Maito Gai
    %lold 10Sarutobi Asuma
    %lold 4Mitarashi Anko
    %lold 4Yuhi Kurenei
    %lold 10Baki
    %lold 6Orochimaru
    %lold 4Jiraiya
    %lold 9Tsunade
    %lold 4Sandaime Hokage
    %lold 5Shodai Hokage
    %lold 12Nidaime Hokage
    %lold 11Hoshikage Kisame
    %lold 4Uchiha Itachi
    %lold 14Sai
    %lold 5Yamato
    %lold 4Inuzuka Tsume
    %lold 4Akimichi Chouza
    %lold 6Yamanaka Inoichi
    %lold 2Morino Ibiki
    %lold 8Killer Bee
    %lold 14Yakushi Kabuto
    %lold 6Hozuki Suijetsu
    %lold 13Karin
    %lold 7Juugo
    %lold 8Deidara
    %lold 4Sasori
    %lold 5Hidan
    %lold 3Kakuzu
    %lold 11Konan
    %lold 4Pein
    %lold 4Madara - Tobi 
  }
}
on *:TEXT:*:#: {
  tokenize 32 $Strip($1-)
  if ($1 = +naruto && !%flood) { inc -u3 %flood
    msg # 11«ø»14NARUTO11«ø»14 $nick is  $read(naruto.txt) $+ .
  }
}
 Respond  
Jethro   -  Jun 12, 2011

In addition, I don't think that's a complete list of naruto characters. Here is the link to it:

http://www.narutohq.com/characterlist.php

 Respond  
Jethro   -  Jun 12, 2011

Using a socket really saves you the use of text file, INI, variables..etc..and it's fun to make one. The only drawback, as mentioned time and again, is when the targeted website goes down or source changes for any reason.

 Respond  
blackvenomm666   -  Jun 12, 2011

haha napa you and your sockets:P

 Respond  
napa182   -  Jun 12, 2011

oh an odd lil snippet ;x

 Respond  
napa182   -  Jun 12, 2011

here it is as a socket ;x
this is nothing more then a working example:

on $*:text:/^\+naruto$/iS:#:{
  if (!$hget(n,c)) {
    if ($sock(naruto)) sockclose naruto
    sockopen naruto pastebin.com 80
    sockmark naruto $r(1,49) msg # $+($chr(3),11«ø»,$chr(3),14$&
      NARUTO,$chr(3),11«ø»,$chr(3),14) $nick is
  }
}
on *:sockopen:naruto: {
  sockwrite -n naruto GET /fRhBk3jN HTTP/1.1
  sockwrite -n naruto Host: $+($sock(naruto).addr,$str($crlf,2))
}
on *:sockread:naruto: {
  var %naruto | sockread %naruto
  if ($regex(%naruto,/<div class="de\d">(.+?)<\/div>/)) {  
    hinc -mu4 n c 1 
    if ($hget(n,c) = $gettok($sock(naruto).mark,1,32)) { 
      $gettok($sock(naruto).mark,2-,32) $+($chr(3),$regml(1),.) 
      sockclose naruto
    } 
  }
}
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.