• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Make auto-cast spell?

Status
Not open for further replies.
Level 2
Joined
Aug 26, 2014
Messages
10
Here my spell based on Spearing Arrow, I've finished 1 part of it, SPELL-EFFECT but the other part is turn-on auto-cast spell, i dont know which event to use and how to add it to my trigger. Please help me.
JASS:
scope Autocast initializer init 
	globals 
		private constant integer ID = 'A00A'
		private constant integer dumID = 'h00F'
	endglobals
	
	private function cond takes nothing returns boolean 
		return GetSpellAbilityId()==ID
	endfunction 
	
	struct Fire 
		static unit u 
		unit dum
		unit tar
		real dist 
		private method onDestroy takes nothing returns nothing 
			call RemoveUnit(dum)
		endmethod 
	endstruct 
	
	struct Spread extends Fire 
		unit array dumsp[5]
		real distsp 
		private method onDestroy takes nothing returns nothing 
			local integer i = 0
			loop 
				exitwhen i>=5
				call RemoveUnit(dumsp[i])
				set i = i + 1
			endloop 
		endmethod 
	endstruct 
	
	private function filter takes unit tar, player p returns boolean
		if not IsUnitEnemy(tar,p) then 
			return false 
		endif  
		if IsUnitType(tar,UNIT_TYPE_STRUCTURE) then 
			return false 
		endif 
		return true 
	endfunction 
	
	private function spread takes nothing returns nothing 
		local Spread that = getRT() 
		local integer i = 0 
		local group g
		local unit f 
		loop 
			exitwhen i>= 5
			call PolarProjection(GetWidgetX(that.dumsp[i]),GetWidgetY(that.dumsp[i]),40,GetUnitFacing(that.dumsp[i])*bj_DEGTORAD)
			call SetUnitX(that.dumsp[i],Misc_X)
			call SetUnitY(that.dumsp[i],Misc_Y)
			set g = CreateGroup()
			call GroupEnumUnitsInRange(g,GetWidgetX(that.dumsp[i]),GetWidgetY(that.dumsp[i]),300,null)
			loop 
				set f = FirstOfGroup(g)
				exitwhen f == null 
				if filter(f,GetOwningPlayer(Fire.u)) then 
					call UnitDamageTarget(Fire.u,f,300,true,false,ATT,DGT,WPT)
				endif 
				call GroupRemoveUnit(g,f)
			endloop 
			call DestroyGroup(g)
			set i = i + 1
		endloop
		if that.distsp <= 0 then 
			call breakRT() 
			call that.destroy() 
		endif 
		set that.distsp = that.distsp - 40
	endfunction 
	
	private function fire takes nothing returns nothing 
		local Fire this = getRT()
		local Spread that 
		local real angle = 0
		local integer i = 0
		call PolarProjection(GetWidgetX(this.dum),GetWidgetY(this.dum),40,GetUnitFacing(this.dum)*bj_DEGTORAD)
		call SetUnitX(this.dum,Misc_X)
		call SetUnitY(this.dum,Misc_Y)
		if this.dist <= 0 then 
			call UnitDamageTarget(this.u,this.tar,100,true,false,ATT,DGT,WPT)
			set that = Spread.create() 
			loop 
				exitwhen angle>=360
				set that.dumsp[i] = CreateUnit(GetOwningPlayer(this.u),dumID,GetWidgetX(this.tar),GetWidgetY(this.tar),angle)
				set i = i + 1 
				set angle = angle + 360/5 
			endloop 
			set that.distsp = 700
			call addRT(that,0.0312500,true, function spread) 
			call breakRT()
			call this.destroy()
		endif 
		set this.dist = this.dist - 40
	endfunction 
	
	private function fireact takes nothing returns nothing 
		local Fire this = Fire.create() 
		set this.u = GetTriggerUnit()
		set this.tar = GetSpellTargetUnit()
		set this.dum = CreateUnit(GetOwningPlayer(this.u),dumID,GetWidgetX(this.u),GetWidgetY(this.u),GetUnitFacing(this.u))
		set this.dist = Distance(GetWidgetX(this.dum),GetWidgetY(this.dum),GetWidgetX(this.tar),GetWidgetY(this.tar))
		call addRT(this,0.0312500,true, function fire) 
	endfunction 
	
	private function init takes nothing returns nothing 
		local trigger t = CreateTrigger()
		call TriggerRegisterPlayerUnitEvent(t,Player(0),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
		call TriggerAddCondition(t, function cond)
		call TriggerAddAction(t, function fireact)
		set t = null 
	endfunction 
endscope

P.s: How to deal damage based on hero damage?
 
Status
Not open for further replies.
Top