• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] set x and y not working.. curious.

Status
Not open for further replies.

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
JASS:
scope violentWave initializer i
    private struct waveDat
        integer steps
        unit array u[4]
        unit wave
    endstruct
    
    globals
        private constant integer SPELCODE='A05J'    //Abilitycode of violent wave
        private constant integer SWAVCODE='h00T'    //Unitcode of smaller wave
        private constant integer BWAVCODE='h00U'    //Unitcode of bigger wave
        private constant integer SWAVOFFS=200       //Starting offset of smaller wave
        private constant integer BWAVOFFS=250       //Starting offset of larger wave
        private constant integer LOCUCODE='Aloc'    //Abilitycode of locust
        private constant real BASEOFFS=10           //Standard offset per step for the waves
        private timer time=CreateTimer()
        private waveDat array waveDB
        private integer dbIndex=-1
    endglobals

    private function c takes nothing returns boolean
        return GetSpellAbilityId()==SPELCODE
    endfunction

    private function p takes nothing returns nothing
        local waveDat tempDat
        local integer iLoop=0
        local real x
        local real y
        local integer index
        local real offset
        local real face
        local group g=CreateGroup()
        //call BJDebugMsg("P RAN") WORKED
        loop
            exitwhen iLoop>dbIndex
            //call BJDebugMsg("LOOP IN P RUNNING WITH"+I2S(iLoop)) WORKED
            set tempDat=waveDB[iLoop]
            set face=GetUnitFacing(tempDat.wave)
            set offset=BASEOFFS
            if tempDat.steps<BASEOFFS then
                set offset=tempDat.steps
                call SetUnitScale(tempDat.wave,tempDat.steps/10,tempDat.steps/10,tempDat.steps/10)
            endif
            set index=0
            loop
                exitwhen index>4
                call SetUnitX(tempDat.u[index],GetUnitX(tempDat.u[index])+offset*Cos(face*bj_DEGTORAD))
                call SetUnitY(tempDat.u[index],GetUnitY(tempDat.u[index])+offset*Sin(face*bj_DEGTORAD))
                set index=index+1
            endloop
            call SetUnitX(tempDat.wave,GetUnitX(tempDat.wave)+offset*Cos(face*bj_DEGTORAD))
            call SetUnitY(tempDat.wave,GetUnitY(tempDat.wave)+offset*Sin(face*bj_DEGTORAD))
            call GroupEnumUnitsInRange(g,GetUnitX(tempDat.wave),GetUnitY(tempDat.wave),250,null)
            loop
                exitwhen FirstOfGroup(g)==null
                if IsUnitType(FirstOfGroup(g),UNIT_TYPE_STRUCTURE)==false and GetOwningPlayer(FirstOfGroup(g))!=GetOwningPlayer(tempDat.wave) then
                    call SetUnitX(FirstOfGroup(g),GetUnitX(FirstOfGroup(g))+offset*Cos(face*bj_DEGTORAD))
                    call SetUnitY(FirstOfGroup(g),GetUnitY(FirstOfGroup(g))+offset*Sin(face*bj_DEGTORAD))
                endif
                call GroupRemoveUnit(g,FirstOfGroup(g))
            endloop
            set tempDat.steps=tempDat.steps-1
            if tempDat.steps<0 then
                set index=0
                loop
                    exitwhen index>4
                    call RemoveUnit(tempDat.u[index])
                    set index=index+1
                endloop
                call RemoveUnit(tempDat.wave)
                call tempDat.destroy()
                set waveDB[iLoop]=waveDB[dbIndex]
                set dbIndex=dbIndex-1
                if dbIndex==-1 then
                    call PauseTimer(time)
                endif
            endif
            set iLoop=iLoop+1
        endloop
        call GroupClear(g)
        call DestroyGroup(g)
    endfunction

    private function a takes nothing returns nothing
        local waveDat tempDat=waveDat.create()
        local real x
        local real y
        local real face
        local integer index=0
        loop
            exitwhen index>4
            set face=GetUnitFacing(GetSpellAbilityUnit())-36+18*index
            set x=GetUnitX(GetSpellAbilityUnit())+SWAVOFFS*Cos(face*bj_DEGTORAD)
            set y=GetUnitY(GetSpellAbilityUnit())+SWAVOFFS*Sin(face*bj_DEGTORAD)
            set tempDat.u[index]=CreateUnit(GetOwningPlayer(GetSpellAbilityUnit()),SWAVCODE,x,y,face)
            call UnitAddAbility(tempDat.u[index],LOCUCODE)
            set index=index+1
        endloop
        set face=GetUnitFacing(GetSpellAbilityUnit())
        set x=GetUnitX(GetSpellAbilityUnit())+BWAVOFFS*Cos(face*bj_DEGTORAD)
        set y=GetUnitY(GetSpellAbilityUnit())+BWAVOFFS*Sin(face*bj_DEGTORAD)
        set tempDat.wave=CreateUnit(GetOwningPlayer(GetSpellAbilityUnit()),BWAVCODE,x,y,face)
        call UnitAddAbility(tempDat.wave,LOCUCODE)
        //call PolledWait and or TriggerSleepAction, something like .1 to .5 seconds. Not sure if I want this...
        set tempDat.steps=90+GetHeroLevel(GetSpellAbilityUnit())
        if dbIndex==-1 then
            call TimerStart(time,.03,true,function p)
        endif
        set dbIndex=dbIndex+1
        set waveDB[dbIndex]=tempDat
    endfunction

    private function i takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t,Condition(function c))
        call TriggerAddAction(t,function a)
    endfunction
endscope

I need to go to football so I can't explain much, but the debug messages work, and the dummy units aren't being moved. They just sit there until the periodic trigger ends and then get removed.

Help is appreciated; I'm fairly new at using coords instead of locations.
 
Level 10
Joined
Jan 21, 2007
Messages
576
I just went through this problem, maybe what caused it for me is the same as what caused it for you.

I had the units movements base speed, and turn rate set to 0. I also had the move type set to none. Once I changed all that back to the defaults (320, .4, flying, respectively) it worked. It may just be the movement type though (I didn't bother to check), because when it moves it it might have something to do with pathing (even though it ignores pathing<=/). Anyways I hope that was it.
 
Status
Not open for further replies.
Top