- 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 ^^
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.
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!
( but it is removed now ^^ )
Test Map:
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!
Test Map:
Attachments
Last edited: