• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

BotL - Coding & Systems

Status
Not open for further replies.
Level 18
Joined
Sep 14, 2012
Messages
3,413
I did that xD
JASS:
library Transparency requires Table
    globals
        private constant real FPS = 0.100
    endglobals
    
    struct Transparency extends array
        private unit target
        private real temp
        private integer trans
        private thistype next
        private thistype prev
        private static integer count
        private static timer period
        private static HandleTable tab
        
        static method GetUnitAlpha takes unit u returns integer
            if tab.exists(u) then
                return tab[u]
            else
                return 255
            endif
        endmethod
        
        private static method cond takes nothing returns boolean
            local unit u = GetTriggerUnit()
            if tab.exists(u) then
                call tab.flush(u)
            endif
            set u = null
            return false
        endmethod
        
        private static method periodic takes nothing returns nothing
            local thistype this = thistype(0).next
            loop
                exitwhen this == 0
                set this.temp = this.temp - FPS
                if this.temp <= 0 then
                    call SetUnitVertexColor(this.target, 255, 255, 255, GetUnitAlpha(this.target) + this.trans)
                    call this.destroy()
                endif
                set this = this.next
            endloop
        endmethod
                    
        static method add takes unit targ, real dur, integer transp returns nothing
            local thistype this
            local integer i = GetUnitAlpha(targ)
            if thistype(0).prev == 0 then
                set count = count + 1
                set this = count
            else
                set this = thistype(0).prev
                set thistype(0).prev = thistype(0).prev.prev
            endif
            if thistype(0).next == 0 then
                call TimerStart(period, FPS, true, function thistype.periodic)
            else
                set thistype(0).next.prev = this
            endif
            set this.next = thistype(0).next
            set thistype(0).next = this
            set this.prev = thistype(0).prev
            set this.target = targ
            set this.temp = dur
            set this.trans = transp
            if transp > i then
                debug call BJDebugMsg("You're giving a bad number !")
                return
            else
                call SetUnitVertexColor(targ, 255, 255, 255, i-transp)
                set tab[targ] = i-transp
            endif
        endmethod
        
        private method destroy takes nothing returns nothing
            if this.next != 0 then
                set this.next.prev = this.prev
            endif
            set this.prev.next = this.next
            set this.prev = thistype(0).prev
            set thistype(0).prev = this
            if thistype(0).next == 0 then
                call PauseTimer(period)
            endif
            set this.target = null
        endmethod

        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
            call TriggerAddCondition(t, Condition(function thistype.cond))
            set tab = HandleTable.create()
            set count = 0
            set period = CreateTimer()
            set t = null
        endmethod
    endstruct
endlibrary
It is the current system no fixes made
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Goodness! why aren't you using TimerUtils for this man? Unless you're going to alpha out hundreds of units?

TimerUtils + hashtable or a unit indexer will suffice for this.
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
JASS:
        private static method periodic takes nothing returns nothing
            local thistype this = thistype(0)
            call BJDebugMsg("LOL")
            loop
                set this = this.next
                exitwhen this == 0
                set this.temp = this.temp -FPS
                call BJDebugMsg(R2S(this.temp))
                if this.temp-FPS <= 0 then
                    if this.type==1 then
                        call SetHeroStr(this.targ, GetHeroStr(this.targ, false)-this.amount, false)
                    elseif this.type==2 then
                        call SetHeroAgi(this.targ, GetHeroAgi(this.targ, false)-this.amount, false)
                    elseif this.type==3 then
                        call SetHeroInt(this.targ, GetHeroInt(this.targ, false)-this.amount, false)
                    debug else
                        debug call BJDebugMsg("You entered the wrong number for the stats thingy")
                    endif
                    call this.destroy()
                endif
            endloop
        endmethod

First debug shows up
second DOESN'T!!!!!

The loop doesn't start
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
Try this >_<
JASS:
library TimedStats

    globals
        private constant real FPS = 0.100
    endglobals
    
    //1 : Strength
    //2 : Agility
    //3 : Intelligence
    struct TimedStats extends array
        private unit targ
        private real temp
        private integer amount
        private integer type
        private thistype prev
        private thistype next
        private static timer period
        private static integer count
        
        private static method periodic takes nothing returns nothing
            local thistype this = thistype(0).next
            loop
                exitwhen this == 0 
                set this.temp = this.temp - FPS
                if this.temp <= 0 then
                    if this.type==1 then
                        call SetHeroStr(this.targ, GetHeroStr(this.targ, false)-this.amount, false)
                    elseif this.type==2 then
                        call SetHeroAgi(this.targ, GetHeroAgi(this.targ, false)-this.amount, false)
                    elseif this.type==3 then
                        call SetHeroInt(this.targ, GetHeroInt(this.targ, false)-this.amount, false)
                    debug else
                        debug call BJDebugMsg("You entered the wrong number for the stats thingy")
                    endif
                    call this.destroy()
                endif
                set this = this.next
            endloop
        endmethod
        
        static method AddTimedStatBonus takes unit targ, integer amount, integer stats, real time returns nothing
            local thistype this
            if thistype(0).prev == 0 then
                set count = count + 1
                set this = count
            else
                set this = thistype(0).prev
                set thistype(0).prev = thistype(0).prev.prev
            endif
            if thistype(0).next == 0 then
                call TimerStart(period, FPS, true, function thistype.periodic)
            else
                set thistype(0).next.prev = this
            endif
            set this.next = thistype(0).next
            set thistype(0).next = this
            set this.prev = thistype(0)
            set this.targ = targ
            set this.amount = amount
            set this.type = stats
            set this.temp = time
            if stats==1 then
                call SetHeroStr(targ, GetHeroStr(targ, false)+amount, false)
            elseif stats==2 then
                call SetHeroAgi(targ, GetHeroAgi(targ, false)+amount, false)
            elseif stats==3 then
                call SetHeroInt(targ, GetHeroInt(targ, false)+amount, false)
            debug else
                debug call BJDebugMsg("You're giving wrong number for the stats thingy")
            endif
        endmethod
        
        private method destroy takes nothing returns nothing
            if this.next != 0 then
                set this.next.prev = this.prev
            endif
            set this.prev.next = this.next
            set this.prev = thistype(0).prev
            set thistype(0).prev = this
            if thistype(0).next == 0 then
                call PauseTimer(period)
            endif
            set this.targ = null
        endmethod
        
        private static method onInit takes nothing returns nothing
            set count = 0
            set period = CreateTimer()
        endmethod
    endstruct
endlibrary
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
It was the allocator right? The loop worked for me when I tested it.

JASS:
            if thistype(0).prev == 0 then
                set this = thistype(0).prev
                set thistype(0).prev = thistype(0).prev.prev
            else
                set count = count + 1
                set this = count
            endif
You got it reversed haha xD
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
easy: (following is an example)
time = 2 s
total transparency difference = 100 (from 0% transparent to 100% transparent)


transparency decreaser = total transparency difference/ time * FPS

On every FPS increase the transparency of the unit by *transparency decreaser*
and stop when the timer reaches max value of time

Done
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
transparency decreaser = total transparency difference/ time * FPS
delta=255/(time/FPS)

255 is the constant value for 100% opacity.

Let time be 2 seconds and FPS be 1/10 of a second:

delta=255/(2/0.10)
delta=255/20
delta=12.75
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
JASS:
library Transparency requires Table
    globals
        private constant real FPS = 0.062500
    endglobals
    
    struct Transparency extends array
        private unit target
        private real temp
        private integer delta
        private thistype next
        private thistype prev
        private static integer count
        private static timer period
        private static HandleTable tab
        
        static method GetUnitAlpha takes unit u returns integer
            if tab.exists(u) then
                return tab[u]
            else
                return 255
            endif
        endmethod
        
        private static method cond takes nothing returns boolean
            local unit u = GetTriggerUnit()
            if tab.exists(u) then
                call tab.flush(u)
            endif
            set u = null
            return false
        endmethod
        
        private static method periodic takes nothing returns nothing
            local thistype this = thistype(0).next
            local integer i
            loop
                exitwhen this == 0
                set this.temp = this.temp - FPS
                if this.temp <= 0 then
                    call SetUnitVertexColor(this.target, 255, 255, 255, 255)
                    call this.destroy()
                else
                    set i = GetUnitAlpha(this.target)-this.delta
                    call SetUnitVertexColor(this.target, 255, 255, 255, i)
                    set tab[this.target] = i
                endif
                set this = this.next
            endloop
        endmethod
                    
        static method add takes unit targ, real dur returns nothing
            local thistype this
            local integer i
            if thistype(0).prev == 0 then
                set count = count + 1
                set this = count
            else
                set this = thistype(0).prev
                set thistype(0).prev = thistype(0).prev.prev
            endif
            if thistype(0).next == 0 then
                call TimerStart(period, FPS, true, function thistype.periodic)
            else
                set thistype(0).next.prev = this
            endif
            set this.next = thistype(0).next
            set thistype(0).next = this
            set this.prev = thistype(0).prev
            set this.target = targ
            set this.temp = dur - FPS
            set this.delta = R2I(255/dur/FPS)+1
            set i = GetUnitAlpha(targ)-this.delta
            call SetUnitVertexColor(targ, 255, 255, 255, i)
            set tab[targ] = i
        endmethod
        
        private method destroy takes nothing returns nothing
            if this.next != 0 then
                set this.next.prev = this.prev
            endif
            set this.prev.next = this.next
            set this.prev = thistype(0).prev
            set thistype(0).prev = this
            if thistype(0).next == 0 then
                call PauseTimer(period)
            endif
            set this.target = null
        endmethod

        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
            call TriggerAddCondition(t, Condition(function thistype.cond))
            set tab = HandleTable.create()
            set count = 0
            set period = CreateTimer()
            set t = null
        endmethod
    endstruct
endlibrary
call Transparency.add(target, duration)
 
Status
Not open for further replies.
Top