mIRC Homepage

Action on a certain name.

Posted By: Casmo

Action on a certain name. - 20/07/10 01:07 AM

Hi guys :]

I have a script that catches trouts.
But can I set an action for each nickname?
(Or just a few, and an action if someone else slaps someone)
Like in a text file, or in aliases or something?
Because if I'd do anything in the script itself it would become messy (which it is now, because I have a few names added already...)

Thanks in advance :]

Greetings,
Casmo.
Posted By: strac

Re: Action on a certain name. - 20/07/10 02:17 AM

you can create a several different variables such as %nick1 %nick2 that contain the names you're looking for and then use an if then else system: if ( $nick isin %nick1 ) { do this action }
Posted By: Tomao

Re: Action on a certain name. - 20/07/10 06:22 AM

You can put all the nicknames in a text file line by line, one nickname per line. Then use:
Code:
 if ($read(slap.txt,w,$nick)) {
 ;do something
To match certain nicknames stored in the slap.txt for example.

Using isin operator is not a good choice because it can result false positives.
Posted By: Casmo

Re: Action on a certain name. - 20/07/10 10:46 AM

@strac

That seems like what I do already, but not using the variables as it seems that I'd just replace the nickname for a variable...


@Tomao

Can you explain that please? :]
Can I put the actions inside the textfile as well?

Quote:

if ($nick == randomnick) {
describe $chan steals the trout


Can that be made like this:
if randomnick slaps that it reads the actions from a textfile?

Example:

Quote:

if ($nick == randomnick) {
describe $chan steals the trout
<read action from file here>
Posted By: Riamus2

Re: Action on a certain name. - 20/07/10 11:39 AM

Text file:
Quote:

nick throws a tomato at nick.
nick2 runs away from nick2.


IF line in script:

Code:
if ($read(temp.txt,ntw,$nick *)) { describe $chan $gettok($v1,2-,32) }
else { describe $chan slaps $nick back with a large trout. }


That's just one example of how you can do it. Note that this example
Posted By: 5618

Re: Action on a certain name. - 20/07/10 12:01 PM

Quote:
nick throws a tomato at nick.
nick2 runs away from nick2.

Just some constructive criticism if you use the above format: instead of the w switch I'd recommend using the s switch in this case.
(See /help $read for what the difference is)
Code:
if ($read(temp.txt,nts,$nick)) { describe $chan $v1 }
else { describe $chan slaps $nick back with a large trout. }
Posted By: jaytea

Re: Action on a certain name. - 20/07/10 12:18 PM

the 'w' switch is arguably more suitable since it returns the matching nick, generally leading to a satisfied if condition. with 's', everything after the search term is returned; when you have one nick per line it will return $null which will effectively falsify the condition (that's why a noop $read(...) | if ($readn) combination is often seen). * ? and & are typically not allowed in nicknames, but you're quite right that in general it is important to make that distinction :P

the same could be said about 'n' and nicknames not typically being allowed a % or $ prefix, but it changes nothing to include it here and is something a lot of people often omit.

Edit: ah, forgive me, i didn't see past the first $read(file,w,$nick) check :P i believe you want $v1 in place of $1- there
Posted By: Riamus2

Re: Action on a certain name. - 20/07/10 03:20 PM

Yeah, I went back and forth with using s or w and opted for w. Either should work fine and s would be fewer characters/commands and probably faster. I'm not really sure anymore why I went with w instead of s there. *shrug*

You'll just want $v1 instead of $1- for your example as mentioned. smile
Posted By: Casmo

Re: Action on a certain name. - 20/07/10 06:23 PM

I'm sorry, but I can hardly understand it...

Can someone please post what's in the text file, and what's in the remote script? (Because I can't figure it out how it works... and I can't find it on Google )

Say, I have 2 people that can slap me.
Nick1 and Nick2, and I want to slap them back, but a different message for each nick.

Say for nick1 I want to slap it back with: describe $chan slaps nick1 back and eats the trout.

For nick2 I want: describe $chan slaps nick2 back, and throws the trout back into the river.


Now what do I put into remotes, and what do I put into the textfile? :X
Posted By: Tomao

Re: Action on a certain name. - 20/07/10 06:54 PM

Code:
on $*:action:$(/\b(slaps?) \Q $+ $me $+ \E\b/iS):*:{
  if (!%x) { inc -u5 %x
    var %slapnick = nick1 nick2 nick3 nick4 nick5 nick6
    describe $iif(#,#,$nick) $regml(1) $nick back $iif($istok(%slapnick,$nick,32),and eats the trout.,and throws the trout back into the river.)
  }
}
Replace nick1, nick2, nick3, etc..with the nicknames you want them to be slapped. (There's a space between each added as shown) Those who are not added in the local variable %slapnick will get the message as, "Casmo slaps nick back and throws the trout back into the river. Conversely, those who are added in the %slapnick var will get the message as, "Casmo slaps nick back and eats the trout."
Posted By: Riamus2

Re: Action on a certain name. - 20/07/10 08:25 PM

Originally Posted By: Casmo
Can someone please post what's in the text file, and what's in the remote script?


If you look at my post, I showed both the text file and the script file. We talked about changing it around a bit, but what I showed will work correctly.
Posted By: Casmo

Re: Action on a certain name. - 20/07/10 10:40 PM

Originally Posted By: Tomao
Code:
on $*:action:$(/\b(slaps?) \Q $+ $me $+ \E\b/iS):*:{
  if (!%x) { inc -u5 %x
    var %slapnick = nick1 nick2 nick3 nick4 nick5 nick6
    describe $iif(#,#,$nick) $regml(1) $nick back $iif($istok(%slapnick,$nick,32),and eats the trout.,and throws the trout back into the river.)
  }
}
Replace nick1, nick2, nick3, etc..with the nicknames you want them to be slapped. (There's a space between each added as shown) Those who are not added in the local variable %slapnick will get the message as, "Casmo slaps nick back and throws the trout back into the river. Conversely, those who are added in the %slapnick var will get the message as, "Casmo slaps nick back and eats the trout."


But I don't want 2 groups of people..
I want to be able to have say 10 different people, which is why I want it to read from a textfile...

Originally Posted By: Riamus2
Originally Posted By: Casmo
Can someone please post what's in the text file, and what's in the remote script?


If you look at my post, I showed both the text file and the script file. We talked about changing it around a bit, but what I showed will work correctly.


I didn't understand that script at all... Shouldn't there be like actions in the text file as well? :|

Posted By: Tomao

Re: Action on a certain name. - 21/07/10 12:00 AM

I find it burdensome to use a text file when you can do it in the script. And I don't see it as messy in any way. You can reconstruct the script like so:
Code:
on $*:action:$(/\b(slaps?) \Q $+ $me $+ \E\b/iS):*:{
  if (!%x) { 
    inc -u5 %x
    var %group1 = nick1 nick2 nick3 nick4 nick5 nick6
    var %group2 = nick1 nick2 nick3 nick4 nick5 nick6 nick7 nick8
    var %group3 =
    var %group4 =
    var %group5 =
    if ($istok(%group1,$nick,32)) {
      describe $iif(#,#,$nick) $regml(1) $nick back and eats the trout.
    }
    elseif ($istok(%group2,$nick,32)) {
      describe $iif(#,#,$nick) $regml(1) $nick back and throws the trout back into the river.
    }
    elseif ($istok(%group3,$nick,32)) {
      ;another message
    }
So on and so forth...
Posted By: botnoob

Re: Action on a certain name. - 21/07/10 01:16 AM

Ok, so here is my version of the 'SlapBack' script (as I call it)

Quote:
on *:ACTION:slaps*:#: {
if ($me == botnoob) HALT
if ($2 == $me) {
if ($nick == becca) || ($nick == rez) || ($nick == Gem) { describe $chan thanks for the slap, oh and by the way hows your momma doing? $nick }
else {
describe $chan slaps $nick back harder.
}
}
}

In short terms if becca rez or gem slaps you they get the "thanks for the slap, oh and by the way hows your momma doing?" message. Anybody else in the channel gets slapped back harder.

Also, if you want danny and bob to get a 'kill' message just add another if ($nick == becca) || ($nick == rez) || ($nick == Gem) { describe $chan thanks for the slap, oh and by the way hows your momma doing? $nick } <change the message, and names>

So it would end up as:

Quote:
on *:ACTION:slaps*:#: {
if ($me == botnoob) HALT
if ($2 == $me) {
if ($nick == becca) || ($nick == rez) || ($nick == Gem) { describe $chan thanks for the slap, oh and by the way hows your momma doing? $nick }
if ($nick == danny) || ($nick == bob) { describe $chan kills $nick }
else {
describe $chan slaps $nick back harder.
}
}
}



And just keep adding them in for all different people and different messages.
Hope this helps.

botnoob
Posted By: Riamus2

Re: Action on a certain name. - 21/07/10 02:10 AM

Originally Posted By: Casmo

I didn't understand that script at all... Shouldn't there be like actions in the text file as well? :|



Quote:
nick throws a tomato at nick.
nick2 runs away from nick2.


There *are* actions there. i.e. "throws a tomato at nick." or "runs away from nick2." They will automatically be actions.

This is it with real nicks:

Quote:

Casmo throws a tomato at Casmo.
Riamus runs away from Riamus.


The first word is the nick who you are watching and the rest is the action. You can include their nick in the action or not depending what you want it to say.
Posted By: botnoob

Re: Action on a certain name. - 21/07/10 02:13 AM

It works pretty fine for me. Maybe pop it in and see how you go with it. Its not like you cannot delete it when you have checked.
Posted By: Tomao

Re: Action on a certain name. - 21/07/10 06:43 AM

botnoob, your script can be improved a bit:
Code:
on *:ACTION:slaps*:#: {
  if (($me != botnoob) && ($2 == $me)) {
    if ($istok(becca rez Gem,$nick,32)) {
      describe $chan thanks for the slap, oh and by the way hows your momma doing? $nick 
    }
    elseif ($istok(danny bob,$nick,32)) { describe $chan kills $nick }
    else { describe $chan slaps $nick back harder. }
  }
}
Posted By: botnoob

Re: Action on a certain name. - 21/07/10 10:04 AM

Yeah, I have only been scripting for about 3-4 weeks now, so im sure i will get the hang of it (eventually) lol

Thanks for the heads up though. I think I will check the new one you pasted and see how it goes.


Oh and we hope this has helped you with your post casmo.

Kind Regards
-botnoob-
Posted By: chacha

Re: Action on a certain name. - 21/07/10 11:50 AM

if you want you can create a file and add several lines of slap back
and the code will be
Code:
on $*:action:$(/\bslaps?\Q $+ $me $+ \E\b/iS):*:{
  if !%w {
    inc -u3 %w
    describe $iif(#,#,$nick) $read(file.txt)
  }
}

then you have a random slap back to every nick
Posted By: Casmo

Re: Action on a certain name. - 22/07/10 07:51 PM

Thanks all, got it working.
© 2020 mIRC Discussion Forums