1. The Melee Mapping Contest #4: 2v2 - Results are out! Step by to congratulate the winners!
    Dismiss Notice
  2. We're hosting the 15th Mini-Mapping Contest with YouTuber Abelhawk! The contestants are to create a custom map that uses the hidden content within Warcraft 3 or is inspired by any of the many secrets within the game.
    Dismiss Notice
  3. The 20th iteration of the Terraining Contest is upon us! Join and create exquisite Water Structures for it.
    Dismiss Notice
  4. Check out the Staff job openings thread.
    Dismiss Notice

[vJASS] Can I get some help please?

Discussion in 'Triggers & Scripts' started by naitsirk, Mar 5, 2010.

  1. naitsirk

    naitsirk

    Joined:
    Jan 24, 2009
    Messages:
    570
    Resources:
    0
    Resources:
    0
    Hi, I've resently refreshed an old spell of mine... but I cant get it to work, so I was wondering if there's something wrong with the script itself.
    Here's the Script:
    Code (vJASS):
    scope HolyExpl initializer Init
    //-----------------Setup Start--------------------------
        globals
            private constant integer SPELL_ID = 'A000'
            private constant attacktype A_TYPE = ATTACK_TYPE_MAGIC
            private constant damagetype D_TYPE = DAMAGE_TYPE_NORMAL
            private constant string EFFECT = "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl"
            private constant string EFFECT2 = "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl"
            private constant string EFFECT3 = "Abilities\\Spells\\NightElf\\Taunt\\TauntCaster.mdl"
        endglobals
       
        private function Damage takes integer level returns real
            return level * 50.
        endfunction
       
        private function Heal takes integer level returns real
            return level * 25.
        endfunction
       
        private function Loopdam takes integer level returns real
            return level * 35.
        endfunction
       
        private function Target takes unit target returns boolean
        return (GetWidgetLife(target) > 0.405) and (IsUnitType(target, UNIT_TYPE_STRUCTURE) == false) and (IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) == false) and (IsUnitType(target, UNIT_TYPE_MECHANICAL) == false)
        endfunction
    //-----------------Setup End----------------------------
    private function Pick takes nothing returns boolean
        return Target(GetFilterUnit())
    endfunction
        globals
            private boolexpr b
            private group groups = CreateGroup()
            private group loopgroup = CreateGroup()
        endglobals

    private function Loop_Action takes group whatGroup, unit caster, unit target, string Effect1, string Effect2, real x, real y returns nothing
        call GroupEnumUnitsInRange( whatGroup, x, y, 125., null)
        call DestroyEffect(AddSpecialEffect( Effect1, x, y))
        call DestroyEffect(AddSpecialEffect(Effect2, x, y))
        set target = FirstOfGroup(whatGroup)
        if IsUnitAlly(target, GetOwningPlayer(caster)) then
            call SetWidgetLife(target, GetWidgetLife(target) + Heal(level))
        else
            call UnitDamageTarget(caster, target, Loopdam(level), true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, null)
        endif
    endfunction

    private function c takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID
    endfunction

    private function a takes nothing returns nothing
        local unit caster = GetTriggerUnit()
        local timer t = CreateTimer()
        local integer loopsec = 0
        local integer level = GetUnitAbilityLevel(caster, SPELL_ID)
        local real x = GetUnitX(caster)
        local real y = GetUnitY(caster)
        local real xRandom = GetRandomReal(x-250, x+250)
        local real yRandom = GetRandomReal(y-250, y+250)
        local real xEffect1 = xRandom+50
        local real yEffect1 = yRandom-50
       
        local real xEffect2 = xRandom-50
        local real yEffect2 = yRandom+50
       
        local real xEffect3 = xRandom-50
        local real yEffect3 = yRandom-50
       
        local real xEffect4 = xRandom+50
        local real yEffect4 = yRandom+50
        local unit target
        call DestroyEffect(AddSpecialEffect(EFFECT, xRandom, yRandom))
        call DestroyEffect(AddSpecialEffect(EFFECT, xEffect1, yEffect1))
        call DestroyEffect(AddSpecialEffect(EFFECT, xEffect2, yEffect2))
        call DestroyEffect(AddSpecialEffect(EFFECT, xEffect3, yEffect3))
        call DestroyEffect(AddSpecialEffect(EFFECT, xEffect4, yEffect4))
       
        call GroupEnumUnitsInRange(groups, xRandom, yRandom, 250., b)
       
        loop
            set target=FirstOfGroup(groups)
            exitwhen target==null
            call UnitDamageTarget(caster, target, Damage(level), true, false, A_TYPE, D_TYPE, null)
        call GroupRemoveUnit(groups,target)
        endloop
            loop
                set yRandom = GetRandomReal(y-250, y+250)
                set xRandom = GetRandomReal(x-250, x+250)
                exitwhen loopsec == 10
                call TimerStart( t, 0.25, false, function Loop_Action(loopgroup, caster, target, EFFECT2, EFFECT3, xRandom, yRandom))


                set target = null
                set loopsec = loopsec + 1
                call GroupClear(loopgroup)
            endloop
            call DestroyTimer(t)
            set t = null
            set loopsec = 0
            set caster = null
            set target = null
        call GroupClear(groups)
    endfunction


    private function Init takes nothing returns nothing
        local trigger Holy = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(Holy, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddAction(Holy, function a)
        call TriggerAddCondition(Holy, Condition(function c))    
       
        set b = Condition( function Pick)
       
        //preloading Effects
        call Preload(EFFECT)
        call Preload(EFFECT2)
        call Preload(EFFECT3)
        //preloading the spell
        set bj_lastCreatedUnit = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'hpea', 0,0,0)
        call UnitAddAbility(bj_lastCreatedUnit, SPELL_ID)
        call RemoveUnit(bj_lastCreatedUnit)
    endfunction
    endscope


    Please help me
     
  2. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    And what exactly "doesn't work"? Please explain the problem.
     
  3. Pharaoh_

    Pharaoh_

    Joined:
    Nov 6, 2008
    Messages:
    8,127
    Resources:
    11
    Icons:
    3
    Skins:
    1
    Spells:
    6
    Tutorials:
    1
    Resources:
    11
    Shouldn't the Target function be within the loop of the Loop_Action? Not as a function, but as an if/then/else, of course. Cause currently, you aim for the target, when it's not actually set. Maybe I'm wrong though, speak of the problem better.
     
  4. Dynasti

    Dynasti

    Joined:
    Oct 18, 2007
    Messages:
    877
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    Well, apart from a bit inefficient vJass coding I don't see the problem, please tell us what the problem is so we can narrow down the problem. Please post map too.


    Improvements as I see it:
    • Take use of vJass' structs
    • No need to have 2 global chunks, won't make a difference
    • Code (vJASS):
          local real xRandom = GetRandomReal(x-250, x+250)
          local real yRandom = GetRandomReal(y-250, y+250)
          local real xEffect1 = xRandom+50
          local real yEffect1 = yRandom-50
         
          local real xEffect2 = xRandom-50
          local real yEffect2 = yRandom+50
         
          local real xEffect3 = xRandom-50
          local real yEffect3 = yRandom-50
         
          local real xEffect4 = xRandom+50
          local real yEffect4 = yRandom+50

          call DestroyEffect(AddSpecialEffect(EFFECT, xRandom, yRandom))
          call DestroyEffect(AddSpecialEffect(EFFECT, xEffect1, yEffect1))
          call DestroyEffect(AddSpecialEffect(EFFECT, xEffect2, yEffect2))
          call DestroyEffect(AddSpecialEffect(EFFECT, xEffect3, yEffect3))
          call DestroyEffect(AddSpecialEffect(EFFECT, xEffect4, yEffect4))
      use a constant global for the +- 50 and +- 250. And btw, you're creating 4 effects on the same spot. Use a random generate each time, not just once
     
  5. Justify

    Justify

    Joined:
    Mar 16, 2008
    Messages:
    935
    Resources:
    5
    Models:
    1
    Icons:
    1
    Spells:
    3
    Resources:
    5
    Code (vJASS):
    call TimerStart( t, 0.25, false, function Loop_Action(loopgroup, caster, target, EFFECT2, EFFECT3, xRandom, yRandom))

    Uhm, timer-callback with parameters? Thats not possible...
     
  6. Dynasti

    Dynasti

    Joined:
    Oct 18, 2007
    Messages:
    877
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    Ya, that is big :eek:

    Edit: Btw, for the effects use this instead:

    Code (vJASS):
    //[...]
    local integer i = 0
    local integer e = 3

    loop
        exitwhen i>e
       
        call DestroyEffect(AddSpecialEffect(EFFECT, GetRandomReal(-250, 250) + x, GetRandomReal(-250, 250) + y))
       
        set i = i + 1
    endloop
    //[...]


    This will create 5 effects at random points around x and y

    How this loop works:

    First run, i == 0
    second, i == 1
    third, i == 2
    fourth, i == 3
    fith, i == 4, bigger than 3 so the loop will end.
     
  7. naitsirk

    naitsirk

    Joined:
    Jan 24, 2009
    Messages:
    570
    Resources:
    0
    Resources:
    0
    Basiccly the Map doesn't work..... And I don't know how to use the Structs... will learn though
    Map's in the Attachments
     

    Attached Files: