IPB

Welcome Guest ( Log In | Register )

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 
Reply to this topicStart new topic
> herolist by TBN, need update
Style
post Mar 9 2009, 10:50 AM
Post #1


Jr. Member
**

Group: Members
Posts: 89
Joined: 6-April 08
From: Germany
Member No.: 35,572



Hey TBN,
some time ago you and riffruff wrote a herolist plugin for me.
CODE
'herolist
'1.4
'&Hero List:RiffRuff and The-Black-Ninja
'&addhero <class> <level> <profession> = adds a hero to the database:updatehero <class> <level> [profession] = updates a user's hero, profession optional:listhero [user] = lists heroes for the user, if user is left out, lists your heroes:searchhero <class> = lists all users with that class:searchprofession = lists all users with that profession:delhero <class> = removes a user's class from the database:delherouser <user> = removes all instances of <user> from the DB (admin only)
'&37945
'&

Public Conn
Public Path

Const addhero_cmd_access = 1
Const updatehero_cmd_access = 1
Const herolist_cmd_access = 1
Const searchhero_cmd_access = 1
Const searchprof_cmd_access = 1
Const delhero_cmd_access = 1
Const delherouser_cmd_access = 100

Const addhero_cmd = "addhero"
Const updatehero_cmd = "updatehero"
Const herolist_cmd = "listhero"
Const searchhero_cmd = "searchhero"
Const searchprof_cmd = "searchprofession"
Const delhero_cmd = "delhero"
Const delherouser_cmd = "delherouser"


Sub herolist_Event_Load()
Path = BotPath() & "HeroList.mdb"
Set FSO = CreateObject("Scripting.FileSystemObject")

If Not FSO.FileExists(Path) Then
herolist_create_database
Else
herolist_connect
End If
End Sub


Sub herolist_Event_UserTalk(Username, Flags, Message, Ping)

herolist_ProcessInput Username, Message, 1
End Sub


Sub herolist_Event_UserEmote(Username, Flags, Message)

herolist_ProcessInput Username, Message, 2
End Sub


Sub herolist_Event_WhisperFromUser(Username, Flags, Message)

herolist_ProcessInput Username, Message, 3
End Sub

Sub herolist_Event_PressedEnter(Text)

herolist_ProcessInput BotVars.Username, Text, 4
End Sub


Sub herolist_ProcessInput(Username, Message, From)

If Left(Message, Len(BotVars.Trigger)) <> BotVars.Trigger And From <> 4 Then Exit Sub
If (Left(Message, 1) <> "/") And (From = 4) Then Exit Sub

GetDBEntry Username, myAccess, myFlags

If From = 4 Then Username = BotVars.Username

Message = Right(Message, Len(Message) - Len(BotVars.Trigger))
If InStr(Message, " ") > 0 Then
TmpMsg = Split(Message, " ", 2)
Select Case LCase(TmpMsg(0))
Case addhero_cmd: herolist_addhero Username, TmpMsg(0), TmpMsg(1), From, myAccess, myFlags
Case updatehero_cmd: herolist_updatehero Username, TmpMsg(0), TmpMsg(1), From, myAccess, myFlags
Case herolist_cmd: herolist_herolst Username, TmpMsg(1), From, myAccess, myFlags
Case searchhero_cmd: herolist_searchhero Username, TmpMsg(1), From, myAccess, myFlags
Case searchprof_cmd: herolist_searchprof Username, TmpMsg(1), From, myAccess, myFlags
Case delhero_cmd: herolist_delhero Username, TmpMsg(1), From, myAccess, myFlags
Case delherouser_cmd: herolist_delherouser Username, TmpMsg(1), From, myAccess, myFlags
Case Else: Exit Sub
End Select
Else
Select Case LCase(Message)
Case herolist_cmd: herolist_herolst Username, Username, From, myAccess, myFlags
Case Else: Exit Sub
End Select
End If
End Sub


Sub herolist_delherouser(Username, Text, From, myAccess, myFlags)

If myAccess < delherouser_cmd_access AND Username <> BotVars.Username Then Exit Sub
VetoThisMessage

If Text <> vbNullString Then
sString = Text
Else
Dsp From, "Invalid! " & BotVars.Trigger & delherouser_cmd & " <name>", Username, vbRed
Exit Sub
End If

Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `name` = '" & sString & "'")
If hs.Fields(0) <> 0 Then
Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes`")
maxCount = hs.Fields(0)
Set rs = conn.Execute("SELECT `name` FROM `heroes` WHERE `name` = '" & sString & "' ORDER BY `name` DESC")
x=0
For i = 1 To maxCount
If NOT (rs.BOF OR rs.EOF) Then
x=x+1
Conn.Execute("UPDATE `heroes` SET `name`='<removed>', `class`='<removed>', `level`='0', `profession`='<removed>' WHERE `name`='" & sString & "'")
rs.MoveNext
End If
Next
Dsp From, x & " instaces of " & sString & "'s hero entries were found and removed.", Username, vbGreen
Else
Dsp From, sString & " does not exist in the database.", Username, vbGreen
End If
End Sub


Sub herolist_delhero(Username, Text, From, myAccess, myFlags)

If myAccess < delhero_cmd_access AND Username <> BotVars.Username Then Exit Sub

VetoThisMessage
If Text <> vbNullString Then
sString = Text
Else
Dsp From, "Invalid! " & BotVars.Trigger & delhero_cmd & " <class>", Username, vbRed
Exit Sub
End If

Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `name` = '" & Username & "' AND `class` = '" & sString & "'")
If hs.Fields(0) <> 0 Then
Conn.Execute("UPDATE `heroes` SET `name`='<removed>', `class`='<removed>', `level`='0', `profession`='<removed>' WHERE `name`='" & Username & "' AND `class` ='" & sString & "'")
Dsp From, "Removed your " & sString & " from the database.", Username, vbGreen
Else
Dsp From, "Unable to execute command: class is invalid.", Username, vbGreen
End If
End Sub


Sub herolist_searchprof(Username, Text, From, myAccess, myFlags)

If myAccess < searchprof_cmd_access AND Username <> BotVars.Username Then Exit Sub

VetoThisMessage
If Text <> vbNullString Then
sString = Text
Else
Dsp From, "Invalid! " & BotVars.Trigger & searchprof_cmd & " <profession>", Username, vbRed
Exit Sub
End If

Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `profession` = '" & sString & "'")
If hs.Fields(0) <> 0 Then
Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes`")
maxCount = hs.Fields(0)
Set rs = conn.Execute("SELECT `name`, `class`, `level` FROM `heroes` WHERE `profession` = '" & sString & "' ORDER BY `name` DESC")
For i = 1 To maxCount
If NOT (rs.BOF OR rs.EOF) Then
If lastUser <> rs.Fields(0) Then
output = output & rs.Fields(0) & " (" & rs.Fields(1) & ", lvl " & rs.Fields(2) & "), "
Else
output = output & " | " & rs.Fields(1) & ", lvl " & rs.Fields(2) & "), "
End If
lastUser = rs.Fields(0)
rs.MoveNext
End If
Next

output = Left(output, Len(output) - 2)
output = Replace(output, "), | ", " | ")
Dsp 2, "Users with a " & sString, Username, vbGreen
Dsp 2, output, Username, vbGreen
Else
Dsp 2, "No users have heroes with profession: " & sString, Username, vbGreen
End If
End Sub


Sub herolist_searchhero(Username, Text, From, myAccess, myFlags)

If myAccess < searchhero_cmd_access AND Username <> BotVars.Username Then Exit Sub

VetoThisMessage
If Text <> vbNullString Then
sString = Text
Else
Dsp From, "Invalid! " & BotVars.Trigger & searchhero_cmd & " <class>", Username, vbRed
Exit Sub
End If

Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `class` = '" & sString & "'")
If hs.Fields(0) <> 0 Then
maxCount = hs.Fields(0)
Set data = conn.Execute("SELECT DISTINCT `class`, `name` FROM `heroes` WHERE `class` = '" & sString & "'")
For i = 1 To maxCount
sName = data.Fields(1)
Set ts = conn.Execute("SELECT * FROM `heroes` WHERE `name` = '" & sName & "' AND `class`='" & sString & "'")
output = output & sName & " (lvl " & ts.Fields(3) & ", " & ts.Fields(4) & "), "
data.MoveNext
Next

output = Left(output, Len(output) - 2)
Dsp 2, "Users with a " & sString, Username, vbGreen
Dsp 2, output, Username, vbGreen
Else
Dsp 2, "No users have heroes with class: " & sString, Username, vbGreen
End If
End Sub


Sub herolist_herolst(Username, Text, From, myAccess, myFlags)

If myAccess < herolist_cmd_access AND Username <> BotVars.Username Then Exit Sub

VetoThisMessage
If Text <> vbNullString Then
user = Text
Else
user = Username
End If

Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `name` ='" & user & "'")
If hs.Fields(0) <> 0 Then
Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `name` = '" & user & "'")
If hs.fields(0) <> 0 Then
maxCount = hs.fields(0)
Set data = conn.Execute("SELECT `class`, `level`, `profession` FROM `heroes` WHERE `name` = '" & user & "'")
For i = 1 To maxCount
sClass = data.Fields(0)
output = output & sClass & " lvl " & data.Fields(1) & " (" & data.Fields(2) & "), "
data.MoveNext
Next

output = Left(output, Len(output) - 2)
Dsp 2, user & " has the following heroes:", Username, vbGreen
Dsp 2, output, Username, vbGreen
Else
Dsp 2, user & " has no heroes.", Username, vbGreen
End If
Else
Dsp 2, user & " is not in the database.", Username, vbGreen
End If
End Sub


Sub herolist_updatehero(Username, cmd, Text, From, myAccess, myFlags)

If myAccess < updatehero_cmd_access AND Username <> BotVars.Username Then Exit Sub

VetoThisMessage

tmp = GetHeroInfo(Username, Text, From, 0, cmd)
If tmp = vbNullString Then Exit Sub
Level = Split(tmp, "|")(0)
hClass = Split(tmp, "|")(1)
Profession = Split(tmp, "|")(2)

Set hs = conn.Execute("SELECT `name` FROM `heroes` WHERE `name` ='" & Username & "'")
If hs.Fields(0) <> vbNullString Then
Set hs = conn.Execute("SELECT `class` FROM `heroes` WHERE `class` ='" & hClass & "'")
If LCase(hs.Fields(0)) = LCase(hClass) Then
If Profession <> vbNullString Then
Conn.Execute("UPDATE `heroes` SET `class`='" & hClass & "', `level`='" & Level & "', `profession`='" & Profession & "' WHERE `name`='" & Username & "' AND `class` ='" & hClass & "'")
Dsp From, "Upgraded " & hClass & " to a level of " & Level & " as a " & Profession & " for " & Username & ".", Username, vbGreen
Else
Conn.Execute("UPDATE `heroes` SET `class`='" & hClass & "', `level`='" & Level & "' WHERE `name`='" & Username & "' AND `class` ='" & hClass & "'")
Dsp From, "Upgraded " & hClass & " to a level of " & Level & " for " & Username & ".", Username, vbGreen
End If
Else
Dsp From, "Invalid hero class.", Username, vbGreen
End If
Else
Dsp From, "You do not have a hero to upgrade.", Username, vbGreen
End If
End Sub


Sub herolist_addhero(Username, cmd, Text, From, myAccess, myFlags)

If myAccess < addhero_cmd_access AND Username <> BotVars.Username Then Exit Sub

VetoThisMessage

tmp = GetHeroInfo(Username, Text, From, 1, cmd)
If tmp = vbNullString Then Exit Sub
Level = Split(tmp, "|")(0)
hClass = Split(tmp, "|")(1)
Profession = Split(tmp, "|")(2)

Set hs = Conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `name`='" & Username & "' AND `class`='" & hClass & "'")
If hs.Fields(0) = 1 Then
Dsp From, "Invalid! You already have a hero for this class.", Username, vbRed
Exit Sub
End If

Conn.Execute("INSERT INTO `heroes` (`name`,`class`,`level`, `profession`) VALUES ('" & LCase(Username) & "', '" & LCase(hClass) & "', '" & Level & "', '" & Profession & "')")
Dsp From, "Added a level " & Level & " " & hClass & " with the profession " & Profession & " for " & Username, Username, vbGreen
End Sub


Function GetHeroInfo(Username, Text, From, profReqd, cmd) '// Returns "" if command is wrong, profReqd=Profession required, 0 is no, 1 is yes

If profReqd = 0 Then
errMsg = BotVars.Trigger & cmd & " <class> <level>"
ElseIf profReqd = 1 Then
errMsg = BotVars.Trigger & cmd & " <class> <level> <profession>"
End If

If InStr(Text, " ") > 0 Then
msg = Split(Text, " ")
If UBound(msg) => 1 Then
'// Determine if they have the level in the right spot or not
'// tMatch returns: 0 if there is no number at all, 1 if it's not in the right spot, any other number means it's fine
'// lvlLoc returns either 2, 3, or 4, which is the position of the level number. We use this to determine the length of the hero class AND our level variable
tMatch = 0
lvlLoc=-1
For Each word In msg
lvlLoc=lvlLoc+1
If IsNumeric(word) Then
If lvlLoc=3 OR lvlLoc=2 OR lvlLoc=1 Then
Level = msg(lvlLoc)
tMatch = 500
Exit For
Else
tMatch = 1
End If
End If
Next
If tMatch=0 Then
Dsp From, "Invalid! Levels must be an integer: " & errMsg, Username, vbRed
GetHeroInfo = vbNullString
Exit Function
ElseIf tMatch=1 Then
Dsp From, "Invalid! " & errMsg, Username, vbRed
GetHeroInfo = vbNullString
Exit Function
End If
tMatch = vbNullString

Select Case lvlLoc
'// Level is the second word in our Text variable, meaning the hero class is one word
Case 1 : hClass = msg(0)
'// Level is the second word in our Text variable, meaning the hero class is two words
Case 2: hClass = msg(0) & " " & msg(1)
'// Level is the second word in our Text variable, meaning the hero class is three words
Case 3: hClass = msg(0) & " " & msg(1) & " " & msg(2)
End Select

'// Get the class of hero
heroStr = "Assassin|Barbarian|Cleric|Druid|Guardian Of Nature|Khaos Champion|Magician|Ranger|Spartan Warrior|Temple Guardian|Warlock|Warlord"
heroArr = Split(heroStr, "|")

tMatch = False
For Each hero In heroArr
If Lcase(hero) = Lcase(hClass) Then
tMatch = True
Exit For
End If
Next
If NOT tMatch Then
Dsp From, "Invalid! You must choose a valid hero class.", Username, vbRed
GetHeroInfo = vbNullString
Exit Function
End If
Else
Dsp From, "Invalid! " & errMsg, Username, vbRed
GetHeroInfo = vbNullString
Exit Function
End If
Else
Dsp From, "Invalid! " & errMsg, Username, vbRed
GetHeroInfo = vbNullString
Exit Function
End If

If profReqd = 1 Then
If lvlLoc = UBound(msg) Then
Dsp From, "Invalid! " & errMsg, Username, vbRed
GetHeroInfo = vbNullString
Exit Function
End If
End If

If lvlLoc < UBound(msg) Then
For i = lvlLoc+1 To UBound(msg)
Profession = Profession & msg(i) & " "
Next
Profession = Left(Profession, Len(Profession) -1)

profStr = "AS|GS|WS|Alch|None"
profArr = Split(profStr, "|")

tMatch = False
For Each prof In profArr
If Lcase(prof) = Lcase(Profession) Then
tMatch = True
Exit For
End If
Next

If NOT tMatch Then
Dsp From, "Invalid! You must choose a valid profession.", Username, vbRed
GetHeroInfo = vbNullString
Exit Function
End If
Else
Profession = vbNullString
End If
GetHeroInfo = Level & "|" & hClass & "|" & Profession
End Function


Sub herolist_create_database()

Set Catalog = CreateObject("ADOX.Catalog")
Catalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=" & Path

herolist_connect()

Conn.Execute("CREATE TABLE `heroes` (`ID` COUNTER, `name` varchar(30) NOT NULL, `class` varchar(30) NOT NULL, " & _
"`level` int NOT NULL, `profession` varchar(30) NOT NULL)")
End Sub


Sub herolist_connect()

Set Conn = CreateObject ("ADODB.connection")
dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & Path
Conn.ConnectionString = dsn
Conn.Open
End Sub


Function AllowedToUseCommand(myAccess, Command)

If myAccess < Command Then
AllowedToUseCommand = False
Else
AllowedToUseCommand = True
End If
End Function


the map got a major update. So I need to adjust this plugin:

The profession is not required anymore. So you can delete all things related to this (the database column, the profsearch, ..)
But i need a search for herolevels. So you can search not only for exact hero level but also for heroes which are near the requested level. (range adjustable via a seperate cmd or at the top of the plugin) e.g. (range 3)
user: .searchlvl 100
Bot: Heroes from level 97 to 103:
Bot: User1: ranger (99), Barbarian (103) | User2: Assassin (100)
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
The-Black-Ninja
post Mar 9 2009, 02:12 PM
Post #2


Pure Sex
********

Group: Moderators
Posts: 7,756
Joined: 13-August 06
Member No.: 7,372



Hero you go. Tested by adding a hero, searching heroes by class, and updating the hero. Pay attention to the yellow message it gives you when you start it up.

CODE
'herolist
'1.5
'&Hero List:RiffRuff and The-Black-Ninja
'&addhero <class> <level> <profession> = adds a hero to the database:updatehero <class> <level> [profession] = updates a user's hero, profession optional:listhero [user] = lists heroes for the user, if user is left out, lists your heroes:searchhero <class> = lists all users with that class:searchprofession = lists all users with that profession:delhero <class> = removes a user's class from the database:delherouser <user> = removes all instances of <user> from the DB (admin only)
'&37945
'&

Public Conn
Public Path

Const addhero_cmd_access = 1
Const updatehero_cmd_access = 1
Const herolist_cmd_access = 1
Const searchhero_cmd_access = 1
Const delhero_cmd_access = 1
Const delherouser_cmd_access = 100

Const addhero_cmd = "addhero"
Const updatehero_cmd = "updatehero"
Const herolist_cmd = "listhero"
Const searchhero_cmd = "searchhero"
Const delhero_cmd = "delhero"
Const delherouser_cmd = "delherouser"


Sub herolist_Event_Load()

Path = BotPath() & "HeroList.mdb"
Set FSO = CreateObject("Scripting.FileSystemObject")

If Not FSO.FileExists(Path) Then
herolist_create_database
Else
herolist_connect
End If

conn.Execute("ALTER TABLE `heroes` DROP COLUMN `profession`")
AddChat vbYellow, "herolist plugin: Removing ""profession"" column from database. Open this plugin and remove lines 37 and 38."
End Sub


Sub herolist_Event_UserTalk(Username, Flags, Message, Ping)

herolist_ProcessInput Username, Message, 1
End Sub


Sub herolist_Event_UserEmote(Username, Flags, Message)

herolist_ProcessInput Username, Message, 2
End Sub


Sub herolist_Event_WhisperFromUser(Username, Flags, Message)

herolist_ProcessInput Username, Message, 3
End Sub

Sub herolist_Event_PressedEnter(Text)

herolist_ProcessInput BotVars.Username, Text, 4
End Sub


Sub herolist_ProcessInput(Username, Message, From)

If Left(Message, Len(BotVars.Trigger)) <> BotVars.Trigger And From <> 4 Then Exit Sub
If (Left(Message, 1) <> "/") And (From = 4) Then Exit Sub

GetDBEntry Username, myAccess, myFlags

If From = 4 Then Username = BotVars.Username

Message = Right(Message, Len(Message) - Len(BotVars.Trigger))
If InStr(Message, " ") > 0 Then
TmpMsg = Split(Message, " ", 2)
Select Case LCase(TmpMsg(0))
Case addhero_cmd: herolist_addhero Username, TmpMsg(0), TmpMsg(1), From, myAccess, myFlags
Case updatehero_cmd: herolist_updatehero Username, TmpMsg(0), TmpMsg(1), From, myAccess, myFlags
Case herolist_cmd: herolist_herolst Username, TmpMsg(1), From, myAccess, myFlags
Case searchhero_cmd: herolist_searchhero Username, TmpMsg(1), From, myAccess, myFlags
Case delhero_cmd: herolist_delhero Username, TmpMsg(1), From, myAccess, myFlags
Case delherouser_cmd: herolist_delherouser Username, TmpMsg(1), From, myAccess, myFlags
Case Else: Exit Sub
End Select
Else
Select Case LCase(Message)
Case herolist_cmd: herolist_herolst Username, Username, From, myAccess, myFlags
Case Else: Exit Sub
End Select
End If
End Sub


Sub herolist_delherouser(Username, Text, From, myAccess, myFlags)

If myAccess < delherouser_cmd_access AND Username <> BotVars.Username Then Exit Sub
VetoThisMessage

If Text <> vbNullString Then
sString = Text
Else
Dsp From, "Invalid! " & BotVars.Trigger & delherouser_cmd & " <name>", Username, vbRed
Exit Sub
End If

Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `name` = '" & sString & "'")
If hs.Fields(0) <> 0 Then
Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes`")
maxCount = hs.Fields(0)
Set rs = conn.Execute("SELECT `name` FROM `heroes` WHERE `name` = '" & sString & "' ORDER BY `name` DESC")
x=0
For i = 1 To maxCount
If NOT (rs.BOF OR rs.EOF) Then
x=x+1
Conn.Execute("UPDATE `heroes` SET `name`='<removed>', `class`='<removed>', `level`='0' WHERE `name`='" & sString & "'")
rs.MoveNext
End If
Next
Dsp From, x & " instaces of " & sString & "'s hero entries were found and removed.", Username, vbGreen
Else
Dsp From, sString & " does not exist in the database.", Username, vbGreen
End If
End Sub


Sub herolist_delhero(Username, Text, From, myAccess, myFlags)

If myAccess < delhero_cmd_access AND Username <> BotVars.Username Then Exit Sub

VetoThisMessage
If Text <> vbNullString Then
sString = Text
Else
Dsp From, "Invalid! " & BotVars.Trigger & delhero_cmd & " <class>", Username, vbRed
Exit Sub
End If

Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `name` = '" & Username & "' AND `class` = '" & sString & "'")
If hs.Fields(0) <> 0 Then
Conn.Execute("UPDATE `heroes` SET `name`='<removed>', `class`='<removed>', `level`='0' WHERE `name`='" & Username & "' AND `class` ='" & sString & "'")
Dsp From, "Removed your " & sString & " from the database.", Username, vbGreen
Else
Dsp From, "Unable to execute command: class is invalid.", Username, vbGreen
End If
End Sub


Sub herolist_searchhero(Username, Text, From, myAccess, myFlags)

If myAccess < searchhero_cmd_access AND Username <> BotVars.Username Then Exit Sub

VetoThisMessage

If Text <> vbNullString Then
sString = Text
Else
Dsp From, "Invalid! " & BotVars.Trigger & searchhero_cmd & " <class>", Username, vbRed
Exit Sub
End If

Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `class` = '" & sString & "'")
If hs.Fields(0) <> 0 Then
maxCount = hs.Fields(0)
Set data = conn.Execute("SELECT DISTINCT `class`, `name` FROM `heroes` WHERE `class` = '" & sString & "'")
For i = 1 To maxCount
sName = data.Fields(1)
Set ts = conn.Execute("SELECT * FROM `heroes` WHERE `name` = '" & sName & "' AND `class`='" & sString & "'")
output = output & sName & " (lvl " & ts.Fields(3) & "), "
data.MoveNext
Next

output = Left(output, Len(output) - 2)
Dsp 2, "Users with a " & sString, Username, vbGreen
Dsp 2, output, Username, vbGreen
Else
Dsp 2, "No users have heroes with class: " & sString, Username, vbGreen
End If
End Sub


Sub herolist_herolst(Username, Text, From, myAccess, myFlags)

If myAccess < herolist_cmd_access AND Username <> BotVars.Username Then Exit Sub

VetoThisMessage
If Text <> vbNullString Then
user = Text
Else
user = Username
End If

Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `name` ='" & user & "'")
If hs.Fields(0) <> 0 Then
Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `name` = '" & user & "'")
If hs.fields(0) <> 0 Then
maxCount = hs.fields(0)
Set data = conn.Execute("SELECT `class`, `level` FROM `heroes` WHERE `name` = '" & user & "'")
For i = 1 To maxCount
sClass = data.Fields(0)
output = output & sClass & " lvl " & data.Fields(1) & ", "
data.MoveNext
Next

output = Left(output, Len(output) - 2)
Dsp 2, user & " has the following heroes:", Username, vbGreen
Dsp 2, output, Username, vbGreen
Else
Dsp 2, user & " has no heroes.", Username, vbGreen
End If
Else
Dsp 2, user & " is not in the database.", Username, vbGreen
End If
End Sub


Sub herolist_updatehero(Username, cmd, Text, From, myAccess, myFlags)

If myAccess < updatehero_cmd_access AND Username <> BotVars.Username Then Exit Sub

VetoThisMessage

tmp = GetHeroInfo(Username, Text, From, 0, cmd)
If tmp = vbNullString Then Exit Sub
Level = Split(tmp, "|")(0)
hClass = Split(tmp, "|")(1)

Set hs = conn.Execute("SELECT `name` FROM `heroes` WHERE `name` ='" & Username & "'")
If hs.Fields(0) <> vbNullString Then
Set hs = conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `class` ='" & hClass & "' AND `name` = '" & Username & "'")
If hs.Fields(0) <> 0 Then
Conn.Execute("UPDATE `heroes` SET `class`='" & hClass & "', `level`='" & Level & "' WHERE `name`='" & Username & "' AND `class` ='" & hClass & "'")
Dsp From, "Upgraded " & hClass & " to a level of " & Level & " for " & Username & ".", Username, vbGreen
Else
Dsp From, "Invalid hero class.", Username, vbGreen
End If
Else
Dsp From, "You do not have a hero to upgrade.", Username, vbGreen
End If
End Sub


Sub herolist_addhero(Username, cmd, Text, From, myAccess, myFlags)

If myAccess < addhero_cmd_access AND Username <> BotVars.Username Then Exit Sub

VetoThisMessage

tmp = GetHeroInfo(Username, Text, From, 0, cmd)
If tmp = vbNullString Then Exit Sub
Level = Split(tmp, "|")(0)
hClass = Split(tmp, "|")(1)

Set hs = Conn.Execute("SELECT COUNT(*) FROM `heroes` WHERE `name`='" & Username & "' AND `class`='" & hClass & "'")
If hs.Fields(0) = 1 Then
Dsp From, "Invalid! You already have a hero for this class.", Username, vbRed
Exit Sub
End If

Conn.Execute("INSERT INTO `heroes` (`name`,`class`,`level`) VALUES ('" & LCase(Username) & "', '" & LCase(hClass) & "', '" & Level & "')")
Dsp From, "Added a level " & Level & " " & hClass & " for " & Username, Username, vbGreen
End Sub


Function GetHeroInfo(Username, Text, From, profReqd, cmd) '// Returns "" if command is wrong, profReqd=Profession required, 0 is no, 1 is yes

If profReqd = 0 Then errMsg = BotVars.Trigger & cmd & " <class> <level>"


If InStr(Text, " ") > 0 Then
msg = Split(Text, " ")
If UBound(msg) => 1 Then
'// Determine if they have the level in the right spot or not
'// tMatch returns: 0 if there is no number at all, 1 if it's not in the right spot, any other number means it's fine
'// lvlLoc returns either 2, 3, or 4, which is the position of the level number. We use this to determine the length of the hero class AND our level variable
tMatch = 0
lvlLoc=-1
For Each word In msg
lvlLoc=lvlLoc+1
If IsNumeric(word) Then
If lvlLoc=3 OR lvlLoc=2 OR lvlLoc=1 Then
Level = msg(lvlLoc)
tMatch = 500
Exit For
Else
tMatch = 1
End If
End If
Next
If tMatch=0 Then
Dsp From, "Invalid! Levels must be an integer: " & errMsg, Username, vbRed
GetHeroInfo = vbNullString
Exit Function
ElseIf tMatch=1 Then
Dsp From, "Invalid! " & errMsg, Username, vbRed
GetHeroInfo = vbNullString
Exit Function
End If
tMatch = vbNullString

Select Case lvlLoc
'// Level is the second word in our Text variable, meaning the hero class is one word
Case 1 : hClass = msg(0)
'// Level is the second word in our Text variable, meaning the hero class is two words
Case 2: hClass = msg(0) & " " & msg(1)
'// Level is the second word in our Text variable, meaning the hero class is three words
Case 3: hClass = msg(0) & " " & msg(1) & " " & msg(2)
End Select

'// Get the class of hero
heroStr = "Assassin|Barbarian|Cleric|Druid|Guardian Of Nature|Khaos Champion|Magician|Ranger|Spartan Warrior|Temple Guardian|Warlock|Warlord"
heroArr = Split(heroStr, "|")

tMatch = False
For Each hero In heroArr
If Lcase(hero) = Lcase(hClass) Then
tMatch = True
Exit For
End If
Next
If NOT tMatch Then
Dsp From, "Invalid! You must choose a valid hero class.", Username, vbRed
GetHeroInfo = vbNullString
Exit Function
End If
Else
Dsp From, "Invalid! " & errMsg, Username, vbRed
GetHeroInfo = vbNullString
Exit Function
End If
Else
Dsp From, "Invalid! " & errMsg, Username, vbRed
GetHeroInfo = vbNullString
Exit Function
End If

GetHeroInfo = Level & "|" & hClass
End Function


Sub herolist_create_database()

Set Catalog = CreateObject("ADOX.Catalog")
Catalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=" & Path

herolist_connect()

Conn.Execute("CREATE TABLE `heroes` (`ID` COUNTER, `name` varchar(30) NOT NULL, `class` varchar(30) NOT NULL, `level` int NOT NULL, `profession` INT)")
End Sub


Sub herolist_connect()

Set Conn = CreateObject ("ADODB.connection")
dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & Path
Conn.ConnectionString = dsn
Conn.Open
End Sub


Function AllowedToUseCommand(myAccess, Command)

If myAccess < Command Then
AllowedToUseCommand = False
Else
AllowedToUseCommand = True
End If
End Function


--------------------
IPB Image

-My Plugins :: Thanks Pyro :)
IPB ImageIPB Image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Style
post Mar 9 2009, 03:19 PM
Post #3


Jr. Member
**

Group: Members
Posts: 89
Joined: 6-April 08
From: Germany
Member No.: 35,572



nice work!
but did you read my last lines?
QUOTE
But i need a search for herolevels. So you can search not only for exact hero level but also for heroes which are near the requested level. (range adjustable via a seperate cmd or at the top of the plugin) e.g. (range 3)
user: .searchlvl 100
Bot: Heroes from level 97 to 103:
Bot: User1: ranger (99), Barbarian (103) | User2: Assassin (100)
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
The-Black-Ninja
post Mar 9 2009, 03:44 PM
Post #4


Pure Sex
********

Group: Moderators
Posts: 7,756
Joined: 13-August 06
Member No.: 7,372



Yeah, I can't do that at the moment though, I just got rid of the profession stuff cause I figured that was the most important, if I did any work on it at all, seeing is how users have to add a profession in order to make a new hero entry and since the map doesn't support professions...well, you get the idea lol I'll try to get on it tonight.


--------------------
IPB Image

-My Plugins :: Thanks Pyro :)
IPB ImageIPB Image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Style
post Mar 9 2009, 06:06 PM
Post #5


Jr. Member
**

Group: Members
Posts: 89
Joined: 6-April 08
From: Germany
Member No.: 35,572



ohh. Ok
just though you didn't read it all.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 14th October 2019 - 08:07 PM
Skin by Andrea
Website Legal Information | Hosted by LunarPages