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.
  • 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 The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top