Last Created Unit Into Variable

S

sinners1234

Guest
Hi all,
I am new to Jass so this question prob seems really stupid, however i did a search and couldnt find and answer to it.
In my code i create a unit, then i want to put this Last created unit into a variable.

function Trig_Ability_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction

function Trig_Ability_Actions takes nothing returns nothing
local unit c = GetTriggerUnit()
local location l = GetUnitLoc(c)

call CreateUnitAtLoc(Player(0), 'n000', l, 0.00)
call SetUnitFlyHeightBJ(GetLastCreatedUnit(), 500.00,100.00)
endfunction

Sorry bout ^^^^^^^ Didnt know how to insert that codde box thingy

As you can see i create 'n000' (which is a dummie) at the casters location. Next the dummie is ment to rise up to 500 flying height, however he does not do that, and i am assuming that is because i have used the LastCreatedUnit(). Is there any way to get my dummie ('n000') into a variable.

Thanks
 

gref

New Member
Reaction score
33
PHP:
function BLAH
    local unit c= GetTriggerUnit()
    local unit dummy
    local location l = GetUnitLoc(c)
    call CreateUnitAtLoc(Player(0), 'n000', l, 0.00)
    set dummy = GetLastCreatedUnit()
    SetUnitFlyHeightBJ(dummy, 500, 100)

endfunction

It's probably messing up because flyheight is being set over time, and GetLastCreatedUnit() doesn't last after the instant of creation. A local variable will.
 
I

IKilledKEnny

Guest
There is also a better way:

set localunit = CreateUnit...
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
> GetLastCreatedUnit() doesn't last after the instant of creation.

Hm?
bj_lastCreatedUnit is a global variable, and keeps whatever it's set to until you give it some other value.


Setting the flying height only works on either flying units or units that passed through "add ability: Crow Form" / "remove ability: Crow Form".


"CreateUnitAtLoc" doesn't set "last created unit" btw...
set bj_lastCreatedUnit = CreateUnitAtLoc(...)
 
I

IKilledKEnny

Guest
> Tinki3

See post 3. ;)

The box tags by the way are on the sime line you see bold, italic and underline and such, towards the end, 3ed from the right.
 
S

sinners1234

Guest
Thanks for all your help i got it working now. 1 last question, how do you add that code box?

Thanks
 
S

sinners1234

Guest
Ok, so i have another qusstion that doesnt realte to the first one at all but i didnt want to make another thread.

EDIT:

I want to create a unit that is a polar offset of the targeted unit of the ability.

Code:
function Trig_Point_Strike_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000' 
endfunction

function Trig_Point_Strike_Actions takes nothing returns nothing
local unit c = GetTriggerUnit()
local unit t = GetSpellTargetUnit()
local location l = GetUnitLoc(c)
local location lt = GetUnitLoc(t)
local real xt = GetUnitX(t)
local real yt = GetUnitY(t)
local real xc = GetUnitX(c)
local real yc = GetUnitY(c)
local real ang = bj_RADTODEG * Atan2(yc - yt, xc - xt)
local real x = GetLocationX(t) + 200 * Cos(ang * bj_DEGTORAD)
local real y = GetLocationX(t) + 200 * Sin(ang * bj_DEGTORAD)
local integer i = GetUnitAbilityLevel(c, 'A000')
local unit dummie1 = CreateUnit(Player(0), 'H000', x, y, 0.00) 
endfunction

it keeps comin up with compiled errors saying that i am missing ')' i dont know why either
any help is appreciated
Thanks
sinners
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
> GetLocationX(t)

xt

You also have that one twice...


There's also not much of a point to multiply ang by bj_RADTODEG only to convert it back later with bj_DEGTORAD.
 
S

sinners1234

Guest
lol thank u for that.
However do you see any reason y i get 4 compiled errors saying
Expected ')' (Unit)

??????

Thanks
Sinners
 

Tom Jones

N/A
Reaction score
437
The only errors is, that your using a unit variable when it is expecting a location variable in GetLocationX().
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Here is how the code will look with the fixes ace suggested:
Code:
function Trig_Point_Strike_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000' 
endfunction

function Trig_Point_Strike_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()
    local real xt = GetUnitX(t)
    local real yt = GetUnitY(t)
    local real xc = GetUnitX(c)
    local real yc = GetUnitY(c)
    local real ang = Atan2(yc - yt, xc - xt)
    local real x = xt + 200 * Cos(ang)
    local real y = yt + 200 * Sin(ang)
    local integer i = GetUnitAbilityLevel(c, 'A000')
    local unit dummie1 = CreateUnit(Player(0), 'H000', x, y, 0.00) 
endfunction
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
There's too many variables in that thing.
Actually, the entire function is a bunch of "local type var"...
Some never used.


> Atan2(yc - yt, xc - xt)

This goes from the target to the caster, right?
 
S

sinners1234

Guest
^^^^^^^^^ He is right they will be used when the whole trigger is done. Any ways thanks for all your help it works now. i would leave +Rep but i dont no how to lol

sinners
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
How to rep someone:

- First step, go to the thread with the person you want to rep.

- Look for the person's post and click the scale icon towards the topright of the post.

- If you hover over it, it should say:
Code:
Add to (Poster)'s reputation

- Click the icon and it should say either "I approve" and "I disapprove".

- Select which one you want to do.

- Feel free to leave any comments in the comment area.

- Then you can click "Add to Reputation" and voila! It should say something like "You have added to (Poster's) reputation. May you be lucky enough to receive the same reputation in return."

I hope this helps! :D :shades:
 
S

sinners1234

Guest
^^^^^ Thank you

Ok so i think that this thread should like turn into my question thread or something lol. I copied and pasted the CsCache system from the provided map.(I was doing the simple dash spell tut) And i keep getting two errors saying Missing end of line. I hav no idea why but any help would be great

Sinners
 
S

sinners1234

Guest
i copied and pasted the script directly from the map that is provided when u go to the site that has the system

sinners
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top