• 🏆 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!

[JASS] HELP THE NOOB: Trying to add MaxHp % damage

Status
Not open for further replies.
Level 8
Joined
Jul 10, 2008
Messages
353
JASS:
function buffb901 takes nothing returns boolean
return ((IsUnitType(GetTriggerUnit(),UNIT_TYPE_SAPPER)) and (UnitHasBuffBJ(GetTriggerUnit(),'B901')))
endfunction

function kwaved takes nothing returns nothing
set kwreal=GetUnitState(GetEnumUnit(), UNIT_STATE_MAX_LIFE)
set kwreal3=GetUnitState(GetEnumUnit(), UNIT_STATE_LIFE)
set kwreal2=0.08*kwreal	// 8%
call SetWidgetLife(GetEnumUnit(), (kwreal3-kwreal2))
call UnitRemoveBuffBJ('B901',GetEnumUnit())
endfunction

function kgroup takes nothing returns nothing
call GroupAddUnit(groupKW,GetTriggerUnit())
call ForGroup(groupKW,function kwaved)
endfunction

//main
set loc_region01=CreateRegion()
set triggerKW=CreateTrigger()
call RegionAddRect(loc_region01,bj_mapInitialPlayableArea)
call TriggerRegisterEnterRegion(triggerKW,loc_region01,null)	
call TriggerAddCondition(triggerKW,Condition(function buffb001))	
call TriggerAddAction(triggerKW,function kgroup)	
set loc_region01=null

The buff b901 is applied by a manually casted skill. But nothing happens in game. I tried to make the 8% to 80% to check.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Your event is wrong.

The condition runs when a unit enters the map.
Then it checks if it has the buff. (Which it obviously hasnt.)
Even if it has, it gets added to some group after which the entire group is dealt damage...
Also... the units are never removed from the group.

But for now, try to focus on having a proper event for when you want to activate the damage.

Also... try to use a proper naming convention... it is horrible to read.
JPAG seems to be good.
 
Level 8
Joined
Jul 10, 2008
Messages
353
Should I make it to check every 0.1sec if units have the buff?
I must remove them from group after they die?

The entire group is suppose to get damaged, at least I got that one thing right, lol.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
The entire group is not supposed to be damaged when a unit is added to the group.
For example, I hit one unit with that spell then cast the spell on 12 other people by 12 other casters... then that first unit is hit for 104% of his max hp within like 1 second...

You should explain what you want to achieve.
I dont know WHEN you want to deal the damage.
So I CANNOT say that 0.1s would be good.
 
Level 8
Joined
Jul 10, 2008
Messages
353
Well the damage is suppose to happen to the units that have the buff on them, which gets applied by manually casting an aoe spell. The buff gets removed once they get the damage applied to them. There is only 1 unit in the game that can cast that spell. It can hit as many as 200 targets at once tho.

what if i add this?
JASS:
function kwaved takes nothing returns nothing
set kwreal=GetUnitState(GetEnumUnit(), UNIT_STATE_MAX_LIFE)
set kwreal3=GetUnitState(GetEnumUnit(), UNIT_STATE_LIFE)
set kwreal2=0.08*kwreal // 8%
call SetWidgetLife(GetEnumUnit(), (kwreal3-kwreal2))
call UnitRemoveBuffBJ('B901',GetEnumUnit())

call GroupRemoveUnit(groupKW,GetEnumUnit()) // <-----

endfunction
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
When... does... the... damage... have... to... be... applied?

"Well the damage is suppose to happen to the units that have the buff on them,"
Yes we now know who should take that damage.

"which gets applied by manually casting an aoe spell."
Which is completely irrelevant to this problem.

"The buff gets removed once they get the damage applied to them."
Why have a buff in the first place then?
 
Level 7
Joined
Oct 19, 2015
Messages
286
"The buff gets removed once they get the damage applied to them."
Why have a buff in the first place then?
I'm wondering about this as well. If the damage is dealt only once when the spell is cast then you don't need a buff for this.
 
Status
Not open for further replies.
Top