Ir para conteúdo
  • 0

(resolvido) erro script shop in game


kaleudd

Pergunta

estou com um problema eu um script criado pelo @zipter98,que consiste e comprar um pokémon por x pokémon,até ai tudo bem,mais ao usar /shop list acontece o seguinte erro:

[Warning - ProtocolGame::sendFYIBox] Trying to send an empty or too huge message.

 

creio que seja que adicionei muitos pokemon na lista,segue script:

 

Spoiler

local pokemon = {
    ["Groudon"] = {price = 50, boost = 100},
    ["Kyogre"] = {price = 55, boost = 100},
    ["Abra"] = {price = 55, boost = 100},
    ["Aerodactyl"] = {price = 55, boost = 100},
    ["Alakazam"] = {price = 55, boost = 100},
    ["Arbok"] = {price = 55, boost = 100},
    ["Arcanine"] = {price = 55, boost = 100},
    ["Articuno"] = {price = 55, boost = 100},
    ["Beedrill"] = {price = 55, boost = 100},
    ["Bellsprout"] = {price = 55, boost = 100},
    ["Blastoise"] = {price = 55, boost = 100},
    ["Bulbasaur"] = {price = 55, boost = 100},
    ["Butterfree"] = {price = 55, boost = 100},
    ["Caterpie"] = {price = 55, boost = 100},
    ["Chansey"] = {price = 55, boost = 100},
    ["Charizard"] = {price = 55, boost = 100},
    ["Charmander"] = {price = 55, boost = 100},
    ["Charmeleon"] = {price = 55, boost = 100},
    ["Clefable"] = {price = 55, boost = 100},
    ["Clefairy"] = {price = 55, boost = 100},
    ["Cloyster"] = {price = 55, boost = 100},
    ["Cubone"] = {price = 55, boost = 100},
    ["Dodrio"] = {price = 55, boost = 100},
    ["Doduo"] = {price = 55, boost = 100},
    ["Dragonair"] = {price = 55, boost = 100},
    ["Dugtrio"] = {price = 55, boost = 100},
    ["Electabuzz"] = {price = 55, boost = 100},
    ["Electrode"] = {price = 55, boost = 100},
    ["Fearow"] = {price = 55, boost = 100},
    ["Gengar"] = {price = 55, boost = 100},
    ["Gloom"] = {price = 55, boost = 100},

    --etc
}

function doCorrectString(str)                       --Slicer
    local name = str:explode(" ")
    local final = {}
    
    for _, s in ipairs(name) do
        table.insert(final, s:sub(1, 1):upper()..s:sub(2, #s):lower())
    end
    return table.concat(final, (name[2] and " " or ""))
end

function onSay(cid, words, param)
    local p = param:lower()
    
    if p == "lista" then
        local str = "******** You can buy: ********"
        
        for p_name, info in pairs(pokemon) do
            str = str.."\n-"..p_name.." [+"..info.boost.."] for "..info.price.." premium point(s)."
        end
        
        doPlayerPopupFYI(cid, str)
    elseif pokemon[doCorrectString(p)] then
        local poke = pokemon[doCorrectString(p)]
        
        if getAccountPoints(cid) < poke.price then
            doPlayerSendCancel(cid, "Sorry, you do not have enough points. ["..poke.price.." premium points]")
            return true
        end
        
        doPlayerSendTextMessage(cid, 27, "You successfully bought a "..doCorrectString(p).." [+"..poke.boost.."] for "..poke.price.." premium point(s).")
        doAccountRemovePoints(cid, poke.price)
        addPokeToPlayer(cid, doCorrectString(p), poke.boost, nil, "normal")
    else
        doPlayerSendCancel(cid, "Invalid parameter. Type 'list' to see a list of pokemon you can buy, or type the name of the wished pokemon.")
    end
    return true
end

gostaria de saber se teria como fazer a lista em duas partes,por exemplo o player digita /shop lista,apareçe um popup com os pokémon daquela lista,depois ele digita /shop lista2 e apareçe da lista 2,assim creio que arrumaria o erro,pois aconteçe ao adicionar muitos pokémon em uma só lista,obrigado!

Link para o comentário
Compartilhar em outros sites

15 respostass a esta questão

Posts Recomendados

  • 0

Para evitar que a ordem dos pokémon na lista seja aleatória (ou seja, para que seja mostrada exatamente na ordenação que você configurou), é melhor estruturar a tabela de outra forma:

local pokemon = {    {name = "nome_do_pokémon", price = xxx, boost = xxx},    --etc}

Depois, troque:

if p == "lista" then    local str = "******** You can buy: ********"        for p_name, info in pairs(pokemon) do        str = str.."\n-"..p_name.." [+"..info.boost.."] for "..info.price.." premium point(s)."    end        doPlayerPopupFYI(cid, str)

por:

if p:find("lista") then    local str, n = "******** You can buy: ********", tonumber(p:explode(" ")[2])        if n > math.ceil(#pokemon / 15) then        doPlayerSendCancel(cid, "There are only lists from 1 to "..math.ceil(#pokemon / 15)..".")        return true    end        for i = (15 * (n - 1)) + 1, 15 * n do        local poke = pokemon[i]        if not poke then break end                str = str.."\n-"..poke.name.." [+"..poke.boost.."] for "..poke.price.." premium point(s)."    end        doPlayerPopupFYI(cid, str)

O comando para mostrar a lista será o seguinte:

/comando lista n                --Sendo n o número da lista. Cada lista contém 15 pokémon.

 

Editado por zipter98
Link para o comentário
Compartilhar em outros sites

  • 0
3 minutos atrás, zipter98 disse:

De fato, esta mensagem é muito grande para um FYI.

Troque:

doPlayerPopupFYI(cid, str)

por:

doShowTextDialog(cid, 2160, str)

 

a janela fico esquesita e desajeitada,não teria como fazer como eu pedi será?,tipo /shop lista2

Editado por kaleudd
Link para o comentário
Compartilhar em outros sites

  • 0

erro ao iniciar servidor distro,e com isso o sistema do shop inteiro comando não funfa

 

[05/12/2016 20:34:56] [Error - LuaScriptInterface::loadFile] data/talkactions/scripts/shop.lua:63: '<eof>' expected near 'end'
[05/12/2016 20:34:56] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/shop.lua)
[05/12/2016 20:34:56] data/talkactions/scripts/shop.lua:63: '<eof>' expected near 'end'

 

script:

Spoiler

local pokemon = {
    {name = "Groudon", price = 100, boost = 100},
    {name = "Kyogre", price = 100, boost = 100},
    {name = "Abra", price = 100, boost = 100},
    {name = "Aerodactyl", price = 100, boost = 100},
    {name = "Alakazam", price = 100, boost = 100},
    {name = "Arbok", price = 100, boost = 100},
    {name = "Arcanine", price = 100, boost = 100},
    {name = "Articuno", price = 100, boost = 100},
    {name = "Beedrill", price = 100, boost = 100},
    {name = "Bellsprout", price = 100, boost = 100},
    {name = "Blastoise", price = 100, boost = 100},
    {name = "Bulbasaur", price = 100, boost = 100},
    {name = "Cubone", price = 100, boost = 100},
    {name = "Dugtrio", price = 100, boost = 100},
    {name = "Fearow", price = 100, boost = 100},
    {name = "Charmander", price = 100, boost = 100},
    {name = "Gloom", price = 100, boost = 100},
    --etc
}

function doCorrectString(str)                       --Slicer
    local name = str:explode(" ")
    local final = {}
    
    for _, s in ipairs(name) do
        table.insert(final, s:sub(1, 1):upper()..s:sub(2, #s):lower())
    end
    return table.concat(final, (name[2] and " " or ""))
end

if p:find() == "lista" then
    local str, n = "******** You can buy: ********", tonumber(p:explode(" ")[2])
    
    if n > math.ceil(#pokemon / 15) then
        doPlayerSendCancel(cid, "There are only lists from 1 to "..math.ceil(#pokemon / 15)..".")
        return true
    end
    
    for i = (15 * (n - 1)) + 1, 15 * n do
        local poke = pokemon
        if not poke then break end
        
        str = str.."\n-"..poke.name.." [+"..poke.boost.."] for "..poke.price.." premium point(s)."
    end
    
    doPlayerPopupFYI(cid, str)
    elseif pokemon[doCorrectString(p)] then
        local poke = pokemon[doCorrectString(p)]
        
        if getAccountPoints(cid) < poke.price then
            doPlayerSendCancel(cid, "Sorry, you do not have enough points. ["..poke.price.." premium points]")
            return true
        end
        
        doPlayerSendTextMessage(cid, 27, "You successfully bought a "..doCorrectString(p).." [+"..poke.boost.."] for "..poke.price.." premium point(s).")
        doAccountRemovePoints(cid, poke.price)
        addPokeToPlayer(cid, doCorrectString(p), poke.boost, nil, "normal")
    else
        doPlayerSendCancel(cid, "Invalid parameter. Type 'list' to see a list of pokemon you can buy, or type the name of the wished pokemon.")
    end
    return true
end

 

Link para o comentário
Compartilhar em outros sites

  • 0

Você esqueceu do callback.

Spoiler
local pokemon = {    {name = "Groudon", price = 100, boost = 100},    {name = "Kyogre", price = 100, boost = 100},    {name = "Abra", price = 100, boost = 100},    {name = "Aerodactyl", price = 100, boost = 100},    {name = "Alakazam", price = 100, boost = 100},    {name = "Arbok", price = 100, boost = 100},    {name = "Arcanine", price = 100, boost = 100},    {name = "Articuno", price = 100, boost = 100},    {name = "Beedrill", price = 100, boost = 100},    {name = "Bellsprout", price = 100, boost = 100},    {name = "Blastoise", price = 100, boost = 100},    {name = "Bulbasaur", price = 100, boost = 100},    {name = "Cubone", price = 100, boost = 100},    {name = "Dugtrio", price = 100, boost = 100},    {name = "Fearow", price = 100, boost = 100},    {name = "Charmander", price = 100, boost = 100},    {name = "Gloom", price = 100, boost = 100},    --etc}function doCorrectString(str)                       --Slicer    local name = str:explode(" ")    local final = {}        for _, s in ipairs(name) do        table.insert(final, s:sub(1, 1):upper()..s:sub(2, #s):lower())    end    return table.concat(final, (name[2] and " " or ""))endfunction onSay(cid, words, param)    local p = param:lower()        if p:find("lista") then        local str, n = "******** You can buy: ********", tonumber(p:explode(" ")[2])                if n > math.ceil(#pokemon / 15) then            doPlayerSendCancel(cid, "There are only lists from 1 to "..math.ceil(#pokemon / 15)..".")            return true        end                for i = (15 * (n - 1)) + 1, 15 * n do            local poke = pokemon            if not poke then break end                        str = str.."\n-"..poke.name.." [+"..poke.boost.."] for "..poke.price.." premium point(s)."        end                doPlayerPopupFYI(cid, str)    elseif pokemon[doCorrectString(p)] then        local poke = pokemon[doCorrectString(p)]                if getAccountPoints(cid) < poke.price then            doPlayerSendCancel(cid, "Sorry, you do not have enough points. ["..poke.price.." premium points]")            return true        end                doPlayerSendTextMessage(cid, 27, "You successfully bought a "..doCorrectString(p).." [+"..poke.boost.."] for "..poke.price.." premium point(s).")        doAccountRemovePoints(cid, poke.price)        addPokeToPlayer(cid, doCorrectString(p), poke.boost, nil, "normal")    else        doPlayerSendCancel(cid, "Invalid parameter. Type 'list' to see a list of pokemon you can buy, or type the name of the wished pokemon.")    end    return trueend

 

 

Editado por zipter98
Link para o comentário
Compartilhar em outros sites

  • 0

isso corrigiu agr deu outro,ao digitar o /comando lista 2 ou outra pagina

apareçe na distro

 

Spoiler

[05/12/2016 21:10:03] [Error - TalkAction Interface]
[05/12/2016 21:10:03] data/talkactions/scripts/shop.lua:onSay
[05/12/2016 21:10:03] Description:
[05/12/2016 21:10:03] data/talkactions/scripts/shop.lua:35: bad argument #1 to 'find' (string expected, got no value)
[05/12/2016 21:10:03] stack traceback:
[05/12/2016 21:10:03]     [C]: in function 'find'
[05/12/2016 21:10:03]     data/talkactions/scripts/shop.lua:35: in function <data/talkactions/scripts/shop.lua:32>

 

Link para o comentário
Compartilhar em outros sites

  • 0

agora ao digitar comando lista 2

apareçe

 

[05/12/2016 21:35:06] [Error - TalkAction Interface]
[05/12/2016 21:35:06] data/talkactions/scripts/shop.lua:onSay
[05/12/2016 21:35:06] Description:
[05/12/2016 21:35:06] data/talkactions/scripts/shop.lua:47: attempt to concatenate field 'price' (a nil value)
[05/12/2016 21:35:06] stack traceback:
[05/12/2016 21:35:06]     data/talkactions/scripts/shop.lua:47: in function <data/talkactions/scripts/shop.lua:32>

 

script:

Spoiler

local pokemon = {
    {name = "Groudon", price = 100, boost = 100},
    {name = "Kyogre", price = 100, boost = 100},
    {name = "Abra", price = 100, boost = 100},
    {name = "Aerodactyl", price = 100, boost = 100},
    {name = "Alakazam", price = 100, boost = 100},
    {name = "Arbok", price = 100, boost = 100},
    {name = "Arcanine", price = 100, boost = 100},
    {name = "Articuno", price = 100, boost = 100},
    {name = "Beedrill", price = 100, boost = 100},
    {name = "Bellsprout", price = 100, boost = 100},
    {name = "Blastoise", price = 100, boost = 100},
    {name = "Bulbasaur", price = 100, boost = 100},
    {name = "Cubone", price = 100, boost = 100},
    {name = "Dugtrio", price = 100, boost = 100},
    {name = "Fearow", price = 100, boost = 100},
    {name = "Charmander", price = 100, boost = 100},
    {name = "Gloom", price = 100, boost = 100},
    --etc
}

function doCorrectString(str)                       --Slicer
    local name = str:explode(" ")
    local final = {}
    
    for _, s in ipairs(name) do
        table.insert(final, s:sub(1, 1):upper()..s:sub(2, #s):lower())
    end
    return table.concat(final, (name[2] and " " or ""))
end

function onSay(cid, words, param)
    local p = param:lower()
    
    if p:find("lista") then
        local str, n = "******** You can buy: ********", tonumber(p:explode(" ")[2])
        
        if n > math.ceil(#pokemon / 15) then
            doPlayerSendCancel(cid, "There are only lists from 1 to "..math.ceil(#pokemon / 15)..".")
            return true
        end
        
        for i = (15 * (n - 1)) + 1, 15 * n do
            local poke = pokemon
            if not poke then break end
            
            str = str.."\n-"..poke.name.." [+"..poke.boost.."] for "..poke.price.." premium point(s)."
        end
        
        doPlayerPopupFYI(cid, str)
    elseif pokemon[doCorrectString(p)] then
        local poke = pokemon[doCorrectString(p)]
        
        if getAccountPoints(cid) < poke.price then
            doPlayerSendCancel(cid, "Sorry, you do not have enough points. ["..poke.price.." premium points]")
            return true
        end
        
        doPlayerSendTextMessage(cid, 27, "You successfully bought a "..doCorrectString(p).." [+"..poke.boost.."] for "..poke.price.." premium point(s).")
        doAccountRemovePoints(cid, poke.price)
        addPokeToPlayer(cid, doCorrectString(p), poke.boost, nil, "normal")
    else
        doPlayerSendCancel(cid, "Invalid parameter. Type 'list' to see a list of pokemon you can buy, or type the name of the wished pokemon.")
    end
    return true
end

 

Editado por kaleudd
Link para o comentário
Compartilhar em outros sites

  • 0

Ugh, esqueci de reescrever a parte de baixo do código com base na nova estrutura da tabela. Estou meio enferrujado, desculpe-me.

 

Spoiler
local pokemon = {    {name = "Groudon", price = 100, boost = 100},    {name = "Kyogre", price = 100, boost = 100},    {name = "Abra", price = 100, boost = 100},    {name = "Aerodactyl", price = 100, boost = 100},    {name = "Alakazam", price = 100, boost = 100},    {name = "Arbok", price = 100, boost = 100},    {name = "Arcanine", price = 100, boost = 100},    {name = "Articuno", price = 100, boost = 100},    {name = "Beedrill", price = 100, boost = 100},    {name = "Bellsprout", price = 100, boost = 100},    {name = "Blastoise", price = 100, boost = 100},    {name = "Bulbasaur", price = 100, boost = 100},    {name = "Cubone", price = 100, boost = 100},    {name = "Dugtrio", price = 100, boost = 100},    {name = "Fearow", price = 100, boost = 100},    {name = "Charmander", price = 100, boost = 100},    {name = "Gloom", price = 100, boost = 100},    --etc}function doCorrectString(str)                       --Slicer    local name = str:explode(" ")    local final = {}        for _, s in ipairs(name) do        table.insert(final, s:sub(1, 1):upper()..s:sub(2, #s):lower())    end    return table.concat(final, (name[2] and " " or ""))endfunction onSay(cid, words, param)    local p, poke = param:lower(), {}        if p:find("lista") then        local str, n = "******** You can buy: ********", tonumber(p:explode(" ")[2])                if n > math.ceil(#pokemon / 15) then            doPlayerSendCancel(cid, "There are only lists from 1 to "..math.ceil(#pokemon / 15)..".")            return true        end                for i = (15 * (n - 1)) + 1, 15 * n do            local poke = pokemon            if not poke then break end                        str = str.."\n-"..poke.name.." [+"..poke.boost.."] for "..poke.price.." premium point(s)."        end                doPlayerPopupFYI(cid, str)    else        local poke                for i = 1, #pokemon do            if pokemon[i].name == doCorrectString(p) then                poke = pokemon[i]                break            end        end                if poke then            if getAccountPoints(cid) < poke.price then                doPlayerSendCancel(cid, "Sorry, you do not have enough points. ["..poke.price.." premium points]")                return true            end                        doPlayerSendTextMessage(cid, 27, "You successfully bought a "..poke.name.." [+"..poke.boost.."] for "..poke.price.." premium point(s).")            doAccountRemovePoints(cid, poke.price)            addPokeToPlayer(cid, poke.name, poke.boost, nil, "normal")        else            doPlayerSendCancel(cid, "Invalid parameter. Type 'list' to see a list of pokemon you can buy, or type the name of the wished pokemon.")        end    end    return trueend

 

 

Editado por zipter98
Link para o comentário
Compartilhar em outros sites

  • 0

hehe de boas,deu mais 2 erros,mais agora é pessivel comprar o pokémon normalmente,mais o /comando lista não funciona,após digitalo da o seguinte erro:

[05/12/2016 21:46:54] [Error - TalkAction Interface]
[05/12/2016 21:46:54] data/talkactions/scripts/shop.lua:onSay
[05/12/2016 21:46:54] Description:
[05/12/2016 21:46:54] data/talkactions/scripts/shop.lua:38: attempt to compare number with nil
[05/12/2016 21:46:54] stack traceback:

 

 

[05/12/2016 21:48:47] [Error - TalkAction Interface]
[05/12/2016 21:48:47] data/talkactions/scripts/shop.lua:onSay
[05/12/2016 21:48:47] Description:
[05/12/2016 21:48:47] data/talkactions/scripts/shop.lua:47: attempt to concatenate field 'price' (a nil value)
[05/12/2016 21:48:47] stack traceback:

Editado por kaleudd
Link para o comentário
Compartilhar em outros sites

  • 0

Substitui isto:

Citar
for i = (15 * (n - 1)) + 1, 15 * n do            local poke = pokemon            if not poke then break end                        str = str.."\n-"..poke.name.." [+"..poke.boost.."] for "..poke.price.." premium point(s)."        end

 

Por isso:

Citar

for index = (15 * (n - 1)) + 1, 15 * n do

local poke = pokemon[index]

if not poke then break end

str = str.."\n-"..poke.name.." [+"..poke.boost.."] for "..poke.price.." premium point(s)."

end

 

Link para o comentário
Compartilhar em outros sites

  • 0

Parece que eu tinha feito isso no primeiro código que postei, mas o autor copiou errado, e, como copiei o dele para corrigir, acabei deixando isso passar. lol

Obrigado, mesmo assim.

Editado por zipter98
Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...