• 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.

[JASS] Special Effects not created

Status
Not open for further replies.
JASS:
//*************************************************************************************
//*
//*
//*                                   CUSTOM ELEMENT
//*
//*                                     BY:ALMIA
//*
//*
//*************************************************************************************
//*
//*    Allows you to create custom elements
//*    which allows you to modify damage
//*    that uses amplification and reduction.
//*
//*    Also allows you to create your own
//*    element effects.
//*
//*    This system is basically a damage 
//*    modification system.
//*
//*    Units you registered will have
//*    their elements attached to the
//*    elements you want them to be.
//*
//*************************************************************************************
//*
//*    Requires:
//*
//*    Damage Engine
//*    - [url]http://www.hiveworkshop.com/forums/spells-569/gui-damage-engine-v2-2-1-0-a-201016[/url]
//*
//*    Unit Indexer
//*    - [url]http://www.hiveworkshop.com/forums/spells-569/gui-unit-indexer-1-2-0-2-a-197329/[/url]
//*
//*
//*************************************************************************************
//*
//*    API
//*
//*    constant function MaxElementValueTable takes nothing returns real
//*
//*    - Maximum static damage value
//*
//*    function CreateNewElement takes nothing returns integer
//*
//*    - Creates new element
//*
//*    function SaveHandle takes hashtable ht, integer pkey, integer ckey, handle h returns nothing
//*    function LoadAttackTypeHandle takes hashtable ht, integer pkey, integer ckey returns attacktype
//*    function LoadDamageTypeHandle takes hashtable ht, integer pkey, integer ckey returns damagetype
//*
//*    - Tool used for saving/loading attacktypes and damagetypes to hashtables
//*
//*    function RegisterElementAmplification takes integer element, integer targetElement, real value, attacktype atk, damagetype dmg, boolean static, trigger customEffect returns nothing
//*
//*    - Registers element damage amplification
//*
//*    function RegisterElementReduction takes integer element, integer targetElement, real value, boolean static, trigger customEffect returns nothing
//*
//*    - Registers element damage reduction
//*
//*    function SetUnitTypeElement takes integer element, integer id returns nothing
//*
//*    - Registers unit type id an element
//*
//*    function RegisterElementSFX takes integer element, string model, string attachment returns nothing
//*
//*    - Registers element's personal sfx for uniqueness and identification
//*
//*    function ElementOnIndexEvent takes nothing returns boolean
//*
//*    - attaches the element's personal sfx to units
//*
//*    function ElementOnDeIndexEvent takes nothing returns boolean
//*
//*    - destroys attached sfx from deindexed units
//*
//*    function ElementOnDamageEvent takes nothing returns boolean
//*
//*    - System core
//*    - this is where amplification and reduction of damage happens
//*    - this also evaluates the custom effects you registered
//*      for the amplification and reduction
//*
//*************************************************************************************
//*
//*    Variables
//*
//*    CE_Table = hashtable
//*    CE_Count = integer
//*
//*************************************************************************************
//*
//*    Credits
//*
//*    Bribe
//*    KingKing
//*
//*************************************************************************************
constant function MaxElementValueTable takes nothing returns real
    return 100.0
endfunction

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

function CreateNewElement takes nothing returns integer
    if 8192 != udg_CE_Count then
        set udg_CE_Count = udg_CE_Count + 1
    else
        set udg_CE_Count = 8192
    endif
    return udg_CE_Count
endfunction

//*************************************************************************************
//*
//*     TYPE CASTING
//*
//*     Typecasts handle and converts it to attacktype and damagetype
//*     and its other childs
//*
//*     I used this for attacktype and damagetype saving/loading
//*
//*************************************************************************************
function SaveHandle takes hashtable ht, integer pkey, integer ckey, handle h returns nothing
    call SaveFogStateHandle(ht, pkey, ckey, ConvertFogState(GetHandleId(h)))
endfunction

function LoadAttackTypeHandle takes hashtable ht, integer pkey, integer ckey returns attacktype
    return ConvertAttackType(GetHandleId(LoadFogStateHandle(ht, pkey, ckey)))
endfunction

function LoadDamageTypeHandle takes hashtable ht, integer pkey, integer ckey returns damagetype
    return ConvertDamageType(GetHandleId(LoadFogStateHandle(ht, pkey, ckey)))
endfunction

//*************************************************************************************
//*
//*
//*                         MAIN FUNCTIONS
//*
//*
//*************************************************************************************

function RegisterElementAmplification takes integer element, integer targetElement, real value, attacktype atk, damagetype dmg, boolean static, trigger customEffect returns nothing
    call SaveBoolean(udg_CE_Table, element, targetElement, true)
    if not static then
        if value > MaxElementValueTable() then
            set value = 100
        endif
    endif
    call SaveReal(udg_CE_Table, element, targetElement,value)
    call SaveBoolean(udg_CE_Table, 8192 + element, targetElement, static)
    call SaveTriggerHandle(udg_CE_Table, element, targetElement, customEffect)
    call SaveHandle(udg_CE_Table, 8192 +  element, targetElement, atk)
    call SaveHandle(udg_CE_Table, 16384 +  element, targetElement, dmg)
endfunction

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

function RegisterElementReduction takes integer element, integer targetElement, real value, boolean static, trigger customEffect returns nothing
    call SaveBoolean(udg_CE_Table, 16384 + element,targetElement, true)
    if not static then
        if value > MaxElementValueTable() then
            set value = 100
        endif
    endif
    call SaveReal(udg_CE_Table, 8192 + element, targetElement,value)
    call SaveBoolean(udg_CE_Table, 24756 + element, targetElement, static)
    call SaveTriggerHandle(udg_CE_Table, 8192 + element, targetElement, customEffect)
endfunction

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

function SetUnitTypeElement takes integer element, integer id returns nothing
    call SaveInteger(udg_CE_Table, id, 0, element)
endfunction


//*************************************************************************************
function RegisterElementSFX takes integer element, string model, string attachment returns nothing
    call SaveStr(udg_CE_Table, element, 0, model)
    call SaveStr(udg_CE_Table, element, 1, attachment)
endfunction

//*************************************************************************************
//*
//*
//*                         EVENT RELATED FUNCTIONS
//*
//*
//*************************************************************************************
function ElementOnIndexEvent takes nothing returns boolean
    local integer id = GetUnitTypeId(udg_UDexUnits[udg_UDex])
    local integer element = LoadInteger(udg_CE_Table, id, 0)
    local string model = LoadStr(udg_CE_Table, element, 0)
    local string attachment = LoadStr(udg_CE_Table, element, 1)
    call SaveEffectHandle(udg_CE_Table, GetHandleId(udg_UDexUnits[udg_UDex]), 0, AddSpecialEffectTarget(model, udg_UDexUnits[udg_UDex], attachment))
    return false
endfunction

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

function ElementOnDeIndexEvent takes nothing returns boolean
    call DestroyEffect(LoadEffectHandle(udg_CE_Table, GetHandleId(udg_UDexUnits[udg_UDex]), 0))
    return false
endfunction

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

//*************************************************************************************
//*
//*    WARNING
//*
//*    DO NOT TOUCH ANYTHING BELOW
//*    THIS IS THE SYSTEMS CORE
//*
//*************************************************************************************

function ElementOnDamageEvent takes nothing returns boolean

    //****************************************************
    //*                 SET VARIABLES
    //****************************************************
    local integer id = GetHandleId(udg_DamageEventSource)

    local integer uid = GetUnitTypeId(udg_DamageEventSource)
    local integer uid2 = GetUnitTypeId(udg_DamageEventTarget)

    local integer element  = LoadInteger(udg_CE_Table, uid, 0)
    local integer targetElement = LoadInteger(udg_CE_Table,uid2,0) 

    local boolean doReduct = LoadBoolean(udg_CE_Table, 16384 + element, targetElement)
    local boolean doAmplify = LoadBoolean(udg_CE_Table, element, targetElement)

    local trigger amplifyEffect
    local trigger reductionEffect

    local boolean amplifyStatic
    local boolean reductionStatic

    local real reduct
    local real amplify
   
    local attacktype atk 
    local damagetype dmg

    local real damage = udg_DamageEventAmount
 
    local trigger t = GetTriggeringTrigger()
    //****************************************************
    //*            DAMAGE REDUCTION EFFECT
    //****************************************************
    if doReduct then
        
        set reduct = LoadReal(udg_CE_Table, 8192 + element, targetElement)
        set reductionStatic = LoadBoolean(udg_CE_Table, 24756 + element, targetElement)
        
        if reductionStatic then
            set damage = reduct
        else
            set damage = damage * (reduct/MaxElementValueTable())
        endif

        call SetUnitState(udg_DamageEventTarget, UNIT_STATE_LIFE, GetUnitState(udg_DamageEventTarget,UNIT_STATE_LIFE) + damage)
        
        set reductionEffect = LoadTriggerHandle(udg_CE_Table, 8192 + element, targetElement)
        if TriggerEvaluate(reductionEffect) then
            call TriggerExecute(reductionEffect)
        endif
            
    endif

    //****************************************************
    //*            DAMAGE AMPLIFICATION EFFECT
    //****************************************************
    if doAmplify then
        set amplifyStatic = LoadBoolean(udg_CE_Table, 8192 + element, targetElement)
        set amplify = LoadReal(udg_CE_Table, element, targetElement)
        if amplifyStatic then
            set damage = amplify
        else
            set damage = damage * (amplify/MaxElementValueTable())
        endif
        set atk = LoadAttackTypeHandle(udg_CE_Table, 8192 + element, targetElement)
        set dmg = LoadDamageTypeHandle(udg_CE_Table, 16384 + element, targetElement)
        call DisableTrigger(t)
        call UnitDamageTarget(udg_DamageEventSource,udg_DamageEventTarget,damage,false,false,atk,dmg,null)
        call EnableTrigger(t)
        
        set amplifyEffect = LoadTriggerHandle(udg_CE_Table, element, targetElement)
        if TriggerEvaluate(amplifyEffect) then
            call TriggerExecute(amplifyEffect)
        endif
    endif
    
    return false
endfunction

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

function InitTrig_CustomElement takes nothing returns nothing

    
    //Declare triggers
    local trigger onIndex = CreateTrigger()
    local trigger onDeIndex = CreateTrigger()
    local trigger onDamage = CreateTrigger()

    
    //Register events
    call TriggerRegisterVariableEvent(onIndex, "udg_UnitIndexEvent", EQUAL, 1.0)
    call TriggerRegisterVariableEvent(onDeIndex, "udg_UnitIndexEvent", EQUAL, 2.0)
    call TriggerRegisterVariableEvent(onDamage, "udg_DamageEvent", EQUAL, 1.0)

    //Register conditions or action func
    call TriggerAddCondition(onIndex, Condition(function ElementOnIndexEvent))
    call TriggerAddCondition(onDeIndex, Condition(function ElementOnDeIndexEvent))
    call TriggerAddCondition(onDamage, Condition(function ElementOnDamageEvent))

    //Initialize
    set udg_CE_Table = InitHashtable()
    
    set onIndex = null
    set onDeIndex = null
    set onDamage = null
endfunction

So,i was testing my system,all things here worked perfectly,except the ElementOnIndex and DeIndexEvent.I tried the function with BJDebugMsg and it worked,the thing is that it doesn't create sfx on units.

Here is the proof of registration:
  • Registration
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- - --------
      • -------- Create Elements --------
      • -------- - --------
      • Custom script: set udg_Water = CreateNewElement()
      • Custom script: set udg_Fire = CreateNewElement()
      • Custom script: set udg_Electric = CreateNewElement()
      • -------- - --------
      • -------- Register Units --------
      • -------- - --------
      • Custom script: call SetUnitTypeElement(udg_Water, 'Hpal')
      • Custom script: call SetUnitTypeElement(udg_Fire, 'Hblm')
      • Custom script: call SetUnitTypeElement(udg_Electric, 'Hmkg')
      • -------- - --------
      • -------- Register Personal Effects --------
      • -------- - --------
      • Custom script: call RegisterElementSFX(udg_Fire, "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl", "weapon")
      • Custom script: call RegisterElementSFX(udg_Water, "Abilities\\Weapons\\WaterElementalMissile\\WaterElementalMissile.mdl", "weapon")
      • Custom script: call RegisterElementSFX(udg_Electric, "Abilities\\Weapons\\FarseerMissile\\FarseerMissile.mdl", "overhead")
      • -------- - --------
      • -------- Register Element Amplification and Reduction --------
      • -------- - --------
      • Custom script: call RegisterElementAmplification(udg_Water, udg_Fire, 40, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_DIVINE,true, gg_trg_Water_Effect)
      • Custom script: call RegisterElementReduction(udg_Fire, udg_Water, 10, true, gg_trg_Fire_Effect)
      • Custom script: call RegisterElementAmplification(udg_Electric, udg_Water, 40, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_DIVINE,true, gg_trg_Electric_Effect)
      • Custom script: call RegisterElementReduction(udg_Water, udg_Electric, 10, true, gg_trg_Water_Effect)


edit
I tried also to create and destroy effects outside the save function and it didn't work
Here is the test map:
 

Attachments

  • CustomElement v1.0.w3x
    34.5 KB · Views: 26
Status
Not open for further replies.
Top