• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Can I get some help please?

Status
Not open for further replies.
Level 10
Joined
Jan 24, 2009
Messages
606
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:
JASS:
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
 
Level 18
Joined
Oct 18, 2007
Messages
930
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
  • JASS:
        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
 
Level 18
Joined
Oct 18, 2007
Messages
930
Ya, that is big :eek:

Edit: Btw, for the effects use this instead:

JASS:
//[...]
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.
 
Status
Not open for further replies.
Top