Valhalla Legends Forums Archive | General Programming | Question

AuthorMessageTime
DarkOne
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.

[code]
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
[/code]

Thanks to anyone that can help!
January 14, 2003, 11:53 PM
MesiaH
[quote]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.

[code]
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
[/code]

Thanks to anyone that can help![/quote]


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.

[code]
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[/code]
January 15, 2003, 1:34 AM
DarkOne
Ok, thanks MessiaH, that helped a lot! :)
January 15, 2003, 7:45 PM
UserLoser
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
January 15, 2003, 9:40 PM
MesiaH
or that, thank u userloser.
January 15, 2003, 10:23 PM
DarkOne
Ah :)

Thanks :P
January 16, 2003, 5:35 PM
Spht
There's also a UCase function! =O
January 16, 2003, 5:37 PM
St0rm.iD
What an amazingly descriptive topic name btw ;)
Sure sets it apart from all the other topics.
January 16, 2003, 8:21 PM
MesiaH
lcase() is so much sexier than ucase() tho, all the cool people use lcase(), if you use lcase(), you ARE the coolest..
January 16, 2003, 10:10 PM
zraw
Debating which stupid function is better? How stupid.
January 16, 2003, 10:22 PM
UserLoser
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.
January 17, 2003, 3:19 PM
DarkOne
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.

[code]
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
[/code]

Thanks again.
January 17, 2003, 6:05 PM
Grok
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.

[code]
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
[/code]

Hope this helps.
Grok
January 17, 2003, 7:34 PM
Spht
That's three people using that unknown product Warcraft III avatar now (that I know of)... scary.
January 17, 2003, 8:18 PM
DarkOne
Thanks Grok, works like a charm ;)
January 18, 2003, 12:29 AM
DarkOne
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:

[code]
Select Case LCase(cTalk(0))
   Case varTrig & "say"
       If aCheck >= 90 Then
           Send cTalk(1), frmMain.WSbnet
       End If
[/code]
January 29, 2003, 7:24 PM
Grok
Zip up your project code and email it to me grok@valhallalegends.com 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.
January 29, 2003, 9:10 PM
DarkOne
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:

[code]
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
[/code]
February 9, 2003, 3:37 PM

Search