A few more Questions with JASS

TheCrystal

New Member
Reaction score
36
Well, I'm new to JASS and all so I'm kind of cheating with GUI on some of my "Err, what do I do?" moments.

1. I'm trying to make a KB system for me (I rather not download one) and I'm having it activate every .03 seconds with a Timer.
Here's the GUI trig

Trigger:
  • KnockBackCall Copy
    • Events
      • Time - ThreeHundredthOfSecTimer expires
    • Conditions
    • Actions
      • Custom script: call KnockBack()


It works, I know it but there's a problem with the KB part itself.

JASS:
function KnockBack takes nothing returns nothing
    local group g = CreateGroup()
    local unit u = null
    local integer i = 0
    call GroupAddGroup(BeingKnockedBack,g)
    call DisplayTextToPlayer(Player(0),0,0,"KnockBackLoopActivating")
    loop           
        set u = FirstOfGroup(g)        
        exitwhen u == null
        set i = GetUnitUserData(u)
        call GroupRemoveUnit(g,u)
        call SetUnitX(u,GetUnitX(u)+15*Cos(KnockBackAngleReal<i>*bj_DEGTORAD))
        call SetUnitY(u,GetUnitY(u)+15*Sin(KnockBackAngleReal<i>*bj_DEGTORAD))
        set KnockBackReal<i>=KnockBackReal<i>-15
            if KnockBackReal<i> &lt;= 30 then
                call GroupRemoveUnit(BeingKnockedBack,u)
            endif
    endloop
endfunction</i></i></i></i></i>

The Text doesn't display, but if I put it BEFORE I set the Group, it displays. I'm not sure what's wrong here.

(Btw, how would I do events with functions?)
2. From what I understand I have to null locals such as "local unit u = BLEH" correct? And points, etc. So I'd best do this by doing a "local unit u = null" and all that at the END of a function?

3. Since I'm guessing points leak, would this leak?
(Writing this up in Firefox, sorry if I messed something up)
JASS:
function BLEH takes unit whichunit returns nothing
    local unit u = whichunit
    local real opx = GetUnitX(u)
    local real opy = GetUnitY(u)

Or only when the thing returns specifically with a Point, like GetUnitLoc?


4. Am I doing the KB for 1 all wrong or am I on the right path? (Trial and Error)

Thanks in advance.



Edit:
5. I'm trying to base an equation or something off of an AoE deal, the damage lowering the farther out of range the unit gets. So if the ability does say, 100 damage with 100 AoE, the unit at the edge of the AoE should have 1 damage dealt. Is there an equation or something I can get out of this that someone is willing to figure out for me? I can't seem to imagine one.
 

cleeezzz

The Undead Ranger.
Reaction score
268
1. what is the group BeingKnockedBack, you sure it isn't null?

2. you dont really have to null in the beginning, but at the end is a must. (or whenever your finished with it)

3. x and y do not leak, they are reals. locations do leak, but to answer your question, it still leaks because you didn't null u.

>Or only when the thing returns specifically with a Point, like GetUnitLoc?

when it returns locations (real x and y are not locations)

4. where are you setting, KnockBackReal, KnockBackAngleReal. and the way you loop through FirstOfGroup would just move the unit instantly to the end of the knockback.

5. pick units in range (the AOE). FirstOfGroup through them, calculate the distance from target point to unit.

lets say your AOE is 500. Then figure out a damage that sounds reasonable when divided by distance. such as 500 dmg. 500 dmg at 1 range = 500. 500 dmg at 500 range = 1 dmg.

(be careful of divide by 0 error)
 

TheCrystal

New Member
Reaction score
36
1.
I see your point, I just tested the Add Knock Back function and it seems to be half working as well. It seems to be surrounded about the group.

Here's the "Add Unit to Group" trigger.
JASS:
function AddKnockBack takes unit whichunit, location whichlocation, real power returns nothing
    local unit u = whichunit
    local real opx = GetLocationX(whichlocation) //Origin Point
    local real opy = GetLocationY(whichlocation)
    local real upx = GetLocationX(GetUnitLoc(u)) //Unit Point
    local real upy = GetLocationY(GetUnitLoc(u))
    call DisplayTextToPlayer(Player(0),0,0,&quot;1234&quot;)
    set KnockBackReal[GetUnitUserData(u)] = power
    set KnockBackAngleReal[GetUnitUserData(u)] = bj_RADTODEG*Atan2(upy-opy,upx-opx)
    call DisplayTextToPlayer(Player(0),0,0,&quot;4567&quot;)
    call GroupAddUnit(BeingKnockedBack,u)
    call DisplayTextToPlayer(Player(0),0,0,&quot;891011&quot;)
endfunction


891011 doesn't appear.

Here's the JASSInit trigger.

JASS:
globals
    integer IndexNumber = 1 //Reset once hit 8000
    real array IndexReal
    real array IndexReal2
    integer array IndexInteger
    real array KnockBackReal
    real array KnockBackAngleReal
    group BeingKnockedBack
endglobals


I'm pretty sure it's working since the index is working fine.



2. I see, so I'll add a set u = null at the end of the loop then.

4. The setting of the unit X and Y, what would you suggest I do there? Just move by 15, and remove 15 from the "Power" variable? That seems too robotic.

5. Divide the damage by range? That'd be all, "1 range = 500 damage, 2 range is 250", which I don't like at all. I want it to spread it out evenly, so a unit (100 at target point, 100 AoE) at 50 range do 50 damage.
 

cleeezzz

The Undead Ranger.
Reaction score
268
for the group, i dont think you ever initialized it, set KnockBackGroup = CreateGroup()

oops i meant subtract

500 dmg - distance

500 dmg at 500 range = 0 dmg

500 dmg at 5 range = 495
 

TheCrystal

New Member
Reaction score
36
What of times when it does 50 damage in an 150 AoE?



Edit: Works now that I've fixed the code.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top