|
Mumra_2790
|
Mumra_2790
|
I'm a bit of a n00b so please be patiant!
I had a script givin to me to use in my channel, its function was to pick up when "you sent" was spoken and store the whole sentance into an .ini file.
And then to read it a nick would type !prizes to see how many prizes had been sent out in the channel or !prizes <nick> to see how many they had sent!
Its format saved like this:
[mumra_2790] 1=You sent your flower to **** with the message: Winner. 2=You sent your...e.t.c
[n00bie] 1=You sent your.........
Was wondering if their is anyone willing to help me on this problem!
btw, it saves to a file called prizes#chan.ini
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
If you're going to have the script output all the prizes under a certain nickname, use the play command under the text event trigger with the !prizes: .play $+(-t,$nick) # $+(prizes,#,.ini)
Last edited by Tomao; 05/06/11 07:28 PM.
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
I've just realized that someone asked the similar question a few days ago, and Riamus2 offered his input on using an alias to skip the equals sign presented in an ini file in conjunction with the play command: on $*:text:/^!prizes$/iS:#: playlines # $nick
alias -l clean msg $1 $gettok($1-,2-,61)
alias -l playlines .play $+(-at,$2) clean $1 $+(prizes,$1,.ini) The above code should do what you want.
Last edited by Tomao; 05/06/11 08:20 PM.
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
From your post, I am guessing that you don't have the script anymore and need the entire thing? If so, here you are...
on *:text:*you sent*:#: {
var %file = $+(prizes,$chan,.ini)
writeini %file Total Total $calc($readini(%file,Total,Total) + 1)
writeini %file $nick $calc($ini(%file,$nick,0) + 1) $1-
}
on *:text:!prizes*:#: {
var %file = $+(prizes,$chan,.ini)
if (!$2) { msg $chan $iif($readini(%file,Total,Total),$v1,0) prizes sent to $chan $+ . }
else { msg $chan $2 sent $iif($ini(%file,$2,0),$v1,0) prizes. }
}
One thing to note... this assumes that each nick's items will be numbered sequentially ... 1,2,3,4,etc. If you delete one so that you have something like 1,3,4,etc., then this is going to overwrite one of your items. Based on your post, I don't think this is an issue, so I didn't put in any checks that may not be needed. If you plan to remove items without putting them back in sequential order, then we'll need to add checks to avoid overwriting items.
Last edited by Riamus2; 05/06/11 10:14 PM.
|
|
|
|
Mumra_2790
|
Mumra_2790
|
Wow thanks.
The main purpose of this script is so a user can see how many prizes they or the room has sent out. (just for info)
All i got from my old script was when it stored over 1000 entries the prizes command did not work!
|
|
|
|
Mumra_2790
|
Mumra_2790
|
Problem It saves like this: --------------------------- [Total] Total=3
[mumra_2790] 1=you sent tttttttttt 2=you sent gggg
[toclafane] 1=you sent gggg
But when i type !prizes toclafane it responds by saying toclafane sent 2 prizes.
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
You can load the ini file to a hash table and then output the relevant results like so: on *:text:!prizes *:#:{
var %f $+(prizes,#,.ini)
if $ini(%f,$2) {
if (!$hget(prize)) hmake prize 200
.msg # * Prize(s) for $2 are as follows:
hload -i prize %f $2
var %r 1
while %r <= $hget(prize,%r).item {
.timer 1 $calc(%r *2) msg # $hget(prize,%r).data
inc %r
}
hfree prize
}
else .msg # * The nickname $2 doesn't exist!
}
|
|
|
|
Mumra_2790
|
Mumra_2790
|
Is it not possible to get the output to read:
!prizes There have been 3 prizes sent from $chan
!prizes toclafane There have been 1 prize(s) sent from toclafane
!prizes mumra_2790 There have been 2 prize(s) sent from mumra_2790
If you know what i mean!
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
There was a typo in what I gave you that gave the incorrect value for prizes sent by the nick. Use the edited version in my post above and it will do what you want.
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
Here is the edit of my example to do what you want: on *:text:!prizes*:#:{
var %f $+(prizes,#,.ini)
if !$2 {
.msg # There has been $readini(%f,total,total) prize(s) sent from #
}
elseif $ini(%f,$2) {
if (!$hget(prize)) hmake prize 200
hload -i prize %f $2
var %r 1
while %r <= $hget(prize,%r).item {
var %x $addtok(%x,$hget(prize,%r).data,44)
inc %r
}
.msg # * There has been $numtok(%x,44) prize(s) sent from $2.
hfree prize
}
else .msg # * The nickname $2 doesn't exist!
} This is merely my way of going about what you wish for. If you find Riamus2's favorable, by all means, use his. The only difference that sets mine apart from his is the use of hload with the -i switch and an additional check for whether a nick to be searched for exists.
Last edited by Tomao; 05/06/11 10:43 PM.
|
|
|
|
Mumra_2790
|
Mumra_2790
|
Is there a limit on how much it can save, or is it unlimited?
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
Currently you use INI file to save. From what I've learned there is a limit for INI, but I'm uncertain as to the maximum storage limit is. You should add the -n switch for the command so that mIRC will attempt to store data that's larger than 64k. You can alter your INI method to hash table. From what I know, hash table storage is unlimited.
Last edited by Tomao; 05/06/11 10:49 PM.
|
|
|
|
Joined: Nov 2006
Posts: 1,552
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,552 |
No offense, but if there's $ini(file,topic,0) (and $hget(table,0).item for hash tables respectively), isn't it ludicrous to hload the ini topic, then loop'n'addtok all its items just to return an error-prone (line length limit, comma in data) $numtok result?
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
In the past, INI files had a 64kB size limit before things started not working right. I believe that's no longer the case, but I could be wrong. If you want to avoid that kind of thing, then you'll need to save the data in another format, such as a text file, or use a hash table (without INI formatting). Keep in mind that a normal hash table doesn't save it's data in as "clean" format as INI, so it isn't as easy to look and/or edit the data from the file itself. And although a text file could be stored in the same format as INI, it would require more code to handle it (no using $ini() or $readini() to quickly get the data you're looking for).
Someone else here who knows more about the inner workings of mIRC/etc, may be able to clear up if there's still a size limit.
Last edited by Riamus2; 06/06/11 12:08 AM.
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
I don't fully grasp what you said, Horstl. I came up with my example based on what Mumra has shown in his ini file format stored. Upon trigger, it loads the ini to a hash table, adds it to a temporary variable separated with a comma and count the number of token existed to output the results. The hash table is then cleared at the end. I'm not saying my example is foolproof; it may be error-prone in some way...I have yet to encounter one when I tested it briefly.
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
He's referring to the fact that if someone were to give, for example, 1000 prizes over time, with the text for those prizes being 40 characters long on average, then your variable would be 40,000 characters... which mIRC can't handle. Also, if the prizes include a comma and your tokens use commas as separators, it would give incorrect results. In addition, $addtok() does not allow duplicate tokens. I'm sure there will be duplicate prizes, so that would also give invalid results.
Basically, don't use $addtok() unless you can be certain that there will never be legitimate duplicates and that the tokens will not contain the same character that is used as a separator. In this instance, you can't guarantee either.
As for hash tables... they are useful. However, they are most useful with data that is accessed often. I doubt prize counts are listed very often, so hash tables don't offer much benefit over other formats. In general, hash tables are best for large amounts of data that is accessed often, variables for small amounts of data that is accessed often or not often (either one), and text/INI/etc files for large amounts of data that is rarely accessed. And "often" would be at least once every 5 minutes, though that's not really all that often. Really, you'd be looking at data accessed more than once a minute to really be considered "often."
Hash tables can be used for rarely accessed data, but are not necessarily the best option. For this situation, INI is the better option as long as the 64k limit is gone. If there is still a limit, then hash tables or text files are about equally good. You just don't want to try and put many items into a single variable or hash table item, and you don't want to save/load INI format if there is a limit. And definitely don't use $addtok().
|
|
|
|
Joined: Jul 2006
Posts: 4,020
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,020 |
In addition, the question was "why using hash table here when the original information is stored in an ini file?", because you could access the information with ini's routine. Another question was "what is the point of storing each data in the same var (the error prone part) if the only thing you want to know is the number of token in that var ?", because, again, you already have that information with $hget(,0).item, or since hash table are not necessary here, $ini(,$2,0)
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
Thanks Riamus2 and Wims for your time and valuable explanations and input. I shall bear them in mind. There are lots to be learned from the experienced and I'm looking forward to your mentoring advice. Keep it coming!
|
|
|
|
Mumra_2790
|
Mumra_2790
|
Well the file is now at 102kb, its saves but now cant pick up the data when requested.
Is there a way for it to add up rather than saves the line?
example
[Total] Total=3
[mumra_2790] Total=2
[toclafane] Total=1
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
I think it's fitting to use hash tables instead of INI for what you want: on *:exit:{
hsave total total
hsave prize prize
}
on *:text:*you sent*:#:{
hinc -m total $chan
hinc -m prize $nick
}
on *:start:{
hmake total 100
hmake prize 100
if ($file(total).shortfn) hload total $v1
if ($file(prize).shortfn) hload prize $v1
}
on *:text:!prizes*:#:{
var %total = $hget(total,$chan), %prize = $hget(prize,$2)
msg $chan $iif(!$2,%total,%prize) prize(s) sent from $iif(!$2,$chan,$2)
} You may want to start from scratch with this script.
Last edited by Tomao; 06/06/11 08:10 AM.
|
|
|
|
|