mIRC Home    About    Download    Register    News    Help

Print Thread
get command to write to file #241755 25/05/13 10:28 PM
Joined: May 2013
Posts: 6
R
rogga Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: May 2013
Posts: 6
Hello, i have been searching and looking through the forums and tried different things, but i can't get the write function to work so i am asking for help now.

I am trying to make a small script that if someone writes "!command text" it saves the nick and text to a text document, but i can't seem to get it to work and i'm not sure where to put the file and the script, can someone help me?

So i got it to write it to a .txt now, but is it a way to filter out what's been said, trying to make it work for a streamer where people could guess stuff, so if multiple persons guess the same thing they could be put into a group in the document so it's easier to search for that guess?

Last edited by rogga; 25/05/13 11:41 PM.
Re: get command to write to file [Re: rogga] #241760 26/05/13 01:12 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
If you want things grouped in a file, look into using an ini file instead of a txt file.

/help /writeini
/help $readini

Then you could have it saved similar to:

[guess1]
nick1=Nick
nick2=AnotherNick
nick3=YetAnotherNick
[guess2]
nick1=FourthNick

etc.


Invision Support
#Invision on irc.irchighway.net
Re: get command to write to file [Re: Riamus2] #241765 26/05/13 11:19 PM
Joined: May 2013
Posts: 6
R
rogga Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: May 2013
Posts: 6
so this is my script for now:

Code:
on *:text:*!leg*:#:{
  writeini -n legendary.ini $+($(<,$nick,>) $1-
}

alias guessleg {
  writeini -n legendary.ini $1 $2 $3 $4 $5 $6-
}

alias readleg {
  echo -a $readini(legendary.ini,$1,$2,$3)
}

alias removeleg {
  remini legendary.ini $1 $2
}


what i want it to do is that when someone in the chat types "!leg text" it would save the nick into a set list of different items, and when i type "/readleg text" it will print out the nicks of those who wrote that text to me.
But now i'm getting error "/echo: insufficient parameters (line 10, remote.ini)"

Last edited by rogga; 26/05/13 11:20 PM.
Re: get command to write to file [Re: rogga] #241767 27/05/13 02:55 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Well, for one, your $readini has too many parameters. Unless $1 is n or p or np, the format is incorrect. Also, there's not much need to have every $N number listed in your guessleg alias unless you want it to throw a default error if there aren't enough words.

Here's an example of how to use an INI file. I'm not entirely clear on what you're doing, so you may have to adjust this some to fit your needs.

Code:
on *:text:!leg *:#:{
  writeini -n legendary.ini $2 $nick $nick
}

alias count {
  echo -a Total nicks who chose $1 -- $readini(legendary.ini,$1,0)
}

alias nicks {
  var %count = $readini(legendary.ini,$1,0)
  while (%count) {
    echo -a $readini(legendary.ini,$1,%count)
    dec %count
  }
}


Uses:
!leg guess (save choice of "guess")
/count guess (show number of nicks who chose "guess")
/nicks guess (list all nicks who chose "guess")

Notes:
Be aware that the /nicks alias can cause flooding and can freeze your client if there are many nicks. You can do various flood control techniques to avoid this, or at least limit it significantly, if it becomes a problem. Remember that this is just a basic example of how to save and read an ini file.

I'm saving the nick to both item and data because I don't think there really is any data needed here. If you do have data that you want to store, you can change the writeini so that it stores the data as something other than $nick.

This was set up to handle a single word after !leg. If multiple words need to be handled, you'll need to adjust how you store the data.

I did not include any checks to verify that the formats used are correct. If you want to include those, you'll need to add them.

Below is an example of what the ini file would look like if I entered !leg guess, then you entered !leg guess, then Guest entered !leg other :

[guess]
Riamus2=Riamus2
rogga=rogga
[other]
Guest=Guest


Invision Support
#Invision on irc.irchighway.net
Re: get command to write to file [Re: Riamus2] #241776 27/05/13 08:46 PM
Joined: May 2013
Posts: 6
R
rogga Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: May 2013
Posts: 6
this is going to be used on a twitch stream for diablo 3.
People can write up a legendary item that they want and if it drops it's easier to find out who's guessed the different items =)
So this works almost perfect, not able to get it to read for me the guesses but i can do /run legendary.ini and get the list there =)
Thank you so much, now i got something to work on that actually works laugh

Re: get command to write to file [Re: rogga] #241788 28/05/13 11:08 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
If you want the guesses, you can loop through them similar to what I did with nicks.

Code:
alias guesses {
  var %count = $ini(legendary.ini,0)
  while (%count) {
    echo -a $ini(legendary.ini,%count)
    dec %count
  }
}


Use:
/guesses

Just as a note, in both nicks and guesses aliases, I am displaying them in reverse order so the most recent nick/guess is first. You can change the loop order to the other direction if needed.


Invision Support
#Invision on irc.irchighway.net
Re: get command to write to file [Re: Riamus2] #241814 29/05/13 07:47 PM
Joined: May 2013
Posts: 6
R
rogga Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: May 2013
Posts: 6
is there any place with more detailed description on how to make writeini scripts?
got some stuff i want in it but have no idea where to start to make it work :S

Re: get command to write to file [Re: rogga] #241818 29/05/13 11:07 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
The help file pretty much contains everything you need for ini files. I'm sure there are tutorials online somewhere such as mircscripts.org that show more information, but I haven't ever looked. Using ini files is pretty basic without many commands needed. You just need to understand the format of an ini file (section, item, and data). So you need to write all of that information to the file. If you want to retrieve it, you use $readini for the data, or you can use $ini to get things like sections and items. That is really all there is to it. Anything else isn't specific to ini files (loops, displaying information, etc.).


Invision Support
#Invision on irc.irchighway.net
Re: get command to write to file [Re: Riamus2] #241856 30/05/13 08:42 PM
Joined: May 2013
Posts: 6
R
rogga Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: May 2013
Posts: 6
ok, will have to do some trial and errors then, but i can't get it to print out who's guessed, when i do /count guess it only prints out "Total Nicks who chose guess --"
i tried almost everything but i'm sure its something i'm missing here :S
going to convert it into a /roll so it chooses one of the nicks who have guessed and prints it to everyone to see =)

and is it possible to limit people to only have 2 guesses each?

Last edited by rogga; 30/05/13 10:58 PM.
Re: get command to write to file [Re: rogga] #241888 31/05/13 12:00 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Sorry about that. Change $readini in the counts alias to $ini and it will work.

To limit the number of guesses, you'd have to either track the number of guesses or scan the file to count how many guesses there were.

The easiest way would be to use writeini to create a section called Totals and then have the item be the $nick and the data be the number of guesses. You would $readini(legendary.ini,Totals,$nick) and the increment the result and /writeini the value back to Totals $nick. And when you check the value with $readini, you can see if it's > 2 and then just halt the script before anything else is done and maybe give the person a notice that they can only pick 2 items.

Later, when you're ready to allow new guesses, delete the file.


Invision Support
#Invision on irc.irchighway.net
Re: get command to write to file [Re: Riamus2] #241890 31/05/13 10:16 PM
Joined: May 2013
Posts: 6
R
rogga Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: May 2013
Posts: 6
ok, now i have gotten a start for this atleast, but i'm trying to make a system for picking a nick on the guesses, so there is one winner.
i'm sure i'm doing something wrong, but i can't find the error here, since i get insufficient parameters on the while ($ini...) part :S


Code:
alias roll {
if ($1) {
  var %r = 1
  while ($ini(legendarytest.ini,$1,%r)){
%random
echo -a $readini(legendaryfun.ini,$1,$v1))
}
}
}


Sorry for asking so many questions, trying my best to learn by trial and error and read up on how to do it, but it's not easy when i haven't been doing mIRC scripting.
So Thank you for your patience and help =)

Re: get command to write to file [Re: rogga] #241892 01/06/13 04:34 AM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Add a space between ) and { after your while-statement.

Re: get command to write to file [Re: 5618] #241893 01/06/13 05:34 AM
Joined: Oct 2012
Posts: 164
D
Deega Offline
Vogon poet
Offline
Vogon poet
D
Joined: Oct 2012
Posts: 164
There's no need to even have a while loop.

Set local var %i to the number of entries in the supplied section
var %i = $ini(legendary.ini,$$1,0)
Note: $$1 makes 'if ($1)' obsolete ("/help $$")

Set %i to a random number between 1 and the number of entries from above ("/help $rand")
var %i = $rand(1,%i)

Those two steps can be combined..
var %i = $rand(1,$ini(legendary.ini,$$1,0))


Now, because your entries are saved in nick=nick (item and value are the same) format, $ini() will return the result you're after.
echo -a $ini(legendary.ini,$1,%i)

Code:
alias roll {
  var %i = $rand(1,$ini(legendary.ini,$$1,0))
  echo -a $ini(legendary.ini,$1,%i)
}