Hello, this is my first post on the Valhalla Legends forum and I have a question for anyone willing to help. I'm currently trying to add commands to my bot using a function. I'm trying to display all text added to the array I've used after the first " " in cmdText.
Public Function Commands()
Dim cTalk() As String
cTalk() = Split(cmdTalk, " ")
If (Mid(cTalk(0), 1, 4) = trig & "say") Then
rtbAdd "Say: " & cTalk(1) & vbNewLine, vbYellow
End If
cmdTalk = ""
End Function
Thanks to anyone that can help!
QuoteHello, this is my first post on the Valhalla Legends forum and I have a question for anyone willing to help. I'm currently trying to add commands to my bot using a function. I'm trying to display all text added to the array I've used after the first " " in cmdText.
Public Function Commands()
Dim cTalk() As String
cTalk() = Split(cmdTalk, " ")
If (Mid(cTalk(0), 1, 4) = trig & "say") Then
rtbAdd "Say: " & cTalk(1) & vbNewLine, vbYellow
End If
cmdTalk = ""
End Function
Thanks to anyone that can help!
well it looks to me like your "trig" is a command prefix, but the way your doing it is saying the trigger has to be 4 characters long, and you need to limit the array to 1, or else splitting it by " " will seperate each word delimited by a space. Id just use a select case for this type of thing.
public function commands()
dim cTalk() as string
cTalk() = split(cmdTalk, " ", 1)
select case ctalk(0)
case trig & "say"
rtbadd "Say: " & ctalk(1) & vbnewline, vbyellow
case trig & "ver"
rtbadd "Version: " & app.major & "." & app.minor & "." & app.revision & vbnewline, vbyellow
case else
exit function
end select
cmdTalk = ""
end function
Ok, thanks MessiaH, that helped a lot! :)
Or better yet,
Select Case LCase(ctalk(0))
Example: If trigger is ., without the LCase, that would make it so you could only do .say, using the LCase, you could do .SaY, .SAY. .sAy, or anyway and it will work
or that, thank u userloser.
Ah :)
Thanks :P
There's also a UCase function! =O
What an amazingly descriptive topic name btw ;)
Sure sets it apart from all the other topics.
lcase() is so much sexier than ucase() tho, all the cool people use lcase(), if you use lcase(), you ARE the coolest..
Debating which stupid function is better? How stupid.
No, hes not debating. I would consider something like that just a little comment or joke.....Just don't respond if you're not helping.
I've sucessfully written a function to allow me to control the bot in various ways. Now I am trying to get another function I've been working on to work. I am trying to get the function to read both the user's name and their access level, which are seperated by a tab in the text file. This is what I have so far.
Public Function Database_CheckUser()
On Error Resume Next
aCheck = 0
Open App.Path & "\Database.txt" For Input As #1
For i = 0 To EOF(1)
Input #1, DBUser(i), Access(i)
If uName = DBUser(i) Then
aCheck = Access(i)
Close #1
Exit Function
End If
Next
Close #1
End Function
Thanks again.
I wrote this for you. In your project->references, scroll down to "Microsoft Scripting Runtime" and put a check in that checkbox. That will resolve the reference to Scripting.FileSystemObject.
Option Explicit
Public fso As New Scripting.FileSystemObject
Public Function GetUserAccess(ByVal UserName As String) As Long
On Error GoTo GetUserAccessErr
Dim fDB As Integer 'FreeFile returns an integer
Dim dbFile As String 'name of file containing database
Dim strLine As String 'buffer for reading lines from file
Dim strUser As String 'Username
Dim strAccess As String 'Access rights
GetUserAccess = 0 'default access level
fDB = FreeFile 'get next available file handle
'build filename -- properly inserts "\" if needed
dbFile = fso.BuildPath(App.Path, "database.txt")
If fso.FileExists(dbFile) = False Then Exit Function
Open dbFile For Input As #fDB
Do While EOF(fDB) = False
Line Input #fDB, strLine
Select Case True
Case Len(strLine) < 3 'lets us skip blank or small lines
Case InStr(strLine, vbTab) < 1 'lets us skip lines without tabs
Case Else
strUser = Split(strLine, vbTab)(0)
'now see if this user matches the requested user
If StrComp(strUser, UserName, vbTextCompare) = 0 Then
strAccess = Split(strLine, vbTab)(1)
GetUserAccess = CLng(Val(strAccess))
Exit Do
End If
End Select
Loop
Close #fDB
GetUserAccessExit:
Exit Function
GetUserAccessErr:
Dim lErr As Long
lErr = Err.Number
Debug.Print "ERROR in GetUserAccess(): (" & lErr & ")-" & Error(lErr)
Resume GetUserAccessExit
End Function
Hope this helps.
Grok
That's three people using that unknown product Warcraft III avatar now (that I know of)... scary.
Thanks Grok, works like a charm ;)
I've tried everything I possibly can, but this is not working. I've used the function Grok kindly posted a week or so ago and implemented it. However, since then I haven't had time to look at any real problems with what I've done, until today. I found that ever after checking the database textfile and comparing all names with those of the names of people who speak aloud in the channel, anyone can access my commands. It ignores my access level specifications, any help on this issue would be appreciated. Here's a snippet of my command code:
Select Case LCase(cTalk(0))
Case varTrig & "say"
If aCheck >= 90 Then
Send cTalk(1), frmMain.WSbnet
End If
Zip up your project code and email it to me
[email protected] and I'll take a look. Include all VBP, FRM, FRX, BAS, CLS, or RES that you are using.
If you don't ZIP it, or if you send me an executable, I will simply delete it and not bother.
I'm trying to add a new feature to my bot which involves updating an HTM document. I'm trying to have the bot check through an HTM document and add all lines to an array. After this has been completed, it will then look for a specific string within the document and convert it to a null string along with the 3 lines above and two lines below. Here's what I have so far:
Public Function HTMLGenerate_Delete()
Dim strLine() As String
Dim w, nLines As Integer
nLines = 0
Open App.Path & "\channel.htm" For Input As #1
Do While EOF(1) = False
nLines = nLines + 1
Line Input #1, strLine(nLines)
Loop
Close #1
Open App.Path & "\channel.htm" For Output As #1
For w = 1 To nLines
If strLine(w) = "test" Then
strLine(w - 3) = ""
strLine(w - 2) = ""
strLine(w - 1) = ""
strLine(w) = ""
strLine(w + 1) = ""
strLine(w + 2) = ""
Else
Print #1, strLine(w)
End If
Next
Close #1
End Function