Jump to content

Scripting [PEDIDO] Regem de stamina Training online


Recommended Posts

Em data/events/scripts/creature.lua procure por function Creature:onTargetCombat(target), a cima adicione o seguinte codigo:

-- Increase Stamina when Attacking Trainer
local staminaBonus = {
	target = 'Training Monk',
	period = 120000, -- time on miliseconds
	bonus = 1, -- gain stamina
	events = {}
}

local function addStamina(name)
	local player = Player(name)
	if not player then
		staminaBonus.events[name] = nil
	else
		local target = player:getTarget()
		if not target or target:getName() ~= staminaBonus.target then
			staminaBonus.events[name] = nil
		else
			player:setStamina(player:getStamina() + staminaBonus.bonus)
			staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
		end
	end
end

No mesmo arquivo procure por function Creature:onTargetCombat(target) e adicione o seguinte codigo a cima de return true

if self:isPlayer() then
    if target and target:getName() == staminaBonus.target then
        local name = self:getName()
        if not staminaBonus.events[name] then
            staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
        end
    end
end

 

Link to post
Share on other sites

__picif = {}
function Creature:onChangeOutfit(outfit)
	return true
end

function Creature:onAreaCombat(tile, isAggressive)
	return true
end

-- Prey slots consumption
local function preyTimeLeft(player, slot)
	local timeLeft = player:getPreyTimeLeft(slot) / 60
	local monster = player:getPreyCurrentMonster(slot)
	if (timeLeft > 0) then
		local playerId = player:getId()
		local currentTime = os.time()
		local timePassed = currentTime - nextPreyTime[playerId][slot]
		if timePassed > 59 then
			timeLeft = timeLeft - 1
			nextPreyTime[playerId][slot] = currentTime + 60
		else
			timeLeft = 0
		end
		-- Expiring prey as there's no timeLeft
		if (timeLeft == 0) then
			player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Your %s's prey has expired.", monster:lower()))
			player:setPreyCurrentMonster(slot, "")
		end
		-- Setting new timeLeft
		player:setPreyTimeLeft(slot, timeLeft * 60)
	else
		-- Expiring prey as there's no timeLeft
		player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Your %s's prey has expired.", monster:lower()))
		player:setPreyCurrentMonster(slot, "")
	end
	return player:sendPreyData(slot)
end

local function removeCombatProtection(cid)
	local player = Player(cid)
	if not player then
		return true
	end

	local time = 0
	if player:isMage() then
		time = 10
	elseif player:isPaladin() then
		time = 20
	else
		time = 30
	end

	player:setStorageValue(Storage.combatProtectionStorage, 2)
	addEvent(function(cid)
		local player = Player(cid)
		if not player then
			return
		end

		player:setStorageValue(Storage.combatProtectionStorage, 0)
		player:remove()
	end, time * 1000, cid)
end

-- Increase Stamina when Attacking Trainer
local staminaBonus = {
	target = 'Training Monk',
	period = 120000, -- time on miliseconds
	bonus = 1, -- gain stamina
	events = {}
}

local function addStamina(name)
	local player = Player(name)
	if not player then
		staminaBonus.events[name] = nil
	else
		local target = player:getTarget()
		if not target or target:getName() ~= staminaBonus.target then
			staminaBonus.events[name] = nil
		else
			player:setStamina(player:getStamina() + staminaBonus.bonus)
			staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
		end
	end
end


function Creature:onTargetCombat(target)
	if not self then
if self:isPlayer() then
    if target and target:getName() == staminaBonus.target then
        local name = self:getName()
        if not staminaBonus.events[name] then
            staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
        end
    end
end
		return true
	end

	if not __picif[target.uid] then
		if target:isMonster() then
			target:registerEvent("RewardSystemSlogan")
			__picif[target.uid] = {}
		end
	end

	if target:isPlayer() then
		if self:isMonster() then
			local protectionStorage = target:getStorageValue(Storage.combatProtectionStorage)

			if target:getIp() == 0 then -- If player is disconnected, monster shall ignore to attack the player
			    if target:isPzLocked() then end
				if protectionStorage <= 0 then
					addEvent(removeCombatProtection, 30 * 1000, target.uid)
					target:setStorageValue(Storage.combatProtectionStorage, 1)
				elseif protectionStorage == 1 then
					self:searchTarget()
					return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
				end

				return true
			end

			if protectionStorage >= os.time() then
				return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
			end
		end
	end

	if ((target:isMonster() and self:isPlayer() and target:getType():isPet() and target:getMaster() == self) or (self:isMonster() and target:isPlayer() and self:getType():isPet() and self:getMaster() == target)) then
		return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
	end

	if PARTY_PROTECTION ~= 0 then
		if self:isPlayer() and target:isPlayer() then
			local party = self:getParty()
			if party then
				local targetParty = target:getParty()
				if targetParty and targetParty == party then
					return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
				end
			end
		end
	end

	if ADVANCED_SECURE_MODE ~= 0 then
		if self:isPlayer() and target:isPlayer() then
			if self:hasSecureMode() then
				return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
			end
		end
	end
	return true
end

function Creature:onDrainHealth(attacker, typePrimary, damagePrimary, typeSecondary, damageSecondary, colorPrimary, colorSecondary)
	if (not self) then
		return typePrimary, damagePrimary, typeSecondary, damageSecondary, colorPrimary, colorSecondary
	end

	if (not attacker) then
		return typePrimary, damagePrimary, typeSecondary, damageSecondary, colorPrimary, colorSecondary
	end

	-- New prey => Bonus damage
	if (attacker:isPlayer()) then
		if (self:isMonster() and not self:getMaster()) then
			for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
				if (attacker:getPreyCurrentMonster(slot) == self:getName() and attacker:getPreyBonusType(slot) == CONST_BONUS_DAMAGE_BOOST) then
					damagePrimary = damagePrimary + math.floor(damagePrimary * (attacker:getPreyBonusValue(slot) / 100))
					break
				end
			end
		end
	-- New prey => Damage reduction
	elseif (attacker:isMonster()) then
		if (self:isPlayer()) then
			for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
				if (self:getPreyCurrentMonster(slot) == attacker:getName() and self:getPreyBonusType(slot) == CONST_BONUS_DAMAGE_REDUCTION) then
					damagePrimary = damagePrimary - math.floor(damagePrimary * (self:getPreyBonusValue(slot) / 100))
					break
				end
			end
		end
	end

	return typePrimary, damagePrimary, typeSecondary, damageSecondary, colorPrimary, colorSecondary
end

Apareceu esse erro

Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onTargetCombat
data/events/scripts/creature.lua:92: attempt to index local 'self' (a nil value)
stack traceback:
[C]: in function '__index'
data/events/scripts/creature.lua:92: in function
[C]: in function 'doTargetCombatHealth'

 

Link to post
Share on other sites

Substitua sua função por:

function Creature:onTargetCombat(target)
	if not self then
		return true
	end

	if not __picif[target.uid] then
		if target:isMonster() then
			target:registerEvent("RewardSystemSlogan")
			__picif[target.uid] = {}
		end
	end

	if target:isPlayer() then
		if self:isMonster() then
			local protectionStorage = target:getStorageValue(Storage.combatProtectionStorage)

			if target:getIp() == 0 then -- If player is disconnected, monster shall ignore to attack the player
			    if target:isPzLocked() then end
				if protectionStorage <= 0 then
					addEvent(removeCombatProtection, 30 * 1000, target.uid)
					target:setStorageValue(Storage.combatProtectionStorage, 1)
				elseif protectionStorage == 1 then
					self:searchTarget()
					return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
				end

				return true
			end

			if protectionStorage >= os.time() then
				return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
			end
		end
	end

	if ((target:isMonster() and self:isPlayer() and target:getType():isPet() and target:getMaster() == self) or (self:isMonster() and target:isPlayer() and self:getType():isPet() and self:getMaster() == target)) then
		return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
	end

	if PARTY_PROTECTION ~= 0 then
		if self:isPlayer() and target:isPlayer() then
			local party = self:getParty()
			if party then
				local targetParty = target:getParty()
				if targetParty and targetParty == party then
					return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
				end
			end
		end
	end

	if ADVANCED_SECURE_MODE ~= 0 then
		if self:isPlayer() and target:isPlayer() then
			if self:hasSecureMode() then
				return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
			end
		end
	end

	if self:isPlayer() then
		if target and target:getName() == staminaBonus.target then
			local name = self:getName()
			if not staminaBonus.events[name] then
				staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
			end
		end
	end
	return true
end

 

Edited by Marco Oliveira (see edit history)
Link to post
Share on other sites

14 horas atrás, Marco Oliveira disse:

Em data/events/scripts/creature.lua procure por function Creature:onTargetCombat(target), a cima adicione o seguinte codigo:


-- Increase Stamina when Attacking Trainer
local staminaBonus = {
	target = 'Training Monk',
	period = 120000, -- time on miliseconds
	bonus = 1, -- gain stamina
	events = {}
}

local function addStamina(name)
	local player = Player(name)
	if not player then
		staminaBonus.events[name] = nil
	else
		local target = player:getTarget()
		if not target or target:getName() ~= staminaBonus.target then
			staminaBonus.events[name] = nil
		else
			player:setStamina(player:getStamina() + staminaBonus.bonus)
			staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
		end
	end
end

No mesmo arquivo procure por function Creature:onTargetCombat(target) e adicione o seguinte codigo a cima de return true


if self:isPlayer() then
    if target and target:getName() == staminaBonus.target then
        local name = self:getName()
        if not staminaBonus.events[name] then
            staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
        end
    end
end

 

 

funciona tfs 0.4 ?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By hiquezerah
      .Qual servidor ou website você utiliza como base? OTX
       
      Qual o motivo deste tópico? Bom dia rapazeada do tk, alguém poderia me ajudar a solucionar esse erro que está ocorrendo com esse script? Acabei achando esse script aqui mesmo no tk e tentei adaptalo para assim que o player chegar a certa porcentagem de vida irá ativar uma spell.
      o script está funcionando, a spell está sendo ativada, porém mostra esse erro na distro "spell not found". Alguém poderia me ajudar por favor?
       
      Está surgindo algum erro? Se sim coloque-o aqui. 
       
      Você tem o código disponível? Se tiver publique-o aqui: 
      local config = { vocations = {10,11, 22}, --IDs das vocações. percent = 95, -- porcentagem de sair a magia (50 = 50% de chance) valorvida = 100, --quanto deve ser o valor minimo de vida a perder para executar o script storage = 112993, time = 1, spell = "shikai" } function onStatsChange(cid, attacker, type, combat, value) if type == STATSCHANGE_HEALTHLOSS and value >= config.valorvida and isInArray(config.vocations, getPlayerVocation(cid)) then if math.random (1,100) <= config.percent and getPlayerStorageValue(cid, 112993) < os.time() then doCreatureCastSpell(cid, config.spell) setPlayerStorageValue(cid, 112993, os.time() + config.time * 20) end end return true end    
      Você tem alguma imagem que possa auxiliar no problema? Se sim, coloque-a aqui. 
       
    • By knepperzik
      Estou usando OTX.

      Fala galera,

      Estou com um probleminha em meu servidor, sobre o castle, não esta salvando a guild dominante.
      Ja verifiquei o config.lua e sim esta como "true" saveGlobalStorage=true.
      Se alguem conseguir dar uma ajuda.
       
    • By GniusPlay
      Pessoal, tenho uma script que o player ganha x item e volta para o cp quando não tem ninguem em x  area, mas eu gostaria de fazer com que essa script fosse ativada depois de 5 segundos após o player pisar nesse tile.
      Exemplo: Player pisa no tile, da 5 segundos e o script é ativado
      Se não tiver ninguem nessa area, o script passa 5 segundos e funciona normal, caso tenha player nessa area, o script não funciona!
      A script ja esta ok, só falta adicionar 5 segundos
       
      function onStepIn(cid, item, position, fromPosition) local pos = {x = 1037, y = 1034, z = 7} local battlewin = 1 if #getCreatureSummons(cid) >= 1 then else if #getPlayersInArea(battleroyale.area) > 1 then return true end doTeleportThing(cid, pos) local item = doPlayerAddItem(cid, 5805, 1) doItemSetAttribute(item, "description", getCreatureName(cid).." conquistou este trofeu apos vencer uma partida no Battle Royale.") doBroadcastMessage(""..getCreatureName(cid).." Venceu o evento Battle Royale") doPlayerAddItem(cid,12618,1) doPlayerAddItem(cid,2152,30) addTopbattle(cid, battlewin) return true end end  
    • By GniusPlay
      Pessoal, preciso de uma script que limitasse x item dos players
      Por exemplo, ele só poderia ter na sua conta 5 pedras, se colocasse pra ter 6 pedra não teria como!
       
    • By GniusPlay
      Pessoal, tenho uma script que o player só passa se ele tiver uma guild, a script funciona  certinho, só q da um erro na distro quando um pokemon (monstro) passa por cima desse tile
      Erro:
      [07/03/2021 16:08:43] [Error - MoveEvents Interface] 
      [07/03/2021 16:08:43] datapack/movements/scripts/guildpiso.lua:onStepIn
      [07/03/2021 16:08:43] Description: 
      [07/03/2021 16:08:43] datapack/movements/scripts/guildpiso.lua:2: attempt to compare number with boolean
      [07/03/2021 16:08:43] stack traceback:
      [07/03/2021 16:08:43]     datapack/movements/scripts/guildpiso.lua:2: in function <datapack/movements/scripts/guildpiso.lua:1>
       
      Script:
       
       
  • Recently Browsing   0 members

    No registered users viewing this page.


×
×
  • Create New...

Important Information

Confirmação de Termo