I have my VBScript code loaded from a text File
Sub OnTalk(Username, Flags, Message, Ping)
if username = "CrAz3D[xL]" then
form1.addchat vbred, message & "::" & username
end if
end sub
Upon the users talking in the channel it calls that code. What I'm not sure how to do is how to add my Ban sub, which is located in a Module, to the msscript to allow the VBScript Code to use the Ban sub.
Any helpful tips?
Not sure about modules, but if it's in a Class Module then you can do it. Here's my example:
Some other global module...
Global LocalCommand as CLocalCommands
---
The sub where you initialize & load the scripts:
Set LocalCommand = New CLocalCommands
MyScript.AddObject "CommandProcessor", LocalCommand, True
Then you can do:
Sub User_Talk(Username, Text, Flags, Ping)
If InStr(1, Username, "xL", 1) Then
CommandProcessor.ProcessCommand "ban " & Username & " ew"
End If
Exit Sub
This works for anything in classes, does anyone have something that might work for modules?
I don't believe you can do it in modules. The Script control only allows you to "expose" objects, including classes and form controls, to it.
The solution? Write a wrapper class such as StealthBot's ScriptSupportClass.txt. You can find ScriptSupportClass.txt (which is basically the class' source code) at http://cold-chaos.net/stealth/ScriptSupportClass.txt or installed with any copy of StealthBot.
Quote from: Stealth on March 23, 2004, 09:30 PM
I don't believe you can do it in modules. The Script control only allows you to "expose" objects, including classes and form controls, to it.
The solution? Write a wrapper class such as StealthBot's ScriptSupportClass.txt. You can find ScriptSupportClass.txt (which is basically the class' source code) at http://cold-chaos.net/stealth/ScriptSupportClass.txt or installed with any copy of StealthBot.
I've looked through this, what I am wondering is how you called the GetAccess function, or your Ban sub.
Quote from: UserLoser. on March 23, 2004, 07:21 PM
Then you can do:
Sub User_Talk(Username, Text, Flags, Ping)
If InStr(1, Username, "xL", 1) Then
CommandProcessor.ProcessCommand "ban " & Username & " ew"
End If
Exit Sub
Jerk lol
;)
Quote from: CrAz3D on March 23, 2004, 10:17 PM
I've looked through this, what I am wondering is how you called the GetAccess function, or your Ban sub.
The class is instantiated within my program. Classes, as a part of your program, can call public methods contained within modules (as GetAccess and Ban are). You write the wrapper functions because the script control can only access what it can see.
Think of it like this: (No smart comments ;) )
Your program is a car. The script control is in the trunk. It can't see the rest of the car -- only other things you put in the trunk. ScriptSupportClass (and similar wrappers) are like adding a small passageway between the trunk and the body of the car. Through this passage you can see a very limited bit of the inside of the car, but still not the majority of its interior.
Your wrapper class acts as a window to the rest of your program's code. You decide what the script control gets to see and what it doesn't get to see -- by controlling what functions you add to the wrapper class, you control the size and shape of the window into the body of the car.
HTH.
Can add anything that's an object, which modules are not (like stated above a few times):
ScriptControl.AddObject "NameToUseInScripting", frmMain.MyObject, True 'Forgot what the boolean is for off the top of my head
ScriptControl.AddObject "PacketBuffer", MyPacketBufferClass, True
ScriptControl.AddObject "UserLiser", frmMain.lvwUsers, True
ect.
Quote from: Stealth on March 23, 2004, 11:12 PM
Quote from: CrAz3D on March 23, 2004, 10:17 PM
I've looked through this, what I am wondering is how you called the GetAccess function, or your Ban sub.
The class is instantiated within my program. Classes, as a part of your program, can call public methods contained within modules (as GetAccess and Ban are). You write the wrapper functions because the script control can only access what it can see.
Think of it like this: (No smart comments ;) )
Your program is a car. The script control is in the trunk. It can't see the rest of the car -- only other things you put in the trunk. ScriptSupportClass (and similar wrappers) are like adding a small passageway between the trunk and the body of the car. Through this passage you can see a very limited bit of the inside of the car, but still not the majority of its interior.
Your wrapper class acts as a window to the rest of your program's code. You decide what the script control gets to see and what it doesn't get to see -- by controlling what functions you add to the wrapper class, you control the size and shape of the window into the body of the car.
HTH.
Oh, makes sense. But how do you encorporate your ScriptSupportClass into your program, so that it works as a class?
It's just an ordinary .cls class file. Public ScriptSupportClass as clsScriptSupportClass in a module, then on Form_Load() I initialize it (set ScriptSupportClass = new ScriptSupportClass) and on Form_Unload() I erase it (Set ScriptSupportClass = nothing). Then, when the script control is initialized I pass it as an object, as UserLoser described above.
okey dokey, quite dandy.
I'll see what I can do.
Thank you very much indeed.