Ir para conteúdo
  • Cadastre-se

[PEDIDO] Jogadores da mesma cidade não podem se atacar e npc guard diferente.


Posts Recomendados

Olá amigos do tibiaking, venho mais uma vez encher o saco da galera e pedir humildimente por dois scripts.

 

Nem sei se é possível, portanto não me custa nada tentar.

 

é o seguinte gostaria de um script em que jogadores de uma mesma cidade não podem se atacar, somente podem atacar jogadores de townid diferente, estilo word of warcraft como se uma cidade fosse horda e a outra aliança.

 

o segundo, que acho um pouco mais complexo, é que um npc guard que só ataque player de uma determinada town id, ou que não ataque jogadores da sua cidade somente de outra cidade que venha a invadir a cidade do qual esse npc é o guardião.

 

Bom, é isso ai galera se alguém puder me ajudar mais uma vez ficarei muito grato além de levar meus rep + lógico.

 

Valeu!

 

 

Link para o post
Compartilhar em outros sites

Eu não testei, mas enfim:

guard.lua (data/npc/lib):

Guard = {
	config = {			  
		attackspeed = 1000,
		townid = 5, -- ID da town que o NPC protege
	},
	combat = {type = COMBAT_PHYSICALDAMAGE, min = 100, max = 200}
}

function Guard:new()
		local ret = {}
		setmetatable({}, {__index = self.combat})
		setmetatable(ret, {__index = self})
		return ret
end

function Guard:reset()
	self.config = Guard.config
	self.target = 0
	selfFollow(0)
	doTeleportThing(self.id, self.position)
end


function Guard:updateTarget()
	if self.target ~= 0 then
		return
	end

	local creatures = getSpectators(getThingPosition(self.id), self.range, self.range, false)
	for i = 1, #creatures do
		local target = creatures[i]
		if isCreature(target) and not isNpc(target) and getPlayerTown(target) ~= self.config.townid then
			if not getTilePzInfo(getThingPosition(target)) then
				if selfFollow(target) then
					selfSay("You're not welcome in this city! ".. getCreatureName(target) ..", get out of here!")
					self.target = target
					self:attack()
					break
				end
			end
		else
			self:reset()
		end
	end
end

function Guard:attack()
	if self.target == 0 then
		self:reset()
		return
	end

	self.time = self.time or os.clock()
	if self.time < os.clock() then
		if getDistanceBetween(getThingPosition(self.id), getThingPosition(self.target)) == 1 then
			doTargetCombatHealth(self.id, self.target, self.combat.type, -self.combat.min, -self.combat.max, CONST_ME_DRAWBLOOD)
		end
		self.time = self.time + (self.config.attackspeed/1000)
	end
end


Os demais arquivos do NPC permanecem os mesmos, apenas substitua os códigos desse arquivo da lib dos npcs.




Enquanto a não atacar players da mesma town:

sametown.lua (data/creaturescripts/scripts):

function onAttack(cid, target)
	if isPlayer(target) and getPlayerTown(target) == getPlayerTown(cid) then
		doPlayerSendCancel(cid, "You can't attack players of the same town.")
		return false
	end
	return true
end




Registre o creature event em login.lua (data/creaturescripts/scripts):

registerCreatureEvent(cid, "SameTown")




Tag - creaturescripts.xml (data/creaturescripts):

<event type="attack" name="SameTown" script="sametown.lua"/>

 

Créditos ao Oneshot pelo desenvolvimento dos códigos do NPC Guard original, eu apenas o alterei.

The corrupt fear us.

The honest support us.

The heroic join us.

Link para o post
Compartilhar em outros sites

mas uma vez gostaria de agradecer pela colaboração suicide, vlw mesmo.

 

Em relação ao script do npc guard eu não entendi direito o que voce quis dizer com os demais arquivos permanecem o mesmo. só para esclarecer eu ainda não possuo nenhum script de npc guard. 

 

o segundo testei aqui e funcionou direitinho, o único problema é que as magias não são barradas somente os atacks com as armas.

 

Rep +, orbigado por ter me ajudado até aqui.

Link para o post
Compartilhar em outros sites
só para esclarecer eu ainda não possuo nenhum script de npc guard.

Ah, ok.

guard.lua (data/npc/lib):

Guard = {
	config = {			  
		attackspeed = 1000,
		townid = 5, -- ID da town que o NPC protege
	},
	combat = {type = COMBAT_PHYSICALDAMAGE, min = 100, max = 200}
}

function Guard:new()
		local ret = {}
		setmetatable({}, {__index = self.combat})
		setmetatable(ret, {__index = self})
		return ret
end

function Guard:reset()
	self.config = Guard.config
	self.target = 0
	selfFollow(0)
	doTeleportThing(self.id, self.position)
end


function Guard:updateTarget()
	if self.target ~= 0 then
		return
	end

	local creatures = getSpectators(getThingPosition(self.id), self.range, self.range, false)
	for i = 1, #creatures do
		local target = creatures[i]
		if isCreature(target) and not isNpc(target) and getPlayerTown(target) ~= self.config.townid then
			if not getTilePzInfo(getThingPosition(target)) then
				if selfFollow(target) then
					selfSay("You're not welcome in this city! ".. getCreatureName(target) ..", get out of here!")
					self.target = target
					self:attack()
					break
				end
			end
		else
			self:reset()
		end
	end
end

function Guard:attack()
	if self.target == 0 then
		self:reset()
		return
	end

	self.time = self.time or os.clock()
	if self.time < os.clock() then
		if getDistanceBetween(getThingPosition(self.id), getThingPosition(self.target)) == 1 then
			doTargetCombatHealth(self.id, self.target, self.combat.type, -self.combat.min, -self.combat.max, CONST_ME_DRAWBLOOD)
		end
		self.time = self.time + (self.config.attackspeed/1000)
	end
end

guard.lua (data/npc/scripts):

local guard = Guard:new()

function onCreatureAppear(cid)
	if cid == getNpcId() then
		guard.id = getNpcId()
		guard.target = 0
		guard.position = getNpcPos()
	end
end

function onCreatureDisappear(cid)
	if cid == guard.target then
		guard:reset()
	end
end

function onCreatureSay(cid, type, msg)
	return false
end

function onThink()
	guard:updateTarget()
	if guard.target ~= 0 then
		if isCreature(guard.target) then
			guard:attack()
		else
			guard:reset()
		end
	else
		guard:reset()
	end
end

Guard.xml (data/npc):

<?xml version="1.0" encoding="UTF-8"?>
<npc name="Guard" script="guard.lua" walkinterval="0" speed="200" floorchange="0">
	<health now="100" max="100"/>
	<look type="134" head="57" body="59" legs="40" feet="76" addons="0"/>
	<parameters/>
</npc>
* Créditos ao Oneshot/Garou pelo desenvolvimento dos códigos do NPC Guard original, eu apenas o alterei.

 

 

o único problema é que as magias não são barradas somente os atacks com as armas.

 

Em relação a não poderem se atingir com as spells, nunca vi um código desenvolvido pra isso.

Disponha ;]

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

The corrupt fear us.

The honest support us.

The heroic join us.

Link para o post
Compartilhar em outros sites

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

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.


  • Conteúdo Similar

    • Por warofscream
      Olá...
      Eu estou aprendendo a lidar com Scripts agora e empaquei aqui
      function onUse(cid, item, fromPosition, itemEx, toPosition)    if itemEx.itemid == 0000 then if getPlayerLevel(cid) >= 150 doTeleportThing(cid, {x=,y=, z=}) doTransformItem(itemEx.uid, 0000) doSendMagicEffect(getThingPos(cid), 30) doPlayerSendCancel(cid,'Voce nao tem level suficiente!)  end    return true end A ideia é que o item que eu usar se transforme em outro item, me teleporte e lance um efeito...
      Porém para poder usar o item sera necessário level 150...
      A questão de Transformar em outro item, teleportar e lançar um efeito eu consigo fazer porem quando tento por a restrição de só fazer isso no Level 150 o Script falha...
      Desde já agradeço!
      --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      Obrigado a Wakon e a Dukeeh
    • Por SiriusBlacks004
      Eu gostaria de um npc Guard qe atk player com pk. Eu vi um topico aki mais so qe n funciono se alguem tem pra 854 poderia me passa?
×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo