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
> [RESOLVED]End Resulting Plugin Help
Sui(C)ide
post Aug 10 2009, 06:19 AM
Post #1


SuI[C]IdE's DotA Leage Plugin Author
***

Group: Members
Posts: 766
Joined: 23-April 09
From: Australia
Member No.: 49,768



I've almost finished the plugin, but i've got 1 last glitch, and I can't seem to fix it. It looks all correct to me, but it doesn't add the stats up correctly. E.g. sometimes it may add too many to games_played or whatever, etc, etc.

here's the subs.

CODE

'// This sub is for the EndDraw command.
'// DO NOT MODIFY THIS SECTION.

Sub sdl_EndDraw(Username, Message, DspId, Access)

   If Access < sdl_EndDraw_ReqAccess AND Username <> BotVars.Username Then Exit Sub
   If Username = BotVars.Username Then VetoThisMessage
   If IsVouched(Username) = False Then Exit Sub

    sdlConnect()
        Set sdl = sdlConn.Execute("SELECT `Current_game` FROM `Users` WHERE `Username` = '" & Username & "'")
            If NOT (sdl.BOF) AND NOT (sdl.EOF) Then
                InGame = sdl.Fields(0)
                    If InStr(InGame, "Inactive") Then Exit Sub
        Set sdl = sdlConn.Execute("UPDATE `Games` SET `Draw_votes` = Draw_votes + 1, `Overall_votes` = Overall_votes + 1 WHERE `Gamename` = '" & InGame & "'")
        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Current_game` = 'Inactive' WHERE `Username` = '" & Username & "'")
            Dsp DspId, "• " & Username & " has voted draw.", Username, VBWhite
            End If
        CheckDraw(InGame)
    sdlConn.Close
End Sub


'// This sub is for the SentinelWin command.
'// DO NOT MODIFY THIS SECTION.

Sub sdl_SentinelWin(Username, Message, DspId, Access)

   If Access < sdl_ScourgeWin_ReqAccess AND Username <> BotVars.Username Then Exit Sub
   If Username = BotVars.Username Then VetoThisMessage
   If IsVouched(Username) = False Then Exit Sub

    sdlConnect()
        Set sdl = sdlConn.Execute("SELECT `Current_game` FROM `Users` WHERE `Username` = '" & Username & "'")
            If NOT (sdl.BOF) AND NOT (sdl.EOF) Then
                InGame = sdl.Fields(0)
                    If InStr(InGame, "Inactive") Then Exit Sub
        Set sdl = sdlConn.Execute("UPDATE `Games` SET `Sentinel_votes` = Sentinel_votes + 1, `Overall_votes` = Overall_votes + 1 WHERE `Gamename` = '" & InGame & "'")
        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Current_game` = 'Inactive' WHERE `Username` = '" & Username & "'")
            Dsp DspId, "• " & Username & " has voted Sentinel.", Username, VBWhite
            End If
        CheckSentWin(InGame)
    sdlConn.Close
End Sub


'// This sub is for the ScourgeWin command.
'// DO NOT MODIFY THIS SECTION.

Sub sdl_ScourgeWin(Username, Message, DspId, Access)

   If Access < sdl_ScourgeWin_ReqAccess AND Username <> BotVars.Username Then Exit Sub
   If Username = BotVars.Username Then VetoThisMessage
   If IsVouched(Username) = False Then Exit Sub

    sdlConnect()
        Set sdl = sdlConn.Execute("SELECT `Current_game` FROM `Users` WHERE `Username` = '" & Username & "'")
            If NOT (sdl.BOF) AND NOT (sdl.EOF) Then
                InGame = sdl.Fields(0)
                    If InStr(InGame, "Inactive") Then Exit Sub
        Set sdl = sdlConn.Execute("UPDATE `Games` SET `Scourge_votes` = Scourge_votes + 1, `Overall_votes` = Overall_votes + 1 WHERE `Gamename` = '" & InGame & "'")
        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Current_game` = 'Inactive' WHERE `Username` = '" & Username & "'")
            Dsp DspId, "• " & Username & " has voted Scourge.", Username, VBWhite
            End If
        CheckScourgeWin(InGame)
    sdlConn.Close
End Sub


Here's the functions.

CODE

'// This function is for checking if Sentinel has won, and modifies stats accordingly.
'// DO NOT MODIFY THIS SECTION.

Function CheckSentWin(ListedGame)

    Set sdl = sdlConn.Execute("SELECT * FROM `Games` WHERE `Gamename` = '" & ListedGame & "' AND `Sentinel_votes` >= 6")
        If NOT (sdl.BOF) AND NOT (sdl.EOF) Then
    Set sdl = sdlConn.Execute("UPDATE `Games` Set `Result` = 'Sentinel' WHERE `Gamename` = '" & ListedGame & "'")
            Dsp FD, "• " & ListedGame & " has been won by The Sentinel!", Username, VBWhite
    Set sdl = sdlConn.Execute("SELECT * FROM `Games` WHERE `Gamename` = '" & ListedGame & "'")
                SentPlayers = Split(sdl.Fields(3), ", ")
                ScourgePlayers = Split(sdl.Fields(4), ", ")
                    For I = 0 To UBound(SentPlayers)
                        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Current_game` = 'Inactive' WHERE `Username` = '" & SentPlayers(I) & "' OR Username = '" & ScourgePlayers(I) & "'")
                        Set sdl = sdlConn.Execute("SELECT * FROM `Users` WHERE `Username` = '" & SentPlayers(I) & "' OR Username = '" & ScourgePlayers(I) & "'")
                            Games_played = sdl.Fields(8)
                            Wins = sdl.Fields(5)
                            Streak = sdl.Fields(13)
                            Losses = sdl.Fields(6)
                            Experience = sdl.Fields(4)
                        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Games_played` = '" & Games_played + 1 & "' WHERE `Username` = '" & SentPlayers(I) & "' OR Username = '" & ScourgePlayers(I) & "'")
                        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Wins` = '" & Wins + 1 & "', `Streak` = '" & Streak + 1 & "', `Experience` = '" & Experience + 30 & "' WHERE `Username` = '" & SentPlayers(I) & "'")
                        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Experience` = '" & Experience - 30 & "', `Streak` = '0', `Losses` = '" & Losses + 1 & "' WHERE `Username` = '" & ScourgePlayers(I) & "'")
                    Next
        End If
End Function


'// This function is for checking if Scourge has won, and modifies stats accordingly.
'// DO NOT MODIFY THIS SECTION.

Function CheckScourgeWin(ListedGame)

    Set sdl = sdlConn.Execute("SELECT * FROM `Games` WHERE `Gamename` = '" & ListedGame & "' AND `Scourge_votes` >= 6")
        If NOT (sdl.BOF) AND NOT (sdl.EOF) Then
    Set sdl = sdlConn.Execute("UPDATE `Games` Set `Result` = 'Scourge' WHERE `Gamename` = '" & ListedGame & "'")
            Dsp FD, "• " & ListedGame & " has been won by The Scourge!", Username, VBWhite
    Set sdl = sdlConn.Execute("SELECT * FROM `Games` WHERE `Gamename` = '" & ListedGame & "'")
                SentPlayers = Split(sdl.Fields(3), ", ")
                ScourgePlayers = Split(sdl.Fields(4), ", ")
                    For I = 0 To UBound(SentPlayers)
                        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Current_game` = 'Inactive' WHERE `Username` = '" & SentPlayers(I) & "' OR Username = '" & ScourgePlayers(I) & "'")
                        Set sdl = sdlConn.Execute("SELECT * FROM `Users` WHERE `Username` = '" & SentPlayers(I) & "' OR Username = '" & ScourgePlayers(I) & "'")
                            Games_played = sdl.Fields(8)
                            Wins = sdl.Fields(5)
                            Streak = sdl.Fields(13)
                            Losses = sdl.Fields(6)
                            Experience = sdl.Fields(4)
                        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Games_played` = '" & Games_played + 1 & "' WHERE `Username` = '" & SentPlayers(I) & "' OR Username = '" & ScourgePlayers(I) & "'")
                        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Wins` = '" & Wins + 1 & "', `Streak` = '" & Streak + 1 & "', `Experience` = '" & Experience + 30 & "' WHERE `Username` = '" & ScourgePlayers(I) & "'")
                        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Streak` = '0', `Losses` = '" & Losses + 1 & "', `Experience` = '" & Experience - 30 & "' WHERE `Username` = '" & SentPlayers(I) & "'")
                    Next
        End If
End Function


'// This function is for checking if there was a draw, and modifies stats accordingly.
'// DO NOT MODIFY THIS SECTION.

Function CheckDraw(ListedGame)

    Set sdl = sdlConn.Execute("SELECT * FROM `Games` WHERE `Gamename` = '" & ListedGame & "' AND `Draw_votes` >= 6")
        If NOT (sdl.BOF) AND NOT (sdl.EOF) Then
    Set sdl = sdlConn.Execute("UPDATE `Games` Set `Result` = 'Draw' WHERE `Gamename` = '" & ListedGame & "'")
            Dsp FD, "• " & ListedGame & " has been drawn!", Username, VBWhite
    Set sdl = sdlConn.Execute("SELECT * FROM `Games` WHERE `Gamename` = '" & ListedGame & "'")
                SentPlayers = Split(sdl.Fields(3), ", ")
                ScourgePlayers = Split(sdl.Fields(4), ", ")
                    For I = 0 To UBound(SentPlayers)
                        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Current_game` = 'Inactive' WHERE `Username` = '" & SentPlayers(I) & "' OR Username = '" & ScourgePlayers(I) & "'")
                        Set sdl = sdlConn.Execute("SELECT * FROM `Users` WHERE `Username` = '" & SentPlayers(I) & "' OR Username = '" & ScourgePlayers(I) & "'")
                            Games_played = sdl.Fields(8)
                            Draws = sdl.Fields(7)
                        Set sdl = sdlConn.Execute("UPDATE `Users` SET `Games_played` = '" & Games_played + 1 & "', `Draws` = '" & Draws + 1 & "' WHERE `Username` = '" & SentPlayers(I) & "' OR Username = '" & ScourgePlayers(I) & "'")
                    Next
        End If
End Function



Any help PLEASE?

Thanks.


--------------------
IPB Image
Interested in joining an Aus/Nz DotA League? Come by Clan AIDL today, on UWEST.
You may visit our website Here.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Call
post Aug 10 2009, 07:35 AM
Post #2


Posting God
*****

Group: Beta Testers
Posts: 1,423
Joined: 15-June 08
From: Denmark, Copenhagen
Member No.: 38,127



Have you tried debugging?


--------------------
IPB Image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Prince Zero
post Aug 10 2009, 09:01 PM
Post #3


Jr. Member
**

Group: Members
Posts: 38
Joined: 3-February 09
Member No.: 46,352



too much code for nothing

Why dont you make 2 subs that are used for executing a query and for grabbing an objecT? Would make life easier for you.

CODE
Sub SQLexecute(Statement)
    Dim connection
    set connection=CreateObject("ADODB.Connection")
    connection.Provider="Microsoft.Jet.OLEDB.4.0"
    connection.Open Database
    connection.execute Statement
    connection.close
    Set connection = Nothing
End Sub



Sub GetObject(object, SQLstring)
    if(connection.State = adStateClosed) then connection.Open Database
    set object = CreateObject("ADODB.RecordSet")
        object.open SQLstring, Connection
End Sub

Sub CloseObject(object)
    object.close
    set object = nothing
end sub


--------------------
The mind is Power
Power is strength
Strength is Might
Might is Magic
I'm the Mind


yyo this is an imba plugin

Removed annoying long code. -PhiX
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
The-Black-Ninja
post Aug 10 2009, 09:05 PM
Post #4


Pure Sex
********

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



You wouldn't even need that close sub because all you would do is do something like object.close after you're done with it in your sub, provided you made the connection string public and made a sub that opens the connection. FiftyToo will argue with me on that one though; he loves his classes tongue.gif


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

-My Plugins :: Thanks Pyro :)
IPB ImageIPB Image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Sui(C)ide
post Aug 10 2009, 11:35 PM
Post #5


SuI[C]IdE's DotA Leage Plugin Author
***

Group: Members
Posts: 766
Joined: 23-April 09
From: Australia
Member No.: 49,768



Thanks for your 'comments', but they haven't really helped. >.>


--------------------
IPB Image
Interested in joining an Aus/Nz DotA League? Come by Clan AIDL today, on UWEST.
You may visit our website Here.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Call
post Aug 11 2009, 06:43 AM
Post #6


Posting God
*****

Group: Beta Testers
Posts: 1,423
Joined: 15-June 08
From: Denmark, Copenhagen
Member No.: 38,127



QUOTE(Sui(C)ide @ Aug 11 2009, 07:35 AM) *

Thanks for your 'comments', but they haven't really helped. >.>


explain how it didn't help?


--------------------
IPB Image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Sui(C)ide
post Aug 11 2009, 06:48 AM
Post #7


SuI[C]IdE's DotA Leage Plugin Author
***

Group: Members
Posts: 766
Joined: 23-April 09
From: Australia
Member No.: 49,768



I was told to use 2 subs... I know I could do that.. I wasn't shown how / why it's bugging.

P.S. - For whoever can help me with this, how long do you think it would take? (I'm trying to get this league up n running asap, and would like to set a release date.) - I don't want to seem pushy at all.

Thanks.


--------------------
IPB Image
Interested in joining an Aus/Nz DotA League? Come by Clan AIDL today, on UWEST.
You may visit our website Here.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
IAreConnection
post Aug 11 2009, 07:16 AM
Post #8


<3
***

Group: Sr. Members
Posts: 402
Joined: 15-May 06
From: Smoochie's Magic Jungle
Member No.: 4,637



QUOTE(Sui(C)ide @ Aug 11 2009, 08:48 AM) *

I was told to use 2 subs... I know I could do that.. I wasn't shown how / why it's bugging.

P.S. - For whoever can help me with this, how long do you think it would take? (I'm trying to get this league up n running asap, and would like to set a release date.) - I don't want to seem pushy at all.

Thanks.


Their points are that you are over complicating things and you could consolidate most of your code into separate, similar subroutines that will make reading it a lot easier. This will make it so much better for you and us to help complete whatever you want to add, and in the future make modification simple.

Consolidate your code and change it accordingly, and see if you can't find the error yourself. If you still have problems post here and people won't be so reluctant to assist you.

Note: have you tried classes and separate functions for simple queries? like ninja was implying, you can class it up in your script and make it amazingly easy to create and manipulate things.. This is especially useful when you are storing things that share values (wins, losses, scores, etc) because you can create, load and save them with a simple statement.


--------------------
VBScript or Toshley @ Azeroth
Stuff: BCP 2.0 Website
, PyBot, JBLS Server Status
BCP User Forum <-- don't pm me, post there

IPB Image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Sui(C)ide
post Aug 12 2009, 07:03 AM
Post #9


SuI[C]IdE's DotA Leage Plugin Author
***

Group: Members
Posts: 766
Joined: 23-April 09
From: Australia
Member No.: 49,768



I'm not exactly sure where I should split them up, etc. Could you possibly show me?
As for the subs, they seemed fine to me, just not the functions.


EDIT: I had the thought of adding a different function for adding / taking away wins, losses, draws, games played, experience, streak (and any others I can't think of off hand), but would that make it too big?


--------------------
IPB Image
Interested in joining an Aus/Nz DotA League? Come by Clan AIDL today, on UWEST.
You may visit our website Here.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
IAreConnection
post Aug 12 2009, 07:38 AM
Post #10


<3
***

Group: Sr. Members
Posts: 402
Joined: 15-May 06
From: Smoochie's Magic Jungle
Member No.: 4,637



QUOTE(Sui(C)ide @ Aug 12 2009, 09:03 AM) *

I'm not exactly sure where I should split them up, etc. Could you possibly show me?
As for the subs, they seemed fine to me, just not the functions.


Thats not the point, the point is you designed it poorly. Look into classes (and if you think you're not good enough for them and don't want to learn, then this script is bigger than your level of expertise.)

QUOTE
EDIT: I had the thought of adding a different function for adding / taking away wins, losses, draws, games played, experience, streak (and any others I can't think of off hand), but would that make it too big?


It's never too big. You can just make the code smaller. tongue.gif

An example:

CODE

Class clsUserTeam '// Represents a team in my plugin
Public Name '// Team name

Sub SetTeam(teamname)
   Name = teamname '// Now you don't need to set it again unless
          '//its changed, and this object now represents whatever you put here
End Sub

Function Wins()
   '// do some cool sql things to get the team's wins and losses, since
   '// this is a class we don't have to do a thing except call it, we stored
   '// the name so we can build a neat query with no additional params
End Function
End Class

'...

Set someteam = new clsUserTeam
someteam.SetTeam "Team #1"


now the someteam variable is an instance of your class representing "Team #1"...

things like that will make it easier, instead of functions with a lot of parameters that you must call every time. This gets messy and its really not effecient... so use classes, they're cool. smile.gif

Note: my code isn't field tested and don't copy it, its just an example.

Edit: broke the table lulz


--------------------
VBScript or Toshley @ Azeroth
Stuff: BCP 2.0 Website
, PyBot, JBLS Server Status
BCP User Forum <-- don't pm me, post there

IPB Image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Sui(C)ide
post Aug 12 2009, 07:48 AM
Post #11


SuI[C]IdE's DotA Leage Plugin Author
***

Group: Members
Posts: 766
Joined: 23-April 09
From: Australia
Member No.: 49,768



For the most part, I understand that. I'll have to do a little more research on it. As for this current plugin, is it possible (I know this seems like a 'big' ask) for someone to complete this last part? It's been bugging me for a week now, and i'd just be glad to see a basic working version that I can play around with then.

P.S. - A note to whoever codes the end part, I currently have +30 EXP for winners, and -30 EXP for losers.
I had planned to change the +EXP gain a little. I had the idea of For every 1 point you had to your streak, you'd gain a bonus +2 EXP when the game is ended. (I know that's another ask, but it would seem really nice for now). Eventually i'd find out how other leagues calculate experience and add it.

Thanks.


--------------------
IPB Image
Interested in joining an Aus/Nz DotA League? Come by Clan AIDL today, on UWEST.
You may visit our website Here.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Call
post Aug 12 2009, 07:50 AM
Post #12


Posting God
*****

Group: Beta Testers
Posts: 1,423
Joined: 15-June 08
From: Denmark, Copenhagen
Member No.: 38,127



Sui©ide no offense but the plugin your making for day one you've asked me to help and tell you what to type, tell your the bugs basically u just wanted to copy patch everything i seems like i see it u didn't code anything your self?

and you should try your self it's a good practice.


--------------------
IPB Image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Sui(C)ide
post Aug 12 2009, 07:59 AM
Post #13


SuI[C]IdE's DotA Leage Plugin Author
***

Group: Members
Posts: 766
Joined: 23-April 09
From: Australia
Member No.: 49,768



Wtf? I've asked for a few tips with things, none of which I used due to MYSELF finding better ways to do things. The only ones that have helped to my knowledge are TBN, Faedrik.

Btw, The only 'code' you've given me as dodgy, and didn't work.

This post has been edited by Sui(C)ide: Aug 12 2009, 07:59 AM


--------------------
IPB Image
Interested in joining an Aus/Nz DotA League? Come by Clan AIDL today, on UWEST.
You may visit our website Here.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
IAreConnection
post Aug 12 2009, 08:31 AM
Post #14


<3
***

Group: Sr. Members
Posts: 402
Joined: 15-May 06
From: Smoochie's Magic Jungle
Member No.: 4,637



QUOTE(Sui(C)ide @ Aug 12 2009, 09:48 AM) *

For the most part, I understand that. I'll have to do a little more research on it. As for this current plugin, is it possible (I know this seems like a 'big' ask) for someone to complete this last part? It's been bugging me for a week now, and i'd just be glad to see a basic working version that I can play around with then.

P.S. - A note to whoever codes the end part, I currently have +30 EXP for winners, and -30 EXP for losers.
I had planned to change the +EXP gain a little. I had the idea of For every 1 point you had to your streak, you'd gain a bonus +2 EXP when the game is ended. (I know that's another ask, but it would seem really nice for now). Eventually i'd find out how other leagues calculate experience and add it.

Thanks.


We can only point you in the right direction, I doubt anyone wants to finish your script. Either way, I told you what I would have done, so there's no reason you can't elaborate on that.

QUOTE
Suiide no offense but the plugin your making for day one you've asked me to help and tell you what to type, tell your the bugs basically u just wanted to copy patch everything i seems like i see it u didn't code anything your self?


This isn't your shooting gallery.

QUOTE
and you should try your self it's a good practice.


o god hes right.


--------------------
VBScript or Toshley @ Azeroth
Stuff: BCP 2.0 Website
, PyBot, JBLS Server Status
BCP User Forum <-- don't pm me, post there

IPB Image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Sui(C)ide
post Aug 17 2009, 04:47 AM
Post #15


SuI[C]IdE's DotA Leage Plugin Author
***

Group: Members
Posts: 766
Joined: 23-April 09
From: Australia
Member No.: 49,768



I guess i'll try a different function for each database field.

CODE
Function ModSentWins(ByVal Username)

    Set sdl = sdlConn.Execute("SELECT * FROM `Users` WHERE `Username` = '" & Username & "'")
        SWins = sdl.Fields(5)
    Set sdl = sdlConn.Execute("UPDATE `Users` SET `Wins` = '" & SWins + 1 & "' WHERE `Username` = '" & Username & "'")
End Function


This should work nice yeah?


EDIT: I request that someone moves this to the scripting request forums. I would like to request someone to complete this as I cannot.

Thanks.

This has been fixed. Resolved.


--------------------
IPB Image
Interested in joining an Aus/Nz DotA League? Come by Clan AIDL today, on UWEST.
You may visit our website Here.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
The-Black-Ninja
post Aug 17 2009, 05:29 PM
Post #16


Pure Sex
********

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



I have marked this topic as resolved. If you did not receive a satisfactory response, please reply and provide as much detail as possible.


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

-My Plugins :: Thanks Pyro :)
IPB ImageIPB Image
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: 30th October 2014 - 11:29 AM
Skin by Andrea
Website Legal Information | Hosted by LunarPages