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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • 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 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