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

[Trigger] Problem with something similar to Meathook

Status
Not open for further replies.
Level 2
Joined
Mar 17, 2009
Messages
19
Hey guys^^ me again^^
Well I need help with some kind of Meathook spell. The spell should work like this: You cast the ability towards one direction and the first enemy in that direction is hit by the ability and is paused for 6 seconds. After that 6 seconds the unit takes 1300 damage and the caster takes 250 damage. My Problem was that this trigger ran 2 or 3 times and I tried to solve that with IF clauses but now the dummy unit I used for the direction thing woun't move so I need your help because I don't know why^^

My Activation Trigger:


My "Run" Trigger:
 
Level 7
Joined
Oct 21, 2008
Messages
234
I didn´t read the whole second trigger, but i guess the first problem is the period of 0.03 seconds, which can only be done by timers (afaik). Normal waiting orders do have an accuracy of 0.25 seconds.
I would also suggest you to use a Stun-function (look for stun libraries) instead of Pausing a unit. Anyway i will try to make a (Jass) version of this spell for you which should work.
Just give me some minutes.

Well, finished.
Note: Its not optimized for performance or legibility.
Replace following strings in the code:
YOURSPELLABILITYID = the integer-code of the ability type
PROTECTILEUNITTYPE = the integer-code of the protectily unit type
Both can be obtained by pressing STRG+D in the object editor.

You also can change following values:
JASS:
local real range = 800              // range in wc3 units
local real speed = 256              // speed = length/second
local real width = 75               // the width of the path to search for targets
local real stunTime = 5             // stun time in seconds
local real dmgV = 1300              // damage to victim
local real dmgC = 250               // damage to caster

This is the code you will have to include:
JASS:
globals
    timer kamuiTimer    // timer
    integer kamuiCount  // counter
    unit kamuiCaster    // casting unit
    unit kamuiVictim    // casting unit
    unit kamuiProtectile// casting unit
    real kamuiDX        // normalized x component of the moving path
    real kamuiDY        // normalized y component of the moving path
    real kamuiX         // caster x position, we save this, so the caster can walk while the spell is executing
    real kamuiY         // caster y position, we save this, so the caster can walk while the spell is executing
endglobals

function Trig_Kamui_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'YOURSPELLABILITYID' ) ) then
        return false
    endif
    return true
endfunction

function exeKamui takes nothing returns nothing
    local real range = 800              // range in wc3 units
    local real speed = 256              // speed = length/second
    local real width = 75               // the width of the path to search for targets
    local real stunTime = 5             // stun time in seconds
    local real dmgV = 1300              // damage to victim
    local real dmgC = 250               // damage to caster
    
    local group g = CreateGroup()
    local unit u
    local real curX
    local real curY
        
    set speed = speed*0.035
    if kamuiVictim==null then
        // no victim found yet
        if range-speed*I2R(kamuiCount)<=0 then
            // we reached the end without victim, clean up
            call PauseTimer(kamuiTimer)
            call DestroyTimer(kamuiTimer)
            call RemoveUnit(kamuiProtectile)
        else
            // run; set current position
            set curX = kamuiX-kamuiDX*speed*I2R(kamuiCount)
            set curY = kamuiY-kamuiDY*speed*I2R(kamuiCount)
            call SetUnitX(kamuiProtectile, curX)
            call SetUnitY(kamuiProtectile, curY)
            // look for units
            call GroupEnumUnitsInRange(g, curX, curY, width/2, null)
            loop
                set u = FirstOfGroup(g)
                exitwhen u==null
                // found a unit, check if its hostile, alive and not magic immune
                if IsUnitEnemy(u, GetOwningPlayer(kamuiCaster)) and GetUnitState(u, UNIT_STATE_LIFE)>0 and not(IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)) then
                    // we have found a victim, harhar :D, pause it
                    call PauseUnit(u, true)
                    set kamuiVictim = u
                    call RemoveUnit(kamuiProtectile)
                    // set counter to zero, so we can count 5 seconds stun
                    set kamuiCount = 0
                    // clear group, so we cant find more then one victim ;-)
                    call GroupClear(g)
                endif
                // next unit
                call GroupRemoveUnit(g, u)
            endloop
        endif
    else
        // we got a victim
        set stunTime = stunTime/0.035
        if I2R(kamuiCount)>=stunTime then
            // we reached 5 seconds, unpause
            call PauseUnit(kamuiVictim, false)
            // deal dmg
            call UnitDamageTarget(kamuiCaster, kamuiVictim, dmgV, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
            call UnitDamageTarget(kamuiCaster, kamuiCaster, dmgC, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
            // clean up
            call PauseTimer(kamuiTimer)
            call DestroyTimer(kamuiTimer)
        endif
    endif
    
    set kamuiCount = kamuiCount+1
    call DestroyGroup(g)
    set g = null
endfunction

function Trig_Kamui_Actions takes nothing returns nothing
    local integer protType = 'PROTECTILEUNITTYPE'
    // first get target point
    local real dist
    local location loc = GetSpellTargetLoc()
    set kamuiDX = GetLocationX(loc)
    set kamuiDY = GetLocationY(loc)
    call RemoveLocation(loc)
    set loc = null
        
    // set vars for timer
    set kamuiVictim = null
    set kamuiCaster = GetTriggerUnit()
    set kamuiCount = 0
    set kamuiX = GetUnitX(kamuiCaster)
    set kamuiY = GetUnitY(kamuiCaster)
    // get normalized vector for path
    set kamuiDX = kamuiX-kamuiDX
    set kamuiDY = kamuiY-kamuiDY
    set dist = SquareRoot(kamuiDX*kamuiDX+kamuiDY*kamuiDY)
    // DIV by 0!
    if dist == 0 then
        return
    endif
    set kamuiDX=kamuiDX/dist
    set kamuiDY=kamuiDY/dist
    // init protectile
    set kamuiProtectile = CreateUnit(GetOwningPlayer(kamuiCaster), protType, kamuiX, kamuiY, 0)
    // init and start timer
    set kamuiTimer = CreateTimer()
    call TimerStart(kamuiTimer, 0.035, true, function exeKamui)
endfunction

//===========================================================================
function InitTrig_Kamui takes nothing returns nothing
    set gg_trg_Kamui = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Kamui, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Kamui, Condition( function Trig_Kamui_Conditions ) )
    call TriggerAddAction( gg_trg_Kamui, function Trig_Kamui_Actions )
endfunction

Once again: its neither optimized, nor a paradigm.

Got any questions? Just ask.
Want some changes - tell me, its no problem.
Have fun with this, hope this is what you need :smile:
Hf & a nice day
 
Last edited:
Level 2
Joined
Mar 17, 2009
Messages
19
Well I'm sorry-.- I forgot something very basicaly-.- there is NO condition in that fucking If funktion-.- argh! There should be KamuiINT[4] equal to 2-.- sry^^" problem solved^^ sorry to bother you but thanks for your help^^
 
Status
Not open for further replies.
Top