Tips on Optimizing my Mana Burn Spell

Beetlebomb

New Member
Reaction score
43
Hey guys,

I've created a simple mana burn spell that could use some help in optimizing. My problem is that I need to use the TriggerSleepAction so that I dont cause a leak. I also need to remove that pesky Lightning effect, or else it'll be there forever. It there a nice way for me to clean the following JASS spell up? All tips will be greatly appreciated ^^,

Now remember, go easy on me-- I'm new!(ie: "ZOMG WTF, U B DOINGZ IT ALL WRONG")

JASS:
scope ManaBurn initializer Unstable

private function CorrectSpell takes nothing returns boolean
    return GetSpellAbilityId() == 'A001'
endfunction

private function BurnIt takes nothing returns nothing
    local lightning light
    local texttag tag = CreateTextTag()
    local unit caster = GetTriggerUnit()
    local location casterloc = GetUnitLoc(caster)
    local integer level = GetUnitAbilityLevel(caster, 'A001')
    local integer rannum
    local unit tar = GetSpellTargetUnit()
    local location tarloc = GetUnitLoc(GetSpellTargetUnit())
    set rannum = GetRandomInt(level*15+25,level*15+100)
    set light = AddLightningLoc("AFOD", casterloc, tarloc)
    call SetUnitState(tar, UNIT_STATE_MANA, GetUnitState(tar, UNIT_STATE_MANA) - rannum) 
    set tag = CreateTextTagLocBJ("-"+I2S(rannum), tarloc, 0, 10, 0, 0, 100, 0)
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Demon\\DemonBoltImpact\\DemonBoltImpact.mdl", GetUnitX(tar), GetUnitY(tar)))
    call SetTextTagVelocityBJ(tag, 64, 90)
    call SetTextTagFadepoint(tag, 2.00 )
    call SetTextTagPermanent(tag, false)
    call TriggerSleepAction(0.25)
    call DestroyLightning(light)
    call TriggerSleepAction(1.75)
    call DestroyTextTag(tag)
    call RemoveLocation(casterloc)
    call RemoveLocation(tarloc)  
endfunction

private function Unstable takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer index = 0
    loop
    exitwhen index == bj_MAX_PLAYER_SLOTS
        call TriggerRegisterPlayerUnitEvent(t, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set index = index+1
    endloop
    call TriggerAddCondition(t, Condition(function CorrectSpell))
    call TriggerAddAction(t, function BurnIt)
endfunction
    
endscope


Thx ^^
 

emjlr3

Change can be a good thing
Reaction score
395
create your lightning when you establish your local
, same with rannum - use reals (then you can use the texttag native) - use velocitybj native(though the way you calculate speed is weird - i think a number like .03 is good, lol), null your local handles

rest is fine
 

Beetlebomb

New Member
Reaction score
43
Alright, I was a bit confused with what you meant by my velocitybj being wierd. Isn't .03 not even a noticable speed?


I changed things around a bit, but now the floating text wont even show up:

JASS:
scope ManaBurn initializer Unstable

private function CorrectSpell takes nothing returns boolean
    return GetSpellAbilityId() == 'A001'
endfunction

private function BurnIt takes nothing returns nothing
    local texttag tag = CreateTextTag()
    local unit caster = GetTriggerUnit()
    local location casterloc = GetUnitLoc(caster)
    local integer level = GetUnitAbilityLevel(caster, 'A001')
    local integer rannum = GetRandomInt(level*15+25,level*15+100)
    local unit tar = GetSpellTargetUnit()
    local location tarloc = GetUnitLoc(GetSpellTargetUnit())
    local lightning light = AddLightningLoc("AFOD", casterloc, tarloc)
    local real tagspeed = TextTagSpeed2Velocity(10)
    local real tagspeedx = tagspeed * Cos(90 * bj_DEGTORAD)
    local real tagspeedy = tagspeed * Sin(90 * bj_DEGTORAD)
    call SetUnitState(tar, UNIT_STATE_MANA, GetUnitState(tar, UNIT_STATE_MANA) - rannum)
    call SetTextTagText(tag, "-"+I2S(rannum), 10)
    call SetTextTagVisibility(tag, true)
    call SetTextTagPos(tag, GetUnitX(tar), GetUnitY(tar), 0)
    call SetTextTagColor(tag, 0, 200, 255, 0) 
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Demon\\DemonBoltImpact\\DemonBoltImpact.mdl", GetUnitX(tar), GetUnitY(tar)))
    call SetTextTagVelocity(tag, tagspeedx, tagspeedy)
    call SetTextTagFadepoint(tag, 2.00 )
    call SetTextTagPermanent(tag, false)
    call SetTextTagAge(tag, 3.00)
    call TriggerSleepAction(0.25)
    call DestroyLightning(light)
    call TriggerSleepAction(1.75)
    call DestroyTextTag(tag)
    call RemoveLocation(casterloc)
    call RemoveLocation(tarloc)  
endfunction

private function Unstable takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer index = 0
    loop
    exitwhen index == bj_MAX_PLAYER_SLOTS
        call TriggerRegisterPlayerUnitEvent(t, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set index = index+1
    endloop
    call TriggerAddCondition(t, Condition(function CorrectSpell))
    call TriggerAddAction(t, function BurnIt)
endfunction
    
endscope


EDIT: I'm guessing it's because I didn't set my local textag (tag) to it. But I don't know how to set it to it.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
The default size of 10 actually turns to 0.023

JASS:
function TextTagSize2Height takes real size returns real
    return size * 0.023 / 10
endfunction



Same deal on speed:
JASS:
function TextTagSpeed2Velocity takes real speed returns real
    return speed * 0.071 / 128
endfunction

function SetTextTagVelocityBJ takes texttag tt, real speed, real angle returns nothing
    local real vel = TextTagSpeed2Velocity(speed)
    local real xvel = vel * Cos(angle * bj_DEGTORAD)
    local real yvel = vel * Sin(angle * bj_DEGTORAD)

    call SetTextTagVelocity(tt, xvel, yvel)
endfunction



Your values are way too high...
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
You're best using a return true function as a filter for this line:


in the Init function.

Change it to this:

JASS:
private function True takes nothing returns boolean
    return true
endfunction

private function Unstable takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer index = 0
    loop
    exitwhen index == bj_MAX_PLAYER_SLOTS
        call TriggerRegisterPlayerUnitEvent(t, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, Filter(function True))
        set index = index+1
    endloop
    call TriggerAddCondition(t, Condition(function CorrectSpell))
    call TriggerAddAction(t, function BurnIt)
endfunction


You can also reduce some of the created vars, and use coordinates instead of locations. For example, you don't relaly need to create

JASS:
    local real tagspeedx = tagspeed * Cos(90 * bj_DEGTORAD)
    local real tagspeedy = tagspeed * Sin(90 * bj_DEGTORAD)


since they're only used once. Just calculate them when you need them.

You can also just use the units' X and Y, so you don't have to bother creating a location variable, and then destroying it. Juse use the AddLightning function instead of AddLightningLoc, since you're already using the GetUnitX and GetUnitY functions for the effect and TextTag.
 

Beetlebomb

New Member
Reaction score
43
Ok, this is what I got now, but now there's a new problem. The TextTag appears a little too far above the unit that I want. Why's that?


JASS:
scope ManaBurn initializer Unstable

private function CorrectSpell takes nothing returns boolean
    return GetSpellAbilityId() == 'A001'
endfunction

private function BurnIt takes nothing returns nothing
    local texttag tag = CreateTextTag()
    local unit caster = GetTriggerUnit()
    local location casterloc = GetUnitLoc(caster)
    local integer level = GetUnitAbilityLevel(caster, 'A001')
    local integer rannum = GetRandomInt(level*15+25,level*15+100)
    local unit tar = GetSpellTargetUnit()
    local location tarloc = GetUnitLoc(GetSpellTargetUnit())
    local lightning light = AddLightningLoc("AFOD", casterloc, tarloc)
    local real tagspeed = TextTagSpeed2Velocity(50)
    call SetUnitState(tar, UNIT_STATE_MANA, GetUnitState(tar, UNIT_STATE_MANA) - rannum)
    call SetTextTagText(tag, "-"+I2S(rannum), 0.023)
    call SetTextTagVisibility(tag, true)
    call SetTextTagPos(tag, GetUnitX(tar), GetUnitY(tar), 0)
    call SetTextTagColor(tag, 0, 200, 150, 0) 
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Demon\\DemonBoltImpact\\DemonBoltImpact.mdl", GetUnitX(tar), GetUnitY(tar)))
    call SetTextTagVelocity(tag, tagspeed * Cos(90 * bj_DEGTORAD), tagspeed * Sin(90 * bj_DEGTORAD))
    call SetTextTagFadepoint(tag, 2.00 )
    call SetTextTagPermanent(tag, false)
    call SetTextTagAge(tag, 3.00)
    call TriggerSleepAction(0.25)
    call DestroyLightning(light)
    call TriggerSleepAction(1.75)
    call DestroyTextTag(tag)
    call RemoveLocation(casterloc)
    call RemoveLocation(tarloc)  
endfunction

private function Unstable takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer index = 0
    loop
    exitwhen index == bj_MAX_PLAYER_SLOTS
        call TriggerRegisterPlayerUnitEvent(t, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set index = index+1
    endloop
    call TriggerAddCondition(t, Condition(function CorrectSpell))
    call TriggerAddAction(t, function BurnIt)
endfunction
    
endscope


EDIT:
JASS:
local real tagspeed = TextTagSpeed2Velocity(50)//The lower I set this value of 50, the more accurate the texttag is to the units position, but it slows the texts movement considerably.
 

Beetlebomb

New Member
Reaction score
43
Anyone? I still haven't resolved this problem :( . Is there something I'm missing or doing wrong? If it isn't too much to ask, could someone post a JASS spell of theirs to see what I'm doing wrong or possibly just explain to me what is missing(or incorrect)?

Thank you!
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Well I don't know if you did anything wrong.

This is what I usually use when I need to create a texttag that looks like a Critical Strike:

JASS:
asdfblah
    local texttag tt = CreateTextTag()
    call SetTextTagTextBJ(tt,STRING,10) //Size is 10 (notice this is the bj function)
    call SetTextTagPos(tt,X LOCATION,Y LOCATION,0) //No Z offset
    call SetTextTagColor(tt,255,0,0,255)    //Red
    call SetTextTagLifespan(tt,2)    //2 Seconds
    call SetTextTagFadepoint(tt,0)   //Start fading right away
    call SetTextTagVelocityBJ(tt,64,90) //64 velocity @ 90 degrees
    call SetTextTagPermanent(tt,false) //Gets removed after lifespan
 

Beetlebomb

New Member
Reaction score
43
Well I went ahead and did what you posted Darth, and it worked great! Thank you very much for helping me once again Darth!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top