06172009, 02:15 PM  #1 
retired coder  real ilfe

General Idea for spell algorithm
Hi guys... we all know that cliché spell that depends on the life of a unit. Per example, the weaker a unit is, the faster it attacks, or more damage it causes or some other bonus happens.
__________________I have an ability in my map called Chaotic Rage which gives some Chaos units a chance that their attacks will do a Chaos damage instead of regular damage (Chaos owns all damages). However it is too simple ... it can even be compared to a cheap version of critical strike ... I would like it depend on the life of the who has the ability (like, give X% chance to deal chaos damage per each Y% of life missing) but I make no idea on how to make it ... If someone has a general algorithm for problems like this I would appreciate the help... Thx in advance. 
Sponsored Links  Login to hide this ad! 

06172009, 02:24 PM  #2 
Rehabbing

JASS: GetWidgetLife(target)/GetUnitState(target,UNIT_STATE_MAX_LIFE) x = the percent life the target has 1  x = percent life the target is missing = y use x or y and multiply it by your percent based factor for said effects i.e. 25% chance to deal bonus damage per 20% missing life of target, max of 75% JASS: GetRandomReal(0.,1.)<.25*IMinBJ(3,R2I(((1.(GetWidgetLife(target)/GetUnitState(target,UNIT_STATE_MAX_LIFE)))/.2)) theory: we get the percent missing life our target has, divide it by .2 (20%) to give us how many 20% portions the target is missing since we want a max of 75% chance, in 25% increments, we take the minimum number of bonuses, up to a max of 3, using IMinBJ, mutliply that by our percent chance to fire factor (25%), and check whether a random real between 0 and 1 is less then this number, thus if the critical should fire say the unit has 75% hp hes missing 25% (1percent life) .25/.2 = 1.25 R2I(1.25) = 1 1<3 1*.25 = .25 GetRandomReal(0.,1.)<.25 will be the chance (25% in this case) the only problem I forsee in this instance is that I am not sure how R2I() rounds numbers, thus 1.6 could become 2, which we dont want it to, we'd rather it remainded 1  however, if you'd rather use a constant progression, as opposed to stepwise, this isn't a problem, and you can just forgo the R2I() conversion and use RMinBJ instead Last edited by emjlr3 : 06172009 at 02:42 PM. 
06172009, 06:45 PM  #3 
retired coder  real ilfe

Mmm I will try to add some twists to that theory (I like better when my units grow in power to +infinitum xD ) but this is a really nice explanation of the algorithm I was looking for.
__________________Now I believe I need to periodically check the HP of the units with the ability, say every 1 second and then change the level of the ability. Thx, I think I may find my way on this. If not, I will just come back for more candy xD rep++ ! 
Thread Tools  Search this Thread 

