mIRC Home    About    Download    Register    News    Help

Topic Options
#154887 - 02/08/06 03:07 AM Help with my first script
moomootree Offline
Nutrimatic drinks dispenser

Registered: 02/08/06
Posts: 7
this is my first wack at any scripting at all and i can't get it to do anything. Please edit my horribly written script into a beautiful swan
please ignore the fact that this script involves the word AIDS (shifty dog eyes)

/var %mod = [M]tree
on *:TEXT:!cast aids*:#:
{
if ($nick isin %mod) && ($3 ison $chan)
{ /msg $chan /me begins to cast AIDS. }
{ /timer1 1 5 /msg $chan /me has sucesfully casted AIDS on $3! }
{ /timer2 1 10 /msg $chan $3 has 5 minutes till AIDS will take affect. }
{ /timer3 1 70 /msg $chan $3 has 4 minutes remaining till consumed by the AIDS effect. }
{ /timer4 1 130 /msg $chan $3 has only 3 minutes remaining. }
{ /timer5 1 190 /msg $chan $3 has only 2 minutes left! GASP! }
{ /timer6 1 250 /msg $chan $3 has only 1 minute left! Please apply the !cure soon. }
{ /timer7 1 310 -k $3 /msg $chan $3 DIED OF AIDS }

}

on *:TEXT:!cure*:#:
{
{ /msg $chan Cures can be purchased using AIDSbot credits. Currently the credit system is down so if you are

currently suffering from AIDS there is no hope for you. }
}

The attempt here is to make it so when only I ([M]Tree say !cast aids (name) it will show a emote of my bot casting AIDS and then have a 5 min countdown , showing every minute. at the end (name) is kicked

also i wish (but not needed) if some one could figure a way to add a 75% succes chance of AIDS actually casting. So that there is a 25% the (name) will not be kicked do to failure.

Another ALSO (but not needed) if any one could post a script that could set a bot to hold a form of currency that can be flagged to nicks or if thats even possible (so people can purchase cures for AIDS)

ex: !give (nick) x
X == number of credits\dollars\money
and have that stored into a txt file maybe?

solving any 3 of my problems will make me very happy

Top
#154888 - 02/08/06 03:17 AM Re: Help with my first script
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2875
  • You're misusing the { } brackets.
  • Variables have to be set inside of events.
  • msg $chan /me does not do a /me, you should use /describe $chan to do that.
  • Timers put out a yucky message when you start them, so you'll more than likely want to use /.timer


Code:
on *:TEXT:!cast aids *:#:{
  var %mod = [M]tree
  if ($nick == %mod) && ($3 ison $chan) { 
    describe $chan begins to cast AIDS.
    if ($rand(1,4) == 1) {
      msg $chan AIDS failed.
      return
    }
    .timer1 1 5 describe $chan has sucesfully casted AIDS on $3!
    .timer2 1 10 msg $chan $3 has 5 minutes till AIDS will take affect. 
    .timer3 1 70 msg $chan $3 has 4 minutes remaining till consumed by the AIDS effect.
    .timer4 1 130 msg $chan $3 has only 3 minutes remaining.
    .timer5 1 190 msg $chan $3 has only 2 minutes left! GASP!
    .timer6 1 250 msg $chan $3 has only 1 minute left! Please apply the !cure soon.
    .timer7 1 310 kick $chan $3 $(|,) msg $chan DIED OF AIDS 
  }
}

on *:TEXT:!cure:#:{
  msg $chan Cures can be purchased using AIDSbot credits. Currently the credit system is down so if you are currently suffering from AIDS there is no hope for you.
}

Top
#154889 - 02/08/06 04:08 AM Re: Help with my first script
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
I cant believe u left timers in there named with numbers!

Top
#154890 - 02/08/06 04:13 AM Re: Help with my first script
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2875
As long as he doesn't use /timer without a name he'll be fine :tongue:

Top
#154891 - 02/08/06 05:39 AM Re: Help with my first script
moomootree Offline
Nutrimatic drinks dispenser

Registered: 02/08/06
Posts: 7
thx for the VERY quick reply hix!

Top
#154892 - 03/08/06 08:25 PM Re: Help with my first script
moomootree Offline
Nutrimatic drinks dispenser

Registered: 02/08/06
Posts: 7
ok one more help here, i learned a bit more and i have now figured how to use .ini files. but i have a problem i dont know how to solve currenlty.


on *:TEXT:!cast aids *:#:{
if ($readini($nick $+ .ini,Register,Complete) != Yes) { Notice $nick Please Register! !Register | halt }
if ($readini($nick $+ .ini,Pass,Logged) != Yes) { Notice $nick Login, By PMing $Me with !Login PassYouMade! | halt }
if ($readini($nick $+ .ini,$nick,money) < 1000) { /msg $chan $nick does not have enough credits to cast Aids! | halt }
Writeini $nick $+ .ini $nick money $calc($readini($nick $+ .ini,$nick,money) - 1000) {
describe $chan begins to cast AIDS.
if ($rand(1,4) == 1) {
msg $chan $nick has spent 1000 credits to cast 1,44,1AIDS!
msg $chan AIDs failed to cast. | halt
}
.msg $chan $nick has spent 1000 credits to cast 1,44,1AIDS!
.Writeini $3 $+ .ini $3 aids yes
.timer1 1 5 describe $chan has successfully casted AIDS on $3!
if ($readini($3 $+ .ini,$3,aids) == yes) { timer2 1 10 msg $chan 1,44,1 $3 has 5 minutes till AIDS will take affect. }
if ($readini($3 $+ .ini,$3,aids) == yes) { timer3 1 70 msg $chan 1,44,1 $3 has 4 minutes remaining till consumed by the AIDS effect. }
if ($readini($3 $+ .ini,$3,aids) == yes) { timer4 1 130 msg $chan 1,44,1 $3 has only 3 minutes remaining. }
if ($readini($3 $+ .ini,$3,aids) == yes) { timer5 1 190 msg $chan 1,44,1 $3 has only 2 minutes left! GASP! }
if ($readini($3 $+ .ini,$3,aids) == yes) { timer6 1 250 msg $chan 1,44,1 $3 has only 1 minute left! Please apply the !cure soon. }
if ($readini($3 $+ .ini,$3,aids) == yes) { timer7 1 310 kick $chan $3 $(|,) msg $chan 1,44,1 $3 HAS DIED OF AIDS! }
}
}

this is my new code. basically i added it to check .ini to see if they person has "aids" as yes or no. If yes i want it to follow threw. however if no i want it to stop. However the way i currently have it is that all the if commands are being read at the moment " !cast aids " is being said. i want to find a way so it will stop at anytime during the 5 minutes the aids value = no.

any ideas ? btw yes i know this code sucks and is alot larger than it needs to be but i just started learning this code 2 days ago =P

Top
#154893 - 03/08/06 08:30 PM Re: Help with my first script
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2875
I'm not sure what you mean.

Top
#154894 - 03/08/06 11:47 PM Re: Help with my first script
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
I think I understand what you're looking for, and if I'm right, then this code should do what you're wanting. Please note that I'm not at home and I don't have mIRC currently available to test this.

Code:
 on *:TEXT:!cast aids*:#:{
  if ($readini($nick $+ .ini,Register,Complete) != Yes) {    Notice $nick Please Register! !Register  }
  elseif ($readini($nick $+ .ini,Pass,Logged) != Yes) {    Notice $nick Login, By PMing $Me with !Login PassYouMade!  }
  elseif ($readini($nick $+ .ini,$nick,money) &lt; 1000) {    /msg $chan $nick does not have enough credits to cast Aids!  }
  else {
    Writeini $nick $+ .ini $nick money $calc($readini($nick $+ .ini,$nick,money) - 1000)
    describe $chan begins to cast AIDS.
    msg $chan $nick has spent 1000 credits to cast 1,44,1AIDS!
    if ($r(1,4) == 1) {      msg $chan AIDs failed to cast.    }
    else {
      .Writeini $3 $+ .ini $3 aids yes
      .timeraids1 1 5 describe $chan has successfully casted AIDS on $3!
      set $+(%,aids,.,$3) $readini($3 $+ .ini,$3,aids)
      while $($+(%,aids,.,$3),2) == yes {
        timeraids2 1 10 msg $chan 1,44,1 $3 has 5 minutes till AIDS will take affect.
        timeraids3 1 70 msg $chan 1,44,1 $3 has 4 minutes remaining till consumed by the AIDS effect.
        timeraids4 1 130 msg $chan 1,44,1 $3 has only 3 minutes remaining.
        timeraids5 1 190 msg $chan 1,44,1 $3 has only 2 minutes left! GASP!
        timeraids6 1 250 msg $chan 1,44,1 $3 has only 1 minute left! Please apply the !cure soon.
        timeraids7 1 310 kick $chan $3 $(|,) msg $chan 1,44,1 $3 HAS DIED OF AIDS!
      }
    }
  }
}
on *:text:!cure*:#:{
  if $readini($nick $+ .ini,$nick,money) &lt; 1000 {
    .msg $chan Sorry $nick $+ , You don't have enough credits to cure Aids!
  }
  else {
    Writeini $nick $+ .ini $nick money $calc($readini($nick $+ .ini,$nick,money) - 1000)
    var %nick = $iif($2,$2,$nick)
    if $readini(%nick $+ .ini,%nick,aids) != yes {
      .msg $chan $nick just wasted 1000 credits to cure someone that doesn't have AIDS
    }
    else {
      .msg $chan $nick just spent 1000 credits to cure %nick of AIDS
      unset $+(%,aids,.,%nick)
      .remini $3 $+ .ini $3 aids
      .timeraids? off
    }
  }
}
 

Top
#154895 - 04/08/06 01:35 AM Re: Help with my first script
moomootree Offline
Nutrimatic drinks dispenser

Registered: 02/08/06
Posts: 7
hixx : when i use !cast aids it counts down every minute for 5 minutes. Well i want it to be able to cure the aids and stop the process at ANY time. i have everything working including the changing inside the ini file however i just can't seem to get it to stop counting down and eventually kicking some one when the !cure is given.

RusselB: i tried your script (and btw thank you very much for the extra of also making a !cure feature) However your script somehow makes my bot crash ... i did not think it was possible. If the cast of aids is unsuccessful it won't but when it does the last line it produces before the crash is the

.timeraids1 1 5 describe $chan has successfully casted AIDS on $3!

which leaves me to believe

set $+(%,aids,.,$3) $readini($3 $+ .ini,$3,aids)
while $($+(%,aids,.,$3),2) == yes {

is somehow messed up. i have no idea what "while" nor "set" does (im guessing while is the key to the answer to my original problem about my cureing at anytime). Also on the !cure it will display all the messages correct but will not actually change the ini file with aids=yes to aids=no what infact does on a susseful use (meaning a person who infact did have aids and money was withdrawn) is it create a no named .ini file with nothing in it.
I tried to find the problem within the !cure code but my knowledge about the unset and remini syntax complete boggle me and i tried to do a few google and a few /helps but could not find anything. however before i keep rambling on it is not neccisary for you to make a !cure command for me becuase i have one already set up. im not sure if you did this becuase your kind and decided to save me some time or becuase my chicken scratch of describing my problem confused you. just for any refference you may want here is my !cure snippets

on *:TEXT:!buycure:#: {
if ($readini($nick $+ .ini,Register,Complete) != Yes) { Notice $nick Please Register! !Register | halt }
if ($readini($nick $+ .ini,Pass,Logged) != Yes) { Notice $nick Login, By PMing $Me with !Login PassYouMade! | halt }
.Writeini $nick $+ .ini items AIDScure $calc($readini($nick $+ .ini,items,aidscure) + 1)
.msg $chan $nick has purchased a cure!
.notice $nick you spent 100 credits on a Cure.
.Writeini $nick $+ .ini $nick money $calc($readini($nick $+ .ini,$nick,money) - 5 )
} }

on *:TEXT:!usecure *:#: {
if ($readini($nick $+ .ini,Register,Complete) != Yes) { Notice $nick Please Register! !Register | halt }
if ($readini($nick $+ .ini,Pass,Logged) != Yes) { Notice $nick Login, By PMing $Me with !Login PassYouMade! | halt }
if ($readini($nick $+ .ini,items,aidscure) < 1) { msg $chan you do not have the aids cure. | halt }
msg $chan $nick has cured $2 $+ 's AIDS!
.Writeini $nick $+ .ini items AIDScure $calc($readini($nick $+ .ini,items,aidscure) - 1 )
.Writeini $2 $+ .ini $2 Aids No }


I thank u for ur time and effort helping me trying to fix this script and dealing with my bad spelling / coding skills. Any help you give is much appreciated and im still amazed how quick people respond to my questions.

edit:
var %nick = $iif($2,$2,$nick)

this command right here im not sure why this is needed when u can use $2 anyways. Is it by chance to make it so the .ini file can be made without errors with some names (i know some characters will make invalid title names). Im just very curious to learn all the new commands i can

Top
#154896 - 04/08/06 01:59 AM Re: Help with my first script
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
I made the !cure because I wasn't sure if you had one or not.

Regarding the problem of crashing your bot, the problem line is the while. Unfortunately I'm not at a location where I can reference mIRC for testing purposes.

Regarding characters in filenames that make invalid filenames, there's no 100% foolproof way around this, so I'm going to recommend that you consider storing the information in a hash table, rather than multiple INI files.

If you want, I'd be more than happy to re-code your script to use a hash table rather than ini files.

I've also noticed that you use the halt command in with straight if statements, rather than using the if/elseif/else format. While using halt isn't wrong, it is considered to be poor programming.

One last note, when posting code in the forums, please use the Code Tags, as they do make things easier for the helpers that may need to copy/paste your code.

Top
#154897 - 04/08/06 02:05 AM Re: Help with my first script
billythekid Offline
Fjord artisan

Registered: 01/03/03
Posts: 612
Loc: Aberdeen, Scotland
/help $mkfn
_________________________
billythekid

Top
#154898 - 04/08/06 02:18 AM Re: Help with my first script
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
That can work, but I found a few years back that even that option isn't always perfect. The main problem that I encountered with using that, was when someone had a nick that was a valid nick, but had invalid characters for a filename, and someone else had a similar nick, but without the characters that made it an invalid filename. In that case (I admit it's rare) but the files wouldn't work properly. Similar problem with using $mknickfn

Top
#154899 - 04/08/06 02:39 AM Re: Help with my first script
moomootree Offline
Nutrimatic drinks dispenser

Registered: 02/08/06
Posts: 7
RusselB: thanks for the response and the offer on re-codeing my script. however my complete script is based with ini files system i scratched together (such as the register procress) and to re-code to make it like it currently is with a hash table would take quite a bit of time. And you have done more than enough for me to be very indebted to you. If you could just fixe the while for me that will be more than enough.

But if by any chance you have alot of spare time on your hands and don't mind actually going threw the process of re-coding with a hash table (which i guess would be like a mysql data base? sorry still new to this) just email me at moomootree@gmail.com (so we don't keep bumping old threads) but please don't feel any pressure.
p.s. will use code tags from now on.

Top
#154900 - 04/08/06 11:29 AM Re: Help with my first script
Taggnostr Offline
Babel fish

Registered: 12/05/06
Posts: 93
Loc: Turku, Finland
i didn't read the whole topic, but isn't better use just one .ini file with this structure:

[nick1]
register=yes/no
pass=logged/doesn't logged
money=xxx$
[nick2]
register=...
...

instead to make an ini file for every user?

Top
#154901 - 04/08/06 08:02 PM Re: Help with my first script
KingTomato Offline
Planetary brain

Registered: 04/01/03
Posts: 3012
Loc: New Hampshire, USA
Hope you odn't mind me beating you tot he punch russel ;p

This is tested, and works. You'll have to move around your !register, !login and maybe a few other commands. The $aids is used as a reference tot he hash table that stores all the player's information. It should be commented enough (as well as used so you can reference it). If it's not, let me know, and I'll explain it as best I can.

Code:
; -------------------------------------------------------------------------------------------------
; moomootree
; http://forums.mirc.com/showflat.php?Cat=0&amp;Number=162717&amp;an=0&amp;page=0&amp;gonew=1#UNREAD
;
; AIDS spell cast. Requires use of $decode (Options dalog, Expand 'Lock', click sub-category
; 'options', and uncheck 'Decode' from the list box half-way down on the right.
; -------------------------------------------------------------------------------------------------

;
; HASH TABLE
; Row: Username
;
; AIDS:                column:   format:
;  - Registered        1         0,1
;  - Logged            2         0,1
;  - Password          3         $encode(...)
;  - Money             4         0-9
;  - Aids              5         0,1

; Startup
; Create hash file containing AIDS info
on *:START: {
  /hmake AIDS 10
  if ($isfile(aids.hsh)) /hload -b AIDS aids.hsh
}

; Exit
; Store AIDS information
on *:EXIT: {
  if ($hget(AIDS) &amp;&amp; $hget($AIDS,0).item) {
    /hsave -bo AIDS aids.hsh
    /hfree AIDS
  }
}

; !cast aids &lt;name&gt;
; Cast AIDS on to &lt;name&gt;
on *:TEXT:!cast aids &amp;:#: {
  var %victim = $3, %cost = 1000, %time = 300

  if (!$aids($nick,Registered)) .notice $nick Please register! (!register)
  else if (!$aids($nick,Logged)) .notice $nick Please login by PMing $me with !login PassYouMade
  else if ($aids($nick,Money) &lt; %cost) .notice $nick You do not have enough credits to cast AIDS!
  else if ($aids(%victim,Aids)) .notice $nick $nick already has AIDS!
  else if (%victim !ison $chan) .notice $nick %victim was not found on $chan
  else {
    if (!$aids(%victim,Money,$calc($aids(%victim,Money) - %cost))) /msg $chan Could not decrease $nick $+ 's account balance.
    else {
      /describe $chan begins to cast AIDS.
      /msg $chan $nick has spent %cost credits to cast AIDS!

      ; more accurate rand
      var %rand = $calc($rand(1,999) % 4)
      if (%rand == 0) /msg $chan AIDS failed to cast!
      else if (!$aids(%victim,Aids,1).set) .msg $chan Could not assign AIDS to %victim $+ .
      else {
        ; Did this until I noticed you changed the messages ;p
        ;var %t = 0
        ;while (%t &lt;= %time) {
        ;  .timer [ $+ [ $+(aids,%victim,$calc(%t / 60)) ] ] 1 $calc(%t + 10) /msg $chan %victim has $duration($calc(%time - %t)) until AIDS will take affect.
        ;  /inc %t 60
        ;}

        .timer [ $+ [ $+(aids,%victim,1) ] ] 1 10 /msg $chan %victim has 5 minutes 'til AIDS will take affect.
        .timer [ $+ [ $+(aids,%victim,2) ] ] 1 70 /msg $chan %victim has 4 minutes remaining 'til consumed by the AIDS affect.
        .timer [ $+ [ $+(aids,%victim,3) ] ] 1 130 /msg $chan %victim has only 3 minutes remaining.
        .timer [ $+ [ $+(aids,%victim,4) ] ] 1 190 /msg $chan %victim has only 2 minutes left! GASP!
        .timer [ $+ [ $+(aids,%victim,5) ] ] 1 250 /msg $chan %victim has only 1 minute left! Please apply the !cure soon.
        .timer [ $+ [ $+(aids,%victim,6) ] ] 1 310 /kick $chan %victim You just died of AIDS! $+(|) /msg $chan %victim has DIES OF AIDS! $+(|) .echo -q $!aids(%victim,Aids,0).set
      }
    }
  }
}

; !cure &lt;name&gt;
; Cures AIDS for &lt;name&gt;
on *:TEXT:!cure &amp;:#: {
  var %victim = $2, %cost = 1000

  if (!$aids($nick,Registered)) .notice $nick Please register! (!register)
  else if (!$aids($nick,Logged)) .notice $nick Please login by PMing $me with !login PassYouMade
  else if ($aids($nick,Money) &lt; %cost) .notice $nick You do not have enough credits to cure AIDS!
  else if (%victim !ison $chan) .notice $nick %victim was not found on $chan
  else if (!$aids(%victim,Aids)) .msg $chan $nick just wasted %cost credits to cure someone who doesn't have AIDS!
  else {
    if (!$aids(%victim,Money,$calc($aids(%victim,Money) - %cost)).set) /msg $chan Could not decrease $nick $+ 's account balance.
    else if (!$aids(%victim,Aids,0).set) /msg $chan Could not unset AIDS value.
    else {
      /msg $chan $nick has spent %cost credits to cure %victim of AIDS!
      .timer [ $+ [ $+(aids,%victim,?) ] ] off
    }
  }
}

; $aids(&lt;name&gt;,&lt;item&gt;,[value]).[set|register]
; Retrieves information on the specified user profile. When the set property is
; specified, the item is assigned the given value. If the register property is
; used, a new profile with default values is created.
;
; Item listing:
;  - Registered
;  - Logged
;  - Password
;  - Money
;  - Aids
alias aids {
  var %tbl = AIDS, %hash = aids.hsh, %nick = $1, %item = $2
  var %item_list = Registered Logged Password Money Aids, %tok = $findtok(%item_list,$2,1,32)
  if ($isid &amp;&amp; (%tok || reg* iswm $prop)) {
    if ($prop == set) {
      var %value = $3
      if (%item == Password) %value = $encode(%value,m)
      /hadd -m %tbl %nick $puttok($hget(%tbl,%nick),%value,%tok,32)
      if ($gettok($hget(%tbl,%nick),%tok,32) == %value) {
        /hsave -bo %tbl %hash
        return $true
      }
    }
    else if (reg* iswm $prop) {
      /hadd -m %tbl %nick 1 0 - 0 0
      if ($hget(%tbl,%nick)) {
        /hsave -bo %tbl %hash
        return $true
      }
    }
    else {
      var %value = $gettok($hget(%tbl,%nick),%tok,32)
      if (%item == Password) %value = $decode(%value,m)
      return %value
    }
    return $false
  }
}
_________________________
-KingTomato

Top
#154902 - 04/08/06 11:45 PM Re: Help with my first script
moomootree Offline
Nutrimatic drinks dispenser

Registered: 02/08/06
Posts: 7
/me jaw drops and hits the floor.

wow ... just wow thanks for taking your time to ... just wow
thanks kingtomato. i do hope if u get mauled by bears they do not mess up ur face becuase that would sure making taking pictures a pain...

edit:
Ok well i loaded your script to my bot, however it did not have the option of turning off decode (mIRCStorm v2.0) but i loaded it to him anyways. On start up no aids.hsh file was made nor when i searched my computer could i find any .hsh files at all. So then i figured it was becuase i could no deselect decode, so i loaded it to myself (a updated client) and turned off decode, yet the same thing happens no aids.hsh is created (searched yet again to make sure). I even closed and re opened both clients to make sure (just to see if the start and exit commands work only on actual start and exit of the client). Please tell me what simple mistake im making that prevents the creation of the .hsh

i tried to manually make the aids.hsh and put in the contents
Code:
;set the name to aidsbot (my bot) becuase loaded the script to my real client becuase it had the decode option.
Row: AIDSbot 

AIDS:                column:   format:
- Registered        1         0,1
- Logged            2         0,1
- Password          3         $encode(...)
- Money             4         0-9
- Aids              5         0,1
  

anyways im pretty sure thats not what the hash file is spoes to look like that but i tried that format anyways and many others, editing the register values, format, and even column (what the heck, i seen stranger stuff work in coding). So far none of my manually made aids.hsh files seem to set it so im registered and or logged on. could you please give a test script of what the .hsh file might look like if i opened it with notepad/codewarrior/ultraedit/or whatever.

Thnx again for contributing alot of time to rewrite my code and teaching me some new syntax


Edited by moomootree (05/08/06 12:51 AM)

Top
#154903 - 05/08/06 03:55 PM Re: Help with my first script
KingTomato Offline
Planetary brain

Registered: 04/01/03
Posts: 3012
Loc: New Hampshire, USA
Okay, I believe I have it all figured out. wink

I added a couple commands to a) give you an idea of how it should look, and b) it helped me test the bot. grin I've also made some improvements and changes, but I think the final product is what you're looking for. If you'd like more 1 on 1 help, look at my profile and find me on IRC.

Code:
; -------------------------------------------------------------------------------------------------
; moomootree
; http://forums.mirc.com/showflat.php?Cat=0&amp;Number=162717&amp;an=0&amp;page=0&amp;gonew=1#UNREAD
;
; AIDS spell cast. Requires use of $decode (Options dalog, Expand 'Lock', click sub-category
; 'options', and uncheck 'Decode' from the list box half-way down on the right.
; -------------------------------------------------------------------------------------------------

;
; HASH TABLE
; Row: Username
;
; AIDS:                column:   format:
;  - Registered        1         0,1
;  - Logged            2         0,1
;  - Password          3         $encode(...)
;  - Money             4         0-9
;  - Aids              5         0,1
;
; v1.1
; - Fixed the hash table not saving--Was error in the /hsave on exit.
; - Added 'global' variables to easily change the hash table name and file.
; - Changed how bot retrieves passwords that aren't set yet.
; - Added query window concealment
; - Added inc and dec properties to $aids alias
; - Added !register &lt;password&gt; (via PM)
; - Added !login &lt;password&gt; (via PM)
; - Added !give &lt;name&gt; &lt;credits&gt; to give another user money (works only for ops)

; 'Global' Variables.
; Change htese if you'd like.
alias -l aids.table { return AIDS }
alias -l aids.hash  { return aids.hsh }

; Startup
; Create hash file containing AIDS info
on *:START: {
  /hmake $aids.table 10
  if ($isfile($aids.hash)) /hload -b $aids.table $aids.hash
}

; Exit
; Store AIDS information
on *:EXIT: {
  if ($hget($aids.table) &amp;&amp; $hget($aids.table,0).item) {
    /hsave -bo $aids.table $aids.file
    /hfree $aids.table
  }
}

; !cast aids &lt;name&gt;
; Cast AIDS on to &lt;name&gt;
on *:TEXT:!cast aids &amp;:#: {
  var %victim = $3, %cost = 1000, %time = 300

  if (!$aids($nick,Registered)) .notice $nick Please register! (!register)
  else if (!$aids($nick,Logged)) .notice $nick Please login by PMing $me with !login PassYouMade
  else if ($aids($nick,Money) &lt; %cost) .notice $nick You do not have enough credits to cast AIDS!
  else if ($aids(%victim,Aids)) .notice $nick $nick already has AIDS!
  else if (%victim !ison $chan) .notice $nick %victim was not found on $chan
  else {
    if (!$aids(%victim,Money,%cost).dec) /msg $chan Could not decrease $nick $+ 's account balance.
    else {
      /describe $chan begins to cast AIDS.
      /msg $chan $nick has spent %cost credits to cast AIDS!

      ; more accurate rand
      var %rand = $calc($rand(1,999) % 4)
      if (%rand == 0) /msg $chan AIDS failed to cast!
      else if (!$aids(%victim,Aids,1).set) .msg $chan Could not assign AIDS to %victim $+ .
      else {
        ; Did this until I noticed you changed the messages ;p
        ;var %t = 0
        ;while (%t &lt;= %time) {
        ;  .timer [ $+ [ $+(aids,%victim,$calc(%t / 60)) ] ] 1 $calc(%t + 10) /msg $chan %victim has $duration($calc(%time - %t)) until AIDS will take affect.
        ;  /inc %t 60
        ;}

        .timer [ $+ [ $+(aids,%victim,1) ] ] 1 10 /msg $chan %victim has 5 minutes 'til AIDS will take affect.
        .timer [ $+ [ $+(aids,%victim,2) ] ] 1 70 /msg $chan %victim has 4 minutes remaining 'til consumed by the AIDS affect.
        .timer [ $+ [ $+(aids,%victim,3) ] ] 1 130 /msg $chan %victim has only 3 minutes remaining.
        .timer [ $+ [ $+(aids,%victim,4) ] ] 1 190 /msg $chan %victim has only 2 minutes left! GASP!
        .timer [ $+ [ $+(aids,%victim,5) ] ] 1 250 /msg $chan %victim has only 1 minute left! Please apply the !cure soon.
        .timer [ $+ [ $+(aids,%victim,6) ] ] 1 310 /kick $chan %victim You just died of AIDS! $+(|) /msg $chan %victim has DIES OF AIDS! $+(|) .echo -q $!aids(%victim,Aids,0).set
      }
    }
  }
}

; !cure &lt;name&gt;
; Cures AIDS for &lt;name&gt;
on *:TEXT:!cure &amp;:#: {
  var %victim = $2, %cost = 1000

  if (!$aids($nick,Registered)) .notice $nick Please register! (!register &lt;password&gt;)
  else if (!$aids($nick,Logged)) .notice $nick Please login by PMing $me with !login &lt;password&gt;
  else if ($aids($nick,Money) &lt; %cost) .notice $nick You do not have enough credits to cure AIDS!
  else if (%victim !ison $chan) .notice $nick %victim was not found on $chan
  else if (!$aids(%victim,Aids)) .msg $chan $nick just wasted %cost credits to cure someone who doesn't have AIDS!
  else {
    if (!$aids(%victim,Money,%cost).dec) /msg $chan Could not decrease $nick $+ 's account balance.
    else if (!$aids(%victim,Aids,0).set) /msg $chan Could not unset AIDS value.
    else {
      /msg $chan $nick has spent %cost credits to cure %victim of AIDS!
      .timer [ $+ [ $+(aids,%victim,?) ] ] off
    }
  }
}

; !give &lt;name&gt; &lt;credits&gt;
; Gives another user credits (works for operators only)
on *:TEXT:!give &amp; &amp;:#: {
  var %victim = $2, %credits = $3

  if (!$aids($nick,Registered)) .notice $nick Please register! (!register &lt;password&gt;)
  else if ($aids($nick,Logged)) .notice $nick Please login by PMing $me with !login &lt;password&gt;
  else if ($aids(%victim,Registered)) .notice %victim is not registered.
  else if (!$isnumeric(%credits) &amp;&amp; %credits &gt; 0) .notice $nick %credits is not a value credit.
  else if ($nick == %victim) .notice $nick You may not give yourself %credits credits.
  else if ($nick !isop $chan) .notice $nick You must be an operator to give credits
  else if (!$aids(%victim,Money,%credits).inc) .notice $nick Could not increase credits; database error
  else {
    .notice $nick You have given %credits credits to %victim $+ .
    if (%victim ison $chan) .notice %victim $nick has just given you %credits credits.
  }
}

; open query window
; Keeps the windows containing bot commands closed. No need to the bot's status bar
; to fill up with windows full of 1 or 2 commands.
on *:OPEN:?:*: {
  var %reg = /^!(register|login|logout)/i
  if ($regex(pm,$1-,%reg)) /window -c $nick
}

; !register &lt;password&gt;
; Registrs your account with the bot's database (via PM)
on *:TEXT:!register &amp;:?: {
  var %password = $2-
  if ($aids($nick,Registered)) {
    if ($aids($nick,Password) &amp;&amp; !$aids($nick,Logged)) {
      .msg $nick You already have an account, but are not logged in. To login, PM $me with !login PassYouMade
    }
    else if (!$aids($nick,Password)) {
      if ($aids($nick,Password,%password).set) .msg $nick Your account password has been set.
      else .msg $nick Sorry, but your account has no password, and could not be updated.
    }
    else .msg $nick You already have an account setup.
  }
  else if ($aids($nick).reg) .msg $chan Your account has been setup with the password $+(,%password,.)
  else .msg $nick Could not setup your account; database error.
}

; !login &lt;password&gt;
; Logs you in the bot
on *:TEXT:!login &amp;:?: {
  var %password = $2-
  if (!$aids($nick,Registered)) .msg $nick Please register! (!register &lt;password&gt;)
  else if (!$aids($nick,Password)) .msg $nick You do not have a password setup. Please use !register &lt;password&gt;
  else if ($aids($nick,Logged)) .msg $nick You are already logged in.
  else if ($aids($nick,Password) == %password) {
    if (!$aids($nick,Logged,1).set) .msg $nick Could not log in; database error
    else {
      [color:blue];
      ; Login Stuffs
      ;[/color]
      .msg $nick You are now logged in.
    }
  }
  else .msg $nick Could not log you in: bad password
}

; !logout
; Logs you out of the bot
on *:TEXT:!logout:?: {
  if (!$aids($nick,Registered)) .msg $nick Please register! (!register &lt;password&gt;)
  else if (!$aids($nick,Logged)) .msg $nick You are not logged in.
  else if (!$aids($nick,Logged,0).set) .msg $nick Could not log out; database error
  else {
    [color:blue];
    ; Logout Stuffs
    ;[/color]
    .msg $nick You are now logged out.
  }
}

; $aids(&lt;name&gt;,&lt;item&gt;,[value]).[set|register|inc|dec]
; Retrieves/assigns information on the specified user profile.
;
; Properties:
;  - set
;    Assigns [value] to the specified &lt;item&gt; in the table. If the value
;    is numeric, you may also use the inc and dec property to increase and
;    decrease their values respectivly.
;  - inc
;    Increase a numeric value in the &lt;item&gt; field
;  - dec
;    Decrease a numeric field in the &lt;item&gt; field
;  - reg/register
;    Registers a new user. This will create the default values necessary for
;    operation.
;
; Item listing:
;  - Registered
;  - Logged
;  - Password
;  - Money
;  - Aids
alias aids {
  var %tbl = $aids.table, %hash = $aids.hash, %nick = $1, %item = $2
  var %item_list = Registered Logged Password Money Aids, %tok = $findtok(%item_list,$2,1,32)
  if ($isid &amp;&amp; (%tok || reg* iswm $prop)) {
    if ($prop == set) {
      var %value = $3
      if (%item == Password) %value = $encode(%value,m)
      /hadd -m %tbl %nick $puttok($hget(%tbl,%nick),%value,%tok,32)
      if ($gettok($hget(%tbl,%nick),%tok,32) == %value) {
        /hsave -bo %tbl %hash
        return $true
      }
    }
    else if ($istok(inc dec,$prop,32) &amp;&amp; $isnumeric($3)) {
      var %value = $3, %mult = 1
      if ($prop == dec) var %mult = -1
      %value = %value * %mult
      if ($isnumeric($gettok($hget(%tbl,%nick),%tok,32))) {
        %value = $gettok($hget(%tbl,%nick),%tok,32) + %value
        /hadd -m %tbl %nick $puttok($hget(%tbl,%nick),%value,%tok,32)
        if ($gettok($hget(%tbl,%nick),%tok,32) == %value) {
          /hsave -bo %tbl %hash
          return $true
        }
      }
    }
    else if (reg* iswm $prop) {
      /hadd -m %tbl %nick 1 0 - 0 0
      if ($hget(%tbl,%nick)) {
        /hsave -bo %tbl %hash
        return $true
      }
    }
    else {
      var %value = $gettok($hget(%tbl,%nick),%tok,32)
      if (%item == Password) {
        ; no password
        if (%value == -) return $null
        %value = $decode(%value,m)
      }
      return %value
    }
    return $false
  }
}

; $isNumeric(&lt;value&gt;)
; Returns true or false if value is a number
alias -l isnumeric { return $regex($1,/^(\-*[0-9]+)$/) }


The login/logout commands are working, and have room for any other things you might want to do with them. As it is now, they set the Logged property of the profile to 1 or 0 if they log in and out respectivly. i.e. to check if a user is logged in, use:

if ($aids($nick,Logged)) { echo -a User is logged in! }

Again, post a reply or find me on IRC if you'd like more help.
_________________________
-KingTomato

Top
#154904 - 05/08/06 07:41 PM Re: Help with my first script
moomootree Offline
Nutrimatic drinks dispenser

Registered: 02/08/06
Posts: 7
man you guys on this forum amaze me. Thanks once again mate

Top
#154905 - 05/08/06 08:34 PM Re: Help with my first script
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
LOL KingTomato..nothing wrong with getting help. I haven't had time to do the re-write yet, so I was pleasantly surprised to see that someone had already taken the initiative.
A couple of things that I noted in your code, which could be improved.
1) Regarding multiple statements that are remarked. You can group these by putting /* on the line before the remarks start and */ on the line after they end. These eliminate the need for ; at the start of each line
2) You use if/else if/else in locations, when the proper form is if/elseif/else. Note the missing space in the elseif portion. Yours will work, but the other is proper format.
3) Your $isnumeric alias & regex can be eliminated by using isnum as all of the items that you're checking (as far as I could tell) fall under the isnum category. I can understand why you might think some might not, specifically the operations characters, but they do.
4) For security purposes, regarding the password, I would've used $md5 when storing the password, then compared the $md5 value of the entered password with the stored value (which is in $md5 format). This eliminates the need for $decode to be unlocked and is more secure.

Top
#154906 - 05/08/06 08:43 PM Re: Help with my first script
KingTomato Offline
Planetary brain

Registered: 04/01/03
Posts: 3012
Loc: New Hampshire, USA
No problem. grin

1. No harm, no foul. I like the appearance of the ; start. Doesn't bother me to use it, and is more of a visual queue to myself that it is infact commentary.
2. I'm a programmer of multiple backgrounds. I use what is the most 'generic'. Not everything I write accepts elseif, and as such i find myself using else if more so.
3. Touche'. Again, comes from doing a lot of other languages. Most recently, I've been trying to complete a web site in php, and using functions such as is_numeric. I never thought of the isnum condition honestly. Noted, and recalled. wink
4. I thought about it, but it's been my philosophy that unless it really matters, encode/decode will do. Additionally, giving the nature of the bot, its purpose, and implimentation, I went on the basis that providing the ability to retrieve the password would be a sort of undocumented feature. If this script served as a different purpose, I would have used $md5.

Thanks for the critisism, and happy coding. cool
_________________________
-KingTomato

Top