Trying to import a spell and screwed it up...

turok255

New Member
Reaction score
30
I was trying to import Earth Spikes into my map, But I couldn't just use the import functions because I had alot of triggers there already. So... I made the Game Cache variable, Copy / pasted the triggers, Changed the custom text in my map header and copy / pasted the dummy units & spells, The spell works some what...

It will pause the unit and make a special effect on the units position but thats it... No rocks.. No spikes.. No damage. Heres the triggers im using please tell me if you see something ;)


Map Header
JASS:
constant function LocalVars takes nothing returns gamecache
    return udg_gc
endfunction

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function H2S takes handle h returns string
    return I2S(H2I(h))
endfunction

function I2U takes integer i returns unit
    return i
    return null
endfunction

function I2L takes integer i returns location
    return i
    return null
endfunction

function SetHandleHandle takes integer i, handle subject, string name, handle value returns nothing
    if value==null then
        call FlushStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name, H2I(value))
    endif
endfunction

function SetHandleInt takes integer i, handle subject, string name, integer value returns nothing
    if value==0 then
        call FlushStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleBoolean takes integer i, handle subject, string name, boolean value returns nothing
    if value==false then
        call FlushStoredBoolean(LocalVars(),GetObjectName(i)+I2S(H2I(subject)),name)
    else
        call StoreBoolean(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleReal takes integer i, handle subject, string name, real value returns nothing
    if value==0 then
        call FlushStoredReal(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
    else
        call StoreReal(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleString takes integer i, handle subject, string name, string value returns nothing
    if value==null then
        call FlushStoredString(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
    else
        call StoreString(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name, value)
    endif
endfunction


function GetHandleHandle takes integer i, handle subject, string name returns handle
    return GetStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleInt takes integer i, handle subject, string name returns integer
    return GetStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
endfunction
function GetHandleBoolean takes integer i, handle subject, string name returns boolean
    return GetStoredBoolean(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
endfunction
function GetHandleReal takes integer i, handle subject, string name returns real
    return GetStoredReal(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
endfunction
function GetHandleString takes integer i, handle subject, string name returns string
    return GetStoredString(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
endfunction

function GetHandleUnit takes integer i, handle subject, string name returns unit
    return GetStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTimer takes integer i, handle subject, string name returns timer
    return GetStoredInteger(LocalVars(),GetObjectName(i)+ I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTrigger takes integer i, handle subject, string name returns trigger
    return GetStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleEffect takes integer i, handle subject, string name returns effect
    return GetStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleGroup takes integer i, handle subject, string name returns group
    return GetStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleLightning takes integer i, handle subject, string name returns lightning
    return GetStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleWidget takes integer i, handle subject, string name returns widget
    return GetStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTrackable takes integer i, handle subject, string name returns trackable
    return GetStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTextTag takes integer i, handle subject, string name returns texttag
    return GetStoredInteger(LocalVars(),GetObjectName(i)+I2S(H2I(subject)), name)
    return null
endfunction

//Varius Mathfunctions//////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
function FlushHandleLocals takes integer i, handle subject returns nothing
    call FlushStoredMission(LocalVars(),GetObjectName(i)+I2S(H2I(subject)) )
endfunction

function AngleXY takes real xa, real ya, real xb, real yb returns real
    return (180/3.14138 * Atan2(yb - ya, xb - xa))
endfunction

function DistanceXY takes real xa, real ya, real xb, real yb returns real
    return SquareRoot((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya))
endfunction

function PolarX takes real x, real dist, real angle returns real
  return (x + dist * Cos(angle * 3.14/180))
endfunction

function PolarY takes real y, real dist, real angle returns real
    return (y + dist * Sin(angle * 3.14/180))
endfunction

function RealMin takes real a, real b returns real
    if (a < b) then
        return a
    else
        return b
    endif
endfunction

function RealMax takes real a, real b returns real
    if (a < b) then
        return b
    else
        return a
    endif
endfunction

Game Cache
JASS:
function Trig_Game_cache_initialization_Actions takes nothing returns nothing
    call FlushGameCache(InitGameCache("testmap"))
    set udg_Cache = InitGameCache("testmap")
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function InitTrig_Initialization takes nothing returns nothing
    set gg_trg_Initialization = CreateTrigger()
    call TriggerAddAction(gg_trg_Initialization, function Trig_Game_cache_initialization_Actions)
endfunction

Earth Spike Trigger
JASS:
// This function is used to avoid timer nulling
function ES_RockActions takes timer rockActionTimer returns nothing
    local location unitLoc
    local location newLoc
    local location rockLoc
    local real     scalingValue
    local sound    impaleSound
    local unit     caster
    local unit     rock
    local unit     spike
    local unit     target
    local integer  i          = 0
    local string   timerID    = H2S(rockActionTimer)
    local integer  totalRocks = GetStoredInteger(udg_Cache, timerID, "total")
    local location targetLoc  = I2L(GetStoredInteger(udg_Cache, timerID, "targetloc"))
    local integer  callsLeft  = GetStoredInteger(udg_Cache, timerID, "callsleft")
    local unit     caster     = I2U(GetStoredInteger(udg_Cache, timerID, "caster"))
    local unit     target     = I2U(GetStoredInteger(udg_Cache, timerID, "target"))
    
    if (callsLeft <= -100 * 3 or (GetUnitState(target, UNIT_STATE_LIFE) <= 0 and callsLeft > 0)) then
        
        // If target dies while rocks are still moving, or if the spell has been completed

        if (callsLeft <= -100 * 3) then
            
            // If the spell has been completed, explode target location
            call DestroyEffect(AddSpecialEffectLoc("Objects\\Spawnmodels\\NightElf\\NEDeathMedium\\NEDeath.mdl", targetLoc))
            
            call PauseUnit(target, false)
            call SetUnitTimeScale(target, 1)
            
        else

            // If target dies while rocks are still moving, explode rocks
            loop
                exitwhen i == totalRocks
                
                set rock = I2U(GetStoredInteger(udg_Cache, timerID, "rocks" + I2S(i)))
                set rockLoc = GetUnitLoc(rock)
                call DestroyEffect(AddSpecialEffectLoc("Objects\\Spawnmodels\\NightElf\\NEDeathSmall\\NEDeathSmall.mdl", rockLoc))
                call RemoveLocation(rockLoc)
                call RemoveUnit(rock)
                
                set i = i + 1
            endloop
            
        endif
        
        call RemoveLocation(targetLoc)
        
        call FlushStoredMission(udg_Cache, timerID)
        call PauseTimer(rockActionTimer)
        call DestroyTimer(rockActionTimer)
    else
        
        if (callsLeft > 0) then
            
            // Rocks are still being moved
            loop
                exitwhen i == totalRocks
                
                set rock = I2U(GetStoredInteger(udg_Cache, timerID, "rocks" + I2S(i)))
                set rockLoc = GetUnitLoc(rock)
                set newLoc = PolarProjectionBJ(rockLoc, 1000 * 0.01, AngleBetweenPoints(rockLoc, targetLoc))
                call SetUnitPositionLoc(rock, newLoc)
                
                // Give it a "dash effect" (reduce it to 1/20x to avoid lag)
                if (GetRandomInt(1, 20) == 1) then
                    call DestroyEffect(AddSpecialEffectLoc("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl", rockLoc))
                endif

                call RemoveLocation(rockLoc)
                call RemoveLocation(newLoc)
                
                set i = i + 1
            endloop
            
        elseif (callsLeft == 0) then
            
            // Rocks have reached their destination, and is now impaling the target
            set unitLoc = GetUnitLoc(target)
            
            // Check if target's still inside his spot and is alive
            if (DistanceBetweenPoints(unitLoc, targetLoc) <= 100 and GetUnitState(target, UNIT_STATE_LIFE) > 0) then
                
                // Pause target
                call SetUnitTimeScale(target, 0)
                call PauseUnit(target, true)
                
                // Create spikes
                loop
                    exitwhen i == totalRocks
                    
                    set rock = I2U(GetStoredInteger(udg_Cache, timerID, "rocks" + I2S(i)))
                    set rockLoc = GetUnitLoc(rock)
                    set spike = CreateUnitAtLoc(GetOwningPlayer(caster), 'h018', rockLoc, GetRandomReal(0, 360))
                    set scalingValue = 2 - i * (1.75 / totalRocks)
                    
                    call SetUnitTimeScale(spike, 2)
                    call SetUnitScale(spike, scalingValue, scalingValue, scalingValue)
                    call SetUnitFlyHeight(spike, 400 / totalRocks * i, 1000)
                    call SetUnitAnimation(spike, "birth")
                    call RemoveLocation(rockLoc)
                    call UnitApplyTimedLife(spike, 'BTLF', 3)
                    call UnitApplyTimedLife(rock, 'BTLF', 3)
                    
                    set i = i + 1
                endloop
                
                // SFX as target gets impaled
                set impaleSound = CreateSound("Abilities\\Spells\\Undead\\Impale\\ImpaleHit.wav", false, true, true, 10, 10, "SpellsEAX")
                call SetSoundParamsFromLabel(impaleSound, "ImpaleHit")
                call SetSoundDuration(impaleSound, 1666)
                call SetSoundPosition(impaleSound, GetLocationX(targetLoc), GetLocationY(targetLoc), 0)
                call SetSoundVolume(impaleSound, 127)
                call StartSound(impaleSound)
                call KillSoundWhenDone(impaleSound)
                
            else
                
                // Target escapes the spell, spell gets cancelled
                loop
                    exitwhen i == totalRocks
                    
                    set rock = I2U(GetStoredInteger(udg_Cache, timerID, "rocks" + I2S(i)))
                    call RemoveUnit(rock)
                    
                    set i = i + 1
                endloop
                
                call DestroyEffect(AddSpecialEffectLoc("Objects\\Spawnmodels\\NightElf\\NEDeathMedium\\NEDeath.mdl", targetLoc))
                
                call RemoveLocation(targetLoc)
                
                call FlushStoredMission(udg_Cache, timerID)
                call PauseTimer(rockActionTimer)
                call DestroyTimer(rockActionTimer)
            endif
            
            call RemoveLocation(unitLoc)
            
        elseif (callsLeft == -100 * 0.5) then
            
            // Do piercing damage to target unit 0.5 seconds after the target gets trapped
            call UnitDamageTarget(caster, target, 50 * totalRocks, false, false, ATTACK_TYPE_PIERCE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
            
        else
            
            // Spikes have already damaged the unit, unit is now in standby for rock to disappear
            
            set unitLoc = GetUnitLoc(target)
            
            if (DistanceBetweenPoints(unitLoc, targetLoc) <= 100) then
                
                // We want to keep the target paused, not allowing other triggers to unpause it as long
                // as it's still inside the rocks
                call SetUnitTimeScale(target, 0)
                call PauseUnit(target, true)
                
            else
                
                // Unpause the victim if he somehow manages to get out of the rocks, but don't remove the rocks
                
                call PauseUnit(target, false)
                call SetUnitTimeScale(target, 1)
                
            endif
            
            call RemoveLocation(unitLoc)
        endif
        
        // Decrement counter
        call StoreInteger(udg_Cache, timerID, "callsleft", callsLeft - 1)
        
    endif
    
    // Variable nulling
    set newLoc      = null
    set rockLoc     = null
    set unitLoc     = null
    set caster      = null
    set rock        = null
    set spike       = null
    set target      = null
    set impaleSound = null
    set targetLoc   = null
    set timerID     = null
    set caster      = null
    set target      = null
endfunction

// This is the timer callback function
function ES_ActionTimerCallback takes nothing returns nothing
    call ES_RockActions(GetExpiredTimer())
endfunction

// The main trigger action
// Event: Unit begins the effect of an ability
// Conditions: None
function ES_TrigActions takes nothing returns nothing
    local unit     target
    local unit     caster
    local integer  abilityLevel
    local integer  i
    local integer  totalRocks
    local location rockLoc
    local location targetLoc
    local real     initialDistance
    local real     rotationOffset
    local sound    spawnSound
    local string   timerID
    local timer    rockActionTimer
    local unit     rock
    
    if (GetSpellAbilityId() == 'A01P') then
        
        // Set the spell variables
        set caster = GetTriggerUnit()
        set target = GetSpellTargetUnit()
        set targetLoc = GetUnitLoc(target)
        set abilityLevel = GetUnitAbilityLevel(caster, 'A01P')
        set initialDistance = 1100 - abilityLevel * 300
        set totalRocks = 4 * abilityLevel
        
        // Create the timer, trigger and start filling in information
        set rockActionTimer = CreateTimer()
        set timerID = H2S(rockActionTimer)
        call StoreInteger(udg_Cache, timerID, "callsleft", R2I((initialDistance - 25) * 100 / 1000))
        call StoreInteger(udg_Cache, timerID, "caster", H2I(caster))
        call StoreInteger(udg_Cache, timerID, "target", H2I(target))
        call StoreInteger(udg_Cache, timerID, "total", totalRocks)
        call StoreInteger(udg_Cache, timerID, "targetloc", H2I(targetLoc))
        
        // Create the rocks and pop them out
        set rotationOffset = GetRandomReal(0, 360)
        set i = 0
        loop
            exitwhen i == totalRocks
            
            set rockLoc = PolarProjectionBJ(targetLoc, initialDistance, rotationOffset + 360 / totalRocks * i)
            set rock = CreateUnitAtLoc(GetOwningPlayer(caster), 'h01H', rockLoc, GetRandomReal(0, 360))
            call SetUnitFlyHeight(rock, 0, 1000)
            call DestroyEffect(AddSpecialEffectLoc("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl", rockLoc))
            call StoreInteger(udg_Cache, timerID, "rocks" + I2S(i), H2I(rock))
            call RemoveLocation(rockLoc)
            
            // Create SFX of rocks popping out
            set spawnSound = CreateSound("Abilities\\Spells\\Undead\\DeathandDecay\\DeathAndDecayTarget2.wav", false, true, true, 10, 10, "SpellsEAX")
            call SetSoundParamsFromLabel(spawnSound, "DeathAndDecayTarget")
            call SetSoundDuration(spawnSound, 1235)
            call SetSoundPosition(spawnSound, GetLocationX(rockLoc), GetLocationY(rockLoc), 0)
            call SetSoundVolume(spawnSound, 127)
            call StartSound(spawnSound)
            call KillSoundWhenDone(spawnSound)
            
            set i = i + 1
        endloop
        
        // Let's wait for a while before moving the rock
        call TriggerSleepAction(0.75)
        call TimerStart(rockActionTimer, 0.01, true, function ES_ActionTimerCallback)
        
    endif
    
    // Variable nulling
    set targetLoc = null
    set timerID = null
    set rock = null
    set rockActionTimer = null
    set rockLoc = null
    set spawnSound = null
    set caster = null
    set target = null
endfunction

// Main trigger initialization
function InitTrig_Earth_Spikes takes nothing returns nothing
    local integer i = 0
    
    set gg_trg_Earth_Spikes = CreateTrigger()
    
    loop
        exitwhen i == bj_MAX_PLAYER_SLOTS - 1
        
        call TriggerRegisterPlayerUnitEvent(gg_trg_Earth_Spikes, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        
        set i = i + 1
    endloop
    
    call TriggerAddAction(gg_trg_Earth_Spikes, function ES_TrigActions)
endfunction

The only thing I changed in the triggers was... I added

JASS:

function H2S takes handle h returns string
    return I2S(H2I(h))
endfunction

function I2U takes integer i returns unit
    return i
    return null
endfunction

function I2L takes integer i returns location
    return i
    return null
endfunction
to the map header with some of it I need for other spells
and the raw unit & spell data in the earth spikes trigger.
 

turok255

New Member
Reaction score
30
I used Jasscraft and ctrl + f then put in the raw code of his units & spell with mine. So unless I missed 1 somewhere...

EDIT: Hmm seems my units got their model file changed and couldn't be seen. I changed them back and now it works. :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top