• 🏆 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] Funcion doesn't want to work

Status
Not open for further replies.
Level 16
Joined
Feb 22, 2006
Messages
960
So i try to write my castbar system into vJass but it doens't want to work :(
what did i wrong?

JASS:
library castsystem
    globals
        private constant real Interval = 0.01
        private timer Ti = CreateTimer()
        private constant string Bar = "|"
        private castbar Dat
    endglobals

    private function CreateTextTagNew takes string s , location loc, real zOffset, real size, real red, real green, real blue, real transparency returns texttag
      local texttag tt
        set tt = CreateTextTagLocBJ( s, loc, zOffset, size, red, green, blue, transparency )
        call SetTextTagVisibility( tt, true )   
      return tt
    endfunction


    struct castbar
        unit u
        texttag tt
        texttag tg
        texttag ttt
        location loc
        real duration
        real interval
        real counter = 0
        real dur
        string text = ""
        static method create takes unit u, location loc,real dur returns castbar
          local castbar dat = castbar.allocate()
            set dat.u = u
            set dat.loc = loc
            set dat.duration = dur
            return dat
        endmethod
        method onDestroy takes nothing returns nothing
            set this.u = null
            set this.tt = null
            set this.tg = null
            set this.ttt = null
            set this.loc = null
        endmethod
    endstruct

    private function castbarexecute takes nothing returns nothing
      local timer t = GetExpiredTimer()  
        set Dat.duration = Dat.duration + Interval
        set Dat.counter = Dat.counter + Interval
        set Dat.dur = Dat.dur + Interval
        if (Dat.counter >= Dat.interval) then
            set Dat.text = Dat.text + Bar
            call SetTextTagTextBJ(Dat.tg,Dat.text,10)
            call SetTextTagTextBJ(Dat.ttt,R2S(Dat.dur),8)
            set Dat.counter = 0
        endif
        if (Dat.dur >= Dat.duration) then
            call castbar.destroy(Dat)
            call DestroyTimer(t)
            set t = null
        endif
        set t = null
    endfunction

    function castbarAction takes real time,unit u returns nothing
      local location loc = GetUnitLoc(u)
      local string newtext = ""
      local integer loopint = 0 
        set Dat = castbar.create(u,loc,time)
        call RemoveLocation(loc)
        set loc = null
        loop
            exitwhen loopint >= 100
            set newtext = newtext + Bar
            set loopint = loopint + 1
        endloop
        set Dat.duration = time
        set Dat.interval = Dat.duration/100
        set Dat.tt = CreateTextTagNew(newtext,loc,200.00,10,10,10,10,0)
        set Dat.tg = CreateTextTagNew(Dat.text,loc,200.00,10,100,0,0,0)
        set Dat.ttt = CreateTextTagNew(R2S(Dat.dur),loc,200.00,8,100,100,100,0) 
        call TimerStart(Ti,Interval,true,function castbarexecute)
    endfunction
endlibrary
 
Last edited:
Level 16
Joined
Feb 22, 2006
Messages
960
So here my updated version, now it works, i made a mistake with loc, but you could say what i could improve etc.

JASS:
library castsystem
    globals
        private constant real Interval = 0.01 //refreshing interval timer
        private timer Ti = CreateTimer() //timer which will execute the main function => Interval
        private constant string Bar = "|" //a constant var which is a part of the castbar
        private castbar Dat //var for the struct casthar
    endglobals

    //my function for the texttag (floating text)
    private function CreateTextTagNew takes string s , location loc, real zOffset, real size, real red, real green, real blue, real transparency returns texttag
      local texttag tt
        set tt = CreateTextTagLocBJ( s, loc, zOffset, size, red, green, blue, transparency )
        call SetTextTagVisibility( tt, true )   
      return tt
    endfunction


    struct castbar
        unit u //the unit where the bar will appear
        texttag tt //grey background-bar
        texttag tg //red bar which grows
        //texttag ttt //timerbar (counts up from 0 - duration)
        real duration // duration of timer
        real interval //interval of updating red bar (in my test case each 0.02sec)
        real counter = 0 //counter which counts to interval and if its >= interval it updates the bar
        real dur //counter if dur = duration destroy everything
        string text = "" //redbar
        //set castbar.u and castbar.duration when created
        static method create takes unit u,real dur returns castbar
          local castbar dat = castbar.allocate()
            set dat.u = u
            set dat.duration = dur
            return dat
        endmethod
        //resets the things on destroy
        method onDestroy takes nothing returns nothing          
            set this.u = null
            set this.tt = null
            set this.tg = null
            //set this.ttt = null
            set this.duration = 0.00
            set this.interval = 0.00
            set this.counter = 0.00
            set this.dur = 0.00             
        endmethod
    endstruct

    //private function, needed for the main, updates redbar and destroys everything on finish
    private function castbarexecute takes nothing returns nothing
      local timer t = GetExpiredTimer()  
        set Dat.counter = Dat.counter + Interval
        set Dat.dur = Dat.dur + Interval
        //call SetTextTagTextBJ(Dat.ttt,R2S(Dat.dur),8)
        if (Dat.counter >= Dat.interval) then
            set Dat.text = Dat.text + Bar
            call SetTextTagTextBJ(Dat.tg,Dat.text,10)
            set Dat.counter = 0
        endif
        if (Dat.dur >= Dat.duration) then           
            call DestroyTextTag(Dat.tg)
            call DestroyTextTag(Dat.tt)
            //call DestroyTextTag(Dat.ttt)              
            call castbar.destroy(Dat)
            call PauseTimer(t)
            set t = null
        endif
        set t = null
    endfunction

    //main function which are called creates grey bar in a loop and starts timer etc.
    function castbarAction takes real time,unit u returns nothing
      local location loc = GetUnitLoc(u)
      local string newtext = ""
      local integer loopint = 0 
        set Dat = castbar.create(u,time)
        loop
            exitwhen loopint >= 100
            set newtext = newtext + Bar
            set loopint = loopint + 1
        endloop
        set Dat.duration = time
        set Dat.interval = Dat.duration/100
        //set Dat.ttt = CreateTextTagNew(R2S(Dat.dur),loc,200.00,8,100,100,100,0) 
        set Dat.tt = CreateTextTagNew(newtext,loc,200.00,10,10,10,10,0)
        set Dat.tg = CreateTextTagNew(Dat.text,loc,200.00,10,100,0,0,0)
        call TimerStart(Ti,Interval,true,function castbarexecute)
        call RemoveLocation(loc)
        set loc = null
    endfunction
endlibrary

this is the calling trigger
  • Unbezeichneter Auslöser 001
    • Events
      • Unit - A unit starts the effect of a spell
    • Conditions
      • (Ability being cast) Equal to Spell
    • Actions
      • Custom script: call castbarAction(2.00,GetTriggerUnit())

i will rework my texttag function because of the BJ, but don't have time at this moment
 
Last edited:
Status
Not open for further replies.
Top