HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Spell Not Working

06-29-2007, 10:31 AM#1
deadlysheep_1
Hi guys. I made this spell in JASS, called Blood Mana. It doesn't seem to work, as it doesn't restore any mana when the hero kills a unit, which is what the spell was designed to do. Any help would be appreciated and rewarded with rep. This is the code. I am pretty new to JASS, but I am eager to learn more and never have to use GUI again. Thanks in advance.

Collapse JASS:
function Trig_Blood_Mana_Conditions takes nothing returns boolean
    if ( not ( GetUnitAbilityLevelSwapped('A002', GetKillingUnitBJ()) >= 1 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Blood_Mana_Actions takes nothing returns nothing
local integer a = GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetTriggerUnit())
local integer b = (a*20)-5
local integer c = (a*20)+5
local integer d = GetRandomInt(b,c)
call SetUnitManaBJ(GetKillingUnitBJ(),d+GetUnitStateSwap (UNIT_STATE_MANA, GetKillingUnitBJ()))
endfunction

//===========================================================================
function InitTrig_Blood_Mana takes nothing returns nothing
    set gg_trg_Blood_Mana = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Blood_Mana, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Blood_Mana, Condition( function Trig_Blood_Mana_Conditions ) )
    call TriggerAddAction( gg_trg_Blood_Mana, function Trig_Blood_Mana_Actions )
endfunction
06-29-2007, 11:03 AM#2
Pyrogasm
Here are some tips on optimization:
  • Instead of "if (condition) then; return true; else; return false; endif" stuff, you can simply write "return (condition)" because "(condition)" is a boolean itself. Thus, you'll want to change your conditions to (removing the BJs and changing the comparison also):
    Collapse JASS:
    function Trig_Blood_Mana_Conditions takes nothing returns boolean
        return GetUnitAbilityLeve(GetKillingUnit(), 'A002') > 0
    endfunction
  • Next, if you use a function call (such as GetTriggerUnit()) more than once that returns a value, you should set it to a variable, like so:
    Collapse JASS:
    local unit u = GetTriggerUnit()
  • The next thing that you're going to want to do is to use reals instead of integers; that's probably why the spell doesn't work. As such, you're now going to have this:
    Collapse JASS:
    local integer a = GetUnitAbilityLevel(u, 'A002')
    local real b = a*20.00+5.00
    local real c = a*20.00-5.00
    local real d = RandomReal(b, c)
  • Finally, remove the BJ functions in the last line, like so:
    Collapse JASS:
    call SetUnitState(u, UNIT_STATE_MANA, (GetUnitState(U, UNIT_STATE_MANA)+d))
06-29-2007, 12:47 PM#3
Strilanc
This is based on what I think you're trying to achieve. You're using GetTriggerUnit() inside of GetUnitAbilityLevelSwapped(). This should be GetKillingUnitBJ(). Also, GetSpellAbilityId() should probably be 'A002'.

You're also going a bit extreme with locals b and c. In this case, it would be much clearer to just say "local integer d = a*20 + GetRandomInt(-5, 5)"
06-29-2007, 09:36 PM#4
deadlysheep_1
Thank you so much guys! As I said, I am very new to JASS, and when I make spells in JASS they constantly have problems that I am unable to fix. +rep to both of you :D. I would shower you with rep Pyrogasm but i see that you have enough rep to last a while. Thanks for your responses.

Yea, I got rid of all the BJ's, and yea I forgot to use GetKillingUnit() instead of GetTriggerUnit().
@Pyrogasm - With reals in JASS, do you have to put the y's in x.yy? Does JASS require the 2 decimals for reals, or does it automatically put a zero for the decimals when you leave the decimal points blank?
06-30-2007, 06:39 AM#5
Pyrogasm
You don't have to write the zeroes: "15." is the same as "15.00". The decimal point, however, is important.

I forgot to mention; Rising_Dusk has made a spell exactly like this for his hero The Grim Pharoah. You should check it out.
07-01-2007, 10:29 PM#6
deadlysheep_1
Ah k, I thought that you had to do something with maybe a decimal place or a couple zeros to make the world editor accept reals. With the Grim Pharoah though, you get the mana if someone around you dies, not just if you kill them. And also mine heals a somewhat random amount of mana, not just a set amount. And now mine as a floating text that appears above you for 0.9 seconds in blue text that says +(however much mana u healed). Thanks again Pyrogasm!