• 🏆 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] Add Buff Function

Status
Not open for further replies.
Level 20
Joined
Jul 12, 2010
Messages
1,717
WARNING! Beginner JASSer alert!

So with that out of the way, I'm trying to make a bunch of jass functions to use in conjunction with GUI and "AddBuff" is one of them.

JASS:
//===============================================================================

//Because I'm bad at naming stuff I will explain here my "naming scheme"
//   unit u = caster unit
//   integer a = the ability to cast for buff
//   unit t = target unit
//   unit lu = last created unit

function addbuff takes unit u, integer a, unit t returns nothing

local location p = GetUnitLoc(u)
local unit lu

    call CreateNUnitsAtLoc( 1, 'buf0', GetOwningPlayer(u), p, 0.00 )
    set lu = GetLastCreatedUnit()
    call UnitAddAbility( lu, a )
    call IssueTargetOrder( lu, "slow", t )
    call UnitApplyTimedLife( lu, 'BTLF', 2.00 )

call RemoveLocation(p)
set u = null
set t = null
set lu = null

endfunction
//===============================================================================

  • chat
    • Events
      • Player - Player 1 (Red) types a chat message containing <Empty String> as A substring
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Entered chat string) Equal to addbuff1
        • Then - Actions
          • Set VariableSet AddBuff = Add Buff (Slow)
          • Custom script: call addbuff ( udg_u , udg_AddBuff, udg_t)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Entered chat string) Equal to addbuff2
            • Then - Actions
              • Set VariableSet AddBuff = Add Buff (Wind Walk)
              • Custom script: call addbuff ( udg_u , udg_AddBuff, udg_t)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Entered chat string) Equal to addbuff3
                • Then - Actions
                  • Set VariableSet AddBuff = Add Buff (Breath of Fire)
                  • Custom script: call addbuff ( udg_u , udg_AddBuff, udg_t)
                • Else - Actions

  • map init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet u = Arthas (wielding Frostmourne) 0001 <gen>
      • Set VariableSet t = Paladin 0014 <gen>

So my method works BUT I wanted to get some opinions from more advanced users IF there's a faster/better way to execute this.

Also yes I know that in JASS most people prefer to use X/Y instead of loc but I prefer the GUI "standard"


Thanks in advance to those that help! :thumbs_up:
 

Attachments

  • add buff.w3m
    10.5 KB · Views: 25

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Well, if you want faster/better:
vJASS:
function addbuff takes unit u, integer a, unit t returns nothing
local real x = GetUnitX(t)
local real y = GetUnitY(t)
local unit lu
    set lu = CreateUnit(GetOwningPlayer(u), 'buf0', x, y, 0)
    call UnitAddAbility( lu, a )
    call IssueTargetOrder( lu, "slow", t )
    call UnitApplyTimedLife( lu, 'BTLF', 0.50 )
set u = null
set t = null
set lu = null
endfunction
There's not much room for improvement besides using coordinates and a non-N create unit function.

You could also use a Dummy system to recycle dummys instead of creating a new one each time but it probably doesn't make much of a difference.

Oh, and your IssueTargetOrder should be setup to use the ability's order id and not "slow" so it can work for any ability.

Edit: Fixed GetLastCreatedUnit @HeavenSmitingDevilEmperor
 
Last edited:
Level 20
Joined
Jul 12, 2010
Messages
1,717
@Uncle ahh thanks for the tips!
JASS:
CreateNUnitsAtLoc -> set lu = CreateUnit(GetOwningPlayer(u), 'buf0', x, y, 0)
This is what happens when you convert triggers to jass and use exactly what it gives without taking a look at jasscraft xD

JASS:
call IssueTargetOrder( lu, "slow", t )
again I used this specific one after converting this:
  • Unit - Order lu to Human Sorceress - Slow t
so you are actually referring to this right?
JASS:
native IssueTargetOrderById         takes unit whichUnit, integer order, widget targetWidget returns boolean
the reason I used slow was because I plan to base all my "AddBuff" spells on slow:
1623260276431.png


it's so fascinating when you first discover jass natives that are non-existent in GUI :grin:

thanks both!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
@Uncle ahh thanks for the tips!
JASS:
CreateNUnitsAtLoc -> set lu = CreateUnit(GetOwningPlayer(u), 'buf0', x, y, 0)
This is what happens when you convert triggers to jass and use exactly what it gives without taking a look at jasscraft xD

JASS:
call IssueTargetOrder( lu, "slow", t )
again I used this specific one after converting this:
  • Unit - Order lu to Human Sorceress - Slow t
so you are actually referring to this right?
JASS:
native IssueTargetOrderById         takes unit whichUnit, integer order, widget targetWidget returns boolean
the reason I used slow was because I plan to base all my "AddBuff" spells on slow:
View attachment 381274

it's so fascinating when you first discover jass natives that are non-existent in GUI :grin:

thanks both!
If all of your buffs are based on Slow then don't change it.

A good practice is to always check if there's a non "BJ" version or a more efficient version of a function that you can use (like using x/y instead of locations). The IntelliSense offered by vJass extensions can help a lot as well.
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Can one even get the order id of an ability on demand?
vJASS:
function SomeFunction
    local integer abil = GetSpellAbilityId() // or just type in the ability id
    local unit caster
    local unit target
    call IssueTargetOrderById(caster, abil, target)
endfunction
In the case of xorkatoss' function, abil would be supplied in the parameters.

If that doesn't work then I believe you would have to rely on something like: [Snippet] Ascii
 
Last edited:
Status
Not open for further replies.
Top