Page 5 of 5 FirstFirst ... 3 4 5
Results 41 to 46 of 46

Thread: anyone managed to use CreateHTTPRequest?

  1. #41
    Basic Member
    Join Date
    Dec 2016
    Posts
    731
    Wrote a quick Player Update data population function as an example. Here is the function:

    Code:
    dkjson = require( "game/dkjson" )
    
    local function dumpHeroInfo( hHero )
        if not ValidTarget(hHero) then return "{}" end
        local data = {}
        
        data.Level      = hHero:GetLevel()
        data.Health     = hHero:GetHealth()
        data.MaxHealth  = hHero:GetMaxHealth()
        data.HealthReg  = hHero:GetHealthRegen()
        data.Mana       = hHero:GetMana()
        data.MaxMana    = hHero:GetMaxMana()
        data.ManaReg    = hHero:GetManaRegen()
        data.Gold       = hHero:GetGold()
        data.AP         = hHero:GetAbilityPoints()
        data.MS         = hHero:GetCurrentMovementSpeed()
        
        local loc = hHero:GetLocation()
        data.X          = loc.x
        data.Y          = loc.y
        data.Z          = loc.z
        
        local items = {}
        for iInvIndex = 0, 15, 1 do
            local hItem = hHero:GetItemInSlot(iInvIndex)
            if hItem ~= nil then
                local str = hItem:GetName()
                local numCharges = hItem:GetCurrentCharges()
                if numCharges > 1 then
                    str = str .. '_' .. numCharges
                end
                table.insert(items, str)
            end
        end
        data.Items      = items
    
        local json = dkjson.encode(data)
        return json
    end
    The JSON packet that is sent:
    Code:
    Sending Player Update: {"Type": "P2", "Time": 3415.7595214844, "Data": {"ManaReg":24.209999084473,"Level":1,"MaxHealth":640,"Health":640,"HealthReg":26.919998168945,"Gold":625,"Z":512,"Mana":240,"AP":1,"X":-6700,"Y":-6700.00390625,"MS":315,"Items":[],"MaxMana":240}}

  2. #42

  3. #43
    Basic Member
    Join Date
    Oct 2017
    Posts
    7
    nostrademous or ChrisC, have you guys tried using the CreateHTTPRequest recently? Using n's simple server example on Page 2 I was not able to see the results from the Send callback function. The server gets the POST request, and seems to send back a packet, but I wasn't able to see any response from the callback function which prints out "GET response" (etc).

    I'm wondering if there were any changes to the API. I'm putting the logic in bot_generic.lua as well, instead of bot_<name>.

  4. #44
    Basic Member
    Join Date
    Dec 2016
    Posts
    731
    @jmadill they changed it to CreateRemoteHTTPRequest() I believe for non-local calls.

  5. #45
    Basic Member
    Join Date
    Oct 2017
    Posts
    7
    Thanks for answering.. we were using a local request. Also tried using CreateRemoteHTTPRequest, and didn't have any luck.

  6. #46
    Basic Member
    Join Date
    Dec 2016
    Posts
    731
    @jmadill oh, btw, only POST requests are supported with Dota 2, no GET.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •