Unit refuse to move

LocalDude

New Member
Reaction score
4
hi i'm making a code (moste of the code i got from a friend) and when i tell the unit to move nothings happening.

JASS:
globals
    unit udg_Caster
    unit udg_companion
endglobals


function MoveDummies takes  unit udg_Caster, unit udg_companion  returns nothing

    local real CasterX = GetUnitX(udg_Caster)
    local real CasterY = GetUnitY(udg_Caster)
    local real PlaceX = GetUnitX(udg_companion)
    local real PlaceY = GetUnitY(udg_companion)
    local real Angle                     
                        
            set Angle = ((bj_RADTODEG * Atan2(PlaceY - CasterY, PlaceX - CasterX)) + 10)
            set PlaceX = CasterX + 100 * Cos((Angle + 5) * bj_RADTODEG)
            set PlaceY = CasterY + 100 * Sin((Angle + 5) * bj_RADTODEG) 
            call SetUnitPosition(udg_companion, PlaceX, PlaceY) 
endfunction

function CreateDummy takes integer a, unit udg_Caster returns unit
    local player pl = GetOwningPlayer(udg_Caster)
    
    if a == 1 then
        set udg_companion = CreateUnit(pl, 'h003', GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 2 then
        set udg_companion = CreateUnit(pl, 'h004', GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 3 then
        set udg_companion = CreateUnit(pl, 'h005', GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 4 then
        set udg_companion = CreateUnit(pl, 'h006', GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 5 then
        set udg_companion = CreateUnit(pl, 'h007', GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    endif     
    set udg_companion = GetLastCreatedUnit()
    return udg_companion                     
endfunction


this is the main trigering code
Code:
Abilitylevel
    Events
        Unit - A unit Begins casting an ability
    Conditions
    Actions
        Set a = (Random integer number between 1 and 5)
        Custom script:   call CreateDummy(udg_a, udg_Caster)
        Trigger - Turn on trigerdummy <gen>
and here is the second one
Code:
trigerdummy
    Events
        Time - Every 0.10 seconds of game time
    Conditions
    Actions
        Custom script:   call MoveDummies(udg_Caster, udg_companion)
 

Samael88

Evil always finds a way
Reaction score
181
hi i'm making a code (moste of the code i got from a friend) and when i tell the unit to move nothings happening.

JASS:
globals
    unit udg_Caster
    unit udg_companion
endglobals


function MoveDummies takes  unit udg_Caster, unit udg_companion  returns nothing

    local real CasterX = GetUnitX(udg_Caster)
    local real CasterY = GetUnitY(udg_Caster)
    local real PlaceX = GetUnitX(udg_companion)
    local real PlaceY = GetUnitY(udg_companion)
    local real Angle                     
                        
            set Angle = ((bj_RADTODEG * Atan2(PlaceY - CasterY, PlaceX - CasterX)) + 10)
            set PlaceX = CasterX + 100 * Cos((Angle + 5) * bj_RADTODEG)
            set PlaceY = CasterY + 100 * Sin((Angle + 5) * bj_RADTODEG) 
            call SetUnitPosition(udg_companion, PlaceX, PlaceY) 
endfunction

function CreateDummy takes integer a, unit udg_Caster returns unit
    local player pl = GetOwningPlayer(udg_Caster)
    
    if a == 1 then
        set udg_companion = CreateUnit(pl, &#039;h003&#039;, GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 2 then
        set udg_companion = CreateUnit(pl, &#039;h004&#039;, GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 3 then
        set udg_companion = CreateUnit(pl, &#039;h005&#039;, GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 4 then
        set udg_companion = CreateUnit(pl, &#039;h006&#039;, GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 5 then
        set udg_companion = CreateUnit(pl, &#039;h007&#039;, GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    endif     
    <b>set udg_companion = GetLastCreatedUnit()</b> // This line is not nessecary
    return udg_companion                     
endfunction

I have marked a line that is not nessecary:p
And you can set "a" as a local in the jass function and set it to a random value as you declare it instead. Much more efficient;)

Edit: And you don't need to return a unit in the CreateDummy function either. It is set by the "set udg_companion =" in the if's.

Edit2: You need to have a condition in your Abilitylevel trigger, reffering to spell your casting.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
hi i'm making a code (moste of the code i got from a friend) and when i tell the unit to move nothings happening.

JASS:
globals
    unit udg_Caster
    unit udg_companion
endglobals


function MoveDummies takes  unit udg_Caster, unit udg_companion  returns nothing

    local real CasterX = GetUnitX(udg_Caster)
    local real CasterY = GetUnitY(udg_Caster)
    local real PlaceX = GetUnitX(udg_companion)
    local real PlaceY = GetUnitY(udg_companion)
    local real Angle                     
                        
            set Angle = ((bj_RADTODEG * Atan2(PlaceY - CasterY, PlaceX - CasterX)) + 10)
            set PlaceX = CasterX + 100 * Cos((Angle + 5) * bj_RADTODEG)
            set PlaceY = CasterY + 100 * Sin((Angle + 5) * bj_RADTODEG) 
            call SetUnitPosition(udg_companion, PlaceX, PlaceY) 
endfunction

function CreateDummy takes integer a, unit udg_Caster returns unit
    local player pl = GetOwningPlayer(udg_Caster)
    
    if a == 1 then
        set udg_companion = CreateUnit(pl, &#039;h003&#039;, GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 2 then
        set udg_companion = CreateUnit(pl, &#039;h004&#039;, GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 3 then
        set udg_companion = CreateUnit(pl, &#039;h005&#039;, GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 4 then
        set udg_companion = CreateUnit(pl, &#039;h006&#039;, GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    elseif a == 5 then
        set udg_companion = CreateUnit(pl, &#039;h007&#039;, GetWidgetX(udg_Caster), GetWidgetY(udg_Caster), 270.)
    endif     
    set udg_companion = GetLastCreatedUnit()
    return udg_companion                     
endfunction

I believe the problem is that you are using the actual globals for the parameters. Replace them with parameters of the same type but don't use the name of the global. For example:
JASS:

function MoveDummies takes  unit Caster, unit companion  returns nothing

    local real CasterX = GetUnitX(Caster)
    local real CasterY = GetUnitY(Caster)
    local real PlaceX = GetUnitX(companion)
    local real PlaceY = GetUnitY(companion)
    local real Angle = ((bj_RADTODEG * Atan2(PlaceY - CasterY, PlaceX - CasterX)) + 10)
            set PlaceX = CasterX + 100 * Cos((Angle + 5) * bj_RADTODEG)
            set PlaceY = CasterY + 100 * Sin((Angle + 5) * bj_RADTODEG) 
            call SetUnitPosition(companion, PlaceX, PlaceY) 
endfunction


BUT the values you fill in when you call it will be the ACTUAL values you want to put in. So don't put in "Caster" and "companion", instead put udg_Caster and udg_companion or whatever you want the arguments to be.

Then the other code should be modified like this:
JASS:
function CreateDummy takes integer a, unit Caster returns unit
    local player pl = GetOwningPlayer(Caster)
    
    if a == 1 then
        set udg_companion = CreateUnit(pl, &#039;h003&#039;, GetWidgetX(Caster), GetWidgetY(Caster), 270.)
    elseif a == 2 then
        set udg_companion = CreateUnit(pl, &#039;h004&#039;, GetWidgetX(Caster), GetWidgetY(Caster), 270.)
    elseif a == 3 then
        set udg_companion = CreateUnit(pl, &#039;h005&#039;, GetWidgetX(Caster), GetWidgetY(Caster), 270.)
    elseif a == 4 then
        set udg_companion = CreateUnit(pl, &#039;h006&#039;, GetWidgetX(Caster), GetWidgetY(Caster), 270.)
    elseif a == 5 then
        set udg_companion = CreateUnit(pl, &#039;h007&#039;, GetWidgetX(Caster), GetWidgetY(Caster), 270.)
    endif     
    set udg_companion = GetLastCreatedUnit()
    return udg_companion                     
endfunction


There you go! Hopefully it works. Good luck. ;)
 

Samael88

Evil always finds a way
Reaction score
181
There is a misstake made in this trigger, just realized it.
I should know, I made them for him:p
Here is the original btw(with the changes to it so that it should work):

JASS:
function MoveDummies takes unit Caster returns nothing
    local integer Ability_Rawcode = &#039;ANms&#039;
    //Do not edit under this line.
    local integer loopint = 1
    local real CasterX = GetWidgetX(Caster)
    local real CasterY = GetWidgetY(Caster)
    local real array PlaceX
    local real array PlaceY
    local real array PlaceZ
    local real Angle
    local integer NumUnits = GetUnitAbilityLevel(Caster, Ability_Rawcode)
    
    if  NumUnits &gt; 0 then
        loop
            exitwhen loopint ==  NumUnits
                set PlaceX[loopint] = GetWidgetX(udg_UnitArray[loopint])
                set PlaceY[loopint] = GetWidgetY(udg_UnitArray[loopint])
                set Angle = ((bj_RADTODEG * Atan2(PlaceY[loopint] - CasterY, PlaceX[loopint] - CasterX)) + 10)
                set PlaceX[loopint] = PlaceX[loopint]+ 100 * Cos(Angle * bj_DEGTORAD)
                set PlaceY[loopint] = PlaceY[loopint]+ 100 * Cos(Angle * bj_DEGTORAD)
                call SetUnitX(udg_UnitArray[loopint], PlaceX[loopint])
                call SetUnitY(udg_UnitArray[loopint], PlaceY[loopint])
        endloop
    endif
endfunction

function CreateDummy takes unit Caster returns nothing
    local integer Ability_Rawcode = &#039;ANms&#039;
    //Do not edit under this line.
    local integer a = GetUnitAbilityLevel(Caster, Ability_Rawcode)
    local player pl = GetOwningPlayer(Caster)
    if a == 1 then
        set udg_UnitArray<b> = CreateUnit(pl, &#039;h003&#039;, GetWidgetX(Caster), GetWidgetY(Caster), 270.)
    elseif a == 2 then
        set udg_UnitArray<b> = CreateUnit(pl, &#039;h004&#039;, GetWidgetX(Caster), GetWidgetY(Caster), 270.)
    elseif a == 3 then
        set udg_UnitArray<b> = CreateUnit(pl, &#039;h005&#039;, GetWidgetX(Caster), GetWidgetY(Caster), 270.)
    elseif a == 4 then
        set udg_UnitArray<b> = CreateUnit(pl, &#039;h006&#039;, GetWidgetX(Caster), GetWidgetY(Caster), 270.)
    elseif a == 5 then
        set udg_UnitArray<b> = CreateUnit(pl, &#039;h007&#039;, GetWidgetX(Caster), GetWidgetY(Caster), 270.)
    endif               
endfunction</b></b></b></b></b>


It was made for having a spinning effect, similiar to the orb effects, except that it should spin aroung the unit instead. But he wanted it to be for a manashield. We had a missunderstanding. It is just for him to change a few functions in there. The MoveDummies function does not nessecarely need to be changed tho. It is only the trigger calls the CreateDummy that needs to be changed.

I suggest you try as you did above, but with these again. You need this to call it.
call CreateDummy(udg_Variable_for_the_caster_unit_here)
call MoveDummies(udg_Variable_for_the_caster_unit_here)
And you will need the variable UnitArray as a udg_ still.
Store the murloc as I told you to in a variable. Then do as you did above.

Code:
Abilitylevel
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
    Actions
        
        Custom script:   call CreateDummy(udg_Caster)

You can might also want to add an expiring timer to the dummy aswell. Then I suggest that you do that in the Jass function that creates it. If it is the manashield you might want it to go away at some point;)

And a tip at the end. Go for the idea you had with the different unit effects for each level, that sounds cool-er:thup: I changed the trigger to really do that know. Try it again, I think it will work a little better this time.

Oh, and Purge:
I believe the problem is that you are using the actual globals for the parameters. Replace them with parameters of the same type but don't use the name of the global.

Shame on you, a such good Jass user as you should no better than this:p Of course it does not matter, there is no collision beacuse of the local cannot be called outside the function:p not when put in the "call", and the udg_ cannot be confused for the local due to the udg_:rolleyes: I think it could had been a little worse with newgen tho, not having the udg_, not sure about that tho;)

Edit: You might want to put a loop inside the CreateUnit function aswell. Just so that it creates the correct amount of units aswell. I suggest using the a value as the end value for that loop aswell, and adding a local integer that is called b or something. And put the ifs in this:
JASS:
loop 
exitwhen b==a
//ifs inserted here
set b=b+1
endloop
 

Flare

Stops copies me!
Reaction score
662
JASS:
//Hmmm...
           set Angle = ((bj_RADTODEG * Atan2(PlaceY - CasterY, PlaceX - CasterX)) + 10)
            set PlaceX = CasterX + 100 * Cos((Angle + 5) * bj_RADTODEG)
            set PlaceY = CasterY + 100 * Sin((Angle + 5) * bj_RADTODEG)

1) Your converting the whole angle to degrees, why? You could do
JASS:
Atan2 (y, x) + 10*bj_DEGTORAD
//Then there&#039;s no need to convert back and forth

//Also, you could add in the +5 there at that line, rather than doing +10 and +5 separately, so it&#039;d be + 15*bj_DEGTORAD

2) Your converting said angle from radians to degrees, even though it's already in degrees?
3) Cos/Sin functions take a value in radians, so your offsets are going to be totally messed up

@Samael: Why are you using arrays there? It's not really necessary, it's just extra work :p Also, you never incremented loopint, and your code will spawn (NumUnits - 1) units - default loopint to 0

And you can set "a" as a local in the jass function and set it to a random value as you declare it instead. Much more efficient
How would it be any more efficient? Either way, the random number would have to be declared, so the point at which it's declared won't impact on efficiency (or whether it's global/local)
 

Samael88

Evil always finds a way
Reaction score
181
JASS:
//Hmmm...
           set Angle = ((bj_RADTODEG * Atan2(PlaceY - CasterY, PlaceX - CasterX)) + 10)
            set PlaceX = CasterX + 100 * Cos((Angle + 5) * bj_RADTODEG)
            set PlaceY = CasterY + 100 * Sin((Angle + 5) * bj_RADTODEG)

1) Your converting the whole angle to degrees, why? You could do
JASS:
Atan2 (y, x) + 10*bj_DEGTORAD
//Then there&#039;s no need to convert back and forth

//Also, you could add in the +5 there at that line, rather than doing +10 and +5 separately, so it&#039;d be + 15*bj_DEGTORAD

2) Your converting said angle from radians to degrees, even though it's already in degrees?
3) Cos/Sin functions take a value in radians, so your offsets are going to be totally messed up

@Samael: Why are you using arrays there? It's not really necessary, it's just extra work :p Also, you never incremented loopint, and your code will spawn (NumUnits - 1) units - default loopint to 0


How would it be any more efficient? Either way, the random number would have to be declared, so the point at which it's declared won't impact on efficiency (or whether it's global/local)

got yah on the convertation thingy. "loopint" is set to 1 when declaring the variable.
And you missed the fact that I forgot to set loopint=loopint+1. That is probably why it was not working from the beginning:eek: Don't tell anyone about that tho:p

offtopic: Nice avatar Flare. It is good to see another fable fan around;)
 

Flare

Stops copies me!
Reaction score
662
"loopint" is set to 1 when declaring the variable.
You're still gonna get (NumUnits - 1) units, so you must either default loopint at 0, or change the operator in the exitwhen from == to > - I never said it wasn't defaulted

And you missed the fact that I forgot to set loopint=loopint+1
No I didn't
Also, you never incremented loopint

Nice avatar Flare. It is good to see another fable fan around
Just found it on Google Images tbh :p
 
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