Author Topic: Specialized Greeting Script  (Read 3381 times)

jack_copper

  • Guest
Specialized Greeting Script
« on: March 21, 2010, 09:38:39 AM »
Hi there.
I am trying to write a script.
The script works as the following;
  • There are 2 text files. One contains people to bow to the other people to salute to. The example data for saluting is as such.
    SGT_
    MSGT_
  • When a person joins in and if his nick starts with SGT_ it must automatically call command "/me salute to nickname"
  • The person must no be saluted if already saluted or I will result in a ban.
  • I must be able to add people from the chat window by simply calling the command "/addsalute nick". And the nick must be added to the salute file.
  • If the user changes his nick so it starts with a value in the salute file it must salute.
I wrote the below code however it isn't really what I want. Since I want all to be in text files and want it to be dynamic i.e.I will able to add variable through the chat window.


Quote
Sub ONJOIN(Nickname,Host,Channel,ServerNumber)
if InStr(1, Nickname, "SPRE") <> 0 then
  SendCommand "/me  bows to " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "ENS") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LTJG") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LT") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "CMDR") <> 0 then
  SendCommand "/me  salutes  to " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "CAPT") <> 0 then
  SendCommand "/me  salutes  to " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "CDRE") <> 0 then
  SendCommand "/me  salutes  to " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "RADM") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "ADM") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "FADM") <> 0 then
  SendCommand "/me  salutes   to " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GADM") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LADM") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "2LT") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "1LT") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "CPT") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "MAJ") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LTCOL") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "COL") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "BGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "MGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LTGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "SMAR") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GDGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LDGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "CHIEF") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "DIR") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "JADJ") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "ADJ") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "VIZ") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LTGOV") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GOV") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "SADJ") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "MOFF") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GMOFF") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "Lord") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "Darth") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "Dark_Lord_of_the_Sith") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "JUS") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GVIZ") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GMOFF") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "EXECUTOR") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "The_Emperor") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
End If
End Sub

Sub ONNICK(Nickname,OldNick,ServerNumber)
if InStr(1, Nickname, "SPRE") <> 0 then
  SendCommand "/me  bows to " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "ENS") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LTJG") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LT") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "CMDR") <> 0 then
  SendCommand "/me  salutes  to " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "CAPT") <> 0 then
  SendCommand "/me  salutes  to " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "CDRE") <> 0 then
  SendCommand "/me  salutes  to " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "RADM") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "ADM") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "FADM") <> 0 then
  SendCommand "/me  salutes   to " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GADM") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LADM") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "2LT") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "1LT") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "CPT") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "MAJ") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LTCOL") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "COL") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "BGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "MGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LTGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "SMAR") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GDGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LDGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LGEN") <> 0 then
  SendCommand "/me  salutes  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "CHIEF") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "DIR") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "JADJ") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "ADJ") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "VIZ") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "LTGOV") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GOV") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "SADJ") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "MOFF") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GMOFF") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "Lord") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "Darth") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "Dark_Lord_of_the_Sith") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "JUS") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GVIZ") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "GMOFF") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "EXECUTOR") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
ElseIf InStr(1, Nickname, "The_Emperor") <> 0 then
  SendCommand "/me  bows  to  " & Nickname & ".",ServerNumber
End If
End Sub

As you can see the above code is very long and very bad looking. Please help me.

I thank you for your time.


Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Specialized Greeting Script
« Reply #1 on: March 22, 2010, 05:56:38 AM »
This is a script I cooked together for you
Code: [Select]
Dim objFSO, bFile, sFile, bPath, sPath
Set objFSO = CreateObject("Scripting.FileSystemObject")

bPath = getidentifier("$scriptdir") & "greet_bow.txt"
sPath = getidentifier("$scriptdir") & "greet_salute.txt"

Set bFile = objFSO.OpenTextFile(bPath,1)
Bow = Split(bFile.ReadAll,vbCrLf)
bFile.close
Set bFile = Nothing

Set sFile = objFSO.OpenTextFile(sPath,1)
Salute = Split(sFile.ReadAll,vbCrLf)
sFile.close
Set sFile = Nothing

Sub ONJOIN(Nickname,Host,Channel,ServerNumber)
If Not LCase(Channel) = "#yourchannelhere" then exit sub
If Nickname = GetIdentifier("$me",ServerNumber) then Exit Sub

If CheckSalute(Nickname) = True then
SendCommand "/describe " & Channel & " salutes " & Nickname,ServerNumber

ElseIf CheckBow(Nickname) = True then
SendCommand "/describe " & Channel & " bows to " & Nickname,ServerNumber

End If

End Sub

Function CheckSalute(Nickname)
For i = 0 to UBound(Salute)
If Len(Nickname) >= Len(Salute(i)) then
if Left(Nickname,Len(Salute(i))) = Salute(i) then
CheckSalute = True
Exit Function
End If
End If
Next
CheckSalute = False
End Function

Function CheckBow(Nickname)
For i = 0 to UBound(Bow)
If Len(Nickname) >= Len(Bow(i)) then
if Left(Nickname,Len(Bow(i))) = Bow(i) then
CheckBow = True
Exit Function
End If
End If
Next
CheckBow = False
End Function

Sub AddGreet(Category,Nick)

If Category = "bow" then
Set bFile = objFSO.OpenTextFile(bPath,8)
bFile.WriteLine(Nick)
bFile.close
Set bFile = Nothing
SendCommand "/echo -a --- Added nick " & Nick & " to the bow list"

ElseIf Category = "salute" then
Set sFile = objFSO.OpenTextFile(sPath,8)
sFile.WriteLine(Nick)
sFile.close
Set sFile = Nothing
SendCommand "/echo -a --- Added nick " & Nick & " to the salute list"

End If
End Sub

Change the "#yourchannelhere" to whatever channel you want the script to work on, or remove the line completely if you want it to work on all channels.

Before you load the script you need to create two files: greet_bow.txt and greet_salute.txt and add the wanted nicknames to those files on separate lines. Also you must make sure you add an empty line to the end of the file, or otherwise it will get messed up when you add more names

Also you need to create this alias
Code: [Select]
/addgreet:/! addgreet $1 | $2
To add more nicknames type /addgreet salute nickname or /addgreet bow nickname

If you have any problems with the script feel free to ask here, I didn't have time to test it a lot, so it might have some bugs.
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

jack_copper

  • Guest
Re: Specialized Greeting Script
« Reply #2 on: March 22, 2010, 01:05:48 PM »
I thank you for your prompt response and help.
Thank you very much with helping me with this problem of mine.
 
But there seems to be a problem.
Now my bow list is

Quote
CHIEF
DDIR
DIR
JADJ
ADJ
VIZ
LTGOV
GOV
SADJ
MOFF
GMOFF
Lord
Darth
Dark_Lord_of_the_Sith
JUS
GVIZ
EXECUTOR
The_Emperor

However when the script runs it bowed to someone with the nick

Quote
[21:52] * Kyumaru_Shibashi (Kyumaru@SWC-IRC.54413FFFC8565B.SWC) has joined #cmg-empire
[21:52] * RCT_Copper bows to Kyumaru_Shibashi
Same problem with saluting
My saluting list is

Quote
ENS_
LTJG_
LT_
LTCMDR_
CMDR_
CAPT_
CDRE_
RADM_
VADM_
ADM_
FADM_
GADM_
LADM_
2LT_
1LT_
CPT_
MAJ_
LTCOL_
COL_
BGEN_
MGEN_
LTGEN_
GEN_
SMAR_
GGEN_
GDGEN_
LDGEN_
LGEN_
ISB-2LT_
ISB-1LT_
ISB-CPT_
ISB-MAJ_
ISB-LTCOL_
ISB-COL_
ISB-BGEN_
ISB-MGEN_
ISB-LTGEN_
ISB-GEN_

However it did this number....
Why?

Quote
[21:56] * MSGT_Sasaki (Johnny_Sas@SWC-IRC.976DFF17D5F49.SWC) has joined #cmg-empire
[21:56] * RCT_Copper salutes MSGT_Sasaki

I added the alias as you told that part works...

I would be grateful if you can help me,
And thank you for your time.

jack_copper

  • Guest
Re: Specialized Greeting Script
« Reply #3 on: March 22, 2010, 03:34:19 PM »
Ok found the problem when I add a blank line at the end of the text file it reads blank and sees the blank in front of all nicks and thus always true... Is there a way around this?

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Specialized Greeting Script
« Reply #4 on: March 23, 2010, 12:43:02 AM »
Ah, of course.

This should be fixed by changing the For lines inside the CheckBow and CheckSalute functions to:

Code: [Select]
For i = 0 to UBound(Salute) - 1

and

Code: [Select]
For i = 0 to UBound(Bow) - 1

Which makes is skip the last element in the array. This should work as long as you keep the text files in order. Another way would be to make both of those functions check if the element is empty or not.
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein