Problem with the addon from the game Garry’s Mod

The problem is this: since I don't know lua very well, I don't know how to recover the code. I have a ready-made addon, so to speak, but it has a problem: the site with music (where I got the music from) was updated, and now I need to connect again, but I don't understand how to do it.

Piece of code:

function SearchSong(slf,key)
    session=session+1
    local ses=session
    local srg=string.Replace(slf:GetText()," ","%20")
    LocalPlayer():ConCommand("boombox_search "..slf:GetText())
    list:Clear()
    search = slf:GetText()
    local blockdone=false

    http.Fetch(
    "http://zaycev.net/search.html?query_search="..string.Replace(string.Replace(string.Replace(string.Replace(string.Replace(slf:GetText()," ","%20")," ","+"),"&","%26"),"+","%2B"),"=","%3D"),
 
     function(s)
            if(not IsValid(list))then return end
            if(session~=ses)then return end
            local x,x2,id,key,artist
            x=string.find(s,'list__items')+6
            s=string.sub(s,x)
            while(string.find(s,'url='))do
            if(string.find(s,'url=') >= string.find(s,'item__pic'))then break end
            x=string.find(s,'url=')+6
            s=string.sub(s,x)
            x=string.find(s,"json")+3
            local id="zaycev.net/"..string.sub(s,1,x)
            x=string.find(s,"track__link")+12
            s=string.sub(s,x)
            x=string.find(s,">")
            s=string.sub(s,x)
            x=string.find(s,"<")-1
            local author=string.sub(s,2,x)
            
            x=string.find(s,"_blank")+8
            s=string.sub(s,x)
            x=string.find(s,"<")-1
            local songname=string.sub(s,2,x)
            
            local addsongtolist=true
            for i=1, #bansonglist do
                if string.find(string.lower(author),string.lower(bansonglist[i]))~=nil then
                    blockdone=true
                    addsongtolist=false
                end
                if string.find(string.lower(songname),string.lower(bansonglist[i]))~=nil then
                    blockdone=true
                    addsongtolist=false
                end
            end
            if addsongtolist then addtolistfromzaycev(id, author, songname) end
            
            end
        end,
            function()
            if(session~=ses)then return end
            LocalPlayer():PrintMessage( HUD_PRINTTALK, "[Магнитола Музон-3000] Ошибка при выполнении запроса. Site:zaycev.net")
        end
     )
    function addtolistfromzaycev(id, author, songname)
    http.Fetch(
        "http://"..id,
        function(s)
            s=string.sub(s,16)
            x=string.find(s,"}")-2
            s=string.sub(s,1,x)
            list:AddLine(author,songname).TID=s
        end)
    end

I think this part is responsible for the search, and that's why it doesn't work. Error that comes out: ERROR (20):. URL:'http://873f783cbc5911f2dc9968bbc1","id":16612936,"url":"https://cdndl.zaycev.net/track/16612936/7NRogmXPkqv5buF9nsiiH8eWM9aMak83tiEdEShJLnmiNKA4nxmrZTgLx1z8c818fEsJ3x6ev1JeFBVCMi52akJU2KHXkDQiYdYiRdfqqEFwdXqYzGmCKcrG8n1t5nhAPze7NCe1teB9E6BZPEbN59nsdTNuCQxrQN24ZiLUWks3ypSKyH6wvx1bsyNipyHpDdWxu39fD9vFke9JVAsbLaX483bfjqDwARHDPZF9JAWg9H9bWd57yWZDALri1XESAsBTqS1y2Vv1ui3RzD8wF8UNpiMzwGeXEHVTPEvkB6wce8XWgxntPYD5G31wugCaaXQha3dLzhqNeuPqhXTCCipt4acYAP5dhDGxcwpj37RwidSzMWst'

Sorry for my bad English.

+I changed the way a person wrote to me(thank you very much), but a new problem appeared - it can't find music in Russian, writes: Lua Error:

[ERROR] boombox:520: attempt to perform arithmetic on a nil value

  1. onsuccess - boombox:520
  2. unknown - lua/includes/modules/http.lua:29

http.lua:


local HTTP = HTTP

--[[---------------------------------------------------------
    HTTP Module. Interaction with HTTP.
-----------------------------------------------------------]]
module( "http" )

--[[---------------------------------------------------------

    Get the contents of a webpage.

    Callback should be

    function callback( (args optional), contents, size )

-----------------------------------------------------------]]
function Fetch( url, onsuccess, onfailure, header )

    local request = {
        url         = url,
        method      = "get",
        headers     = header or {},

        success = function( code, body, headers )

            if ( !onsuccess ) then return end

            onsuccess( body, body:len(), headers, code )

        end,

        failed = function( err )

            if ( !onfailure ) then return end

            onfailure( err )

        end
    }

    HTTP( request )

end

function Post( url, params, onsuccess, onfailure, header )

    local request = {
        url         = url,
        method      = "post",
        parameters  = params,
        headers     = header or {},

        success = function( code, body, headers )

            if ( !onsuccess ) then return end

            onsuccess( body, body:len(), headers, code )

        end,

        failed = function( err )

            if ( !onfailure ) then return end

            onfailure( err )

        end
    }

    HTTP( request )

end

--[[

Or use HTTP( table )

local request = {
    url         = "http://pastebin.com/raw.php?i=3jsf50nL",
    method      = "post",

    parameters = {
        id          = "548",
        country     = "England"
    }

    success = function( code, body, headers )

        Msg( "Request Successful\n" )
        Msg( "Code: ", code, "\n" )
        Msg( "Body Length:\n", body:len(), "\n" )
        Msg( "Body:\n", body, "\n" )
        PrintTable( headers )

    end,

    failed = function( reason )
        Msg( "Request failed: ", reason, "\n" )
    end
}

HTTP( request )

--]]

There was also an error with the work:

[Магнитола Музон-3000]: ERROR (20):. URL:'http://b906181834edaf6f0738425728","id":17282269,"url":"https://cdndl.zaycev.net/track/17282269/7rjXpcxVcpkFizTZEEm7Gxa5nD4PFP8EAZVVpNQNn9uH335QHUv1Y2QWDGFoZ4HsEWq3jy4V768gHq32hjaAhezQa4udXmHXAHMugTobg97PzjY1myxufE3mQj7phH8PD8A5CLMiZPaCDAr68fej9bhkgChroTj54nTrUfsPmia6kv48zpxE1HwnG8UTJPMA8t7pQoqHGLDo6fLvdMSS1Xztnow8mGxBDVWYPWP8RocstCDczFKstVpFTcnSR2THiG2Wx8SoTXiABSo2R9DDUxkTZNe7UA16S3sWB3HZE43qEWANQGHuyBKtJtkdkhMzN7XNeQVc9r3sQs3fGPLG5baP1uvd24UDqt6kYbXK7YADUuR2WME'



Read more here: https://stackoverflow.com/questions/64396694/problem-with-the-addon-from-the-game-garrys-mod

Content Attribution

This content was originally published by 7dante7 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: