Hey there.
I'm currently beginning on a system that's required for my map.
Well 'system' might be a big word, but it's a function that's going to be pretty common in the game itself. I'll explain what it is first.
There are Heros in the game that are inspiring other units with a specific ability. This means that the ability will be given to other units in range of the Hero, exactly like an aura. Let's say Keeper of the Grove has 'Inspire: Force of Nature'. Then this system should give units within his range the same ability, and remove that ability when they go out of range, or when Keeper of the Grove dies.
(Ignoring the fact that Force of Nature is a hero ability, and the others are units. In my map all abilities are simpel unit abilities.)
Now the tricky thing is that if a unit comes within range of the Keeper of the Grove, and he has the Force of Nature ability already, nothing should happen. But when that unit leaves range again, he should NOT lose the ability.
Now I got to understand that using a struct here would be a good way to handle it, so that's why I started trying to understand structs.
A good friend of mine made me a Floating Combat Text system once, and that's where I saw a basic struct being used. I'd like to base my self-made system on this way of coding so that I have an 'example' to look at.
I just see that as soon as
is being called in the actions function, apperantly the struct gets some information sent to itself so that it can start looping for every specific case of (in this case) floating text.
I'm not sure how to understand what that line
exactly does and how I should interpret it.
Would anyone like to give me some advice or info on this?
I'm currently beginning on a system that's required for my map.
Well 'system' might be a big word, but it's a function that's going to be pretty common in the game itself. I'll explain what it is first.
There are Heros in the game that are inspiring other units with a specific ability. This means that the ability will be given to other units in range of the Hero, exactly like an aura. Let's say Keeper of the Grove has 'Inspire: Force of Nature'. Then this system should give units within his range the same ability, and remove that ability when they go out of range, or when Keeper of the Grove dies.
(Ignoring the fact that Force of Nature is a hero ability, and the others are units. In my map all abilities are simpel unit abilities.)
Now the tricky thing is that if a unit comes within range of the Keeper of the Grove, and he has the Force of Nature ability already, nothing should happen. But when that unit leaves range again, he should NOT lose the ability.
Now I got to understand that using a struct here would be a good way to handle it, so that's why I started trying to understand structs.
A good friend of mine made me a Floating Combat Text system once, and that's where I saw a basic struct being used. I'd like to base my self-made system on this way of coding so that I have an 'example' to look at.
JASS:
library CombatText initializer init needs DamageSystem
globals
private string S
endglobals
private struct Data
texttag t
string s
real size
real duration
boolean bool
static integer array Ar
static integer Total = 0
static timer Time = CreateTimer()
static method create takes texttag t, string s returns Data
local Data Dat = Data.allocate()
set Dat.t = t
set Dat.s = s
set Dat.size = 0.019
set Dat.bool = false
set Dat.duration = 0
if Dat.Total == 0 then
call TimerStart(Dat.Time,.03,true,function Data.Loop)
endif
set Dat.Ar[Dat.Total] = Dat
set Dat.Total = Dat.Total + 1
return Dat
endmethod
static method Loop takes nothing returns nothing
local Data Dat
local integer i = 0
loop
exitwhen i >= Dat.Total
set Dat = Dat.Ar[i]
set Dat.duration = Dat.duration + 0.03
if not Dat.bool then
set Dat.size = Dat.size + 0.0012
elseif Dat.bool and Dat.size >= 0.022 then
set Dat.size = Dat.size - 0.0012
endif
if Dat.size >= 0.0285 then
set Dat.bool = true
endif
call SetTextTagText(Dat.t,Dat.s,Dat.size)
if Dat.duration >= 2. then
set Dat.Total = Dat.Total - 1
set Dat.Ar[i] = Dat.Ar[Dat.Total]
set i = i - 1
call Dat.destroy()
endif
set i = i + 1
endloop
endmethod
endstruct
private function Actions takes nothing returns boolean
local texttag T
local unit u
local unit t
local integer dt = GetTriggerDamageType()
local real d
local integer R
local integer B
local integer G
local real Size
local integer id
local integer idt
local integer i
local Data Dat
if dt != DAMAGE_TYPE_EXTRA then
set T = CreateTextTag()
set u = GetTriggerDamageSource()
set t = GetTriggerDamageTarget()
set d = GetTriggerDamage()
set id = GetPlayerId(GetOwningPlayer(u))
set idt = GetPlayerId(GetOwningPlayer(t))
set Size = .019
if d != 0.00 then
if dt == DAMAGE_TYPE_ATTACK then
call SetWidgetLife(t,GetWidgetLife(t)+d)
elseif dt == DAMAGE_TYPE_PHYSICAL then
set S = I2S(R2I(d))
call Dat.create(T,S)
set R = 191
set B = 0
set G = 0
call SetTextTagVelocity(T, 0, .0277 )
elseif dt == DAMAGE_TYPE_MAGIC_HOLY then
set S = I2S(R2I(d))
call Dat.create(T,S)
set R = 242
set B = 57
set G = 187
call SetTextTagVelocity(T, 0, .0277 )
elseif dt == DAMAGE_TYPE_MAGIC_UNHOLY then
set S = I2S(R2I(d))
call Dat.create(T,S)
set R = 191
set B = 191
set G = 0
call SetTextTagVelocity(T, 0, .0277 )
endif
call SetTextTagVisibility(T, true)
call SetTextTagVisibility(T, false)
call SetTextTagColor(T,R,G,B, 255 )
call SetTextTagText(T,S,Size)
call SetTextTagPosUnit(T,t, 0 )
call SetTextTagPermanent(T, false)
call SetTextTagLifespan(T, 2)
set u = null
set t = null
set T = null
endif
endif
return false
endfunction
public function init takes nothing returns nothing
local trigger trg = CreateTrigger()
call TriggerAddCondition(trg, Condition(function Actions))
call TriggerRegisterDamageEvent(trg)
set trg = null
endfunction
endlibrary
I just see that as soon as
JASS:
local Data Dat
I'm not sure how to understand what that line
JASS:
local Data Dat
Would anyone like to give me some advice or info on this?
Last edited: