• 🏆 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!

In vJass and NOT MUI? LOL I FAIL

Status
Not open for further replies.
Level 10
Joined
Sep 21, 2007
Messages
517
HELP PLX
JASS:
library KBSystem initializer Init

    globals
        private constant real KBSpeed = 10 //every interval
        private constant real interval = .03
        private constant real distance = 333
        private constant real ParabolaHeight = 150
        private constant string SFX = "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl"
        private timer KBTimer = CreateTimer()
        // for struct
        private KB array KBContainer
        private KB dat
        private integer KBLoop = 0
        private integer KBTotal = 0
        // Z
        private location ZLoc = Location(0,0)
        private real LocZ = 0
        
    endglobals
    
    struct KB
        unit u = null
        real x = 0.
        real y = 0.
        real dx = 0.
        real dy = 0.
        real CurDist = 0.
        real z1 = 0.
        
        method onDestroy takes nothing returns nothing
            set .u = null
            if KBTotal == 0 then
                call PauseTimer(KBTimer)
            endif
        endmethod
        
        static method LocZ takes nothing returns real
            call MoveLocation(ZLoc, dat.x, dat.y)
            return GetLocationZ(ZLoc)
        endmethod
        
        static method ParabolaZ takes nothing returns real
            return (4 * ParabolaHeight / distance) * (distance - dat.CurDist) * (dat.CurDist / distance)
        endmethod

        static method MoveX takes real a returns real
            return Cos(a)*KBSpeed
        endmethod
        
        static method FlyZ takes nothing returns real
            return GetUnitFlyHeight(dat.u)
        endmethod
        
        static method MoveY takes real a returns real
            return Sin(a)*KBSpeed
        endmethod
        
        //***** Finish Movement Methods *************************************
        
        static method KnockingBackUnits takes nothing returns nothing
            set KBLoop = 0
            loop
                exitwhen KBLoop >= KBTotal
                set dat = KBContainer[KBLoop]
                set dat.x = dat.x + dat.dx
                set dat.y = dat.y + dat.dy
                set dat.CurDist = dat.CurDist + KBSpeed
                call SetUnitFlyHeight(dat.u, (KB.ParabolaZ()+dat.z1) - KB.LocZ(), 0)
                if not( IsTerrainPathable(dat.x, dat.y, PATHING_TYPE_FLYABILITY) ) or KB.FlyZ() < 1 then
                    call SetUnitPosition(dat.u, dat.x, dat.y)
                else
                    call SetUnitFlyHeight(dat.u, 0, 0)
                    call SetUnitPathing(dat.u, true)
                    set KBTotal = KBTotal - 1
                    set KBContainer[KBLoop] = KBContainer[KBTotal]
                    set udg_KBOn[GetUnitUserData(dat.u)] = false
                    call dat.destroy()
                endif
                set KBLoop = KBLoop + 1
            endloop
        endmethod
        
        static method SetUp2 takes unit KBUnit, real angle returns KB
            set dat = KB.allocate()
            set KBContainer[KBTotal] = dat
            set dat.u = KBUnit
            set dat.x = GetUnitX(dat.u)
            set dat.y = GetUnitY(dat.u)
            call DestroyEffect( AddSpecialEffectTarget(SFX, dat.u, "origin") )
            set dat.dx = KB.MoveX(angle)
            set dat.dy = KB.MoveY(angle)
            set dat.z1 = KB.LocZ()
            call UnitAddAbility(dat.u, 'Amrf')
            call UnitRemoveAbility(dat.u, 'Amrf')
            call SetUnitPathing(dat.u, false)
            call TimerStart(KBTimer, interval, true, function KB.KnockingBackUnits)
            set KBTotal = KBTotal + 1
            return dat
        endmethod
        
        static method SetUp takes unit KUnit, real Angle returns nothing
            if udg_KBOn[GetUnitUserData(KUnit)] != true then
                call KB.SetUp2(KUnit, Angle)
                set udg_KBOn[GetUnitUserData(KUnit)] = true
            endif
        endmethod
        
    endstruct
    
    //-------------------------------------------------
    private function Init takes nothing returns nothing
        call Preload(SFX)
    endfunction
    
endlibrary
btw in Init trigger i did set the custom values of the units to diff values, so the boolean udg_KBOn shouldnt be a problem... meh
 
Level 4
Joined
Apr 16, 2009
Messages
85
2 things: don't use udg_ globals with vJass (makes no sense as declaring vJass globals is easier as declaring GUI globals and in the end its the same anyway)

and most importantly: don't use UnitUserData (most indexing systems rely on that and you could easily use them and a array for the same effect (or just use Table))

i'll look over it soon to see why its not working ...


Edit: ok after a quick overview: could you post the rest of the code that belongs to this (or even better the map) would make much easier and an explanation what that stuff should do and what isn't working correctly would be cool too
 
Level 10
Joined
Sep 21, 2007
Messages
517
no i cant use an array because i need to loop through to find out the array index :/
thats why i dont want to use array, i want to make it really fast. as for using table, i really dont feel like putting a whole library just b/c of something so simple, as i prob wont use table for anything else in my map :s

for global variables, its just easier for me, but yea its more organized.
 
Level 4
Joined
Apr 16, 2009
Messages
85
no i cant use an array because i need to loop through to find out the array index :/
thats why i dont want to use array, i want to make it really fast

i really don't get what you want to say :/

as for using table, i really dont feel like putting a whole library just b/c of something so simple, as i prob wont use table for anything else in my map :s

well its only a tiny bit of code and 1 hashtable - nothing bad about that


(btw testmap would still be nice)
 
Level 10
Joined
Sep 21, 2007
Messages
517
err, this is really how i want it to be though ) this is depending on Z blasts units out ^^ and is really efficient with all the globals and methods )

i think this is to do with initializing
JASS:
        private KB array KBContainer        private KB dat
:/ cus i had bugs happen before about the init
 
Level 4
Joined
Apr 16, 2009
Messages
85
mh k: 2 problems currently: you use GetUnitUserData() but you never set it (so its for all units 0) and can therefor only work for 1 unit and you start the timer every time you create a new KB instance (should only do that if KBCount was 0)
 
Level 10
Joined
Sep 21, 2007
Messages
517
i did init it, didnt u see the triggers in map?

as for the timer, i just start it whenever a new unit is registered dont understand why starting a timer everytime would not make it work for all units tho :X

.................. err as for the init, i dont think its working cus its not displaying the integer variable id... lmao

EDIT: i posted wrong map to you and i played wrong map too... lmao thanks now it works >_<
 
Status
Not open for further replies.
Top