Creating a cross (X) with SFXs ? :S

Komaqtion

You can change this now in User CP.
Reaction score
469
Hello !

Ok, so I would simply like to know:
How do I go about creating a simple cross (X) using special effects ? :S

What do I need to know to make it ? (If I want to make a function with arguments for it :D)

Center X/Y, width and height ?
Is that about it ?
 

Executor

I see you
Reaction score
57
Well thats relativly easy I think.

Best way would be packing the effects in a struct for clean and nice code.

Code:
X      X
  X   X
    X
  X   X
X       X

JASS:
struct Cross[20]
   private static string MODEL = " .......... "
   effect array sfx[9]
   static method create takes real x, real y returns thistype 
      local thistype this = thistype.allocate()
      local integer i 
      
      set .sfx[0] = AddSpecialEffect(...,.MODEL,...)
 
      // here one loop for the first line

      // here one loop for the second line
   endmethod
endstruct


If you need further help, tell us.

I'd say you could include a "real angle" var in the create method to variate the angle of the lines.
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
like Executor said, using effect array it's pretty easy

something like this:

JASS:
function PolarX takes real dist, real angle returns real
      return dist * Cos(angle * 0.0174)
endfunction

function PolarY takes real dist, real angle returns real
      return dist * Sin(angle * 0.0174)
endfunction

private struct data
      effect array [20]

      static method CreateCross takes real x, real y, real dist, string EFFECT_TYPE returns data
           local data d = data.allocate()
           local real offset = dist
           local integer i = 0

           loop
                set d.<i> = AddSpecialEffect(EFFECT_TYPE, x + PolarX(offset, 45), y + PolarY(offset, 45)
                set offset = offset - 100. //depends on the size of the effect, if you use 100. make the dist a multiplier of 100 for best result

                set i = i + 1
                exitwhen offset &lt; dist * -2
           endloop
          
           set offset = dist
              
           loop
                set d.<i> = AddSpecialEffect(EFFECT_TYPE, x + PolarX(offset, 135), y + PolarY(offset, 135)
                set offset = offset - 100. //depends on the size of the effect, if you use 100. make the dist a multiplier of 100 for best result

                set i = i + 1
                exitwhen offset &lt; dist * -2
           endloop

           return d
      endfunction

endstruct</i></i>


dist being the distance between the center of the cross and it's end

EDIT: try the edited code
 

Komaqtion

You can change this now in User CP.
Reaction score
469
What if the dimensions of the square the box is supposed to be in isn't an exact square ?
Like if one side is longer than the other, so you want to adapt the cross to that ? :S
 

Executor

I see you
Reaction score
57
Is it that hard? I mean you have the 4 corner points of the rect.

Code:
A                B
       rect
D                C

______________

A(minX/maxY) 
B(maxX/maxY)
C(maxX/minY)
D(minX/minY)

And you have the functions:

JASS:
function PolarProjectionBJ takes location source, real dist, real angle returns location
    local real x = GetLocationX(source) + dist * Cos(angle * bj_DEGTORAD)
    local real y = GetLocationY(source) + dist * Sin(angle * bj_DEGTORAD)
    return Location(x, y)
endfunction

function AngleBetweenPoints takes location locA, location locB returns real
    return bj_RADTODEG * Atan2(GetLocationY(locB) - GetLocationY(locA), GetLocationX(locB) - GetLocationX(locA))
endfunction

function DistanceBetweenPoints takes location locA, location locB returns real
    local real dx = GetLocationX(locB) - GetLocationX(locA)
    local real dy = GetLocationY(locB) - GetLocationY(locA)
    return SquareRoot(dx * dx + dy * dy)
endfunction


For each line, you calculate the distance (A to C, or B to D) and divide it by the number of effects you want to use for each line.

step = Distance(A,C) / number of effects
a = Angle(A,C)

loop
x = PolarProjection( Ax, step, a)
y = PolarProjection( Ay, step, a)
CreateEffect(x,y)
i = i + 1
exitwhen i > number of effects
endloop
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
////////////////////////
//  
//   Functions :
//   XCandy.create(string path, real posX, real posY, real AoE, real Interval) -&gt; struct
//  &lt;vars&gt;.destroy()
//
//  Normal Jass Syntax :
//  XCandy_Create(string path, real posX, real posY, real AoE, real Interval) -&gt; struct
//  XCandy_Destroy(&lt;vars&gt;)
//
////////////////////////

library XCandy
    
    private struct EffectStruct
        effect eff
        thistype prev
        thistype next
        
        method onDestroy takes nothing returns nothing
            call DestroyEffect(.eff)
        endmethod
    endstruct
    
    struct XCandy
        private EffectStruct left
        private EffectStruct right
        
        static method create takes string path, real x, real y, real size, real interval returns thistype
            local thistype this = .allocate()
            local real sizex = size / 2
            local integer tick = R2I(size / interval)
            local real cosA = interval * Cos(5.25)
            local real sinA = interval * Sin(5.25)
            local real cosB = interval * Cos(4.2)
            local real sinB = interval * Sin(4.2)
            local real xA = x + sizex * Cos(2.1)
            local real yA = y + sizex * Sin(2.1)
            local real xB = x + sizex * Cos(7.35)
            local real yB = y + sizex * Sin(7.35)
            local EffectStruct temp
            set .left = EffectStruct.create()
            set .left.eff = AddSpecialEffect(path,xA,yA)
            set .left.prev = .left
            set .left.next = .left
            set .right = EffectStruct.create()
            set .right.eff = AddSpecialEffect(path,xB,yB)
            set .right.prev = .right
            set .right.next = .right
            
            loop
            exitwhen tick == 0
                set xA = xA + cosA
                set yA = yA + sinA
                set temp = EffectStruct.create()
                set temp.eff = AddSpecialEffect(path,xA,yA)
                set temp.prev = left.prev
                set temp.next = left
                set left.prev.next = temp
                set left.prev = temp
                
                set xB = xB + cosB
                set yB = yB + sinB
                set temp = EffectStruct.create()
                set temp.eff = AddSpecialEffect(path,xB,yB)
                set temp.prev = right.prev
                set temp.next = right
                set right.prev.next = temp
                set right.prev = temp
                
                set tick = tick - 1
            endloop
            
            return this
        endmethod
        
        method onDestroy takes nothing returns nothing
            local EffectStruct left = .left.next
            local EffectStruct right = .right.next
            loop
            exitwhen left == .left and .right == .right
                call left.destroy()
                call right.destroy()
                set left = left.next
                set right = right.next
            endloop
            call .left.destroy()
            call .right.destroy()
        endmethod
        
    endstruct
    
    public function Create takes string path, real x, real y, real size, real interval returns XCandy
        return XCandy.create(path,x,y,size,interval)
    endfunction
    
    public function Destroy takes XCandy i returns nothing
        call i.destroy()
    endfunction
    
endlibrary


Better version with Linked List. Generally the number of effect array is depends on the size of X you need. Both examples on top will break when the size of X is enough big. But my version of X creation library does not. The number of effect array is dynamic for each struct, it will not break even your X is very big.
 

jig7c

Stop reading me...-statement
Reaction score
123
can you please explain to me in simple terms on how to use the above code?
I'm very new to jass, so i have hard time picking things up...

can someone give me an example.. lets say i have to create flamestrike model file in an X pattern..

i know how to get X,Y of a unit

local unit u = GetTriggerUnit
local integer x = GetUnitX(u)
local integer y = GetUnitY(u)

how would i used the above code?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
local XCandy fx = XCandy_Create(&quot;Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl&quot;,x,y,600.,200.)
call TriggerSleepAction(2.)
call XCandy_Destroy(fx) //Destroy it after 2 seconds.
//You must destroy the effect else it will leak.

Example.
 

Executor

I see you
Reaction score
57
JASS:

////////////////////////
//  
//   Functions :
//   XCandy.create(string path, real posX, real posY, real AoE, real Interval) -&gt; struct
//  &lt;vars&gt;.destroy()
//
//  Normal Jass Syntax :
//  XCandy_Create(string path, real posX, real posY, real AoE, real Interval) -&gt; struct
//  XCandy_Destroy(&lt;vars&gt;)
//
////////////////////////

library XCandy
    
    private struct EffectStruct
        effect eff
        thistype prev
        thistype next
        
        method onDestroy takes nothing returns nothing
            call DestroyEffect(.eff)
        endmethod
    endstruct
    
    struct XCandy
        private EffectStruct left
        private EffectStruct right
        
        static method create takes string path, real x, real y, real size, real interval returns thistype
            local thistype this = .allocate()
            local real sizex = size / 2
            local integer tick = R2I(size / interval)
            local real cosA = interval * Cos(5.25)
            local real sinA = interval * Sin(5.25)
            local real cosB = interval * Cos(4.2)
            local real sinB = interval * Sin(4.2)
            local real xA = x + sizex * Cos(2.1)
            local real yA = y + sizex * Sin(2.1)
            local real xB = x + sizex * Cos(7.35)
            local real yB = y + sizex * Sin(7.35)
            local EffectStruct temp
            set .left = EffectStruct.create()
            set .left.eff = AddSpecialEffect(path,xA,yA)
            set .left.prev = .left
            set .left.next = .left
            set .right = EffectStruct.create()
            set .right.eff = AddSpecialEffect(path,xB,yB)
            set .right.prev = .right
            set .right.next = .right
            
            loop
            exitwhen tick == 0
                set xA = xA + cosA
                set yA = yA + sinA
                set temp = EffectStruct.create()
                set temp.eff = AddSpecialEffect(path,xA,yA)
                set temp.prev = left.prev
                set temp.next = left
                set left.prev.next = temp
                set left.prev = temp
                
                set xB = xB + cosB
                set yB = yB + sinB
                set temp = EffectStruct.create()
                set temp.eff = AddSpecialEffect(path,xB,yB)
                set temp.prev = right.prev
                set temp.next = right
                set right.prev.next = temp
                set right.prev = temp
                
                set tick = tick - 1
            endloop
            
            return this
        endmethod
        
        method onDestroy takes nothing returns nothing
            local EffectStruct left = .left.next
            local EffectStruct right = .right.next
            loop
            exitwhen left == .left and .right == .right
                call left.destroy()
                call right.destroy()
                set left = left.next
                set right = right.next
            endloop
            call .left.destroy()
            call .right.destroy()
        endmethod
        
    endstruct
    
    public function Create takes string path, real x, real y, real size, real interval returns XCandy
        return XCandy.create(path,x,y,size,interval)
    endfunction
    
    public function Destroy takes XCandy i returns nothing
        call i.destroy()
    endfunction
    
endlibrary


Better version with Linked List. Generally the number of effect array is depends on the size of X you need. Both examples on top will break when the size of X is enough big. But my version of X creation library does not. The number of effect array is dynamic for each struct, it will not break even your X is very big.

What if the dimensions of the square the box is supposed to be in isn't an exact square ?
Like if one side is longer than the other, so you want to adapt the cross to that ? :S
.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
What if the dimensions of the square the box is supposed to be in isn't an exact square ?
Like if one side is longer than the other, so you want to adapt the cross to that ? :S

My library does not create exact-squared X, if you tested it.
 

Executor

I see you
Reaction score
57
What if the dimensions of the square the box is supposed to be in isn't an exact square ?
Like if one side is longer than the other, so you want to adapt the cross to that ? :S

My library does not create exact-squared X, if you tested it.

Yes indeed, thats the point. As I understand him, he wants a 'X' to be created in and adapted to a given rect. This means the angle has to be calculated dynamically dependend on the relation of height and width.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top