Ir para conteúdo

Featured Replies

Postado

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!

 

 

Postado

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.

Postado
  • Autor

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.

Postado
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.

Postado
  • Autor

infelizmente não deu certo. coloquei o npc guard pelo rme mas na hora de abrir o server ele não aparece

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.6k

Informação Importante

Confirmação de Termo