- Joined
- Oct 2, 2013
- Messages
- 95
Hey all!
This is my very first vJASS script. It is a work in progress for a spell.
My spell will create three damage-absorbing runes around the caster. All damage done to the caster is redirected to the rune with the least health. The caster may then use a secondary, targeted spell to throw one of his rune's at an enemy, dealing damage based on the rune's health.
Right now, I've finished the damage mitigation and rune rotation. But when working on the rune throwing i get some problems. At the DoomRitesThrowCast function, you can see I've used multiple debug messages. When using the throw ingame, all the messages I see are:
"Checking throw..."
"0..."
and thats it.
It looks like the trigger I created inside my main trigger won't load the scope's private vars, trashing the GroupAdd/RemoveUnit functions.
Also, because it is my first code, it IS full of trashy functions and unnecessary vars. If you guys could help me at that too, I'd be grateful
This is my very first vJASS script. It is a work in progress for a spell.
My spell will create three damage-absorbing runes around the caster. All damage done to the caster is redirected to the rune with the least health. The caster may then use a secondary, targeted spell to throw one of his rune's at an enemy, dealing damage based on the rune's health.
Right now, I've finished the damage mitigation and rune rotation. But when working on the rune throwing i get some problems. At the DoomRitesThrowCast function, you can see I've used multiple debug messages. When using the throw ingame, all the messages I see are:
"Checking throw..."
"0..."
and thats it.
It looks like the trigger I created inside my main trigger won't load the scope's private vars, trashing the GroupAdd/RemoveUnit functions.
Also, because it is my first code, it IS full of trashy functions and unnecessary vars. If you guys could help me at that too, I'd be grateful
JASS:
scope DoomRites
globals
private unit caster
private unit target
private timer duration = CreateTimer()
private group runes = CreateGroup()
private real rotation = 0
private integer runecount = 0
private unit thrownrune
private group thrown = CreateGroup()
// Vars used for the damage protection.
private real oldlife = 0
private integer runecount2 = 0
private unit defendingrune
private real damage = 0
private real comparehealth
private real comparehealth2
//====================================//
private unit attacker
// This is the trigger used for damage detection.
private trigger gg_trg_DoomRitesDmg
// This is the one used to detect the gaze spellcast.
private trigger gg_trg_DoomRitesThw
endglobals
function Trig_DoomRites_Conditions takes nothing returns boolean
if ( not (GetSpellAbilityId() == 'A05R')) then
return false
endif
return true
endfunction
function Trig_DoomRites_Conditions2 takes nothing returns boolean
if ( not (GetSpellAbilityId() == 'A05S')) then
return false
endif
return true
endfunction
function DoomRitesRotateGo takes nothing returns nothing
local unit u = GetEnumUnit()
local location l = GetUnitLoc(caster)
local real x = GetLocationX(l) + 100 * Cos((rotation + ( 120 * runecount)) * bj_DEGTORAD)
local real y = GetLocationY(l) + 100 * Sin((rotation + ( 120 * runecount)) * bj_DEGTORAD)
local location m = Location(x,y)
set runecount = runecount + 1
set rotation = rotation + 1
call SetUnitPositionLoc( u, m)
call RemoveLocation(m)
call RemoveLocation(l)
set u = null
endfunction
function DoomRitesRotationPre takes nothing returns nothing
set runecount = 0
call ForGroup( runes, function DoomRitesRotateGo)
endfunction
function DoomRitesNewCast takes nothing returns nothing
local integer i = 0
local location l = GetUnitLoc(caster)
local player p = GetOwningPlayer(caster)
local timer t = CreateTimer()
loop
exitwhen i == 3
call GroupAddUnit( runes, CreateUnitAtLoc( p, 'e00P' , l, 0))
call DisplayTextToForce( GetPlayersAll(), "Unit created" )
set i = i + 1
endloop
call TimerStart( t, 0.03, true, function DoomRitesRotationPre)
call DisplayTextToForce( GetPlayersAll(), "The cast declares" )
call RemoveLocation(l)
set t = null
set p = null
endfunction
function DoomRitesSortRunesByHealth takes nothing returns nothing
local unit picked = GetEnumUnit()
if ( GetUnitState( picked, UNIT_STATE_LIFE)<= comparehealth) then
set defendingrune = picked
endif
set runecount2 = runecount2 + 1
set picked = null
endfunction
function DoomRitesDefend takes nothing returns nothing
local real templife
local real passdmg
call DisplayTextToPlayer(GetLocalPlayer(),0,0,"Works!")
set comparehealth = 999999
loop
exitwhen damage <= 0
set runecount2 = 0
call ForGroup( runes, function DoomRitesSortRunesByHealth)
set templife = GetUnitState( defendingrune, UNIT_STATE_LIFE)
call SetUnitState( defendingrune, UNIT_STATE_LIFE,((GetUnitState( defendingrune, UNIT_STATE_LIFE)) - damage))
if ( damage >= templife ) then
set damage = (damage - (damage - templife))
else
set damage = 0
endif
if ( runecount2 == 0 ) then
call DisplayTextToForce( GetPlayersAll(), "Some damage passes throw the runes!" )
set passdmg = damage
set damage = 0
endif
endloop
call UnitRemoveAbility( caster,'A043')
call UnitDamageTarget( attacker, caster, passdmg, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
endfunction
function Trig_DoomRitesDmg_Actions takes nothing returns nothing
local timer t = CreateTimer()
set oldlife = GetUnitState( caster, UNIT_STATE_LIFE)
set attacker = udg_DamageEventSource
set damage = udg_DamageEventAmount
call UnitAddAbility(caster,'A043')
call TimerStart( t, 0, false, function DoomRitesDefend )
set t = null
endfunction
function DmgTrig_DoomRites takes nothing returns nothing
set gg_trg_DoomRitesDmg = CreateTrigger( )
call TriggerRegisterVariableEvent( gg_trg_DoomRitesDmg, "udg_DamageEvent", EQUAL, 1.00 )
call TriggerAddAction( gg_trg_DoomRitesDmg, function Trig_DoomRitesDmg_Actions)
endfunction
function DoomRitesThrowMove takes nothing returns nothing
local unit u = GetEnumUnit()
local location t = GetUnitLoc(target)
local location r = GetUnitLoc(u)
local real a = bj_RADTODEG * Atan2(GetLocationY(t) - GetLocationY(r), GetLocationX(t) - GetLocationX(r))
local real x = GetLocationX(r) + 60 * Cos(a * bj_DEGTORAD)
local real y = GetLocationY(r) + 0 * Sin(a * bj_DEGTORAD)
local location m = Location(x, y)
call SetUnitPositionLoc( u, m)
set u =null
call RemoveLocation(t)
call RemoveLocation(r)
call RemoveLocation(m)
endfunction
function DoomRitesThrowPre takes nothing returns nothing
call ForGroup( thrown, function DoomRitesThrowMove )
endfunction
function DoomRitesSortRunesByHealth2 takes nothing returns nothing
local unit picked = GetEnumUnit()
if ( GetUnitState( picked, UNIT_STATE_LIFE)<= comparehealth2) then
set thrownrune = picked
endif
set picked = null
endfunction
function DoomRitesThrowCast takes nothing returns nothing
local timer t = CreateTimer()
set comparehealth2 = 0
set runes = runes
set target = GetSpellTargetUnit()
call DisplayTextToForce( GetPlayersAll(), "Checking Throw..." )
set comparehealth2 = 0
call ForGroup( runes, function DoomRitesSortRunesByHealth2)
call DisplayTextToForce( GetPlayersAll(), "0..." )
call GroupRemoveUnit( runes, thrownrune )
call DisplayTextToForce( GetPlayersAll(), "1..." )
call GroupAddUnit( thrown, thrownrune )
call DisplayTextToForce( GetPlayersAll(), "2..." )
call TimerStart( t, 0.03, true, function DoomRitesThrowPre )
call DisplayTextToForce( GetPlayersAll(), "Throw. Fuck yiss." )
set t = null
endfunction
function DoomRitesThrowTrig takes nothing returns nothing
set gg_trg_DoomRitesThw = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_DoomRitesThw, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_DoomRitesThw, Condition( function Trig_DoomRites_Conditions2 ) )
call TriggerAddAction( gg_trg_DoomRitesThw, function DoomRitesThrowCast )
endfunction
function Trig_DoomRites_Actions takes nothing returns nothing
set caster = GetTriggerUnit()
set target = GetSpellTargetUnit()
if ( GetSpellAbilityId() == 'A05R' ) then
call DoomRitesNewCast()
call DmgTrig_DoomRites()
call DoomRitesThrowTrig()
call DisplayTextToForce( GetPlayersAll(), "Coomrites catr" )
endif
call DisplayTextToForce( GetPlayersAll(), "Spellcast" )
endfunction
endscope
//===========================================================================
function InitTrig_DoomRites takes nothing returns nothing
local integer index
set gg_trg_DoomRites = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_DoomRites, EVENT_PLAYER_UNIT_SPELL_EFFECT )
//loop
//call TriggerRegisterPlayerUnitEvent(gg_trg_DoomRites, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
//set index = index + 1
//exitwhen index == bj_MAX_PLAYER_SLOTS
//endloop
call TriggerAddCondition( gg_trg_DoomRites, Condition( function Trig_DoomRites_Conditions ) )
call TriggerAddAction( gg_trg_DoomRites, function Trig_DoomRites_Actions )
endfunction