- Joined
- Feb 11, 2011
- Messages
- 1,860
[Solved] Basic Struct Help
Hello,
I am trying to learn how structs work. I am planning to use them in a spell called Death Coil, which deals damage to the target equal to 20% of their current hit points.
The timer in the script is because I want the damage to be done only when the missile hits, i.e. I am calculating how long it takes to hit and waiting that amount of time.
Please note that I am new to vJASS and simple explanations will be appreciated
Basically, I want to store the caster and target units instead of using global variables.
When saving, I get the following message:
"target is not of a type that allows . syntax"
Thanks for your help!
Hello,
I am trying to learn how structs work. I am planning to use them in a spell called Death Coil, which deals damage to the target equal to 20% of their current hit points.
The timer in the script is because I want the damage to be done only when the missile hits, i.e. I am calculating how long it takes to hit and waiting that amount of time.
Please note that I am new to vJASS and simple explanations will be appreciated
JASS:
scope DeathCoil
struct Spell
unit Unit
endstruct
function exp_act takes nothing returns nothing
local real dmg = (GetUnitState(target.Unit, UNIT_STATE_LIFE) * 0.2)
local texttag t = CreateTextTag()
call UnitDamageTarget(caster.Unit, target.Unit, dmg, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
call SetTextTagText(t, "|cff8000FF-" + I2S(R2I(dmg)) + "|r", 0.023)
call SetTextTagPosUnit(t, target.Unit, 50)
call SetTextTagVelocity(t, 0, 64 * 0.071 / 128)
call SetTextTagPermanent(t, false)
call SetTextTagLifespan(t, 2)
call SetTextTagFadepoint(t, 1)
call SetTextTagVisibility(t, true)
set t = null
endfunction
function act takes nothing returns nothing
local Spell caster = Spell.create()
local Spell target = Spell.create()
set caster.Unit = GetTriggerUnit()
set target.Unit = GetSpellTargetUnit()
local timer t = CreateTimer()
local real dx = (GetUnitX(caster.Unit) - GetUnitX(target.Unit))
local real dy = (GetUnitY(caster.Unit) - GetUnitY(target.Unit))
local real dist
set dist = SquareRoot((dx * dx) + (dy * dy))
call TimerStart(t, dist / 1000, false, function exp_act)
set t = null
endfunction
function cond takes nothing returns boolean
if (GetSpellAbilityId() == 'A03W') then
call act()
endif
return false
endfunction
function InitTrig_Lvl_10_Death_Coil takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function cond))
endfunction
endscope
Basically, I want to store the caster and target units instead of using global variables.
When saving, I get the following message:
"target is not of a type that allows . syntax"
Thanks for your help!
Last edited: