Вопрос по таймерам

I_GRIN_I

Друзья CG
15 Мар 2016
1,335
105
Вот еще вопрос, уже по таймерам.
Код:
if bh_mark == nil then
	bh_mark = class({})
end
LinkLuaModifier("modifier_markenemy","heroes/bh/mark",LUA_MODIFIER_MOTION_NONE)
LinkLuaModifier("modifier_markfriend","heroes/bh/mark",LUA_MODIFIER_MOTION_NONE)
LinkLuaModifier("modifier_stacks","heroes/bh/mark",LUA_MODIFIER_MOTION_NONE)
function bh_mark:GetCooldown( nLevel )
	if self:GetCaster():HasScepter() then
		return self:GetSpecialValueFor( "coldownscepter" )
	end
	return self.BaseClass.GetCooldown( self, nLevel )
end
function bh_mark:GetCastAnimation() 
  return ACT_DOTA_CAST_ABILITY_4 
end
function bh_mark:CastFilterResultTarget( hTarget )
	if self:GetCaster() == hTarget then
		return UF_FAIL_CUSTOM
	end
	if hTarget:IsCreep() or hTarget:IsAncient() then
		return UF_FAIL_CUSTOM
	end
	local nResult = UnitFilter( hTarget, DOTA_UNIT_TARGET_TEAM_BOTH, DOTA_UNIT_TARGET_HERO, DOTA_UNIT_TARGET_FLAG_MAGIC_IMMUNE_ENEMIES, self:GetCaster():GetTeamNumber() )
	if nResult ~= UF_SUCCESS then
		return nResult
	end
	return UF_SUCCESS
end
function bh_mark:GetCustomCastErrorTarget( hTarget )
	if self:GetCaster() == hTarget then
		return "#dota_hud_error_cant_cast_on_self"
	end
	if hTarget:IsAncient() then
		return "#dota_hud_error_cant_cast_on_ancient"
	end
	if hTarget:IsCreep() then
		return "#dota_hud_error_cant_cast_on_creep"
	end
	return ""
end
function bh_mark:OnSpellStart()
	local hCaster = self:GetCaster()
	local hTarget = self:GetCursorTarget()
	local hAbility = self
	local duration = self:GetSpecialValueFor("duration")
	local durationscepter = self:GetSpecialValueFor("durationscepter")
	if hTarget ~= nil then
		if hTarget:HasModifier("modifier_markenemy") or hTarget:HasModifier("modifier_markfriend") then
			local kek
		else
			local current_stack = hCaster:GetModifierStackCount("modifier_stacks", hCaster)
			if not hCaster:HasModifier("modifier_stacks") then
  			hCaster:AddNewModifier(hCaster,hAbility,"modifier_stacks",{})
			end
			if hCaster:HasScepter() then
				Timers:CreateTimer({
  					endTime = durationscepter,
  					callback = function()
  						if current_stack > 1 then
  							hCaster:SetModifierStackCount("modifier_stacks", hCaster, current_stack - 1)
  						else
  							hCaster:RemoveModifierByName("modifier_stacks")
  						end
  					end
 					})
			else
				Timers:CreateTimer({
  					endTime = duration,
  					callback = function()
  						if current_stack > 1 then
  							hCaster:SetModifierStackCount("modifier_stacks", hCaster, current_stack - 1)
  						else
  							hCaster:RemoveModifierByName("modifier_stacks")
  						end
  					end
 					})
			end
			hCaster:SetModifierStackCount("modifier_stacks", hCaster, current_stack + 1)
		end
		if hTarget:GetTeam() ~= hCaster:GetTeam() then
			if hCaster:HasScepter() then
				hTarget:AddNewModifier(hCaster,hAbility,"modifier_markenemy",{duration = durationscepter})
			else
				hTarget:AddNewModifier(hCaster,hAbility,"modifier_markenemy",{duration = duration})
			end
		else
			hTarget:AddNewModifier(hCaster,hAbility,"modifier_markfriend",{duration = duration})
		end
	end
end

В коде(в конце примерно) есть таймер, вызывающий функцию, если стаков > 1, то отнимать 1 стак с модификатора, иначе снимать модификатор, но модификатор снимается в любом случае. Я уже пробовал делать и = и <, ничего не получается...
 
Последнее редактирование модератором:

I_GRIN_I

Друзья CG
15 Мар 2016
1,335
105
Все, ребят, решил:
Код:
if hCaster:HasScepter() then
				Timers:CreateTimer({
  					endTime = durationscepter,
  					callback = function()
  						local stacks = hCaster:GetModifierStackCount("modifier_stacks", hCaster)
  						if stacks == 1 then
  							hCaster:RemoveModifierByName("modifier_stacks")
  						else
  							hCaster:SetModifierStackCount("modifier_stacks", hCaster, stacks - 1)
  						end
  					end
 					})
			else
				Timers:CreateTimer({
  					endTime = duration,
  					callback = function()
  						local stacks = hCaster:GetModifierStackCount("modifier_stacks", hCaster)
  						if stacks == 1 then
  							hCaster:RemoveModifierByName("modifier_stacks")
  						else
  							hCaster:SetModifierStackCount("modifier_stacks", hCaster, stacks - 1)
  						end
  					end
 					})
			end
 
Последнее редактирование модератором:
Реклама: