• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

vJASS Spell Sample v1.0

Status
Not open for further replies.
Level 8
Joined
Dec 30, 2011
Messages
134
vJASS Spell Sample
Made by KhaosMachine

To use this sample you have need the JassNewGenPack editor!
LAST VERSION (can download from here o from the attachments):
JASS NEW GEN PACK
vJASS SPELL SAMPLE MAP
NOTE: ADD JNPG FOLDER TO THE ANTIVIRUS EXCEPTION LIST!!!
Information
I made this system because I'm new on vJASS and it's some complicated to start to learn struct, index, etc. Well this system works fine (I think) and is USEFUL for all vJASS coders and starters... :D

Code


JASS:
//****************************************************************************************************
//
//                                 @@@@@                          @@@@@  
//    @@@@@@@                     @     @            @   @       @     @                 @
//          @       @@@  @@@      @       @@@   @@@  @   @       @            @   @ @@@  @    @@@
//@  @      @ @@@  @    @          @@@@@  @  @ @   @ @   @        @@@@@  @@@  @@ @@ @  @ @   @   @
//@ @       @ @  @  @@@  @@@            @ @@@  @@@@  @   @             @ @  @ @ @ @ @@@  @   @@@@
//@@  @     @ @@@@     @    @     @     @ @    @     @   @       @     @ @@@@ @   @ @    @   @
//@    @@@@@  @  @  @@@  @@@       @@@@@  @    @@@@  @@@ @@@      @@@@@  @  @ @   @ @    @@@ @@@@
//
//****************************************************************************************************

//VERSION 1.0

//MADE BY KhaosMachine ([url]http://www.hiveworkshop.com/forums/members/khaosmachine/[/url])

//****************************************************************************************************

scope yourSpellName initializer init

globals
    //CONSTANT VARIABLES (ABILITY ID, DUMMY ID, SPECIAL EFFECT STRING, FRAMES PER SECOND, ETC.) (START)
    
    private constant integer ABILITY_ID = 'XXXX'
    private real FPS = 32
    
    //CONSTANT VARIABLES (ABILITY ID, DUMMY ID, SPECIAL EFFECT STRING, FRAMES PER SECOND, ETC.) (END)
endglobals

//FUNCTIONS THAT RETURNS VARIOUS VALUES (DAMAGE, HEAL, AREA OF EFFECT, ETC.) (START)



//FUNCTION THAT RETURNS VARIOUS VALUES (DAMAGE, HEAL, AREA OF EFFECT, ETC.) (END)

private struct DATA
    //MAKE THE ELEMENTS YOU NEED TO MAKE THE LOOP OF THE SPELL (START)
    
    
    
    //MAKE THE ELEMENTS YOU NEED TO MAKE THE LOOP OF THE SPELL (END)
endstruct

globals
    private constant timer TIMER = CreateTimer()
    private DATA array ARRAY
    private integer TOTAL = 0
endglobals

private function action takes nothing returns nothing
    local DATA D
    local boolean DESTROY_DATA
    local integer i = 0
    //CREATING THE LOCAL VARIABLES YOU NEED (START)
    
    
    
    //CREATING THE LOCAL VARIABLES YOU NEED (END)
    loop
    exitwhen i >= TOTAL
        set D = ARRAY[i]
        //LOOP ACTIONS (START)
        
        
        
        //LOOP ACTIONS (END)
        set DESTROY_DATA = TRUE //REPLACE 'TRUE' WITH YOUR CONDITIONS TO END THE SPELL
        if DESTROY_DATA then
            set ARRAY[i] = ARRAY[TOTAL - 1]
            set TOTAL = TOTAL - 1
            call D.destroy()
        endif
        set i = i + 1
    endloop
    if TOTAL == 0 then
        call PauseTimer(TIMER)
    endif
endfunction

private function run takes nothing returns boolean
    local DATA D
    //CREATING THE LOCAL VARIABLES YOU NEED (START)
    
    
    
    //CREATING THE LOCAL VARIABLES YOU NEED (END)
    if GetSpellAbilityId() == ABILITY_ID then
        set D = DATA.create()
        //STARTING THE SPELL (START)
        
        
        
        //STARTING THE SPELL (END)
        if TOTAL == 0 then
            call TimerStart(TIMER, FPS, true, function action)
        endif
        set TOTAL = TOTAL + 1
        set ARRAY[TOTAL - 1] = D
    endif
    return false
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
    endloop
    call TriggerAddCondition(t, Condition(function run))
    set FPS = 1 / FPS
    set t = null
endfunction

endscope


JASS:
//****************************************************************************************************
//
//                                 @@@@@                          @@@@@  
//    @@@@@@@                     @     @            @   @       @     @                 @
//          @       @@@  @@@      @       @@@   @@@  @   @       @            @   @ @@@  @    @@@
//@  @      @ @@@  @    @          @@@@@  @  @ @   @ @   @        @@@@@  @@@  @@ @@ @  @ @   @   @
//@ @       @ @  @  @@@  @@@            @ @@@  @@@@  @   @             @ @  @ @ @ @ @@@  @   @@@@
//@@  @     @ @@@@     @    @     @     @ @    @     @   @       @     @ @@@@ @   @ @    @   @
//@    @@@@@  @  @  @@@  @@@       @@@@@  @    @@@@  @@@ @@@      @@@@@  @  @ @   @ @    @@@ @@@@
//
//****************************************************************************************************

//VERSION 1.0

//MADE BY KhaosMachine ([url]http://www.hiveworkshop.com/forums/members/khaosmachine/[/url])

//****************************************************************************************************

scope concentration initializer init

globals
    //CONSTANT VARIABLES (ABILITY ID, DUMMY ID, SPECIAL EFFECT STRING, FRAMES PER SECOND, ETC.) (START)
    
    private constant integer ABILITY_ID = 'A000'
    private constant integer UNIT_TYPE_DUMMY = 'u000'
    private constant string SPECIAL_EFFECT_AREA = "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl"
    private constant string SPECIAL_EFFECT_TARGET = "Abilities\\Spells\\Other\\Drain\\ManaDrainTarget.mdl"
    private constant real SFX_AREA_SCALE = 5
    private constant real SFX_TARGET_SCALE = .5
    private constant real SFX_AREA_HEIGHT = -100
    private constant real SFX_TARGET_HEIGHT = 60
    private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
    private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
    private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
    private real FPS = 24
    private constant group UNIT_GROUP = CreateGroup()//WE NEED A GROUP TO ENUM THE TARGET UNITS
    private constant player PLAYER = Player(PLAYER_NEUTRAL_AGGRESSIVE)//WE NEED A PLAYER TO SET THE OWNER OF THE DUMMY
    
    //CONSTANT VARIABLES (ABILITY ID, DUMMY ID, SPECIAL EFFECT STRING, FRAMES PER SECOND, ETC.) (END)
endglobals

//FUNCTIONS THAT RETURNS VARIOUS VALUES (DAMAGE, HEAL, AREA OF EFFECT, ETC.) (START)

private function DAMAGE takes integer level returns real
    return 120. + 50. * level
    //RETURNS 120 + 50 * level
    //LEVEL 1: 120 + 50 * 1 = 170
    //LEVEL 2: 120 + 50 * 2 = 220
    //LEVEL 3: 120 + 50 * 3 = 270
    //LEVEL 4: 120 + 50 * 4 = 320
    //LEVEL n: 120 + 50 * n = X
endfunction

private function DURATION takes integer level returns real
    local real duration = 20. - 2. * level
    //SET THE LOCAL VARIABLE duration TO 20 - 2 * level
    //LEVEL 1: 20 - 2 * 1 = 18
    //LEVEL 2: 20 - 2 * 2 = 16
    //LEVEL 2: 20 - 2 * 3 = 14
    //LEVEL 2: 20 - 2 * 4 = 12
    //LEVEL n: 20 - 2 * n = X...
    if duration < 1 then
        //IF THE DURATION IS BELOW OF 0 THEN SET duration TO 1
        set duration = 1
    endif
    return duration
endfunction

private function AREA_OF_EFFECT takes integer level returns real
    return 400.
    //RETURNS 400
    //LEVEL 1: 400 = 400
    //LEVEL 2: 400 = 400
    //LEVEL 3: 400 = 400
    //LEVEL 4: 400 = 400
    //LEVEL n: 400 = 400...
endfunction

//FUNCTION THAT RETURNS VARIOUS VALUES (DAMAGE, HEAL, AREA OF EFFECT, ETC.) (END)

private struct DATA
    //MAKE THE ELEMENTS YOU NEED TO MAKE THE LOOP OF THE SPELL (START)
    
    //WE NEED THE NEXT THINGS
    unit caster
    //CASTER, IT DAMAGES TO THE TARGET
    unit target
    //TARGET, IT RECEIVES THE DAMAGE
    unit dummy
    //DUMMY, THAT HAVE THE SPECIAL EFFECT
    real duration
    //DURATION, THE DURATION OF THE DAMAGE
    integer level
    //LEVEL, THE LEVEL OF THE ABILITY
    effect teffect
    //EFFECT, THE SPECIAL EFFECT OF THE TARGET
    
    //MAKE THE ELEMENTS YOU NEED TO MAKE THE LOOP OF THE SPELL (END)
endstruct

globals
    private constant timer TIMER = CreateTimer()
    private DATA array ARRAY
    private integer TOTAL = 0
endglobals

private function action takes nothing returns nothing
    local DATA D
    local boolean DESTROY_DATA
    local integer i = 0
    //CREATING THE LOCAL VARIABLES YOU NEED (START)
    
    
    
    //CREATING THE LOCAL VARIABLES YOU NEED (END)
    loop
    exitwhen i >= TOTAL
        set D = ARRAY[i]
        //LOOP ACTIONS (START)
        
        call SetUnitPosition(D.dummy, GetUnitX(D.target), GetUnitY(D.target))
        call UnitDamageTarget(D.caster, D.target, DAMAGE(D.level) * FPS / DURATION(D.level), true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
        set D.duration = D.duration - FPS
        //SET WHEN THE SPELL STOPS
        
        set DESTROY_DATA = IsUnitType(D.target, UNIT_TYPE_DEAD) or D.duration <= 0
        
        //SET WHEN THE SPELL STOPS
        
        //LOOP ACTIONS (END)
        if DESTROY_DATA then
            call SetUnitExploded(D.dummy, true)
            call KillUnit(D.dummy)
            call DestroyEffect(D.teffect)
            set ARRAY[i] = ARRAY[TOTAL - 1]
            set TOTAL = TOTAL - 1
            call D.destroy()
        endif
        set i = i + 1
    endloop
    if TOTAL == 0 then
        call PauseTimer(TIMER)
    endif
endfunction

private function run takes nothing returns boolean
    local DATA D
    //CREATING THE LOCAL VARIABLES YOU NEED (START)
    
    local unit caster
    local unit target
    local integer level
    local real x
    local real y
    
    //CREATING THE LOCAL VARIABLES YOU NEED (END)
    if GetSpellAbilityId() == ABILITY_ID then
        //STARTING THE SPELL (START)
        
        set caster = GetTriggerUnit()
        set level = GetUnitAbilityLevel(caster, ABILITY_ID)
        set x = GetUnitX(caster)
        set y = GetUnitY(caster)
        set bj_lastCreatedUnit = (CreateUnit(PLAYER, UNIT_TYPE_DUMMY, x, y, 0))
        call UnitApplyTimedLife(bj_lastCreatedUnit, 'BTLF', 1)
        call SetUnitScale(bj_lastCreatedUnit, SFX_AREA_SCALE, SFX_AREA_SCALE, SFX_AREA_SCALE)
        call SetUnitFlyHeight(bj_lastCreatedUnit, SFX_AREA_HEIGHT, 0)
        call DestroyEffect(AddSpecialEffectTarget(SPECIAL_EFFECT_AREA, bj_lastCreatedUnit, "origin"))
        call GroupEnumUnitsInRange(UNIT_GROUP, x, y, AREA_OF_EFFECT(level), null)
        loop
            set target = FirstOfGroup(UNIT_GROUP)
        exitwhen target == null
            call GroupRemoveUnit(UNIT_GROUP, target)
            if not IsUnitType(target, UNIT_TYPE_DEAD) and not IsUnitType(target, UNIT_TYPE_STRUCTURE) and not IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) and IsUnitEnemy(caster, GetOwningPlayer(target)) then
                set D = DATA.create()//WHEN YOU ARE TO SET THE ELEMENTS OF THE STRUCT YOU HAVE FIRST TO CREATE IT!
                set D.caster = caster
                set D.target = target
                set D.duration = DURATION(level)
                set D.level = level
                set D.dummy = CreateUnit(PLAYER, UNIT_TYPE_DUMMY, x, y, 0)
                call SetUnitScale(D.dummy, SFX_TARGET_SCALE, SFX_TARGET_SCALE, SFX_TARGET_SCALE)
                call SetUnitFlyHeight(D.dummy, SFX_TARGET_HEIGHT, 0)
                set D.teffect = AddSpecialEffectTarget(SPECIAL_EFFECT_TARGET, D.dummy, "origin")
                //WHEN YOU SET ALL ELEMENTS OF THE STRUCT YOU HAVE TO CHECK IF THE TIMER IS ON AND INDEX THE STRUCT
                if TOTAL == 0 then
                    call TimerStart(TIMER, FPS, true, function action)
                endif
                set TOTAL = TOTAL + 1
                set ARRAY[TOTAL - 1] = D
                //WHEN YOU SET ALL ELEMENTS OF THE STRUCT YOU HAVE TO CHECK IF THE TIMER IS ON AND INDEX THE STRUCT
            endif
        endloop
        set bj_lastCreatedUnit = null
        set caster = null
        
        //STARTING THE SPELL (END)
    endif
    return false
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
    endloop
    call TriggerAddCondition(t, Condition(function run))
    set FPS = 1 / FPS
    set t = null
endfunction

endscope


CREDITS

THANKS TO ALL TUTORIALS OF vJASS, JASS, etc. On this forum!!!

UPDATES


  • vJASS Spell Sample v1.0:
    -Release


 

Attachments

  • vJASS Spell Sample.w3x
    33.4 KB · Views: 84
  • JNGP.rar
    10.7 MB · Views: 175
Status
Not open for further replies.
Top