mIRC Home    About    Download    Register    News    Help

Print Thread
$calc trouble #200886 14/06/08 07:01 AM
Joined: May 2008
Posts: 127
J
Joe_Dean Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
I'm trying to use $calc to calculate some numbers and save the result to a file. When this text is said..

Quote:

[CASH SEND] [lincoln_ls(7)] Has Sent $500 To [benminiman0999(4)]


I want it to store the '500' (excluding the '$' char) in a file, and when it is said again, add the existing '500' from the file to the '500' that was just said, and store the result (1000).

This is the script I'm trying to use. I spent hours messing around with it trying to use it differently, but I can't seem to get it working:
http://www.paste.mircscripting.info/index.php?id=2939

So basically this is how it should be:
Quote:

[CASH SEND] [lincoln_ls(7)] Has Sent $500 To [benminiman0999(4)]

(write '500' to a file here)

and then when this is said again...
Quote:

[CASH SEND] [lincoln_ls(7)] Has Sent $500 To [benminiman0999(4)]

(take the previous '500' that was stored in the file and add it to the new '500', resulting in '1000', and replace everything in the file with the result (1000))

Re: $calc trouble [Re: Joe_Dean] #200887 14/06/08 07:04 AM
Joined: May 2008
Posts: 127
J
Joe_Dean Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Right now it's storing the first '500' in the file, but when this event is triggered again, it doesn't add both 500's and store the result (1000), it always remains the same which is '500'.

Re: $calc trouble [Re: Joe_Dean] #200890 14/06/08 12:20 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Your code doesn't store the nick who received the money anywhere. If you are only storing the total sent to everyone, just use a variable:

Code:
on *:text:[CASH SEND]*:#echo: {
  if ($7) { inc %cashsent $remove($5,$chr(36)) }
}



If you want to store the money received for each nick, you'd be better off using hash tables, imo. Still...

Code:
on *:text:[CASH SEND]*:#echo: {
    var %result = $read(txt\ingame_stats\sentamount.txt,ns,$7)
    .write -l $readn txt\ingame_stats\sentamount.txt $7 $calc(%result + $remove($6,$chr(36)))
}


Invision Support
#Invision on irc.irchighway.net