I need some help wit this. I'm trying to add usernames with access 0-100. I can't figure out how to even start this. The current access system I'm using right now is this:
'Say
If Left((LCase(message)), 5) = (Loadtrigger & "say ") Then
For X = 1 To Form15.MasterList.ListItems.Count
If LCase(Form15.MasterList.ListItems.Item(X).Text) = LCase(Username) Then
AddChat (Mid(message, 6, Len(message) - 1))
End If
Next X
End If
As you can see, this meathod sucks. I want to get access from users using the split meathod. (Like stealthbot does) Since I just found out about the split meathod about a month ago, I dono how to make it twork the way I want it to.
This is the split meathod I used with another part of my bot.
Dim Splt() As String
Splt() = Split(userlist.FindItem(txtUser2.Text).Text, ":")
txtUser.Text = Splt(0)
txtPass.Text = Splt(1)
I need to make it so when the user types " .say asdf", the bot will check the access (0-100)and if it's 50 or higher, activate the command.
How can I do this?
Well I have no idea how your databasing works so im going to wing it.
Dim UsrCmd() as String 'Array to store messages
UsrCmd = Split(Message,Space(1)) ' Store our Split Message in the Array
Select Case LCase(UsrCmd(0)) 'First word in Message in lowercase
Case Trigger & "say" 'UsrCmd(0) would contain the first group of letters which would be your trigger and "say"
If DBGetAccess(Username) => 20 Then 'Access is greater or equal to 20
Call Queue.AddMessage(Mid(Message,Len(UsrCmd(0))+1) 'Send to BNET
End If
Case Else 'The Command isn't say
End Select
Wrote this code right in the reply box, doubt there is errors though. Logicly for more commands you would add more cases but that should get you started
Quote from: Warrior on December 17, 2004, 08:54 PM
Well I have no idea how your databasing works so im going to wing it.
The commadn checks the listbox in a different form for the username. If the username is in the listbox, the command activates. I was goin to make the access system wit Master, Op, Mod, Guest. But I would have to rewrite all the commands 3x more ( 1 set of commands for each type of user). So I said fuck that.
Back to topic:
Whats DBGetAccess. Where is the command getting the access numbers from(Textfile, textbox..) thats another problem I need to figure out.
DBGetAccess is my function which reads my Database array.
Thats what I need. I dont know how to make the command get the username and access from somewhere else. Help?
Alright sure
'Using Arrays with Structs is =)
Public UserDB() As UDB
Public Type UDB
Username As String 'Username stored
Access As Integer 'Access stored
End Type
Public Sub DBAddUser(ByVal User As String, ByVal Access As Integer)
ReDim Preserve UserDB(UBound(UserDB) + 1) 'Resize the Array for the new User
'Now we are going to use the highest Index in the Array
'Since we are using an Array with a struct for organization, we can do this nice and neat
'Reason for using highest index in Array: Since we resized the array its only logical that we use the highest index
UserDB(UBound(UserDB)).Username = User 'Set the Username
UserDB(UBound(UserDB)).Access = Access 'Set the Access
'Maybe call somesort of SaveFunction here to save to a file =)
End Sub
Public Function DBGetAccess(ByVal User As String) As String 'Return a integer
Dim i As Integer 'Declare our Integer
'A Function to get the User's index would be easier in the longrun so might want to think about writing one
'Here we begin to loop LBound() being the lowest index in an Array to UBound() being the highest
'So that would loop through the Entire Array Incrementing our Variable 'i'
'Since UserDB is an Array using UserDB(i) would return the current Index it is searching good for comparing
For i = LBound(UserDB) To UBound(UserDB)
If LCase(User) = LCase(UserDB(i).Username) Then 'The Username requested was found
DBGetAccess = UserDB(i).Access 'Return the Access
Exit Sub 'We are all done =)
End If
Next i 'Since it wasnt found continue looping
Exit Function 'We are done and nothing was found =|
End Function
Public Function ClearDB()
ReDim UserDB(0)
End Function
'Note: I only gave a few key Functions as examples you would need to write the code to read/write to the text file
'I hope this helped =)
Edit: Added Clear function which must be called on Form_Load perferebly
In the DBGetAccess, where it sais," 'A Function to get the User's index would be easier in the longrun so might want to think about writing one", is it telling you to write a code taht gets the usernames from a text file or...? Not sure I understand that sentence. Kinda confused about where the code is gettin the usernames form.
Its a sepearate function to do the loop and return thier index from the array so you wouldnt have to rewrite a loop every time. Its pretty straight forward.
Quote from: GoSu_KaOs on December 17, 2004, 11:54 PM
In the DBGetAccess, where it sais," 'A Function to get the User's index would be easier in the longrun so might want to think about writing one", is it telling you to write a code taht gets the usernames from a text file or...? Not sure I understand that sentence. Kinda confused about where the code is gettin the usernames form.
Could you plz read the code and make an effort to understand? Thanks.
Quote
'Note: I only gave a few key Functions as examples you would need to write the code to read/write to the text file