• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Effect System

Status
Not open for further replies.
Level 11
Joined
Apr 6, 2008
Messages
760
Credits
Redscores: For showing me timer "stacks"

Fixes:
A minor improvment
Changed the code abit and addes textmacros

JASS:
globals
    constant real intervals = .05
endglobals

//! textmacro Effect takes NAME, TYPE, TAKES, RETURN, KIND, ACTION, DESTROY

globals
    timer $NAME$_Time = CreateTimer()
    integer $NAME$_Total = 0
    integer array $NAME$_Struct
endglobals

public struct $NAME$_Data
$TYPE$

unit u
unit t

real dura
real maxdur

    static method create takes $TAKES$ returns $NAME$_Data
        local $NAME$_Data d = $NAME$_Data.allocate()
        
        set d.u = u
        set d.$NAME$ = $ACTION$
        set d.dura = 0.
        set d.maxdur = dura
        
        if $NAME$_Total == 0 then
            call TimerStart($NAME$_Time,intervals,true,function $NAME$_Data.Exe)
        endif
        
        set $NAME$_Struct[$NAME$_Total] = d
        set $NAME$_Total = $NAME$_Total + 1
        
        return d
    endmethod
    
    static method Exe takes nothing returns nothing
        local $NAME$_Data d
        local integer index = 0
        
        loop
            exitwhen index >= $NAME$_Total
            set d = $NAME$_Struct[index]
            set d.dura = d.dura + intervals
            
            if d.dura >= d.maxdur then
                set $NAME$_Total = $NAME$_Total - 1
                set $NAME$_Struct[index] = $NAME$_Struct[$NAME$_Total]
                
                if $NAME$_Total == 0 then
                    call PauseTimer($NAME$_Time)
                endif
                
                call d.destroy()
            endif
            
            set index = index + 1
        endloop
    endmethod
    
    method onDestroy takes nothing returns nothing
        call $DESTROY$(.$NAME$)
        set .$NAME$ =  null
        set .u = null
        set .t = null
        set .dura = 0.
        set .maxdur = 0.
    endmethod
endstruct

function Create$NAME$$KIND$ takes $TAKES$ returns nothing
    local $NAME$_Data d = $NAME$_Data.create($RETURN$)
endfunction

//! endtextmacro


library EffectSystem

//! runtextmacro Effect("Effect","effect Effect","unit u,real dura,string SFX,string attachPoint","u,dura,SFX,attachPoint","Unit","AddSpecialEffectTarget(SFX,d.u,attachPoint)","DestroyEffect")

endlibrary

This is a simple system i wrote to create effect on units or at locations(x/y). u can decide how long it will last and is very easy to use

To come:
Add support for Lightnings

Requires: Jass NewGen Pack
 
Last edited:
Level 29
Joined
Jul 29, 2007
Messages
5,174
Might want to add at the start the list of function calls (CreateEffect, CreateEffectXY, CreateEffectUnit) and their arguments.

Also for convenience, you can define all the attachment points in private globals so people who are not experienced (You know what word I mean, it starts with a "N" :p) and do not know them can just use your globals.
For example, private string LEFT_HAND = "left,hand" if that's even how you use them. Never really touched attachment points.
 
Level 3
Joined
Aug 19, 2007
Messages
24
I don't see why you'd need textmacros in the way you are using. All you need for a timed special effect is a way to "attach" the effect to a timer - even if you had one timer controlling the destruction of many special effects by running through an array (as you are doing), you still would not need a text macro. I would only use a textmacro to create functions for generic, oft-used special effects (dust clouds, blood, etc). Your functions seem overly complicated and messy.
 
Level 13
Joined
Mar 16, 2008
Messages
941
Funny, since the first system that destroys effects after time was published, I saw around 5-6... and that was before maybe 3 weeks. WHY? there are enough of them :/

EDIT: lawl, didn't watched at the date either... why did you post in here? And btw then sorry to Ciebron :)
 
Last edited:
Level 12
Joined
Apr 27, 2008
Messages
1,228
Oh my ****** ***** ***** 07-28-2008 *****
Maybe I should pay some respect, after all this thread is older than me ...
Anyway using the black arts to raise the dead has been prohibited by law ;)
 
Level 3
Joined
Aug 19, 2007
Messages
24
Oh my ****** ***** ***** 07-28-2008 *****
Maybe I should pay some respect, after all this thread is older than me ...
Anyway using the black arts to raise the dead has been prohibited by law ;)

Sorry, I didn't notice last posting date, was something I noticed while searching
 
Status
Not open for further replies.
Top