- Joined
- Dec 21, 2013
- Messages
- 910
So I already spent 2 weeks reading vjass tutorials daily. And now I tried to make some spell. Its kinda confusing because each tutorials is different and not really mention the different method..My current target is just to make it works properly, so there are no configuration thingy. And I'm pretty sure its still got bugged if casted multiple times by same unit. Am I doing it right?
Here is some general question:
1. I'm still not sure when to use a global timer or timer each spell....
2.
is actually same like when I use
but can be changed inside (so I can use the loop i), am I right?
3. do i need to add private for struct's child?
I saw some tutorial use it but I tried it and compiler report about private thingy..
4. How to use method OnInit properly? I see its different with normal init function. I tried but it doesnt work so i decided to make the init with function, and use call structname.methodname
5. How to revert back
?
6. if I use
inside scope, is that globals only works inside scope? so thats mean its fined to have same globals name on another scope, right?
7. how about a globals name is same with local inside scope? err... to make it easier, how to check to compiled vjass? I wanted to see it myself
8. whats the different between method and function? I see it same, only method is inside struct, so it can use thistype this. Or maybe I'm doing it wrong
9. If i use an unit indexer system, thats mean i cant setunitcustomvalue right? I think it will cause other system that use that bugged..
And here is my second spell. the first one, the map got corrupted somehow.
Currently it still use detect if unit in group, gonna change it unit has buff since the ability add buff. I use that stun system because i might be want to add stun duration modifier based on stats
and second spell.
Now this one is confusing me. Err.. there are some unuesed variable because I actually copy paste previous ability and want to use method instead. But i dont know how to make method OnInit, so still use some function. So I make a trigger to detect cast that shield ability. the other trigger is dettect if that guy attacked.
function action is kinda straight forward, just register thingy sand start countdown. The periodic just detect if shield still on and remove unit from group when done.
function barriereflect (i changed this name because i thought it cause error, it was "shield" but same name with scope is not allowed). It registed if the shielded guy attacked. I dont know how to set up the "temp this" other than saving a global indeger storing each unit id to "this" value. well, it will bugged if caster multiple times by same unit... actually i can fix this by adding more thing in function action, by checking if unit is already shielded if will call another function to load the "this". Is there another way to make this spell?
I cant remember every question i have, so i will post here again if i remember them
Here is some general question:
1. I'm still not sure when to use a global timer or timer each spell....
2.
JASS:
private tempdat array data
JASS:
local tempdat this = i
3. do i need to add private for struct's child?
JASS:
private struct tempdat
private unit caster
4. How to use method OnInit properly? I see its different with normal init function. I tried but it doesnt work so i decided to make the init with function, and use call structname.methodname
5. How to revert back
JASS:
call AddUnitAnimationProperties( unit, "defend", true )
6. if I use
JASS:
globals
private integer dindex = -1
7. how about a globals name is same with local inside scope? err... to make it easier, how to check to compiled vjass? I wanted to see it myself
8. whats the different between method and function? I see it same, only method is inside struct, so it can use thistype this. Or maybe I'm doing it wrong
9. If i use an unit indexer system, thats mean i cant setunitcustomvalue right? I think it will cause other system that use that bugged..
And here is my second spell. the first one, the map got corrupted somehow.
JASS:
scope MercilesPursuit initializer init
//use ability, the next attack stun target
globals
private integer dindex = -1
//timer period = CreateTimer()
private integer spellID = 'AHds'
private group g
endglobals
private struct tempdat
unit caster
real duration
endstruct
globals
private tempdat array data
endglobals
private function stuns takes nothing returns nothing
local unit u = udg_DamageEventSource
local unit target = udg_DamageEventTarget
local real timestun = 5
call BJDebugMsg("attack")
if IsUnitInGroup(u, g) == true then
call stunplz(target, timestun)
//set udg_GDS_Duration = timestun
//set udg_GDS_Target = target
//call TriggerExecute( gg_trg_GDS_Main )
call AddUnitAnimationProperties( u, "", false )
call UnitRemoveAbility(u, 'BHds')
call GroupRemoveUnit(g, u)
call BJDebugMsg("STUNshouldbe")
endif
endfunction
private function periodic takes nothing returns nothing
local integer i = 0
local timer tmr = GetExpiredTimer()
local tempdat this
loop
exitwhen i>dindex
call BJDebugMsg("i= " + I2S(i))
set this=data[i]
set this.duration= this.duration - 0.03125
if IsUnitInGroup(this.caster,g)==false then
set data[i] = data[dindex]
set i = i - 1
set dindex = dindex - 1
call this.destroy()
call BJDebugMsg("CASTED")
endif
if this.duration <= 0 then
call GroupRemoveUnit(g, this.caster)
call AddUnitAnimationProperties( this.caster, "", false )
set data[i] = data[dindex]
set i = i - 1
set dindex = dindex - 1
set this.caster = null
call this.destroy()
call BJDebugMsg("TimeOUT")
endif
if dindex == -1 then
call ReleaseTimer(tmr)
endif
set i = i+1
endloop
endfunction
private function action takes nothing returns nothing
local tempdat this= tempdat.create()
set this.caster=GetTriggerUnit()
set this.duration=5
call ResetUnitAnimation(this.caster)
call GroupAddUnit(g,this.caster)
call AddUnitAnimationProperties( this.caster, "defend", true )
set dindex=dindex + 1
set data[dindex]=this
call BJDebugMsg("dindex= " + I2S(dindex))
if dindex==0 then
call TimerStart(NewTimer(), 0.03125, true, function periodic)
call BJDebugMsg("TimerStart")
endif
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterVariableEvent( t, "udg_DamageEvent", EQUAL, 1.00 )
call TriggerAddAction( t, function stuns )
call RegisterSpellEffectEvent(spellID, function action)
set g = CreateGroup()
endfunction
endscope
and second spell.
JASS:
scope Shield initializer OnInit
//deflect damage to nearby enemy
globals
private integer spellID = 'AHtc'
private integer array index
private group g
endglobals
private struct tempdat
unit caster
real duration
real shield
static integer dindex = -1
static thistype array data
static method damage takes unit caster, real damage returns nothing
local group gro = CreateGroup()
local real x = GetUnitX(caster)
local real y = GetUnitY(caster)
local unit f
call GroupEnumUnitsInRange(gro, x, y, 900, null)
call GroupRemoveUnit(gro,caster)
loop
set f = FirstOfGroup(gro)
exitwhen f==null
call UnitDamageTarget(caster,f,damage,true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC,null)
call GroupRemoveUnit(gro,f)
endloop
call BJDebugMsg("Damage")
endmethod
static method periodic takes nothing returns nothing
local timer tmr = GetExpiredTimer()
local thistype this = GetTimerData(tmr)
//call BJDebugMsg("this= " + I2S(GetTimerData(tmr)))
set this.duration= this.duration - 0.03125
if IsUnitInGroup(this.caster,g)==false then
call this.destroy()
call BJDebugMsg("ShieldOFF")
call ReleaseTimer(tmr)
endif
if this.duration <= 0 then
call GroupRemoveUnit(g, this.caster)
call this.destroy()
call BJDebugMsg("TimeOUT")
call ReleaseTimer(tmr)
endif
endmethod
endstruct
private function barriereflect takes nothing returns nothing
local real damage = udg_DamageEventAmount
local unit attacker = udg_DamageEventSource
local unit attacked = udg_DamageEventTarget
local integer i = GetUnitUserData(attacked)
local tempdat this = index[i]
if IsUnitInGroup(attacked, g) == true then
//call UnitRemoveAbility(attacked, 'BHds')
call BJDebugMsg("attacked")
if this.shield <= 0 then
call GroupRemoveUnit(g, attacked)
else
set udg_DamageEventAmount=0
call tempdat.damage(attacked,damage)
set this.shield=this.shield-damage
set this.duration=this.duration - 1
endif
endif
endfunction
private function action takes nothing returns nothing
local tempdat this= tempdat.create()
local integer i = GetUnitUserData(GetTriggerUnit())
set this.caster=GetTriggerUnit()
set this.duration=10
set this.shield=300
call GroupAddUnit(g,this.caster)
set index[i]=this
call TimerStart(NewTimerEx(this), 0.03125, true, function tempdat.periodic)
call BJDebugMsg("TimerStart")
endfunction
private function OnInit takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterVariableEvent( t, "udg_DamageEvent", EQUAL, 1.00 )
call TriggerAddAction( t, function barriereflect )
call RegisterSpellEffectEvent(spellID, function action)
set g = CreateGroup()
endfunction
endscope
Now this one is confusing me. Err.. there are some unuesed variable because I actually copy paste previous ability and want to use method instead. But i dont know how to make method OnInit, so still use some function. So I make a trigger to detect cast that shield ability. the other trigger is dettect if that guy attacked.
function action is kinda straight forward, just register thingy sand start countdown. The periodic just detect if shield still on and remove unit from group when done.
function barriereflect (i changed this name because i thought it cause error, it was "shield" but same name with scope is not allowed). It registed if the shielded guy attacked. I dont know how to set up the "temp this" other than saving a global indeger storing each unit id to "this" value. well, it will bugged if caster multiple times by same unit... actually i can fix this by adding more thing in function action, by checking if unit is already shielded if will call another function to load the "this". Is there another way to make this spell?
I cant remember every question i have, so i will post here again if i remember them
Last edited: