Valhalla Legends Archive

Programming => General Programming => Topic started by: DarkOne on January 14, 2003, 05:53 PM

Title: Question
Post by: DarkOne on January 14, 2003, 05:53 PM
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!
Title: Re: Question
Post by: Mesiah / haiseM on January 14, 2003, 07:34 PM
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
Title: Re: Question
Post by: DarkOne on January 15, 2003, 01:45 PM
Ok, thanks MessiaH, that helped a lot! :)
Title: Re: Question
Post by: UserLoser on January 15, 2003, 03:40 PM
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
Title: Re: Question
Post by: Mesiah / haiseM on January 15, 2003, 04:23 PM
or that, thank u userloser.
Title: Re: Question
Post by: DarkOne on January 16, 2003, 11:35 AM
Ah :)

Thanks :P
Title: Re: Question
Post by: Spht on January 16, 2003, 11:37 AM
There's also a UCase function! =O
Title: Re: Question
Post by: Banana fanna fo fanna on January 16, 2003, 02:21 PM
What an amazingly descriptive topic name btw ;)
Sure sets it apart from all the other topics.
Title: Re: Question
Post by: Mesiah / haiseM on January 16, 2003, 04:10 PM
lcase() is so much sexier than ucase() tho, all the cool people use lcase(), if you use lcase(), you ARE the coolest..
Title: Re: Question
Post by: zraw on January 16, 2003, 04:22 PM
Debating which stupid function is better? How stupid.
Title: Re: Question
Post by: UserLoser on January 17, 2003, 09:19 AM
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.
Title: Another Question
Post by: DarkOne on January 17, 2003, 12:05 PM
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.
Title: Re: Question
Post by: Grok on January 17, 2003, 01:34 PM
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
Title: Re: Question
Post by: Spht on January 17, 2003, 02:18 PM
That's three people using that unknown product Warcraft III avatar now (that I know of)... scary.
Title: Re: Question
Post by: DarkOne on January 17, 2003, 06:29 PM
Thanks Grok, works like a charm ;)
Title: I'm confused! -_-
Post by: DarkOne on January 29, 2003, 01:24 PM
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
Title: Re: Question
Post by: Grok on January 29, 2003, 03:10 PM
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.
Title: Yet another Question
Post by: DarkOne on February 09, 2003, 09:37 AM
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