# System SpellStruct

Discussion in 'Systems and Snippets' started by Jesus4Lyf, Nov 20, 2009.

1. ### Jesus4LyfGood Idea™

Ratings:
+394 / 0 / -0
2. ### tooltiperrorSuper ModeratorStaff Member

Ratings:
+233 / 0 / -0
You could make it so that it sorts out any errors by itself.

I don`t really know, just throwing stuff out there, haven`t read much of the script.

3. ### GrundyUltra Cool Member

Ratings:
+35 / 0 / -0
Here's a function I wrote to go along with SpellStruct, I'm not sure if it should be included in SpellStruct because it's just extra junk that will probably not be used very often, but for people who do want to use it for a couple spells it could come in handy. It checks to see if a widget is between the caster and the target widget or target point +/- a given range. So passing in 128.0 for the real would check to see if a unit is within melee range of the line segment that connects the caster to the target:

JASS:
``````public method isWidgetBetweenCasterAndTarget takes widget whichWidget, real range returns boolean
local real x // using local x and y for target loc because the target could
local real y // have moved since this.targetX and this.targetY were set
local real distance
local real a // coefficient in the line equation Ax + By + C = 0
local real b // coefficient in the line equation Ax + By + C = 0
local real c // constant in the line equation Ax + By + C = 0
if this.targetWidget == null then
set x = this.targetX
set y = this.targetY
set distance = this.getDistanceToTargetPoint()
else
set x = GetWidgetX(this.targetWidget)
set y = GetWidgetY(this.targetWidget)
set distance = this.getDistanceToTargetWidget()
endif
set a = this.casterY() - y
set b = x - this.casterX()
set c = -(a*x + b*y)
return ( abs(a*GetWidgetX(whichWidget) + b*GetWidgetY(whichWidget) + c)/distance ) <= range
endmethod``````

Sorry about variable names, I know they aren't very descriptive. They come form the line equation Ax + By + C = 0 so I didn't know what else to call them.

This could be used in the filter for this.enumUnitsInAoE and could be useful for something like... a channelled lightning spell with a lightning effect between the caster and the target that deals damage to every unit that the lightning passes through. If someone has a more efficient way to do this let me know. And I'm at work right now so I can't check to see if my syntax is all right.

4. ### Jesus4LyfGood Idea™

Ratings:
+394 / 0 / -0
@Grundy:
I think there is a much better (more efficient) way to do that with vectors. I used vector resolution once in a spell of mine to get the distance to a line segment (better than returning whether or not a widget is within range of a line segment ) and it was something like ~5 lines, off memory.

5. ### GrundyUltra Cool Member

Ratings:
+35 / 0 / -0
Yea, I guess your right. I just wanted to make a function that would be easy to stick in a SpellStruct and figure out everything for me but to make it more efficient you'd have to figure out the end points yourself and pass them in instead of letting the function figure out what end points you want:
JASS:
``````public method getWidgetDistanceToLine takes widget whichWidget, real startX, real startY, real endX, real endY returns real
local real a=startY-endY
local real b=endX-startX
return abs(a*GetWidgetX(whichWidget)+b*GetWidgetY(whichWidget)-(a*startX+b*startY))/sqrt(a*a+b*b)
endmethod``````
but now it's totally irrelevant to SpellStruct haha too bad I can't delete old posts.

And if you really wanted to you could put that all on 1 line, but I wouldn't:
JASS:
``````public method getWidgetDistanceToLine takes widget whichWidget, real startX, real startY, real endX, real endY returns real
return abs((startY-endY)*GetWidgetX(whichWidget)+(endX-startX)*GetWidgetY(whichWidget)-((startY-endY)*startX+(endX-startX)*startY))/sqrt((startY-endY)*(startY-endY)+(endX-startX)*(endX-startX))
endmethod``````

6. ### Jesus4LyfGood Idea™

Ratings:
+394 / 0 / -0
And hence why such things are not in SpellStruct.

7. ### NarksVastly intelligent whale-like being from the stars

Ratings:
+92 / 0 / -0
Just wanted to say this is awesome. It does everything!

• Like x 1
8. ### 13lade619is now a game developer :)

Ratings:
+399 / 0 / -0
what the?.. i cant SAVE it into my map...

i get an error saying:

Missing Requirement : optional (Libraries cannot require scopes)

when i save it... is my jassHelper not working?
it says it's 0.9.I.2

9. ### Jesus4LyfGood Idea™

Ratings:
+394 / 0 / -0
Update JassHelper.

10. ### KennyBack for now.

Ratings:
+202 / 0 / -0
Just wanted to say that I scabbed your `.forGroup` idea for a `ForProjectileGroup()` function. I know it probably isn't a good idea (at all), but the interface is so much better than `FirstOfGroup()` loops for projectiles.

Anywho, this thing seriously needs a mod review. Too bad all mods have been busy lately, haha.

11. ### 13lade619is now a game developer :)

Ratings:
+399 / 0 / -0
where do i find the latest?.. the one i'm using is the default on JNGP 1.5d.

12. ### KennyBack for now.

Ratings:
+202 / 0 / -0

You can find it here.

13. ### GrundyUltra Cool Member

Ratings:
+35 / 0 / -0
Jesus you suggested making
JASS:
``````module Blockable
method onChannel takes nothing returns nothing
if BlockSpell[this.targetUnit] != 0 then
call BlockSpell[this.targetUnit].destroy()
call this.destroy()
endif
endmethod
endmodule``````

and having every spell I want to be blockable implement this module.

I was thinking of making another module for Multi-casting, I don't have the code for it but I was going to make a module that would implement the onChannel method and some calculation whatever it may be to decide if multicast should be used on the current cast and then order a dummy unit to cast the same spell again. the method would check the unit type so the dummy unit wouldn't be able to multi cast it. But i'm not sure what I should do if I want a spell to be blockable and multicastable. Right now all I can think of is a module for Blockable and a module for Multicastable and a module for BlockableMulticastable but that is not a good solution because if i come up with something else that I might want to apply to different spells then I'd need to make modules for every combination of effects and it would just get too messy I think.

Do you have any ideas for this?

Maybe a "blockable" text macro and a "multicastable" text macro that i can put inside of the onChannel method and just add text macros for whatever comes in the future, that's the best I can come with, but I don't really like that either.

Maybe multicast should just be coded in a buff and not in spellstruct at all, i don't know.

14. ### Jesus4LyfGood Idea™

Ratings:
+394 / 0 / -0
If it applies to all spells, you could do it totally outside of SpellStruct, if BlockSpell was only meant to block one cast. Depends how you want it treated... you need to decide that first.

15. ### GrundyUltra Cool Member

Ratings:
+35 / 0 / -0
if the spell is blocked, it should not be able to multicast.

i was thinking of putting it inside of spellstruct due to the way it would choose targets. some spells might want to be multicast on random allied units only. some might be random enemy units only, some might be the same target multiple times, some might be random units with the possibility of hitting the same one multiple times, some might be random targets without repeating the same target. I was going to make it with some variables that can be set in onInit for target selection.

16. ### Jesus4LyfGood Idea™

Ratings:
+394 / 0 / -0
Mm! Have fun with that one, you might end up just coding it for each spell individually at that rate...

Or get a few algorithms and use textmacros or something. Either way, you should actually run both spell block and multi cast in onEffect, otherwise a spell which is cancelled will proc them. It's a little difficult, I don't know that there's any good vJass features for solving this problem. Textmacros may be the way to go for both (most power over what happens in your code).

On the other hand, you could actually use functions.
JASS:
``````method onEffect takes nothing returns nothing
if CheckSpellBlock(targetUnit) then
call this.destroy()
return
endif
if CheckMulticast(caster) then
call SomethingToDoWithRecastingTheSpell(some, parameters)
endif
// do the spell actions
endmethod``````

17. ### AnachronNew Member

Ratings:
+53 / 0 / -0
Dled last version, test it and got a lot of double free errors, also my wc3 crashed.

View attachment 36085

Canceling spells cause a lot of errors and bugs too.

18. ### Jesus4LyfGood Idea™

Ratings:
+394 / 0 / -0
I can't seem to find any errors, except by cancelling Life Drain, which displays a T32 error due to a mistake in the example code...

Can you explain further how to reproduce the results you're stating? I use this system actively in all my mapping, at the latest version, with debug mode on, and have no such issues.

19. ### AnachronNew Member

Ratings:
+53 / 0 / -0
I started the testmap.
Selected the ranger.
Skilled lifedrain.
Tested it a few times.
(Hero moved outside of playable map rect because)
Chosed the moon priestess.
Skilled Starfall.
Used starfall once.
Gone around.
Used starfall for about 2-5 times again. (Without delay, instant cast)
Clicked abort.

Then all the errors appeared.

20. ### Jesus4LyfGood Idea™

Ratings:
+394 / 0 / -0
Although there is no "Abort" key, I tried stop, after following all your instructions.
And I am unable to reproduce any errors, except for T32x complaining if you stop casting Life Drain before it starts actually draining.

Edit: FYI I am using the test map downloaded from the first post, upgraded to version 1.0.7 which is also in the first post.