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

[vJass] Why wont my system work??

Status
Not open for further replies.
Level 18
Joined
Oct 18, 2007
Messages
930
Ok im making a rage system, all works except for the "bar" that is supposed to float over the raging unit. So, please post if you find anything. Thx

RAS Code ( Credits to The_Reborn_Devil for this system ) " modded it a bit "
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")
    //! runtextmacro SAS("Timer")
endlibrary

ok now for my Rage System
JASS:
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//*                                                          Rage System Manual                                                           *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//*                                                                                                                                       *
//*     To implement into your map copy the trigger "Simple Attachment System" and this trigger called "Rage System"                      *
//*                                                                                                                                       *
//*     O o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o O               *
//*     o How to use:                                                                                                     o               *
//*     o     - To create a Rage for any given unit, do this: "call Rage.create( unit YourUnitVar )"                      o               *
//*     o                                                                                                                 o               *
//*     o     - Modifying the rage is easy, do a "call Rage.RageIncrease( unit YourUnitVar , real Increasement )", or     o               *
//*     o         for decreasement "call Rage.RageDecrease( unit YourUnitVar , real Decreasement )"                       o               *
//*     o                                                                                                                 o               *
//*     o     - You can pause the periodic Rage decreasement by doing a call, false for stopping and true for resuming:   o               *
//*     o         "call Rage.RageTimer( unit YourUnitVar , boolean State )"                                               o               *
//*     o                                                                                                                 o               *
//*     o     - To reset the rage without any other variables just do: "call Rage.RageReset( unit YourUnitVar )"          o               *
//*     o                                                                                                                 o               *
//*     o     - To Remove the rage system from a unit, do: "call Rage.Destroy( unit YourUnitVar )"                        o               *
//*     o                                                                                                                 o               *
//*     O o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o O               *
//*                                                                                                                                       *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//* Rage System v1.1 by Dynasti *
//* * * * * * * * * * * * * * * *
library RageSystem initializer Init requires SAS 

    globals
        
        // For TextTag struct system
            private constant real TTsize            =   8.

            private constant integer TTalpha        =   1000 // 1000 is max, 0 is minimum

            private constant integer TTred          =   1000
            private constant integer TTgreen        =   1000
            private constant integer TTblue         =   1000
            
            private constant real TTVelAngle        =   0.
            private constant real TTVel             =   0.060
            
            private constant real TTfade            =   0.5
            private constant real TTlife            =   1.
            
            private constant real TToffset          =   15.
            
            private constant string CT              =   "|cffffcc00" // Common Text
            
            private constant string Minus           =   "|cffff0000" // Minus Text
            
            private constant string Pluss           =   "|cff00ff00" // Pluss Text
        // End of TextTag struct constants
        
        // For Ragebar
            private constant string RageBarStyle    =   "|"

            private constant real RBsize            =   10.
            
            private constant integer RBred          =   1000
            private constant integer RBgreen        =   0
            private constant integer RBblue         =   0
            
            private constant integer RBalpha        =   1000
            
            private constant real RBoffset          =   120.
        // End of Ragebar constants
            
        private integer RageLoss    =   1
        private real RageTimer      =   0.8
        private real MaxRage        =   100.
        private real RageTextLife   =   1.
        private real RabeBarMove    =   0.03

    endglobals
    
    private function CreateTextTagEx takes real x, real y, real offset, string text, real size, integer red, integer green, integer blue, integer alpha, boolean perm, real fade, real life, real velAngle, real vel, boolean visible returns texttag
        local texttag t=CreateTextTag()
                  
        call SetTextTagText(t,text,(size * 0.023 / 10))
        call SetTextTagColor(t,red,green,blue,alpha)
        call SetTextTagPermanent(t,perm)
        call SetTextTagFadepoint(t,fade)
        call SetTextTagLifespan(t,life)
        call SetTextTagPos(t,x,y,offset)
        call SetTextTagVelocity(t,velAngle,vel)
        call SetTextTagVisibility(t,visible)

        return t
    endfunction
    private struct TextTagSystem
        texttag tt
        timer tim   =   CreateTimer()
        
        static method KillTextTag takes nothing returns nothing
            local TextTagSystem t = GetAttachedStructTimer(GetExpiredTimer())
            call t.destroy()
        endmethod

        static method create takes string text, real x, real y returns TextTagSystem
            local TextTagSystem t = TextTagSystem.allocate()
            set t.tt = CreateTextTagEx( x , y , TToffset , text , TTsize , TTred , TTgreen , TTblue , TTalpha , false , TTfade , TTlife , TTVelAngle , TTVel , true )
            call TimerStart( t.tim , RageTextLife , false , function TextTagSystem.KillTextTag)
            call AttachStructTimer( t.tim , t )
            return t
        endmethod
        
        method onDestroy takes nothing returns nothing
            call DestroyTextTag(.tt)
            call DestroyTimer(.tim)
            set .tt     =   null
            set .tim    =   null
        endmethod
        
    endstruct

    struct Rage
        unit u
        real rage
        trigger death       =   CreateTrigger()
        timer tim           =   CreateTimer()
        texttag rb       // Rage Bar
        string rbtxt     //Rage Bar Text
        timer rbt           =   CreateTimer() // Rage Bar Timer

        private static method RageResetonDeath takes nothing returns nothing
            local Rage r = GetAttachedStructRage(GetDyingUnit())
            set r.rage = 0
        endmethod

        private static method RageBar takes nothing returns nothing
            local Rage r = GetAttachedStructTimer( GetExpiredTimer() )
            call SetTextTagPos( r.rb , GetUnitX(r.u) , GetUnitY(r.u) , RBoffset )
        endmethod

        private static method PeriodicRageDecrease takes nothing returns nothing
            local Rage r = GetAttachedStructTimer( GetExpiredTimer() )
            local integer index = StringLength( r.rbtxt )
            local TextTagSystem tts
            if (r.rage - RageLoss) < 0 then
                set r.rage = 0
            else
                set r.rage = r.rage - RageLoss
                loop
                    exitwhen index < r.rage/10
                    set r.rbtxt = SubString( r.rbtxt , 0 , index - 1 )
                    if r.rbtxt != null and r.rbtxt != "" then
                        call SetTextTagText( r.rb , r.rbtxt , TToffset )
                    endif
                    set index = index - 1
                endloop
                set tts = tts.create( Minus + "-" + "|r" + CT + I2S(RageLoss) + "|r" , GetUnitX( r.u ) , GetUnitY( r.u ) )
            endif
        endmethod

        static method create takes unit u returns Rage
            local Rage r = Rage.allocate()
            set r.u = u
            set r.rbtxt = " "
            // Somehow this has something to do with the Bar not appearing!
            set r.rb = CreateTextTag()
            call SetTextTagText( r.rb , r.rbtxt , ( RBsize * 0.023 / 10 ) )
            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 )
            call TimerStart( r.rbt , RabeBarMove , true , function Rage.RageBar )
            // -------------------------------------------------------------------
            call TimerStart( r.tim , RageTimer , true , function Rage.PeriodicRageDecrease )
            call TriggerRegisterUnitEvent( r.death , r.u , EVENT_UNIT_DEATH )
            call TriggerAddAction( r.death , function Rage.RageResetonDeath )
            call AttachStructTimer( r.tim , r )
            call AttachStructTimer( r.rbt , r )
            call AttachStructRage( r.u , r )
            return r
        endmethod

        static method RageIncrease takes unit u, real rinc returns nothing
            local Rage r = GetAttachedStructRage(u)
            local TextTagSystem tts
            local integer index = StringLength( r.rbtxt )
            if (r.rage + rinc) > MaxRage then
                set r.rage = MaxRage
            else
                set r.rage = r.rage + rinc
                loop
                    exitwhen index > r.rage/10
                    set r.rbtxt = r.rbtxt + RageBarStyle
                    call SetTextTagText( r.rb , r.rbtxt , TToffset )
                    set index = index + 1
                endloop
                set tts = tts.create( Pluss + "+" + "|r" + CT + I2S( R2I( rinc ) ) + "|r" , GetUnitX( r.u ) , GetUnitY( r.u ) )
            endif
        endmethod
        
        static method RageDecrease takes unit u, real rdec returns nothing
            local Rage r = GetAttachedStructRage(u)
            local TextTagSystem tts
            local integer index = StringLength( r.rbtxt )
            if (r.rage - rdec) < 0 then
                set r.rage = 0
                call SetTextTagText( r.rb , "" , TToffset )
            else
                set r.rage = r.rage - rdec
                loop
                    exitwhen index < r.rage/10
                    set r.rbtxt = SubString( r.rbtxt , 0 , index - 1 )
                    if r.rbtxt != null and r.rbtxt != "" then
                        call SetTextTagText( r.rb , r.rbtxt , TToffset )
                    endif
                    set index = index - 1
                endloop
                set tts = tts.create( Minus + "-" + "|r" + CT + I2S( R2I( rdec ) ) + "|r" , GetUnitX( r.u ) , GetUnitY( r.u ) )
            endif
        endmethod
        
        static method RageTimer takes unit u, boolean state returns nothing
            local Rage r = GetAttachedStructRage(u)
            if state then
                call ResumeTimer(r.tim)
            else
                call PauseTimer(r.tim)
            endif
        endmethod
        
        static method RageReset takes unit u returns nothing
            local Rage r = GetAttachedStructRage(u)
            set r.rage = 0
        endmethod
        
        static method Destroy takes unit u returns nothing
            local Rage r = GetAttachedStructRage(u)
            if r.u != null then
                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 RemoveAttachedStructTimer( .tim )
            call RemoveAttachedStructTimer( .rbt )
            call RemoveAttachedStructRage( .u )
            call DestroyTimer( .tim )
            call DestroyTimer( .rbt )
            call DestroyTextTag( .rb )
            call TriggerClearActions( .death )
            call DestroyTrigger( .death )
            set .death  = null
            set .rb     = null
            set .tim    = null
            set .rbt    = null
            set .u      = null
            set .rage   = 0
        endmethod

    endstruct

    private function Init takes nothing returns nothing
    endfunction

endlibrary

Any ideas?

Update, Map:
 

Attachments

  • Warrior.w3x
    25 KB · Views: 55
Last edited:
Level 23
Joined
Nov 29, 2006
Messages
2,482
Okay let see^^. I have never been helping users with huge codes or system, since I am a pretty bad person myself to find small issues:p But Ill try... :D

Edit: I might have an idea why it doesnt work properly.
JASS:
private constant real RBoffset = 12.
[...]
call SetTextTagPos(r.rb , GetUnitX(u) , GetUnitY(u) , RBoffset )

The Z height is 12? That means it will stay pretty close to the ground. have you tried 256 or something similar?
 
Last edited:
Level 18
Joined
Oct 18, 2007
Messages
930
Okay let see^^. I have never been helping users with huge codes or system, since I am a pretty bad person myself to find small issues:p But Ill try... :D

Edit: I might have an idea why it doesnt work properly.
JASS:
private constant real RBoffset = 12.
[...]
call SetTextTagPos(r.rb , GetUnitX(u) , GetUnitY(u) , RBoffset )

The Z height is 12? That means it will stay pretty close to the ground. have you tried 256 or something similar?

hmm, il check it out

Edit: But the main problem is that the bar is not showing up...
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
ohoh... (removed stupid question here)

Edit: I have problems thinking now. Mainly because it is 4 in the morning and mainly because I have not always been that bright on texttags -.-'
If someone else knows then tell Dynasti. I got to go to bed.
 
Level 16
Joined
Feb 22, 2006
Messages
960
first of all, lil question, why you do this (RBsize * 0.023 / 10) seems rather senseless because RBsize is 10. and 10*0.023/10 = 0.023 xD
then. why this two times ? (the set r.rage = r.rage - RageLoss line

JASS:
            set r.rage = r.rage - RageLoss
            if (r.rage - RageLoss) < 0 then
                set r.rage = 0
            else
                set r.rage = r.rage - RageLoss


also try it with an offset of 0

and maybe another order ... texttag sucks XD

JASS:
    call SetTextTagText(r.rb,"", 0.024)
    call SetTextTagPos(r.rb, GetUnitX(u), GetUnitY(u), 0.00)
    call SetTextTagColor(r.rb, RBred, RBgreen, RBblue, 255)
    call SetTextTagVisibility(r.rb, true)
    call SetTextTagPermanent(r.rb, true)

good luck, me not that good in finding bugs you know this :p

edit: so now i'm creating a bar system XD (or rework my old one)
 
Level 18
Joined
Oct 18, 2007
Messages
930
first of all, lil question, why you do this (RBsize * 0.023 / 10) seems rather senseless because RBsize is 10. and 10*0.023/10 = 0.023 xD
then. why this two times ? (the set r.rage = r.rage - RageLoss line

JASS:
            set r.rage = r.rage - RageLoss
            if (r.rage - RageLoss) < 0 then
                set r.rage = 0
            else
                set r.rage = r.rage - RageLoss


also try it with an offset of 0

and maybe another order ... texttag sucks XD

JASS:
    call SetTextTagText(r.rb,"", 0.024)
    call SetTextTagPos(r.rb, GetUnitX(u), GetUnitY(u), 0.00)
    call SetTextTagColor(r.rb, RBred, RBgreen, RBblue, 255)
    call SetTextTagVisibility(r.rb, true)
    call SetTextTagPermanent(r.rb, true)

good luck, me not that good in finding bugs you know this :p

edit: so now i'm creating a bar system XD (or rework my old one)

ok those set r.rage = r.rage - RageLoss fixed those. and the (RBsize * 0.023 / 10) is used to get the exact size
 
Status
Not open for further replies.
Top