Chaosy
Tutorial Reviewer
- Joined
- Jun 9, 2011
- Messages
- 13,219
Code is updated, opinions?
www.hiveworkshop.com/forums/triggers-scripts-269/dot-spell-255603/index2.html#post2567452
www.hiveworkshop.com/forums/triggers-scripts-269/dot-spell-255603/index2.html#post2567452
Hello, I always thought I understood how to code spells using structs even though I never actually tried. But when I started to think about it, it wasn't so obvious. The problem I couldn't manage to solve properly was that I can't catch an struct instance afterwards.
For example, let's create a simple DoT spell that deals 50 damage every second.
I can create an instance of the struct ONCE, which allows me to set some variables and deal 50 damage ONCE. However, how do I repeat to process, there is no list that I can use to gather all the instances etc. In GUI we use unit groups mos t of the time but that doesn't work with structs. So I came up with a really silly idea.
It works fine, it's MUI. (I tested with 6 units casting the same spell at the same time) But I highly doubt this is the correct way to do things.
For example, let's create a simple DoT spell that deals 50 damage every second.
I can create an instance of the struct ONCE, which allows me to set some variables and deal 50 damage ONCE. However, how do I repeat to process, there is no list that I can use to gather all the instances etc. In GUI we use unit groups mos t of the time but that doesn't work with structs. So I came up with a really silly idea.
JASS:
struct DoT
integer i
public static method create takes unit u returns DoT
local DoT this = DoT.allocate()
//do stuff
loop
exitwhen this.i == 5
set this.i = this.i + 1
call TriggerSleepAction(1)
call SetUnitState(u, UNIT_STATE_LIFE, RMaxBJ(0,GetUnitState(u, UNIT_STATE_LIFE) - 50))
endloop
call this.deallocate()
return this
endmethod
endstruct
-
Untitled Trigger 002
-
Events
- Unit - A unit Starts the effect of an ability
- Conditions
-
Actions
- Custom script: local DoT instance = DoT.create(GetTriggerUnit())
-
Events
It works fine, it's MUI. (I tested with 6 units casting the same spell at the same time) But I highly doubt this is the correct way to do things.
Last edited: