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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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