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

Rage System ( Beta )

Level 18
Joined
Oct 18, 2007
Messages
930
Ok major update, redone most of the code and increased efficiency

this system used The_Reborn_Devil's RAS system ( modded it a bit ), credits to him for that ^^
JASS:
library SAS

    private function H2I takes handle h returns integer
        return h
        return 0
    endfunction

    globals
        private constant integer size = 10000
    endglobals

    //! textmacro SAS takes TYPE
        globals
            private integer array struct$TYPE$ [size]
        endglobals

        function GetAttachedStruct$TYPE$ takes handle h returns integer
            return struct$TYPE$[H2I(h) - 0x100000]
        endfunction

        function AttachStruct$TYPE$ takes handle h, integer i returns nothing
            set struct$TYPE$[H2I(h) - 0x100000] = i
        endfunction
        
        function RemoveAttachedStruct$TYPE$ takes handle h returns nothing
            set struct$TYPE$[H2I(h) - 0x100000] = 0
        endfunction
    //! endtextmacro

    //! runtextmacro SAS("Rage")
endlibrary

JASS:
library RageSystem requires SAS 

    globals

        // For Ragebar
            private constant string RageBarStyle    =   "|"     // How the bar will look

            private constant real RBsize            =   6.      // Size of the bar
            
            private constant integer RBred          =   255     // Red color of the Bar
            private constant integer RBgreen        =   0       // Green color of the Bar
            private constant integer RBblue         =   0       // Blue color of bar
            
            private constant integer RBalpha        =   255     // The Alpha, 0 is invisible 255 is fully visible

            private constant real RBoffset          =   120.    // The Rage Bar offset from the ground

            private constant real RBtextOffset      =   55.     // The offset to the left of the bar, so the bar will look centered
        // End of Ragebar constants

        private constant real RageLoss       =   1       // Number of rage lost each "RageTimer" secconds
        
        private constant real RageTimer      =   0.45    // The timer that decreases the rage by "RageLoss"
        
        private constant real MaxRage        =   100.    // The maximum amount of rage
        
        private constant real MaxExtraRage   =   30.     // The Maximum amount of Extra Rage allowed
        
        private constant real RabeBarMove    =   0.03    // The interval that the ragebar uses

        // End of constants
        private timer Tim = CreateTimer()
        private timer RTim = CreateTimer()
        private integer Total = 0

        private integer array Ar
        
        private constant real BarSize = ( RBsize * 0.023 / 10 )
    endglobals

    private struct Rage
        unit u              =   null            // Raging unit

        real rage           =   0               // Amount of Rage
        
        real extraRage      =   0               // Amount of Extra Rage that can be generated
        
        texttag rb          =   CreateTextTag() // Rage Bar
        
        string rbtxt        =   ""              //Rage Bar Text
        
        boolean rbtp        =   false           // the move of the Rage Bar Timer ( if it is true the bar wont move )

        static method RageBar takes nothing returns nothing
            local Rage r
            local integer i = 0

            loop
                exitwhen i >= Total
                set r = Ar[i]

                call SetTextTagPos( r.rb , GetUnitX(r.u)-RBtextOffset , GetUnitY(r.u) , RBoffset )

                set i = i + 1
            endloop
            

            if Total == 0 then
                call PauseTimer(RTim)
            endif
        endmethod

        static method PeriodicRageDecrease takes nothing returns nothing
            local Rage r
            local integer i = 0
            local integer index

            loop
                exitwhen i >= Total
                set r = Ar[i]

                if (r.rage - RageLoss) < 0 then
                    set r.rage = 0
                else
                    set r.rage = r.rage - RageLoss
                    set index = StringLength( r.rbtxt )

                    loop
                        exitwhen index < r.rage
                        set r.rbtxt = SubString( r.rbtxt , 0 , index - 1 )

                        if r.rbtxt != null and r.rbtxt != "" then
                            call SetTextTagText( r.rb , r.rbtxt , BarSize )
                        endif
                        set index = index - 1
                    endloop

                endif
                
                if ( GetUnitState( r.u,UNIT_STATE_LIFE ) <= 0 ) then
                    set r.rage = 0
                    call SetTextTagText( r.rb , "" , BarSize )
                endif
                

                set i = i + 1
            endloop

        endmethod

        static method create takes unit u returns Rage
            local Rage r = Rage.allocate()

            set r.u = u

            call SetTextTagText( r.rb , r.rbtxt , BarSize )
            call SetTextTagColor( r.rb , RBred , RBgreen , RBblue , RBalpha )
            call SetTextTagPermanent( r.rb , true )
            call SetTextTagPos( r.rb , GetUnitX(u) , GetUnitY(u) , RBoffset )
            call SetTextTagVisibility( r.rb , true )

            if Total == 0 then
                call TimerStart( RTim , RabeBarMove , true , function Rage.RageBar )
                call TimerStart( Tim , RageTimer , true , function Rage.PeriodicRageDecrease )
            endif

            call AttachStructRage( r.u , r )
            
            set Total = Total + 1
            set Ar[Total - 1] = r

            return r
        endmethod

        static method SRageIncrease takes unit u, real rinc returns nothing
            local Rage r = GetAttachedStructRage(u)
            local integer index = StringLength( r.rbtxt )
    
            if (r.rage + rinc) > (MaxRage + r.extraRage) then
                set r.rage = (MaxRage + r.extraRage)
            else
                set r.rage = (r.rage + rinc)
    
                loop
                    exitwhen index > r.rage
                    set r.rbtxt = (r.rbtxt + RageBarStyle)

                    call SetTextTagText( r.rb , r.rbtxt , BarSize )

                    set index = index + 1
                endloop

            endif
        endmethod
        
        static method SRageDecrease takes unit u, real rdec returns nothing
            local Rage r = GetAttachedStructRage(u)
            local integer index = StringLength( r.rbtxt )

            if (r.rage - rdec) < 0 then
                set r.rage = 0

                call SetTextTagText( r.rb , "" , BarSize )
            else
                set r.rage = r.rage - rdec

                loop
                    exitwhen index < r.rage
                    set r.rbtxt = SubString( r.rbtxt , 0 , index - 1 )
    
                    if r.rbtxt != null and r.rbtxt != "" then
                        call SetTextTagText( r.rb , r.rbtxt , BarSize )
                    endif
                    set index = index - 1
                endloop

            endif
        endmethod
        
        static method MaxoutRage takes unit u, real max returns nothing
            local Rage r = GetAttachedStructRage(u)
            local integer index = StringLength( r.rbtxt )
            if max > r.rage then
                if max > (MaxRage + r.extraRage) then
                    set r.rage = MaxRage + r.extraRage
                else
                    set r.rage = max
        
                    loop
                        exitwhen index > r.rage
                        set r.rbtxt = r.rbtxt + RageBarStyle

                        call SetTextTagText( r.rb , r.rbtxt , BarSize )

                        set index = index + 1
                    endloop

                endif
            else
                if max < 0 then
                    set r.rage = 0

                    call SetTextTagText( r.rb , "" , BarSize )
                else
                    set r.rage = max

                    loop
                        exitwhen index < r.rage
                        set r.rbtxt = SubString( r.rbtxt , 0 , index - 1 )
        
                        if r.rbtxt != null and r.rbtxt != "" then
                            call SetTextTagText( r.rb , r.rbtxt , BarSize )
                        endif
                        set index = index - 1
                    endloop

                endif
            endif
        endmethod

        static method ExtraRage takes unit u, real extra returns nothing
            local Rage r = GetAttachedStructRage(u)
            local integer index
            if extra > MaxExtraRage then
                set r.extraRage = MaxExtraRage
            else
                set r.extraRage = extra

                if ( MaxRage + extra ) < r.rage then
                    set r.rage = (MaxRage + extra)
                    set index = StringLength( r.rbtxt )
                    loop
                        exitwhen index < r.rage
                        set r.rbtxt = SubString( r.rbtxt , 0 , index - 1 )
        
                        if r.rbtxt != null and r.rbtxt != "" then
                            call SetTextTagText( r.rb , r.rbtxt , BarSize )
                        endif
                        set index = index - 1
                    endloop
                endif
            endif
        endmethod

        static method Destroy takes unit u returns nothing
            local Rage r = GetAttachedStructRage(u)
            if r.u != null then
                set Ar[r] = Ar[Total - 1]
                set Total = Total - 1
                if Total == 0 then
                    call PauseTimer(Tim)
                    call PauseTimer(RTim)
                endif
                call r.destroy()
            else
                call BJDebugMsg("\n|cffff0000Cannot Destroy; Rage - because it is allready destroyed!|r\n")
            endif
        endmethod

        method onDestroy takes nothing returns nothing
            call RemoveAttachedStructRage( .u )
            call DestroyTextTag( .rb )
            set .rb     = null
            set .u      = null
        endmethod

    endstruct
    
    function GetRage takes unit u returns real
        local Rage r = GetAttachedStructRage(u)
        return r.rage
    endfunction
    
    function GetExtraRage takes unit u returns real
        local Rage r = GetAttachedStructRage(u)
        return r.extraRage
    endfunction
    
    function ExtraRageReset takes unit u returns nothing
        local Rage r = GetAttachedStructRage(u)
        set r.extraRage = 0
    endfunction

    function RageReset takes unit u returns nothing
        local Rage r = GetAttachedStructRage(u)
        set r.rage = 0
    endfunction
    
    function DestroyRage takes unit u returns nothing
        call Rage.Destroy(u)
    endfunction
    
    function RageIncrease takes unit u, real rinc returns nothing
        call Rage.SRageIncrease(u, rinc)
    endfunction
    
    function RageDecrease takes unit u, real rdec returns nothing
        call Rage.SRageDecrease(u, rdec)
    endfunction
    
    function SetRage takes unit u, real Set returns nothing
        call Rage.MaxoutRage(u, Set)
    endfunction

    function SetExtraRage takes unit u, real extra returns nothing
        call Rage.ExtraRage(u, extra)
    endfunction

    function CreateRage takes unit u returns nothing
        call Rage.create(u)
    endfunction

endlibrary

This system could be useful for spells, rpgs, etc.

The system is easy to use, read the manual to get a better understanding of what you can do and what it does.
JASS:
]//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//*                                                          Rage System Manual                                                           *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//*
//*     To implement into your map copy the trigger "Simple Attachment System" and this trigger called "Rage System"
//*
//*     
//*      How to use:
//*          - To create a Rage for any given unit, do this: "call CreateRage( unit YourUnitVar )"
//*     
//*          - Modifying the rage is easy, do a "call RageIncrease( unit YourUnitVar , real Increasement )", or
//*              for decreasement "call RageDecrease( unit YourUnitVar , real Decreasement )"
//*     
//*          - To reset the rage without any other variables just do: "call RageReset( unit YourUnitVar )"
//*     
//*          - To Remove the rage system from a unit, do: "call DestroyRage( unit YourUnitVar )"
//*     
//*          - To get the rage value, do: "call GetRage( unit YourUnitVar )"
//*     
//*          - To set the Rage to a value do: "call SetRage( unit YourUnitVar , real Value )
//*     
//*          - To set the Extra Amount of rage that can be generated do:
//*              "call SetExtraRage( unit YoutUnitVar , real Extra )". If the value is in "-" then the Raged unit will
//*              gather less rage.
//*
///          - To Reset the Extra Amount of rage that can be generated do: "call ResetExtraRage( unit YourUnitVar )
//*     
//*
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//* Rage System v1.4 by Dynasti *
//* * * * * * * * * * * * * * * *

Please give credits when used.


If found any bugs or ways of imrpovement, please tell ^^


v1.4 - Removed a bug

v1.5 - Found the first leak! o_O ( but it is removed now ^^ )


Test Map:
 

Attachments

  • Rage System.w3x
    30.1 KB · Views: 115
Last edited:
Level 14
Joined
Nov 18, 2007
Messages
816
what does this do? Maybe explain it in your original post?

Suggestions:
- Work around using DestroyTrigger and DestroyTimer (dont use DestroyTrigger at all, and use TimerUtils for timers)
- Dont use ResumeTimer, that function is bugged. Use TimerStart instead
- attaching to unit handles is a no-go for various reasons. Use a unit indexing system instead (PUI, DUI, ... )
- Why is there a initializer when its not needed?
 
Level 18
Joined
Oct 18, 2007
Messages
930
what does this do? Maybe explain it in your original post?

Suggestions:
- Work around using DestroyTrigger and DestroyTimer (dont use DestroyTrigger at all, and use TimerUtils for timers)
- Dont use ResumeTimer, that function is bugged. Use TimerStart instead
- attaching to unit handles is a no-go for various reasons. Use a unit indexing system instead (PUI, DUI, ... )
- Why is there a initializer when its not needed?

1 - You need to use DestroyTrigger to not get a handle leak.
2 - The resume timer is not bugged, or is it?
3 - Why do i need to use TimerUltis?? it is not needed, the system i use works fine with good speed
4 - It works fine to attach this struct to a unit because one unit should not have more than 1 rage system attached to it.
5 - Removing that ^^ thx for info
 
Level 14
Joined
Nov 18, 2007
Messages
816
1 - DestroyTrigger fucks up your handle stack. You dont need to use dynamic triggers anyway.
2 - It is.
3 - DestroyTimer is bugged too. But fortunately there are systems like TimerUtils that let you recycle timers so you dont need to destroy them.
4 - Attaching to units is unsafe. See PUI-thread at wc3c for more information. forget about that.
 
Level 18
Joined
Oct 18, 2007
Messages
930
1 - DestroyTrigger fucks up your handle stack. You dont need to use dynamic triggers anyway.
2 - It is.
3 - DestroyTimer is bugged too. But fortunately there are systems like TimerUtils that let you recycle timers so you dont need to destroy them.
4 - Attaching to units is unsafe. See PUI-thread at wc3c for more information.

Ok if you are sooo allmighty and know everything, why dont you make your own system? o_O
 
Level 22
Joined
Jun 24, 2008
Messages
3,050
Sorry Daeod, but judging from that noobish behaviour of yours, from the first post, where you seemed that you haven't looked in the WE, where the monsters were, i defined you as a noob.
Sorry on that, but still, check Dynsati's stuff first.

Also @The other bar system, you didn't read that the Bolean was for which way. Thus i took you as a noob.
 
Level 14
Joined
Nov 18, 2007
Messages
816
no, i took a look at the code. And i reported what i found strikingly unacceptable.
This is supposed to be a system. Then describe what this does. I dont want to guess from looking at the code.

Oh, and maybe you should post that attachment system of yours too.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
No. I wont rep anyone for that system. See above why i think its not good enough. So this is basically like adrenaline in Guild Wars (assuming you played that...)?
So what if it would be like a system made in Guild Wars? This is warcraft 3 and it doesn't exist here...

Dynasti, the system looks great, I'm sorry I just couldn't help you with the error before:p
It could indeed be handy for a bunch of wc3 maps:)

Edit: There was one more page? Oh damn.
 
Level 14
Joined
Nov 18, 2007
Messages
816
I dont care it its exactly like the system in Guild Wars. Its just that i didnt know what it does and where i can apply it, so i tried to find something that i know of and does similar things.

I pointed out that the system used/uses functions that are known to cause bugs. And i suggested possible fixes. I wont do the work of Dynasti and apply all fixes i suggested, since this is his system and he decides what to do with it.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Alright, I buy that of course.

About the trigger handle messup, I don't believe you. I'm going to check that now though. It is true timers and groups will make warcraft 3 totally crazy, as they say. But destroying triggers? If that was the case no accurate damage detection engine would be triggered, since recycling a trigger would never be lost its events.
 
Level 22
Joined
Jun 24, 2008
Messages
3,050
Deaod. You remind me of a guy called Rising Dusk.
-Thats not good.

First of all, you don't really say anything, you use a lot of words, and thats just irretating.
Just tell what you think is wrong, why its wrong, and how to fix it.
But saying 'Its wrong cause it bugs' is not right. What is the bug you will encourage?
 
Level 14
Joined
Nov 18, 2007
Messages
816
First of all, i already said what i think is wrong. And iirc i gave abstract instructions on how to fix the issues. I just didnt know that you dont know about the DestroyTrigger/Timer bugs.
ResumeTimer is another thing, i once wrote a system where i used ResumeTimer and after resuming the timer nothing worked. Once i replaced ResumeTimer with TimerStart everything worked flawlessly.

Dont try to influence anyone. Let people see for themselves if another person is bad/w/e.
 
Level 18
Joined
Oct 18, 2007
Messages
930
First of all, i already said what i think is wrong. And iirc i gave abstract instructions on how to fix the issues. I just didnt know that you dont know about the DestroyTrigger/Timer bugs.
ResumeTimer is another thing, i once wrote a system where i used ResumeTimer and after resuming the timer nothing worked. Once i replaced ResumeTimer with TimerStart everything worked flawlessly.

Dont try to influence anyone. Let people see for themselves if another person is bad/w/e.

The ResumeTimer(YourTimerVar) does not bug at me, it works in my system, because when the rage is empty the texttag is not moved or shown anymore. so ResumeTimer does actually work ^^
 
Top