Ir para conteúdo
  • 0
N0mad

OTClient Barra de life do pokémon

Pergunta

N0mad    1
N0mad

Fala galera linda do meu coração tudo certo?
Então estou com um seguinte problema é um modulo de inventario voltado a poketibia, consegui adaptar parte dele ao meu servidor porem a barra de life do pokémon estou tendo alguns problemas e não consigo fazer ela funcionar:

O código do inventario:

 

InventoryPokemon = {
  [InventorySlotHead] = "HeadSlot",
  [InventorySlotNeck] = "NeckSlot",
  [InventorySlotBack] = "BackSlot",
  [InventorySlotBody] = "BodySlot",
  [InventorySlotRight] = "RightSlot",
  [InventorySlotLeft] = "LeftSlot",
  [InventorySlotLeg] = "LegSlot",
  [InventorySlotFeet] = "FeetSlot",
  [InventorySlotFinger] = "FingerSlot",
  [InventorySlotAmmo] = "AmmoSlot"
}

local pbs = {}
local duelIcon = nil
local bagIcon = nil
local fishingIcon = nil
local pokedexIcon = nil
local ropeIcon = nil
local badgeIcon = nil
local currentSlot = 0
inventoryWindow = nil
inventoryPokemon = nil
pokemonButton = nil
purseButton = nil
healthPokemon = nil
pokeHealthTooltip = 'Your pokemon health is %d out of %d.'
pokeHappyTooltip = 'Your pokemon amizade is %d out of %d.'
local icons = {}
local namesPokes = ''

function init()
  connect(LocalPlayer, { onInventoryChange = onInventoryChange })
  connect(g_game, 'onTextMessage', onPokeHealthChange)
  connect(g_game, { onGameStart = refresh })
  connect(g_game, 'onTextMessage', onPokeHealthChange)
  connect(g_game, 'onTextMessage', getParams)
  connect(g_game, 'onTextMessage', onPokes)
  connect(g_game, 'onTextMessage', onPokesLife)
  g_keyboard.bindKeyDown('Ctrl+I', toggle)

  pokemonButton = modules.client_topmenu.addRightGameToggleButton('pokemonButton', ('Inventario') .. ' (Ctrl+I)', '/images/topbuttons/inventory', toggle)
  pokemonButton:setOn(true)
  inventoryWindow = g_ui.loadUI('pokemon', modules.game_interface.getRightPanel())
  inventoryWindow:disableResize()
  inventoryPokemon = inventoryWindow:getChildById('contentsPanel')
  
  purseButton = inventoryPokemon:getChildById('purseButton')
  local function purseFunction()
    local purse = g_game.getLocalPlayer():getInventoryItem(InventorySlotPurse)
    if purse then
      g_game.use(purse)
    end
  end
  purseButton.onClick = purseFunction
  refresh()

  inventoryWindow:setup()
end

function terminate()
  disconnect(LocalPlayer, { onInventoryChange = onInventoryChange })
  disconnect(g_game, { onGameStart = refresh })
  disconnect(g_game, 'onTextMessage', onPokeHealthChange)
  disconnect(g_game, 'onTextMessage', getParams)
    disconnect(g_game, 'onTextMessage', onPokes)
	disconnect(g_game, 'onTextMessage', onPokesLife)
  g_keyboard.unbindKeyDown('Ctrl+I')

  inventoryWindow:destroy()
  pokemonButton:destroy()
end

function getParams(mode, text)
if not g_game.isOnline() then return end
   if mode == MessageModes.Failure then 
      if string.find(text, "InfoClosed") then
      hide()
      elseif string.sub(text, 1, 8) == "#NewInfo" then
         sendPokeInfo(text)
   end
end
end

function doisNumerosDpsDoPonto(n)
    return string.format( "%.2f", n)
end

function sendPokeInfo(text)
boost = inventoryWindow:recursiveGetChildById('boost')
happy = inventoryWindow:recursiveGetChildById('happy')
if not g_game.isOnline() then return end
inventoryWindow:setVisible(true)
local t = string.explode(text, ",")

icon = inventoryWindow:recursiveGetChildById('iconpoke')
icon:setImageSource('pokes/'..t[2]..'.png')

local happ= tonumber(t[3])
local maxHapp= tonumber(t[4])
happy:setText(doisNumerosDpsDoPonto(happ).. ' / ' ..doisNumerosDpsDoPonto(maxHapp)) 
inventoryWindow:recursiveGetChildById("happy"):setTooltip(tr(pokeHappyTooltip, happ, maxHapp))
happy:setValue(happ, 0, maxHapp)

end

function refresh()
  local player = g_game.getLocalPlayer()
  for i = InventorySlotFirst, InventorySlotPurse do
    if g_game.isOnline() then
      onInventoryChange(player, i, player:getInventoryItem(i))
    else
      onInventoryChange(player, i, nil)
    end
  end
  if not player then return end
  purseButton:setVisible(g_game.getFeature(GamePurseSlot))
end

function toggle()
  if pokemonButton:isOn() then
    inventoryWindow:hide()
    pokemonButton:setOn(false)
  else
    inventoryWindow:show()
    pokemonButton:setOn(true)
  end
end

function onMiniWindowClose()
  pokemonButton:setOn(false)
end


-- hooked events
function onInventoryChange(player, slot, item, oldItem)
  if slot > InventorySlotPurse then return end

  if slot == InventorySlotPurse then
    if g_game.getFeature(GamePurseSlot) then
      purseButton:setEnabled(item and true or false)
    end
    return
  end

  local itemWidget = inventoryPokemon:getChildById('slot' .. slot)
  if item then
    itemWidget:setStyle('Item')
    itemWidget:setItem(item)
  else
    itemWidget:setStyle(InventoryPokemon[slot])
    itemWidget:setItem(nil)
  end
end

function startChooseItem(releaseCallback)
  if not releaseCallback then
    error("No mouse release callback parameter set.")
  end
  local mouseGrabberWidget = g_ui.createWidget('UIWidget')
  mouseGrabberWidget:setVisible(false)
  mouseGrabberWidget:setFocusable(false)

  connect(mouseGrabberWidget, { onMouseRelease = releaseCallback })
  
  mouseGrabberWidget:grabMouse()
  g_mouse.pushCursor('target')
end

function onClickWithMouse(self, mousePosition, mouseButton)
  local item = nil
  if mouseButton == MouseLeftButton then
    local clickedWidget = modules.game_interface.getRootPanel():recursiveGetChildByPos(mousePosition, false)
    if clickedWidget then
      if clickedWidget:getClassName() == 'UIMap' then
        local tile = clickedWidget:getTile(mousePosition)
        if tile then
          if currentSlot == 1 then
             item = tile:getGround()
          else
              local thing = tile:getTopMoveThing()
              if thing and thing:isItem() then
                 item = thing
              else
                 item = tile:getTopCreature()
              end
          end
        elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
           item = clickedWidget:getItem()
        end
      end
    end
  end
    if item then
       if currentSlot == 4 and not item:isPlayer() then
          modules.game_textmessage.displayFailureMessage('Use it only in players!')
       else   
          local player = g_game.getLocalPlayer()               --2  --6 pokedex
          g_game.useInventoryItemWith(player:getInventoryItem(currentSlot):getId(), item) 
       end
    end
  g_mouse.popCursor()
  self:ungrabMouse()
  self:destroy()
end

function toggleBagIcon()            
   if bagIcon:isOn() then
      bagIcon:setOn(false)
      bagIcon:setIcon('/images/topbuttons/bag_icon')
   else
      bagIcon:setOn(true)
      bagIcon:setIcon('/images/topbuttons/bag_icon_apagado')
   end
   local player = g_game.getLocalPlayer() 
   g_game.useInventoryItem(player:getInventoryItem(3):getId())
end

function toggleBadgeIcon()            
   if badgeIcon:isOn() then
      badgeIcon:setOn(false)
      badgeIcon:setIcon('/images/topbuttons/insignias')
   else
      badgeIcon:setOn(true)
      badgeIcon:setIcon('/images/topbuttons/insignias')
   end
   local player = g_game.getLocalPlayer() 
   g_game.useInventoryItem(player:getInventoryItem(5):getId())
end

function toggleFishingIcon()
   currentSlot = 10
   startChooseItem(onClickWithMouse)
end

function togglePokedexIcon()
   currentSlot = 6
   startChooseItem(onClickWithMouse)
end

function onPokeHealthChange(mode, text)
   if not g_game.isOnline() then return end
   if mode == MessageModes.Failure then 
   local pokeHealthBar = inventoryWindow:recursiveGetChildById("pokeHealthBar")
      if string.find(text, '#ph#,') then
         local t = text:explode(',')
         local hp, maxHp = tonumber(t[2]), tonumber(t[3])
         pokeHealthBar:setText(hp .. ' / ' .. maxHp)
         inventoryWindow:recursiveGetChildById("pokeHealthBar"):setTooltip(tr(pokeHealthTooltip, hp, maxHp))
         pokeHealthBar:setValue(hp, 0, maxHp)
      end
   end
end 

   
 
function onPokesLife(mode, text)
   if not g_game.isOnline() then return end
   if mode == MessageModes.Failure then
      if text:find("#life#") then
	  	  local t = string.explode(text, ",")
for l = 2, #t do
         if t[l] == namesPokes then return end
		 local Life = tonumber(t[l]) or 100
		 pokeHealth:setTooltip(Life.."%")
end
end
end
end


O código do goback caso precise, não sei:

 

function onUse(cid, item, frompos, item2, topos)
	if #getPlayerPokeballs(cid) > 6 then
		doPlayerSendCancel(cid, "You are carrying more than 6 pokémons in your team.")
		return true
	end
	
	if getPlayerSlotItem(cid, CONST_SLOT_FEET).uid ~= item.uid then
		doSendMagicEffect(getCreaturePosition(cid), 2)
		doPlayerSendCancel(cid, "Place this pokéball in the right slot.")
		return true
	end
	
	local pokeballInfo = getPokeballInfo(item.uid)
	local backmessages = {"Good job, ",	 "Well done, ",	"Back, ", "Enough, ", "Great, "}
	local gomessages = {"Time to battle, ", "Go, ",	"Do your job, ", "Prepare, ", "It's your time, "}
	local backmsg = backmessages[math.random(#backmessages)]
	local gomsg = gomessages[math.random(#gomessages)]
	
	if isPokeballOut(item.itemid) then
		local pokemon = getPlayerPokemon(cid)
		if pokemon ~= false then
			if pokeballInfo.name == getCreatureName(pokemon) then
				if getCreatureCondition(pokemon, CONDITION_PACIFIED) or getCreatureCondition(pokemon, CONDITION_DRUNK) then
					doPlayerSendCancel(cid, "Your pokémon doesn't want to return to its pokeball!")
					return true
				end
				
				local controled = getPokemonControled(cid)
				if controled ~= false then
					doUnconvinceCreature(controled)
					doSetMonsterControled(controled, false)
				end
				
				doTransformItem(item.uid, getPokeballIn(item.itemid))
				doCreatureSay(cid, backmsg..""..(pokeballInfo.nick ~= nil and pokeballInfo.nick or pokeballInfo.name).."!", TALKTYPE_ORANGE_1)
				setPokeballDescription(item.uid, pokeballInfo.name, pokeballInfo.nick, getCreatureHealth(pokemon), getCreatureMaxHealth(pokemon))
				setPokeballConditions(item.uid, pokemon)
				setPlayerStorageValue(cid, STORAGE_POKEMON_GOBACK, 0)
				setPlayerStorageValue(cid, STORAGE_POKEMON_OUTLIVE, 0)
				showPokeballEffect(getCreaturePosition(pokemon), item.itemid)
				doRemoveCreature(pokemon)
				return true
			end
		elseif not isSurfing(cid) and not isRiding(cid) and not isFlying(cid) then
			if pokeballInfo.name then
				local monster = getMonsterInfo(pokeballInfo.name)
				if monster then
					doTransformItem(item.uid, getPokeballIn(item.itemid))
					
					setPokeballDescription(item.uid, pokeballInfo.name, pokeballInfo.nick, 0, monster.healthMax)
				end
			end
		end

	elseif isPokeballIn(item.itemid) then
		
		if isSurfing(cid) then
			doPlayerSendCancel(cid, "You can't use pokeball while surfing.")
			return true
		end

		if isFlying(cid) then
			doPlayerSendCancel(cid, "You can't use pokeball while flying.")
			return true
		end
		
		if isRiding(cid) then
			doPlayerSendCancel(cid, "You can't use pokeball while riding.")
			return true
		end

		if pokeballInfo.health <= 0 then
			return doPlayerSendTextMessage(cid, 27, "This pokémon is defeated.")
		end
		
		if getPlayerPokemon(cid) ~= false then
			doPlayerSendCancel(cid, "You already called a pokemon.")
			return true
		end
		
		if getPlayerLevel(cid) < getMonsterMinimumLevel(pokeballInfo.name) then
			doPlayerSendCancel(cid, "You must be level "..getMonsterMinimumLevel(pokeballInfo.name).." or higher for this pokemon obbey you.")
			return true
		end
		
		local pk = doCreateMonster(pokeballInfo.name, getThingPosition(cid), false)
		if not isCreature(pk) then
			pk = doCreateMonster(pokeballInfo.name, getThingPosition(cid), false, true)
			if not isCreature(pk) then
				doSendMagicEffect(getCreaturePosition(cid), 2)
				doPlayerSendCancel(cid, "You can't call your pokemon here.")
				return true
			end
		end
		
		if pokeballInfo.nick ~= nil then
			doCreatureSetNick(pk, pokeballInfo.nick)
			doCreatureUpdate(pk)
		end
		
		if pokeballInfo.sex ~= nil then
			doSetMonsterSex(pk, pokeballInfo.sex)
		else
			local newSex = getMonsterSex(pk)
			doItemSetAttribute(item.uid, "pokemon_sex", newSex)
		end
		
		doConvinceCreature(cid, pk)
		setCreatureMaxHealth(pk, pokeballInfo.healthmax)
		doCreatureAddHealth(pk, pokeballInfo.healthmax)
		doCreatureAddHealth(pk, pokeballInfo.health-pokeballInfo.healthmax)
		doTransformItem(item.uid, getPokeballOut(item.itemid))
		doCreatureSay(cid, gomsg..""..(pokeballInfo.nick ~= nil and pokeballInfo.nick or pokeballInfo.name).."!", TALKTYPE_ORANGE_1)
		doSendMagicEffect(getCreaturePosition(cid), 177)
		setPokeballDescription(item.uid, pokeballInfo.name, pokeballInfo.nick)
		showPokeballEffect(getCreaturePosition(pk), item.itemid)
		setPlayerStorageValue(cid, STORAGE_POKEMON_GOBACK, 1)
		setPlayerStorageValue(cid, STORAGE_POKEMON_OUTLIVE, 1)
		doPlayerStoreSummonHealth(cid, pokeballInfo.health, pokeballInfo.healthmax)
		registerCreatureEvent(pk, "DiePoke")
		local conditions = getPokeballConditions(item.uid)
		doAddPokemonConditions(pk, conditions)
	end
	return true
end

Eu sei que preciso utilizar o doPlayerSendCancel porem não consigo pegar o hp do pokémon para isso, se alguma alma bondosa conseguir me ajudar, ficarei muito agradecido.

Editado por Genzo

Compartilhar este post


Link para o post

1 resposta a esta questão

Recommended Posts

  • 0
TEKADON    7
TEKADON

mostra print ai mano

Compartilhar este post


Link para o post
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.

×