• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

It didnt chain

Status
Not open for further replies.
Level 2
Joined
Aug 26, 2014
Messages
10
JASS:
scope Chain initializer init 
	globals 
		private constant integer id = 'A008'
		private constant integer dumid = 'h004'
	endglobals 
	
	struct Chain 
		unit u 
		unit tar
		unit dum 
		group check 
		integer count 
		method onDestroy takes nothing returns nothing 
			call RemoveUnit(dum)
			call DestroyGroup(check)
			set check = null 
			set u = null 
			set tar = null 
			set dum = null 
		endmethod 
	endstruct 
	
	private function update takes nothing returns nothing 
		local Chain this = getRT()
		local group g 
		local unit f 
		local integer i = 0
		local real x = GetWidgetX(this.dum)
		local real y = GetWidgetY(this.dum)
		local real angle = Angle(x, y, GetWidgetX(this.tar), GetWidgetY(this.tar))
		local real d = Distance(GetWidgetX(this.dum), GetWidgetY(this.dum), GetWidgetX(this.tar), GetWidgetY(this.tar))
		call PolarProjection(x, y, 40, angle)
		call SetUnitX(this.dum, Misc_X)
		call SetUnitY(this.dum, Misc_Y)
		if d < 40 then 
			set this.count = this.count - 1
			call UnitDamageTarget(this.u, this.tar, 50000, true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_FIRE, null)
			set g = CreateGroup()
			call GroupEnumUnitsInRange(g, x, y, 400, null)
			loop 
				set f = FirstOfGroup(g)
				exitwhen f == null or i >= 1
				if IsUnitEnemy(f, GetOwningPlayer(this.u)) and GetWidgetLife(f)>0.45 and not IsUnitType(f, UNIT_TYPE_STRUCTURE) and not IsUnitInGroup(f, this.check) then 
					set this.tar = f 
					call GroupAddUnit(this.check, f)
				endif 
				call GroupRemoveUnit(g, f)
				set i = i + 1
			endloop 
			call DestroyGroup(g)
		endif 
		if this.count <=0 then 
			call breakRT()
			call this.destroy()
		endif 
		set g = null 
		set f = null 
	endfunction 
	
	private function onCast takes nothing returns nothing 
		local Chain this = Chain.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.check = CreateGroup()
		set this.count = 10
		call addRT(this, 0.03125, true, function update)
	endfunction 
	
	private function init takes nothing returns nothing 
		call RegisterSpellEffectEvent(id, function onCast)
	endfunction 
endscope
Here my code.
I want to make a chain spell, so I have asked everybody in this forum how to make it, and here is my code after following their instruction. But It did chain, just move to the first target and removed :vw_wtf:. I have check many times but I couldnt figure it out. :vw_unimpressed:
 
Level 2
Joined
Aug 26, 2014
Messages
10
Just a hunch, it might be reducing this.count every 0.03 because of variable mis-set. xD

JASS:
if IsUnitEnemy(f, GetOwningPlayer(this.u)) and GetWidgetLife(f)>0.45 and not IsUnitType(f, UNIT_TYPE_STRUCTURE) and not IsUnitInGroup(f, this.check) then 
                    set this.tar = f 
                    call GroupAddUnit(this.check, f)
                endif
I had?
 
Status
Not open for further replies.
Top