Ir para conteúdo
  • 0
Drenks

OTClient Error Gym system

Pergunta

Drenks    0
Drenks

 

Olá, alguém pode me ajudar a resolver esse erro? Quando ganhar  o líder não dá a medalha

Base: PDA com source (Pokemon Mysterion Team)

2lse1qv.jpg

Spoiler

local focus = 0
local max_distance = 8
local talk_start = 0
local conv = 0
local fighting = false
local challenger = 0
local afk_limit_time = 30    -- seconds
local afk_time = 0        -- don't change
local battle_turn = 1        -- don't change
local challenger_turn = 0    -- don't change

local pokemons = {
{name = "Geodude", level = 28, extralevel = 12, sex = SEX_MALE, nick = "", ball = "normal"},
{name = "Rhyhorn", level = 27, extralevel = 17, sex = SEX_MALE, nick = "", ball = "normal"},
{name = "Graveler", level = 31, extralevel = 19, sex = SEX_MALE, nick = "", ball = "normal"},
{name = "Onix", level = 40, extralevel = 12, sex = SEX_MALE, nick = "", ball = "normal"},
{name = "Golem", level = 38, extralevel = 18, sex = SEX_MALE, nick = "Golemniso", ball = "normal"},
}


local function doSummonGymPokemon(npc)
    battle_turn = battle_turn + 1
    local this = npc
    if #getCreatureSummons(this) >= 1 or focus == 0 then return true end
    local it = pokemons[battle_turn]
    pokeNpc = doSummonCreature(it.name, getThingPos(this))
    local summon = getCreatureSummons(this)[1]
    local balleffect = pokeballs["normal"].effect
    if it.ball and pokeballs[it.ball] then
        balleffect = pokeballs[it.ball].effect
    end
    doSendMagicEffect(getThingPos(pokeNpc), balleffect)

    setPlayerStorageValue(pokeNpc, 990, this)
    setPlayerStorageValue(pokeNpc, 991, "battle")
    setPlayerStorageValue(pokeNpc, 8595, 1)
    registerCreatureEvent(pokeNpc, "Gym1")
    registerCreatureEvent(pokeNpc, "Gym2")
    registerCreatureEvent(pokeNpc, "Gym3")
    registerCreatureEvent(pokeNpc, "Gym4")
    registerCreatureEvent(pokeNpc, "Gym5")
    setPlayerStorageValue(this, 990, 1)
    addEvent(adjustWildPoke, 15, pokeNpc, it.optionalLevel)
    mgo = gobackmsgs[math.random(1, #gobackmsgs)].go:gsub("doka", it.name)
    doCreatureSay(this, mgo, 1)
    fighting = true
end

local function doWinDuel(cid, npc)
    if not isCreature(cid) then return true end
    local this = npc
    local a = gymbadges[getCreatureName(this)] + 8
    doCreatureSay(npc, "You won the duel! Congratulations, take this "..getItemNameById(a - 8).." as a prize.", 1)
    local b = getPlayerItemById(cid, true, a)
    if b.uid > 0 then doTransformItem(b.uid, b.itemid - 8) end
    doPlayerSendCancel(cid, "#getBadges# "..getCreatureName(this).." "..getPlayerItemCount(cid, gymbadges[getCreatureName(this)]))
end

function onCreatureSay(cid, type, msg)
    local msg = string.lower(msg)

    if focus == cid then
        talk_start = os.clock()
    end

    if msgcontains(msg, 'hi') and focus == 0 and getDistanceToCreature(cid) <= 4 then
        focus = cid
        talk_start = os.clock()
        conv = 1
        selfSay("Hello "..getCreatureName(cid)..", my name is Blaine and I'm Cinnabar's Gym Leader. How may I help you?")
        return true
    end

    if isDuelMsg(msg) and conv == 1 and focus == cid then
        --if getPlayerItemCount(cid, gymbadges[getCreatureName(getThis())]) >= 1 then
            --selfSay("You have already won my Volcano Badge, maybe some other day we can fight.")
            --focus = 0
        --return true
        --end

         if not hasPokemon(cid) then
             selfSay("To battle agains't a gym leader you need pokemons.")
        return true
         end

        selfSay("You are challenging me to a battle. It will be a "..#pokemons.." pokemon limit battle, let's start?")
        conv = 2

    return true
    end

    if isConfirmMsg(msg) and conv == 2 and focus == cid then
        challenger = focus
        setPlayerStorageValue(cid, 990, 1)
        setPlayerStorageValue(cid, 999, 1)
        if #getCreatureSummons(cid) >= 1 then
        local pk = getCreatureSummons(cid)[1]
        setPlayerStorageValue(pk, 990, 1)
        end
        selfSay("Yea, let's fight!")
        talk_start = os.clock()
        setPlayerStorageValue(getThis(), 990, 1)
        addEvent(doSummonGymPokemon, 5, getThis())
        conv = 3
    return true
    end

    if isNegMsg(msg) and conv == 2 and focus == cid then
        focus = 0
        selfSay("It is better for you to refuse a battle against me!")
    return true
    end

    local function doRemove(npc)
    local it = pokemons[battle_turn]
        local balleffect = pokeballs["normal"].effect
    if it.ball and pokeballs[it.ball] then
        balleffect = pokeballs[it.ball].effect
    end
    doSendMagicEffect(getThingPos(pokeNpc), balleffect)
    doRemoveCreature(pokeNpc)
    end

    if msgcontains(msg, 'bye') and focus == cid then
        selfSay('Bye and do your best trainer!')
        setPlayerStorageValue(focus, 990, -1)
        setPlayerStorageValue(focus, 999, -1)
        if #getCreatureSummons(focus) >= 1 then
        local pk = getCreatureSummons(focus)[1]
        setPlayerStorageValue(pk, 990, -1)
        end
    doSendMagicEffect(getThingPos(pokeNpc), balleffect)
    doRemoveCreature(pokeNpc)
        focus = 0
    return true
    end
end

local afk_warning = false

function checkPoke(player, poke)

end

function onThink()

    if focus == 0 then
        selfTurn(2)
        fighting = false
        challenger = 0
        challenger_turn = 0
        battle_turn = 0
        afk_time = 0
        afk_warning = false
        setPlayerStorageValue(getThis(), 990, -1)
        return true
    else
        if not isCreature(focus) then
            focus = 0
            return true
        end
        if fighting then
            talk_start = os.clock()

            if #getCreatureSummons(challenger) >= 1 then
                if pokeChalenger == nil then
                    pokeChalenger = getCreatureName(getCreatureSummons(challenger)[1])
                    afk_time = 0
                    challenger_turn = challenger_turn + 1
                elseif pokeChalenger == getCreatureName(getCreatureSummons(challenger)[1]) then
                    afk_time = 0
                else
                    afk_time = 0
                    challenger_turn = challenger_turn + 1
                    pokeChalenger = getCreatureName(getCreatureSummons(challenger)[1])
                end
            else
                    afk_time = afk_time + 0.5
            end

            if afk_time > afk_limit_time then
                setPlayerStorageValue(focus, 990, -1)
        setPlayerStorageValue(focus, 999, -1)
        doRemoveCreature(pokeNpc)
                                  focus = 0
                selfSay("I have waited too long, come back when you are ready!")
            return true
            end

            if not afk_warning and afk_time > afk_limit_time / 2 then
                selfSay("Where's your pokemon? Let's fight!")
                afk_warning = true
            end


            if getPlayerStorageValue(getThis(), 990) == -1 then
                if battle_turn >= #pokemons then
                    addEvent(doWinDuel, 1000, focus, getThis())
                    setPlayerStorageValue(focus, 990, -1)
                    focus = 0
                return true
                end
                setPlayerStorageValue(getThis(), 990, 1)
                addEvent(doSummonGymPokemon, 1000, getThis())
            end

            if challenger_turn >= 7 or challenger_turn > #pokemons then
                selfSay("You lost our duel! Maybe some other time you'll defeat me.")
                setPlayerStorageValue(focus, 990, -1)
                focus = 0
            return true
            end
        end

        local npcpos = getThingPos(getThis())
        local focpos = getThingPos(focus)

        if npcpos.z ~= focpos.z then
            setPlayerStorageValue(focus, 990, -1)
            focus = 0
            selfSay("Bye then.")
            return true
        end

        if (os.clock() - talk_start) > 30 then
            selfSay("Good bye and keep training!")
            setPlayerStorageValue(focus, 990, -1)
            focus = 0
        end

        if getDistanceToCreature(focus) > max_distance then
            setPlayerStorageValue(focus, 990, -1)
        setPlayerStorageValue(focus, 999, -1)
            if #getCreatureSummons(focus) >= 1 then
        local pk = getCreatureSummons(focus)[1]
        setPlayerStorageValue(pk, 990, -1)
        end
        doRemoveCreature(pokeNpc)
            focus = 0
    selfSay("You were strong enough to win this battle!")
        return true
        end

        local dir = doRedirectDirection(getDirectionTo(npcpos, focpos))
        selfTurn(dir)
    end
return true
end

 

Editado por Drenks

Compartilhar este post


Link para o post
Compartilhar em outros sites

5 respostass a esta questão

Recommended Posts

  • 0
Drenks    0
Drenks

troquei otclient sem editar 

Compartilhar este post


Link para o post
Compartilhar em outros sites
  • 0
Aralom    9
Aralom

Olá @Drenks
Este sistema é composto por duas etapas.

1. O Client lê as informações do jogador, se o jogador tem x informação necessária ele disponibiliza a insígnia. (A imagem fica clara).

Poste aqui embaixo o seguinte arquivo para analisarmos qual informação que ele precisa para disponibilizar a insígnia, o arquivo se encontra na pasta do seu OTClient. /Modules/game_skills/skills.lua [Poste o Skills.lua].

2. O NPC Adicionar x Storage ao jogador quando ele vence o Ginásio.

 Precisamos identificar qual a storage que o NPC está adicionando ao jogador para validar se é a mesma que o Client está efetuando a consulta. Se possível poste o npc.lua localizado na pasta do seu server/data/npcs/scripts/nomedonpc.lua para verificarmos.

 

Compartilhar este post


Link para o post
Compartilhar em outros sites
  • 0
Drenks    0
Drenks

 

o script esta acima. 

Skills.lua

Spoiler

local badges = {
[1] = 'boulder_badge',
[2] = 'cascade_badge',
[3] = 'thunder_badge',
[4] = 'rainbow_badge',
[5] = 'marsh_badge',
[6] = 'soul_badge',
[7] = 'volcano_badge',
[8] = 'earth_badge',
}

skillsWindow = nil
skillsButton = nil

function init()
  connect(LocalPlayer, {
    onExperienceChange = onExperienceChange,
    onLevelChange = onLevelChange,
    onStaminaChange = onStaminaChange,
    onSkillChange = onSkillChange,
    onBaseSkillChange = onBaseSkillChange
  })
  ProtocolGame.registerExtendedOpcode(102, function(protocol, opcode, buffer) onPokemonSkillChange(protocol, opcode, buffer) end)

  connect(g_game, {
    onGameStart = refresh,
    onGameEnd = offline
  })

  skillsButton = modules.client_topmenu.addRightGameToggleButton('skillsButton', tr('Skills') .. ' (Ctrl+S)', '/images/topbuttons/skills', toggle)
  skillsButton:setWidth(35)
  skillsButton:setOn(true)
  skillsWindow = g_ui.loadUI('skills', modules.game_interface.getRightPanel())

  g_keyboard.bindKeyDown('Ctrl+S', toggle)

  refresh()
  skillsWindow:setup()
end

function terminate()
  disconnect(LocalPlayer, {
    onExperienceChange = onExperienceChange,
    onLevelChange = onLevelChange,
    onStaminaChange = onStaminaChange,
    onSkillChange = onSkillChange,
    onBaseSkillChange = onBaseSkillChange
  })
  ProtocolGame.unregisterExtendedOpcode(102)

  disconnect(g_game, {
    onGameStart = refresh,
    onGameEnd = offline
  })

  g_keyboard.unbindKeyDown('Ctrl+S')
  skillsWindow:destroy()
  skillsButton:destroy()
end

function expForLevel(level)
  return math.floor((50*level*level*level)/3 - 100*level*level + (850*level)/3 - 200)
end

function expToAdvance(currentLevel, currentExp)
  return expForLevel(currentLevel+1) - currentExp
end

function setSkillBase(id, value, baseValue)
  if baseValue <= 0 or value < 0 then
    return
  end
  local skill = skillsWindow:recursiveGetChildById(id)
  local widget = skill:getChildById('value')

  if value > baseValue then
    widget:setColor('#008b00') -- green
    skill:setTooltip(baseValue .. ' +' .. (value - baseValue))
  elseif value < baseValue then
    widget:setColor('#b22222') -- red
    skill:setTooltip(baseValue .. ' ' .. (value - baseValue))
  else
    widget:setColor('#bbbbbb') -- default
    skill:removeTooltip()
  end
end

function setSkillName(id, name)
  local skill = skillsWindow:recursiveGetChildById(id)
  local widget = skill:getChildById('name')
  widget:setText(name)
end

function setSkillValue(id, value)
  local skill = skillsWindow:recursiveGetChildById(id)
  local widget = skill:getChildById('value')
  widget:setText(value)
end

function setSkillPercent(id, percent, tooltip)
  local skill = skillsWindow:recursiveGetChildById(id)
  local widget = skill:getChildById('percent')
  widget:setPercent(math.floor(percent))

  if tooltip then
    widget:setTooltip(tooltip)
  end
end

function refresh()
  local player = g_game.getLocalPlayer()
  if not player then return end

  if expSpeedEvent then expSpeedEvent:cancel() end
  expSpeedEvent = cycleEvent(checkExpSpeed, 30*1000)

  onExperienceChange(player, player:getExperience())
  onLevelChange(player, player:getLevel(), player:getLevelPercent())
  onStaminaChange(player, player:getStamina())

  for i=0,6 do
    onSkillChange(player, i, player:getSkillLevel(i), player:getSkillLevelPercent(i))
    onBaseSkillChange(player, i, player:getSkillBaseLevel(i))
  end

  g_game.getProtocolGame():sendExtendedOpcode(102, 'refresh')

  skillsWindow:setContentMinimumHeight(50)
  skillsWindow:setContentMaximumHeight(330)
end

function offline()
  if expSpeedEvent then expSpeedEvent:cancel() expSpeedEvent = nil end
end

function toggle()
  if skillsButton:isOn() then
    skillsWindow:close()
    skillsButton:setOn(false)
  else
    skillsWindow:open()
    skillsButton:setOn(true)
  end
end

function checkExpSpeed()
  local player = g_game.getLocalPlayer()
  if not player then return end

  local currentExp = player:getExperience()
  local currentTime = g_clock.seconds()
  if player.lastExps ~= nil then
    player.expSpeed = (currentExp - player.lastExps[1][1])/(currentTime - player.lastExps[1][2])
    onLevelChange(player, player:getLevel(), player:getLevelPercent())
  else
    player.lastExps = {}
  end
  table.insert(player.lastExps, {currentExp, currentTime})
  if #player.lastExps > 30 then
    table.remove(player.lastExps, 1)
  end
end

function onMiniWindowClose()
  skillsButton:setOn(false)
end

function onSkillButtonClick(button)
  local percentBar = button:getChildById('percent')
  if percentBar then
    percentBar:setVisible(not percentBar:isVisible())
    if percentBar:isVisible() then
      button:setHeight(21)
      skillsWindow:setHeight(skillsWindow:getHeight() + 6)
      skillsWindow:setContentMaximumHeight((skillsWindow:getMaximumHeight() - 25) + 6)
    else
      button:setHeight(21 - 6)
      skillsWindow:setHeight(skillsWindow:getHeight() - 6)
      skillsWindow:setContentMaximumHeight((skillsWindow:getMaximumHeight() - 25) - 6)
    end
  end
end

function onExperienceChange(localPlayer, value)
  setSkillValue('experience', value)
end

function onLevelChange(localPlayer, value, percent)
  setSkillName('level', localPlayer:getName())
  setSkillValue('level', value)
  level = value
  local text = tr('You have %s percent to go', 100 - percent) .. '\n' ..
               tr('%s of experience left', expToAdvance(localPlayer:getLevel(), localPlayer:getExperience()))

  if localPlayer.expSpeed ~= nil then
     local expPerHour = math.floor(localPlayer.expSpeed * 3600)
     if expPerHour > 0 then
        local nextLevelExp = expForLevel(localPlayer:getLevel()+1)
        local hoursLeft = (nextLevelExp - localPlayer:getExperience()) / expPerHour
        local minutesLeft = math.floor((hoursLeft - math.floor(hoursLeft))*60)
        hoursLeft = math.floor(hoursLeft)
        text = text .. '\n' .. tr('%d of experience per hour', expPerHour)
        text = text .. '\n' .. tr('Next level in %d hours and %d minutes', hoursLeft, minutesLeft)
     end
  end

  setSkillPercent('experience', percent, text)
end

function onStaminaChange(localPlayer, stamina)
  local hours = math.floor(stamina / 60)
  local minutes = stamina % 60
  if minutes < 10 then
    minutes = '0' .. minutes
  end
  local percent = math.floor(100 * stamina / (42 * 60)) -- max is 42 hours

  setSkillValue('stamina', hours .. ":" .. minutes)
end

function onSkillChange(localPlayer, id, level, percent)
  if not skillsWindow:recursiveGetChildById('skillId' .. id) then return end
  setSkillValue('skillId' .. id, level)
  setSkillPercent('skillId' .. id, percent, tr('You have %s percent to go', 100 - percent))

  onBaseSkillChange(localPlayer, id, localPlayer:getSkillBaseLevel(id))
end

function onBaseSkillChange(localPlayer, id, baseLevel)
  if not skillsWindow:recursiveGetChildById('skillId' .. id) then return end
  setSkillBase('skillId'..id, localPlayer:getSkillLevel(id), baseLevel)
end

function onPokemonSkillChange(protocol, opcode, buffer)
  for id=0,7 do
    setSkillValue('pokemonSkillId' .. id, string.explode(buffer, '|')[id+2])
    skillsWindow:recursiveGetChildById('level'):setIcon('/images/game/clan/' .. string.explode(buffer, '|')[1])
  end
  for i=1,8 do
    if tonumber(string.explode(string.explode(buffer, '|')[10], ';')) == 0 then
      skillsWindow:recursiveGetChildById('pokemonSkillId8'):getChildByIndex(i):setImageSource('/images/game/badges/'..badges..'_off')
    else
      skillsWindow:recursiveGetChildById('pokemonSkillId8'):getChildByIndex(i):setImageSource('/images/game/badges/'..badges..'_on')
    end
  end
end
 

 

Editado por Drenks

Compartilhar este post


Link para o post
Compartilhar em outros sites
  • 0
Aralom    9
Aralom

Certo, aparentemente o jogador ganha a Storage 990, 1 quando vence o Brock.

O Script do Client está consultando o extendedopcode 102.

O servidor pode estar enviando a storage 990 por este opcode para o Client. 

Esta informação é registrada no creaturescripts do servidor. data/creaturescripts/scripts/extendedopcodes.lua

 

Consegue abrir este arquivo extendedopcodes.lua e verificar se está enviando a storage 990 no extendedopcode 102? (também é registrado em login.lua)
Há algum outro arquivo de Badges no OTC?

Eu não costumo mexer com servidores de Pokémon.

Compartilhar este post


Link para o post
Compartilhar em outros sites
  • 0
Majesty    1755
Majesty

O autor do tópico resolveu a questão por conta própria e postou a solução. Este tópico está fechado agora. Se você tiver outras perguntas, crie um novo tópico.

Compartilhar este post


Link para o post
Compartilhar em outros sites
Visitante
Este tópico está impedido de receber novos posts.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×