SetUnitPosition question, and my dummy unit isn't created

MasterRofl

New Member
Reaction score
8
My dummy unit isn't created. Timer problem?

If I move a unit (pos: x,y) to pos:(x+v, y+v), would it move towards the upper right?

Also, my main problem. Now, a unit is made. But the unit isn't moved.
JASS:
library ThrowKnife initializer ThrowKnife uses HSAS

globals
    private constant integer SPELLID = 'A01U'
    private constant string SLOWSTRING = "slow"
    private constant integer DUMMYID = 'n00N'
    private constant integer DUMMYSPELLID = 'A026'
endglobals

struct Dagger
    unit u
    unit t
    unit d
    real x
    real y
    real damage
        method onDestroy takes nothing returns nothing
            set.u = null
            set.t = null
            set.d = null
        endmethod
endstruct

private function AngleBetweenXY takes real x, real y, real xy, real yx returns real
    return bj_RADTODEG * (Atan2(y - yx, x - xy))
endfunction

private function DistanceBetweenXY takes real x, real y, real xy, real yx returns real
    local real dx = xy - x
    local real dy = yx - y
    return SquareRoot((dx * dx) + (dy * dy))
endfunction

//! runtextmacro HSAS_Static("d", "1288", "private")

private function Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local Dagger d = GetAttachedStructd(t)
    local real x
    local real y 
    local real xy
    local real yx
    set x = GetUnitX(d.d)
    set y = GetUnitY(d.d)
    set xy = GetUnitX(d.t)
    set yx = GetUnitX(d.t)
    call SetUnitPositionLocFacingLocBJ( d.d, PolarProjectionBJ(GetUnitLoc(d.d), 25., AngleBetweenPoints(GetUnitLoc(d.d), GetUnitLoc(d.t))), GetUnitLoc(d.t))
    if  DistanceBetweenPoints(GetUnitLoc(d.d), GetUnitLoc(d.t)) < 12. then
        call SetUnitAbilityLevel(d.d, DUMMYSPELLID, GetUnitAbilityLevel(d.u, SPELLID))
        call IssueTargetOrder( d.d, SLOWSTRING, d.t)
        call UnitDamageTarget(d.d, d.t, d.damage, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
        call RemoveUnit(d.d)
        call d.destroy()
        call PauseTimer(t)
        call DestroyTimer(t)
    endif
endfunction

private function Actions takes nothing returns nothing
    local Dagger d = Dagger.create()
    local timer t = CreateTimer()
    set d.u = GetTriggerUnit()
    set d.t = GetSpellTargetUnit()
    set d.x = GetUnitX(d.u)
    set d.y = GetUnitY(d.u)
    set d.damage = GetUnitAbilityLevel(d.u, SPELLID) * 100.
    set d.d = CreateUnit( GetOwningPlayer(d.u), DUMMYID, d.x, d.y, AngleBetweenPoints(GetUnitLoc(d.u), GetUnitLoc(d.t)))
    call AttachStructd(t, d)
    call TimerStart(t, 0.03, true, function Callback)
    set t = null
endfunction

private function Conds takes nothing returns boolean
    return GetSpellAbilityId() == SPELLID
endfunction

private function ThrowKnife takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition( function Conds ))
    call TriggerAddAction(t, function Actions)
    set t = null
endfunction

endlibrary
 

quraji

zap
Reaction score
144
Did you try using debug messages to see if the struct is being retrieved properly, and the callback is being executed, etc?

Also, you don't need to null struct members, as they are globals.
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
Then, I wonder why the he11 there is a .destroy() option if they aren't supposed to be nulled.
 

Flare

Stops copies me!
Reaction score
662
Then, I wonder why the he11 there is a .destroy() option if they aren't supposed to be nulled.

That recycles the struct index :p They are just global arrays, so they do have their limitations and how many can be used simultaneously.
JassHelper manual said:
JassHelper is just a preprocessor not a hack so whatever adition to Jass we add is still limited by Jass' own limitations, in this case, structs use arrays which have a 8191 values limit, and we cannot use index 0 which is null for structs, so there is an 8190 instances limit. This limit is for instances of each type, so you may have 8190 objects of a pair struct type and still are able to have many other instances of other types.

It means that if you keep creating many structs of a type without destroying them you would eventually reach the limit. So keep in mind this: IN the case the instances limit of a type is reached structtype.create() WILL RETURN 0.
But, AFAIK, with HSAS, you must null struct members too or else you risk crippling the game to single-figure FPS :\ And don't you need to null t in Callback?

JASS:
call RemoveUnit(d.d)


You're removing the unit immediately, so it probably doesn't have time to cast. Try
JASS:
call UnitApplyTimedLife (d.d, 'BTLF', 2.) //I think BTLF is the correct ID for generic expiration timer
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
> But, AFAIK, with HSAS, you must null struct members too or else you risk crippling the game to single-figure FPS :\ And don't you need to null t in Callback?

Yeah, that's it. I don't want to risk ruining the FPS because "structs are global". And about the timer, I noticed that afterwards and edited it. The code is made by me by the way, atleast parts of it.
 

Trollvottel

never aging title
Reaction score
262
why would you NULL struct members in HSAS? struct members are just global type arrays. So they will be re-used... you only have to null locals.
 

MasterRofl

New Member
Reaction score
8
The code should create a unit and move it to the target location and deal damage when it gets within 128 units of the unit, right? But right now, the unit isn't even being created. :(

I'm assuming this is because Callback isn't being executed, but why?

Edit: I know the unit isn't being created b/c it has a model.
 

Hatebreeder

So many apples
Reaction score
381
Well...
JASS:
private function whatever takes nothing returns nothing
   local real v = 30
   local real x = GetUnitX(whateverunit)
   local real y = GetUnitY(whateverunit)
   call SetUnitPosition(whateverunit, x+v, y+v)
endfunction

You are not "taking" a Unit (in this case whateverunit). So, if you even manage to create a unit, you won't be able to move it, since you can't refer to your dummy like this...
 

Flare

Stops copies me!
Reaction score
662
The code should create a unit and move it to the target location and deal damage when it gets within 128 units of the unit, right? But right now, the unit isn't even being created. :(

I'm assuming this is because Callback isn't being executed, but why?

Edit: I know the unit isn't being created b/c it has a model.

Read the bottom of post #4 :p Add some BJDebugMsg's to your callback function to check if it's running (and add a different one to the if block within the callback, to see if that condition is being fulfilled)
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133

MasterRofl

New Member
Reaction score
8
That's exactly what I have... the Callback isn't called.

Is something wrong with this?
JASS:
//! runtextmacro HSAS_Static("d", "1288", "private")

I don't really get what "1288" does. All I know is that it's the array size (for what?).

I know the struct is working in the Actions block. For all I know, either the Callback block isn't called, or the struct isn't being attached in the Callback block. (or I am just spewing bs...)
 

Trollvottel

never aging title
Reaction score
262
That's exactly what I have... the Callback isn't called.

Is something wrong with this?
JASS:
//! runtextmacro HSAS_Static("d", "1288", "private")

I don't really get what "1288" does.

I know the struct is working in the Actions block. For all I know, either the Callback block isn't called, or the struct isn't being attached in the Callback block. (or I am just spewing bs...)


its not the same....


he changed ThrowKnife___Callback into Callback. in you library you dont have to use the prefix.
 
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