• Welcome to Valhalla Legends Archive.
 

Question

Started by DarkOne, January 14, 2003, 05:53 PM

Previous topic - Next topic

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.

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!

Mesiah / haiseM

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
]HighBrow Innovations
Coming soon...

AIM Online Status: 

DarkOne

#2
Ok, thanks MessiaH, that helped a lot! :)

UserLoser

#3
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

Mesiah / haiseM

#4
or that, thank u userloser.
]HighBrow Innovations
Coming soon...

AIM Online Status: 

DarkOne

#5
Ah :)

Thanks :P

Spht

#6
There's also a UCase function! =O

Banana fanna fo fanna

#7
What an amazingly descriptive topic name btw ;)
Sure sets it apart from all the other topics.

Mesiah / haiseM

#8
lcase() is so much sexier than ucase() tho, all the cool people use lcase(), if you use lcase(), you ARE the coolest..
]HighBrow Innovations
Coming soon...

AIM Online Status: 

zraw

#9
Debating which stupid function is better? How stupid.

UserLoser

#10
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.

DarkOne

#11
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.

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.

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

Spht

#13
That's three people using that unknown product Warcraft III avatar now (that I know of)... scary.

DarkOne

#14
Thanks Grok, works like a charm ;)