mIRC Home    About    Download    Register    News    Help

Print Thread
B
bwuser
bwuser
B
Hi, I'm confused and unfamiliar with the mirc scripting syntax. I know this is a lot to ask, but if you could translate the following pseudocode into mirc-script it would be a great learning tool for me.

The purpose of the script is to message a user only once when they trigger a certain event and read & analyze the PM response of the user as well... I use an array syntax to handle the script remembering the user, feel free to best translate this to mirc-script. (like tokenezing.. or whatever the language can support)
Easier to read the script here:
http://phpfi.com/339185

I want all variables to be LOCAL vars including the array so once I exit mIRC client all vars are lost and reset to nothing.

//initialize handleArray
$handleArray[0] = '';

on some event {
$handleExists = false;
$nickHandle = getNickHandle(); //gets the user's handle that sent the event

//see if nickHandle already exists within array
for ($i=0; $i<=$handleArray.length-1; $i++) {
if ($handleArray[$i] == $nickHandle){
$handleExists = true;
break loop;
}
}

if (!$handleExists) {
//store it in array
$handleArray[] = $nickHandle; //adds new entry to handleArray

//message nick
msg $nickHandle I will only message you once during my stay here

//read nick's PM reply as a string
$nickPM_reply = getNickPM_reply();

if (containsWord('no', $nickPM_reply) { //containsWord function returns true if 'no' is present
//do some action
}
}
}


Thanks for reading!

Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
Here's the best I could come up with given the lack of information in your post.
Code:
on *:start:{
  ;when the client is started
  if !$hget(Array) { .hmake Array 100 }
  ;check if the hash table Array exists, and if it doesn't, make it with 100 locations.
}
on !*:join:#:{
;except for when I join the channel
  if !$hget(Array,$+($network,.,$chan,.,$nick)) {
;look to see if the nick in the hash table
    .msg $nick I will only message you once during my stay here
;if it isn't, send the message and add it
    .hadd -m Array $+($network,.,$chan,.,$nick) $true
  }
;otherwise do nothing
}
on *:text:*:?:{
;upon receiving text in a pm/query window
  if $istok($1-,no,32) {
    ;look to see if the word no is in the sentence.
    ;actions if no is in the reply
  }
  else {
    ;actions if no is not in the reply
  }
}

To make this better, it would help if I knew what kind of event you were referring to by 'on some event', as there are lots of different events in mIRC, and they don't all share the same format.
I used an ON JOIN event in my code.
I made the code multi-server ready and channel specific.

The more details you can give, even without psuedocode, the easier it is for us to write a code for you.

I have included commented lines (; is used to comment out a line in mIRC) to try to explain what each line does.

B
bwuser
bwuser
B
Woo! Thanks Russ!
Some questions and clarification...
Here's my updated code with tabs:
http://phpfi.com/339262

Without tabs (works in mirc script editor):
http://phpfi.com/339263

1.
The trigger event I wanted was !list, so whenever any user !lists inside a specific channel. I also moved the onTEXT trigger block and put it inside the if block that messages the user. The point was to say I only want to message back those users which I message. If some random person sends me a message that contains the word 'no' in it.. that's okay my script doesn't have to be that intense and be able to tell whether it is someone I messaged or not...

I tested it out on the reply with the ONTEXT block inside the if statement AND with the onTEXT block outside of it like you had it originally. On both cases, when the user responds I successfully send the message. But, then I respond to my OWN message that I send! I realize this because of the generic nature of the ONTEXT block, it will send & analyze the response of any response in the PM. However, I only want to respond to the user's response and not mine as well.. How could I fix this.. I thought putting it in the IF statement like you see now would do the trick.. but app. it didn't. If there was a variable of the $nick of the user responding that I could use that would be helpful in determining that nick to NOT be mine. Also if it matters, the user may respond NOW or LATER or not at all. Now or later meaning that user might respond 2 secs later or 5 hours..


2.
Phew.. I explain a lot don't I? Anyways, another question about the code:
;upon receiving text in a pm/query window
if $istok($1-,no,32) {

on this line of code, how do you get the response of the user in the PM as a string?
Is it $1- , some kind of global variable to mean response of user in PM window? I'm interested in the method to obtain the response of the PM window as a string.. maybe if you could explain this part...


3. Other than those issues.. the part of the script where it remembers the user works great! smile

Last edited by bwuser; 03/08/08 12:49 PM.
Joined: Oct 2005
Posts: 1,671
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,671
In mIRC, onTEXT events MUST be outside of all other structures (IFs, WHILEs, ALIASes, other events, etc.). They must be hard left in the mIRC editor window. They will simply not function at any other location. Example:

OK:
Code:

on *:TEXT:!list:*:{
  echo -a This is my !list event
}

on *:TEXT:!quit:*:{
  echo -a This is my !quit event
}



Not OK:

Code:

on *:TEXT:!list:*:{
  echo -a This is my !list event

  on *:TEXT:!quit:*:{
    echo -a This is my !quit event
  }
}



To prevent the code from parsing replies from anyone you haven't msg'd, you can add this line immediately under the second onTEXT event in Russel's code:

Code:

on *:TEXT:*:?:{
  if !$hfind(Array,$+($network,.*.,$nick),1,w) return

;....
}



It is necessary to do a wildcard search because you can ask in any (or several) channel, and the response from the user will not indicate which channel they received the question from.


-genius_at_work

Last edited by genius_at_work; 03/08/08 04:14 PM.

Link Copied to Clipboard