Quote:
Originally Posted by Weegs
Now I'm lost, it still finds multiple Ids. Could you copy paste the whole script here so I can take a look? Wrap CODE tags around it so it doesn't fill the whole page. We'll get this thing to work
thanks,weegs!
; StopLoss / StopWin / Handcounter
; by _dave_ on 2p2 forums
; ------------- SETTINGS -----------------------------
sn := "shunshixia"
database_name := "HoldemManager" ; <-- change db name if needed
host_address := "127.0.0.1" ; <-- change db host if needed
;sql := "SELECT player_id from players WHERE playername = '" . sn . "';"
pt_id := 53779
stop_loss := 2
stop_win := 2
hand_goal := 30
show_money := 1
show_vpp := 0
stop_loss_sound_effect := "E:\music\junhao.wav"
stop_win_sound_effect := "E:\music\junhao.wav"
hand_goal_sound_effect := "E:\music\junhao.wav"
; ------------- END SETTINGS ------------------------
#NoEnv
#SingleInstance, Force
SendMode Input
FileGetSize, loss_sound, %stop_loss_sound_effect%
if (!loss_sound)
{
Msgbox, stop_loss_sound_effect is not found - please edit script settings
}
FileGetSize, loss_sound, %stop_win_sound_effect%
if (!loss_sound)
{
Msgbox, stop_win_sound_effect is not found - please edit script settings
}
FileGetSize, loss_sound, %hand_goal_sound_effect%
if (!loss_sound)
{
Msgbox, hand_goal_sound_effect is not found - please edit script settings
}
name_version := "Stop Loss - HEM TEST (by _dave_)"
FileGetSize, psqlexe, psql.exe
if (!psqlexe)
{
MsgBox, psql.exe not found!`n`nPlease copy/paste psql.exe from %A_ProgramFiles%\PostgreSQL\8.x\bin to %A_ScriptDir%,`nor add %A_ProgramFiles%\PostgreSQL\8.x\bin to the system $PATH variable.
exit
}
;start_handcounter := 0
;handpcnt := 0
;sql := "SELECT pokerhand_id FROM playerhandscashkeycolumns ORDER BY pokerhand_id DESC LIMIT 1;"
;start_handcounter := psql(sql)
GoSub, resetcount
;Msgbox %start_handcounter%
Gui, 2:Font, bold , Courier
Gui, 2:Add, Text, w170 vhandcount, Hands: 0
;Menu, Tray, Add, Reset, resetcount
if (show_money)
{
Gui, 2:Add, Text, w170 vnetprofits , Money: $0
}
if (show_vpp)
{
Gui, 2:Add, Text, w170 vnetvpp , VPP: 0
}
Gui, 2:Show, w170, %name_version%
SetTimer, track, 15000
;SetTimer, track, Off
return
resetcount:
start_handcounter := 0
handpcnt := 0
sql := "SELECT pokerhand_id FROM playerhandscashkeycolumns ORDER BY pokerhand_id DESC LIMIT 1;"
start_handcounter := psql(sql)
return
track:
;Msgbox, %sn%
sql := "SELECT player_id from players WHERE playername = '" . sn . "';"
pt_id := psql(sql)
;Msgbox, Found player_id for %sn%: %pt_id%
sql := "SELECT COUNT(phckc.pokerhand_id) AS hc FROM playerhandscashkeycolumns phckc WHERE phckc.player_id = " . pt_id . " AND phckc.pokerhand_id > " . start_handcounter . ";"
hc := psql(sql)
info := "Hands: " . hc
GuiControl, 2:,handcount, %info%
;Msgbox, hc: %hc%
;if (show_money || stop_loss > 0 || stop_win > 0)
;{
sql := "SELECT ROUND(SUM((phckc.netamountwon)))/100 AS net FROM playerhandscashkeycolumns phckc WHERE phckc.player_id = " . pt_id . " AND phckc.pokerhand_id > " . start_handcounter . ";"
net := psql(sql)
info := "Money: $" . net
GuiControl, 2:,netprofits, %info%
;Msgbox, net: %net%
;}
/*
if (show_vpp)
{
sql := "SELECT COUNT(phckc.pokerhand_id) AS hc FROM playerhandscashkeycolumns phckc WHERE phckc.rakeamount > 0.39 AND g.game_id = gp.game_id AND gp.player_id = " . pt_id . " AND g.game_id > " . start_handcounter . ";"
vpp := psql(sql)
sql := "SELECT COUNT(phckc.pokerhand_id) AS hc FROM playerhandscashkeycolumns phckc WHERE phckc.rakeamount > 2 AND g.number_of_players <= 5 AND g.game_id = gp.game_id AND gp.player_id = " . pt_id . " AND g.game_id > " . start_handcounter . ";"
vpp2 := psql(sql)
sql := "SELECT COUNT(phckc.pokerhand_id) AS hc FROM playerhandscashkeycolumns phckc WHERE phckc.rakeamount = 3 AND g.number_of_players = 6 AND g.game_id = gp.game_id AND gp.player_id = " . pt_id . " AND g.game_id > " . start_handcounter . ";"
vpp3 := psql(sql)
vpp := vpp + vpp2 + vpp3
info := "VPP: " . vpp
GuiControl, 2:,netvpp, %info%
}
*/
; update titlebar
if (hc > 1)
{
handpcnt := Round((hc / hand_goal)*100, 1)
Gui, 2:Show, NA,%handpcnt%`%`, %hc% Hands Played
}
;check win/loss/goal
if (hc > 1)
{
if (stop_loss > 0)
{
if (net < (stop_loss*-1))
{
TrayTip, STOP LOSS!, Losing too much!`n`nQUIT NOW!
if (StrLen(stop_loss_sound_effect)>1)
{
FileGetSize, loss_sound, %stop_loss_sound_effect%
if (loss_sound)
{
SoundPlay, %stop_loss_sound_effect%
}
}
return
}
}
if (stop_win > 0)
{
if (net > stop_win)
{
TrayTip, STOP WIN!, You have won enough for today!`n`nCongratulations!
if (StrLen(stop_win_sound_effect)>1)
{
FileGetSize, win_sound, %stop_win_sound_effect%
if (win_sound)
{
SoundPlay, %stop_win_sound_effect%
}
}
return
}
}
if (hc > hand_goal)
{
TrayTip, Hand Goal Completed!, Goal: %hand_goal%`nPlayed: %hc%
if (StrLen(hand_goal_sound_effect)>1)
{
FileGetSize, hand_sound, %hand_goal_sound_effect%
if (hand_sound)
{
SoundPlay, %hand_goal_sound_effect%
}
}
}
}
return
; ----------------------------------------------------------------------------
;
; >>>>----- WARNING - READ ALL OF THIS !!! -----<<<<
;
; THERE ARE NO GUARANTEES MADE BY THE AUTHOR OF THIS SCRIPT !!!
;
; USERS ARE EXPECTED TO KNOW WHAT THEY ARE DOING WITH A DATABASE / SQL !!!
;
; ALWAYS MAINTAIN AN UP-TO-DATE BACKUP OF ANY DATABASES YOU VALUE !!!
;
; SQL CAN BE DANGEROUS TO YOUR DATA - BE AWARE OF WHAT YOU ARE DOING !!!
;
; ----------------------------------------------------------------------------
;
; Include this funtion in your AHK scripts to query a PostgreSQL database
; (e.g. PokerTracker databases) and you can use PT data within AHK
;
; Result sets are returned as tab seperated feilds, new-line seperated rows,
; similar to the result of a "ControlGet, List" command. Therefore should be
; easy to process using "Loop, Parse" commands etc.
;
;
; For this to work at all, the PostgreSQL "psql.exe" executable must be
; available to the system. Generally you will need to add the PostgreSQL bin
; folder to the system $PATH environment variable. This is normally:
; "C:\Program Files\PostgreSQL\8.0\bin" on a default install of PostgreSQL.
;
; You can add PostgreSQL to your system's $PATH by the following procedure:
; - Right Click "My Computer"
; - Choose "Properties"
; - Choose "Advanced"
; - Hit "Environment Variables"
; - Select "Path" in the "System Variables" section
; - Hit "Edit"
; - Paste ";C:\Program Files\PostgreSQL\8.0\bin" on the end of "Variable Value"
; - NOTE THE LEADING ; SIGN. Do not paste the "quotes"
; - Hit "OK", Hit "OK", Hit "APPLY", Hit "OK"
; - Reboot the computer
;
; With any luck the above is not necessary - a default installation of Postgres
; does this by itself I think.
;
; You can test if you need to do this by typing "psql" at a DOS command prompt.
; If it works, great. If it errors, you will need to do the above procedure.
;
;
; ----------------------------------------------------------------------------
;
; _______ psql() FUNCCTION ARGUMENTS: _______
;
; sql (REQUIRED): The SQL statement to be executed
;
; database (OPTIONAL): The Postgres database name to be queried.
; If not set, the PokerTracker default "PTPGSQL1" is used.
;
; debug (OPTIONAL): Can be set 0 (zero) or 1 (one). If not set, defaults to zero.
;
; If enabled (1), anny error from the psql command will be
; displayed in a Msgbox, and execution of the calling script
; will be terminated. Useful for experiments with SQL commands.
;
; If zero, errors will be appended to a text file, named after
; the the calling script. Execution of the calling script will
; continue, albeit with no result returned for the function
; call that resulted in the error. Useful when a working script
; may occasionally generate a faulty SQL statement.
;
; host (OPTIONAL): The IP address of the PostgreSQL server to be queried.
; Defaults to "localhost" - same machine as is running the script.
;
; username (optional): Username to connect to the database as. Defaults to the
; superuser, "postgres". This is
psql(sql="", database="", debug=0, host="", username="")
{
global database_name, host_address
; set default values below if you want to use different all the time
if (database = "")
{
if (database_name)
{
database := database_name
}
else
{
database := "PTPGSQL1"
}
}
if (host = "")
{
if (host_address)
{
host := host_address
}
else
{
host := "localhost"
}
}
if (username = "")
{
username := "postgres"
}
; END default value section
stamp = %A_Now%
Random, r, 1000, 9999
file1 := stamp . "_" . A_ScriptName . "_" . r . "_in.txt"
file2 := stamp . "_" . A_ScriptName . "_" . r . "_out.txt"
file3 := stamp . "_" . A_ScriptName . "_" . r . "_error.txt"
command := "psql.exe -A -t -h " . host . " -p 5432 -U " . username . " -d """ . database . """ -f " . file1 . " -o " . file2 . " 2> " . file3 ; . " 2>&1"
;Msgbox, %command%
FileDelete, %file1%
FileDelete, %file2%
FileDelete, %file3%
FileAppend, \f '\t'`n, %file1%
FileAppend, %sql%`n, %file1%
FileAppend, \q`n, %file1%
RunWait, %comspec% /c %command%, , Hide
FileGetSize, errorsize, %file3%
If (errorsize > 0)
{
FileRead, errortext, %File3%
FileRead, errorcause, %File1%
FileDelete, %file1%
FileDelete, %file2%
FileDelete, %file3%
if (debug)
{
Msgbox, %errorcause%`n`n`n%errortext%
ExitApp
}
else
{
FileAppend, %A_Now% - An Error Occured:`n`nInput:`n%errorcause%`n`nOutput:`n%erro rtext%`n`n`n`n, %A_Scriptname%_Error_Log.txt
}
}
FileRead, sqlout, %File2%
FileDelete, %file1%
FileDelete, %file2%
FileDelete, %file3%
StringTrimRight, sqlout, sqlout, 2
return %sqlout%
}