Ir para conteúdo

Featured Replies

Postado

Bom dia, estou adaptando o npc Ginásio do PDA para meu servidor, terminei o npc, porém precisava bloquear para quem não estiver em batalha com o npc não poder atacar o summon do npc, alguém pode me ajudar?

 

Script do npc

local focus = 0
local max_distance = 8
local talk_start = 0
local conv = 0
local fighting = false
local challenger = 0
local pokeNpc = nil
local pokeChalenger = nil
local afk_limit_time = 300	-- seconds
local afk_time = 0		-- don't change
local battle_turn = 0		-- don't change
local challenger_turn = 0	-- don't change

local pokemons = {
	{name = "Rattata", optionalLevel = 300, sex = SEX_MALE, nick = "", ball = "normal"},
	{name = "Pidgey", optionalLevel = 300, sex = SEX_MALE, nick = "", ball = "normal"},
	-- {name = "Vaporeon", optionalLevel = 300, sex = SEX_FEMALE, nick = "", ball = "normal"},
	-- {name = "Golduck", optionalLevel = 300, sex = SEX_MALE, nick = "", ball = "normal"},
	-- {name = "Blastoise", optionalLevel = 300, sex = SEX_MALE, nick = "", ball = "normal"},
	-- {name = "Starmie", optionalLevel = 300, sex = SEX_FEMALE, nick = "", 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)
	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 Misty and I'm Cerulean'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 Cascade 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)
		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)
		addEvent(doRemove, 50, this)
		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)
				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) == 0 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)
			focus = 0
		return true
		end

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

Tentativa que fiz para bloquear o ataque para quem não estar em duel com o npc.

function onTarget(cid, target)

if getPlayerStorageValue(target, 990) ~= -1 then
if getPlayerStorageValue(target, getPlayerStorageValue(target, 999)) == 1 then
	if getPlayerStorageValue(cid, getPlayerStorageValue(target, 999)) ~= 1 then
	doPlayerSendCancel(cid, "You can't attack this pokemon.")
	return false
	end
end
end

                                                                                               1zcn2mb.jpg

 

                                                                                                                       Danera Global Server

                                                                                                                       Versão: 10.77 - 10.79

                                                                                                                       Sem Items VIP

                                                                                                                       Venha se divertir

  • Respostas 5
  • Visualizações 465
  • Created
  • Última resposta

Top Posters In This Topic

Postado

Da pra você por para que players sem a storage que o NPC dá, não consiga atacar monstros com determinado nome, acho que fica mais simples de fazer.

Gosta do meu trabalho?

Curta e siga a página do meu projeto de 2016 e 2017 (Lab Z Games) que trará vários servidores OTServs.

 

Atenciosamente,
Adriano Swatt'

 

Para ver meus tutoriais acesse meu perfil.

 

cbCyOSZ.png

Postado
  • Autor

@Adriano SwaTT

Não daria certo, pois os monstros do Ginásio tem o mesmo nome dos monstros selvagens.


up

                                                                                               1zcn2mb.jpg

 

                                                                                                                       Danera Global Server

                                                                                                                       Versão: 10.77 - 10.79

                                                                                                                       Sem Items VIP

                                                                                                                       Venha se divertir

Postado
  • Autor

Alguém ai tem uma solução?

                                                                                               1zcn2mb.jpg

 

                                                                                                                       Danera Global Server

                                                                                                                       Versão: 10.77 - 10.79

                                                                                                                       Sem Items VIP

                                                                                                                       Venha se divertir

Postado

Não testei, e nem tenho como testar. Estou confiando na sua base.

 

 

function onTarget(cid, target)
 
if not getPlayerStorageValue(cid, 990) == 1 then
doPlayerSendCancel(cid, "You can't attack this pokemon.")
end
return false
end

Editado por mateusak (veja o histórico de edições)

Não se esqueça de dar REP+ para quem te ajudou e caso seja a solução marcar como melhor resposta!

 

NÃO CLIQUE AQUI!

NEM AQUI!

________________________________________________________________________________________________________________________________________________________________________________________________________________________

 

A imaginação é mais importante que o conhecimento.” Albert Einstein

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo