CS:GO Steam API and Backpack API

Post gaming related scripts
User avatar
rootmos
Posts: 35
Joined: 11 Mar 2016, 04:38
Location: Sweden
Contact:

CS:GO Steam API and Backpack API

29 Jul 2016, 09:31

Sharing this if anyone is instrested knowing how the Steam API and CSGO backpack API works with AHK! Just a basic example though. :)

AutoHotkey and Steam API:
How to get float value of item and parse the json data so it's readable.

Code: Select all

API_Key	  = ; Enter your Steam API key
Steam64_ID = ; Enter your Steam64 ID
Item_ID	  = ; Enter the Item ID you want to get float values of
defindex  	  =8
SteamURL   :="http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?key=" API_Key "&SteamID=" Steam64_ID ""

ResponseData:=SteamAPI(SteamURL)
Loop
{
	if(JSON(ResponseData,"result.items[" . A_Index . "].id") = "")
		break
	if(JSON(ResponseData,"result.items[" . A_Index . "].id") = Item_ID){
		OuterIndex := A_Index
		Loop
		{
			if(JSON(ResponseData,"result.items[" . OuterIndex . "].attributes[" . A_Index . "].defindex") = "")
				Break
			If (JSON(ResponseData,"result.items[" . OuterIndex . "].attributes[" . A_Index . "].defindex") = defindex)
			{
				Msgbox % JSON(ResponseData,"result.items[" . OuterIndex . "].attributes[" . A_Index . "].float_value") ;We Found it
				ExitApp
			}
		}
	}	
}
ExitApp

SteamAPI(SteamURL)
{
	ComObjError(false)
	ApiObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	ApiObject.SetRequestHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)")
	ApiObject.Open("GET", SteamURL, false)
	ApiObject.Send()
	Return ApiObject.ResponseText
}
Return

Prompt(Message,MessageBoxTitle,Icon) {
	 DllCall("MessageBox","Uint",0,"Str"
		,Message,"Str" 			
		,MessageBoxTitle,"Uint" 
		,Icon) 				
Return
}

json(ByRef js, s, v = "") {
	j = %js%
	Loop, Parse, s, .
	{
		p = 2
		RegExMatch(A_LoopField, "([+\-]?)([^[]+)((?:\[\d+\])*)", q)
		Loop {
			If (!p := RegExMatch(j, "(?<!\\)(""|')([^\1]+?)(?<!\\)(?-1)\s*:\s*((\{(?:[^{}]++|(?-1))*\})|(\[(?:[^[\]]++|(?-1))*\])|"
				. "(?<!\\)(""|')[^\7]*?(?<!\\)(?-1)|[+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:,|$|\})", x, p))
				Return
			Else If (x2 == q2 or q2 == "*") {
				j = %x3%
				z += p + StrLen(x2) - 2
				If (q3 != "" and InStr(j, "[") == 1) {
					StringTrimRight, q3, q3, 1
					Loop, Parse, q3, ], [
					{
						z += 1 + RegExMatch(SubStr(j, 2, -1), "^(?:\s*((\[(?:[^[\]]++|(?-1))*\])|(\{(?:[^{\}]++|(?-1))*\})|[^,]*?)\s*(?:,|$)){" . SubStr(A_LoopField, 1) + 1 . "}", x)
						j = %x1%
					}
				}
				Break
			}
			Else p += StrLen(x)
		}
	}
	If v !=
	{
		vs = "
		If (RegExMatch(v, "^\s*(?:""|')*\s*([+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:""|')*\s*$", vx)
			and (vx1 + 0 or vx1 == 0 or vx1 == "true" or vx1 == "false" or vx1 == "null" or vx1 == "nul"))
			vs := "", v := vx1
		StringReplace, v, v, ", \", All
		js := SubStr(js, 1, z := RegExMatch(js, ":\s*", zx, z) + StrLen(zx) - 1) . vs . v . vs . SubStr(js, z + StrLen(x3) + 1)
	}
	Return, j == "false" ? 0 : j == "true" ? 1 : j == "null" or j == "nul"
	? "" : SubStr(j, 1, 1) == """" ? SubStr(j, 2, -1) : j
}
AutoHotkey and CSGO backpack API:
Get the totalt inventory value any steam user and price check on items.

Code: Select all

IvenSearch   = ; Steam username, example: grenjaeveln
ItemSearch  = ; Full Item name, example: AK-47 | Fuel Injector (Factory New)
ItemURL     := "http://csgobackpack.net/api/GetItemPrice/?currency=USD&id=" ItemSearch "&time=7"
InveURL	  := "http://csgobackpack.net/api/GetInventoryValue/?id=" IvenSearch

ResponseData := GetBackpack(ItemURL)
Loop,0x01
{
	if(json(ResponseData,"success") = "false")
	Break
	if(json(ResponseData,"average_price") is (float))
	Msgbox % "Average Price: " . json(ResponseData,"average_price") . " - " . json(ResponseData,"currency")
		ResponseData = ; empty memory
		Continue
}

ResponseData := GetBackpack(InveURL)
Loop,0x01
{
	if(json(ResponseData,"success") = "false")
	Break
	if(json(ResponseData,"value") is (float))
	Msgbox % "Inventory value: " . json(ResponseData,"value") . " - " . json(ResponseData,"currency")
		ResponseData = ; empty memory
		Continue
}
Return

GetBackpack(URL)
{
	ComObjError(false)
	ApiObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	ApiObject.SetRequestHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)")
	ApiObject.Open("GET", URL, false)
	ApiObject.Send()
	Return ApiObject.ResponseText
}
Return

json(ByRef js, s, v = "") {
	j = %js%
	Loop, Parse, s, .
	{
		p = 2
		RegExMatch(A_LoopField, "([+\-]?)([^[]+)((?:\[\d+\])*)", q)
		Loop {
			If (!p := RegExMatch(j, "(?<!\\)(""|')([^\1]+?)(?<!\\)(?-1)\s*:\s*((\{(?:[^{}]++|(?-1))*\})|(\[(?:[^[\]]++|(?-1))*\])|"
				. "(?<!\\)(""|')[^\7]*?(?<!\\)(?-1)|[+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:,|$|\})", x, p))
				Return
			Else If (x2 == q2 or q2 == "*") {
				j = %x3%
				z += p + StrLen(x2) - 2
				If (q3 != "" and InStr(j, "[") == 1) {
					StringTrimRight, q3, q3, 1
					Loop, Parse, q3, ], [
					{
						z += 1 + RegExMatch(SubStr(j, 2, -1), "^(?:\s*((\[(?:[^[\]]++|(?-1))*\])|(\{(?:[^{\}]++|(?-1))*\})|[^,]*?)\s*(?:,|$)){" . SubStr(A_LoopField, 1) + 1 . "}", x)
						j = %x1%
					}
				}
				Break
			}
			Else p += StrLen(x)
		}
	}
	If v !=
	{
		vs = "
		If (RegExMatch(v, "^\s*(?:""|')*\s*([+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:""|')*\s*$", vx)
			and (vx1 + 0 or vx1 == 0 or vx1 == "true" or vx1 == "false" or vx1 == "null" or vx1 == "nul"))
			vs := "", v := vx1
		StringReplace, v, v, ", \", All
		js := SubStr(js, 1, z := RegExMatch(js, ":\s*", zx, z) + StrLen(zx) - 1) . vs . v . vs . SubStr(js, z + StrLen(x3) + 1)
	}
	Return, j == "false" ? 0 : j == "true" ? 1 : j == "null" or j == "nul"
	? "" : SubStr(j, 1, 1) == """" ? SubStr(j, 2, -1) : j
}
Look at me, I am your god now.

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 27 guests