• 🏆 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!

Problem with JASS

Status
Not open for further replies.
Level 5
Joined
Nov 29, 2007
Messages
106
Hello,
I tried to import that ability : http://www.thehelper.net/forums/showthread.php?t=146359
I copied all units, abilities, buffs and triggers (JASS) but when I'm saving the map I take bilion errors
Here's the Jass script:
JASS:
//TESH.scrollpos=19
//TESH.alwaysfold=0
scope field initializer init

// Energy Field v1.4, by Dinowc
//        Credits to HoN

// Requirements:
// NewGen, Timer Utils, Group Utils, AIDS, dummy.mdx (everything included in map)

//How to import:
// Simply create a new trigger, convert it to custom text and replace everything with this code bellow. There are 3 abilities, 1 that casts the EF itself and other 2 are dummy abilities (Purge, Soul Burn). You can find them in Object editor.

//Configurables
globals
    private constant integer SPELL_ID = 'A000'
    private constant integer PURGE_ID = 'A001'
    private constant integer SOUL_BURN_ID = 'A002'
    private constant integer DUMMY_CASTER = 'h002' // the dummy that casts Purge/Soul Burn
    private constant integer GADGET_DUMMY = 'h000' // self explanatory
    private constant integer TURRET_DUMMY= 'h001' // same as above
    private constant integer ARRAY_SIZE = 200
    private constant real INTERVAL = 0.05 // make it a multiplier of 1
    
    //Lightning Settings
    private constant string LIGHTNING_EFFECT = "CLSB" // since Wc3 doesn't have any pretty lightning effects and I do not want to use imports, I've decided to use this one
    private constant real Z1 = 10.
    private constant real Z2 = 50.
    private constant real Z3 = 90.
    private constant integer LIGHTNING1_DIRECTION = 0 // 0 for left, 1 for right, everything else doesn't create the lightning
    private constant integer LIGHTNING2_DIRECTION = 0 // 0 for left, 1 for right, everything else doesn't create the lightning
    private constant integer LIGHTNING3_DIRECTION = 0 // 0 for left, 1 for right, everything else doesn't create the lightning
    private constant boolean VISIBILITY_CHECK = true // I'm not sure what this means, but I left it at true xd
    
    //Energy Field Settings
    private constant real GADGET_OFFSET = 120. // distance between the caster and the gadget
    private constant real BOUNDS_SIZE = 50. // // distance between the lightning and entering unit before he get's damaged; it's not really accurate since the field is Xangled, not round
    private constant real TREE_CUT_AOE = 130. // AOE around turret where the destructables are destroyed
    private constant real BASE_DAMAGE = 0.03 // in percent
    private constant real DAMAGE_PER_LEVEL = 0.02 // in percent
    private constant integer TURRET_COUNT = 8 // less than 3 and more than 20 is not really recommended
    private constant real BASE_DURATION = 6.
    private constant real DURATION_PER_LEVEL = 3.
    private constant real BASE_AOE = 475.
    private constant real AOE_PER_LEVEL = 0.
    private constant integer BASE_HITS = 5
    private constant integer HITS_PER_LEVEL = 0
    private constant string BUILD_EFFECT = "Abilities\\Spells\\Orc\\FeralSpirit\\feralspiritdone.mdl" // the effect that appears when you create the gadget, set to "" to display no effect (reduces lag)
    private constant string TURRET_EFFECT = "Abilities\\Weapons\\Bolt\\BoltImpact.mdl" // the effect that appears on turrets (obelisks), set to "" to display no effect (reduces lag)
    
    private constant attacktype ATTACK_TYPE = ATTACK_TYPE_MAGIC
    private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_MAGIC
    
    private constant boolean TURRET_COLLISION = true //if turret has collision
endglobals

//Don't touch
globals
    private rect R
    private unit DUMMY
    private group G = CreateGroup()
    private trigger Tr = CreateTrigger()
    private real RADIANS = 0.0174
endglobals

private function PolarX takes real dist, real angle returns real
    return dist * Cos(angle * RADIANS)
endfunction

private function PolarY takes real dist, real angle returns real
    return dist * Sin(angle * RADIANS)
endfunction

private function distance takes real x1, real y1, real x2, real y2 returns real
    local real dx = x2 - x1
    local real dy = y2 - y1
    return SquareRoot(dx * dx + dy * dy)
endfunction

private function LevelIncrease takes real a, real b, integer level returns real
    return a + ((I2R(level - 1)) * b)
endfunction

private function GroupClean takes nothing returns nothing
    local unit picked = GetEnumUnit()
    local real x = GetUnitX(picked)
    local real y = GetUnitY(picked)
    
    call SetTerrainPathable(x, y, PATHING_TYPE_WALKABILITY, true)
    call KillUnit(picked)
    
    set picked = null
endfunction

private function destructableFilter takes nothing returns boolean
    local destructable d = GetFilterDestructable()
    
    if GetDestructableLife(d) > 0 then
        call KillDestructable(d)
    endif
    
    set d = null
    return false
endfunction

private function damage takes unit target, real amount returns real
    return GetUnitState(target, UNIT_STATE_MAX_LIFE) * amount
endfunction

private struct data
    unit caster
    unit gadget
    
    lightning array sfx[ARRAY_SIZE]
    integer index
    
    group g
    group g2
    
    real damagePercent
    real duration
    real ticks
    integer hits
    
    timer t
    
    static data D
    
    static method AddUnits takes nothing returns boolean
        local unit picked = GetFilterUnit()
        local player p = GetOwningPlayer(D.caster)

        if IsUnitEnemy(picked, p) == true and IsUnitInGroup(picked, D.g2) == false and IsUnitType(picked, UNIT_TYPE_DEAD) == false and GetUnitTypeId(picked) != GADGET_DUMMY and IsUnitType(picked, UNIT_TYPE_STRUCTURE) == false then
            call GroupAddUnit(D.g2, picked)
        endif
        
        set picked = null
        set p = null
        return false
    endmethod
    
    static method create takes unit whichUnit, real x, real y returns data
        local data d = data.allocate()
        local player p = GetOwningPlayer(whichUnit)
        local real angle = GetUnitFacing(whichUnit)
        local real x1 = x + PolarX(GADGET_OFFSET, angle)
        local real y1 = y + PolarY(GADGET_OFFSET, angle)
        local real x2
        local real y2
        local real angleInc = 360. / TURRET_COUNT
        local integer i = 0
        local integer level = GetUnitAbilityLevel(whichUnit, SPELL_ID)
        local real AOE = LevelIncrease(BASE_AOE, AOE_PER_LEVEL, level)
        local unit dummy
        local unit turret
        
        set d.caster = whichUnit
        set d.damagePercent = LevelIncrease(BASE_DAMAGE, DAMAGE_PER_LEVEL, level)
        set d.duration = LevelIncrease(BASE_DURATION, DURATION_PER_LEVEL, level)
        
        call MoveRectTo(R, x1, y1)
        call EnumDestructablesInRect(R, Filter(function destructableFilter), null)
        
        if BUILD_EFFECT != "" then
            set dummy = CreateUnit(p, DUMMY_CASTER, x1, y1, angle) // this dummy is used only as an effect for more eye candy, it's ok if you delete these 3 lines to reduce lag
            call DestroyEffect(AddSpecialEffectTarget(BUILD_EFFECT, dummy, "origin"))
            call KillUnit(dummy)
        endif
        
        set d.gadget = CreateUnit(p, GADGET_DUMMY, x1, y1, angle)
        set d.g = NewGroup()
        set d.g2 = NewGroup()
        
        set x = GetUnitX(d.gadget)
        set y = GetUnitY(d.gadget)
        
        loop
            set x1 = x + PolarX(AOE, angle)
            set y1 = y + PolarY(AOE, angle)
            
            call MoveRectTo(R, x1, y1)
            call EnumDestructablesInRect(R, Filter(function destructableFilter), null)
            
            if TURRET_EFFECT != "" then
                set dummy = CreateUnit(p, DUMMY_CASTER, x1, y1, angle) // this dummy is used only as an effect for more eye candy, it's ok if you delete these 3 lines to reduce lag
                call DestroyEffect(AddSpecialEffectTarget(TURRET_EFFECT, dummy, "origin"))
                call KillUnit(dummy)
            endif
            
            set turret = CreateUnit(p, TURRET_DUMMY, x1, y1, angle)
            
            if TURRET_COLLISION then
                call SetTerrainPathable(x1, y1, PATHING_TYPE_WALKABILITY, false)
            endif
            
            call GroupAddUnit(d.g, turret)
            
            set x2 = x + PolarX(AOE, angle + angleInc)
            set y2 = y + PolarY(AOE, angle + angleInc)
            
            if LIGHTNING1_DIRECTION == 0 then
                set d.sfx[d.index] = AddLightningEx(LIGHTNING_EFFECT, VISIBILITY_CHECK, x1, y1, Z1, x2, y2, Z1)
                set d.index = d.index + 1
            elseif LIGHTNING1_DIRECTION == 1 then
                set d.sfx[d.index] = AddLightningEx(LIGHTNING_EFFECT, VISIBILITY_CHECK, x2, y2, Z1, x1, y1, Z1)
                set d.index = d.index + 1
            endif
            
            if LIGHTNING2_DIRECTION == 0 then
                set d.sfx[d.index] = AddLightningEx(LIGHTNING_EFFECT, VISIBILITY_CHECK, x1, y1, Z2, x2, y2, Z2)
                set d.index = d.index + 1
            elseif LIGHTNING2_DIRECTION == 1 then
                set d.sfx[d.index] = AddLightningEx(LIGHTNING_EFFECT, VISIBILITY_CHECK, x2, y2, Z2, x1, y1, Z2)
                set d.index = d.index + 1
            endif
            
            if LIGHTNING3_DIRECTION == 0 then
                set d.sfx[d.index] = AddLightningEx(LIGHTNING_EFFECT, VISIBILITY_CHECK, x1, y1, Z3, x2, y2, Z3)
                set d.index = d.index + 1
            elseif LIGHTNING3_DIRECTION == 1 then
                set d.sfx[d.index] = AddLightningEx(LIGHTNING_EFFECT, VISIBILITY_CHECK, x2, y2, Z3, x1, y1, Z3)
                set d.index = d.index + 1
            endif
            
            set angle = angle + angleInc
            set i = i + 1
            
            exitwhen i >= TURRET_COUNT
        endloop
        
        set D = d
        call GroupEnumUnitsInRange(G, x, y, AOE - BOUNDS_SIZE, Filter(function data.AddUnits))
        call TriggerRegisterUnitEvent(Tr, d.gadget, EVENT_UNIT_DAMAGED)
        
        set d.ticks = 0.
        set d.hits = 0
        set d.t = NewTimer()
        
        set turret = null
        set dummy = null
        set p = null
        return d
    endmethod
    
    static method damageExiters takes nothing returns boolean
        local unit picked = GetFilterUnit()
        local player p = GetOwningPlayer(D.caster)
        local real x = GetUnitX(picked)
        local real y = GetUnitY(picked)
        local real dist = distance(x, y, GetUnitX(D.gadget), GetUnitY(D.gadget))
        local integer level = GetUnitAbilityLevel(D.caster, SPELL_ID)
        local real AOE = LevelIncrease(BASE_AOE, AOE_PER_LEVEL, level)
        
        if IsUnitEnemy(picked, p) == true and IsUnitInGroup(picked, D.g2) == true and IsUnitType(picked, UNIT_TYPE_DEAD) == false and IsUnitType(picked, UNIT_TYPE_MAGIC_IMMUNE) == false and GetUnitTypeId(picked) != GADGET_DUMMY and IsUnitType(picked, UNIT_TYPE_STRUCTURE) == false and dist + BOUNDS_SIZE > AOE then
            call SetUnitOwner(DUMMY, p, false)
            call SetUnitX(DUMMY, x)
            call SetUnitY(DUMMY, y)
            
            call SetUnitAbilityLevel(DUMMY, PURGE_ID, level)
            call SetUnitAbilityLevel(DUMMY, SOUL_BURN_ID, level)
            call IssueTargetOrder(DUMMY, "purge", picked)
            call IssueTargetOrder(DUMMY, "soulburn", picked)
        
            call GroupRemoveUnit(D.g2, picked)
        endif
    
        set picked = null
        set p = null
        return false
    endmethod
    
    static method filterFunc takes nothing returns boolean
        local unit picked = GetFilterUnit()
        local player p = GetOwningPlayer(D.caster)
        local integer level
        
        if IsUnitEnemy(picked, p) == true and IsUnitType(picked, UNIT_TYPE_DEAD) == false and IsUnitType(picked, UNIT_TYPE_MAGIC_IMMUNE) == false and GetUnitTypeId(picked) != GADGET_DUMMY and IsUnitType(picked, UNIT_TYPE_STRUCTURE) == false then
            if IsUnitInGroup(picked, D.g2) == false then
                set level = GetUnitAbilityLevel(D.caster, SPELL_ID)
                
                call SetUnitOwner(DUMMY, p, false)
                call SetUnitX(DUMMY, GetUnitX(picked))
                call SetUnitY(DUMMY, GetUnitY(picked))
                
                call SetUnitAbilityLevel(DUMMY, PURGE_ID, level)
                call SetUnitAbilityLevel(DUMMY, SOUL_BURN_ID, level)
                call IssueTargetOrder(DUMMY, "purge", picked)
                call IssueTargetOrder(DUMMY, "soulburn", picked)
        
                call GroupAddUnit(D.g2, picked)
            endif
            
            if ModuloReal(D.ticks, 1) == 1 then
                call UnitDamageTarget(D.caster, picked, damage(picked, D.damagePercent), false, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE_WHOKNOWS)
                if TURRET_EFFECT != "" then
                    call DestroyEffect(AddSpecialEffectTarget(TURRET_EFFECT, picked, "origin"))
                endif
            endif
        endif
    
        set p = null
        set picked = null
        return false
    endmethod
    
    private method onDestroy takes nothing returns nothing
        local integer a = 0
        
        call ForGroup(.g, function GroupClean)
        call ReleaseGroup(.g)
        
        loop
            call DestroyLightning(.sfx[a])
            set .sfx[a] = null
            set a = a + 1
            exitwhen a > .index
        endloop
        set .index = 0
        
        call ReleaseGroup(.g2)
        call KillUnit(.gadget)
        call ReleaseTimer(.t)
    endmethod
endstruct

globals
    private data array STORE
endglobals

private function callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local data d = GetTimerData(t)
    local integer a = 0
    local real AOE = LevelIncrease(BASE_AOE, AOE_PER_LEVEL, (GetUnitAbilityLevel(d.caster, SPELL_ID)))
    set d.ticks = d.ticks + INTERVAL
    
    if d.ticks >= d.duration then
        call d.destroy()
    else
        set data.D = d
        call GroupEnumUnitsInRange(G, GetUnitX(d.gadget), GetUnitY(d.gadget), AOE - BOUNDS_SIZE, function data.filterFunc)
        call GroupEnumUnitsInRange(G, GetUnitX(d.gadget), GetUnitY(d.gadget), AOE + BOUNDS_SIZE, function data.damageExiters)
    endif
    
    set t = null
endfunction

private function actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local real x = GetUnitX(caster)
    local real y = GetUnitY(caster)
    local data d = data.create(caster, x, y)
    
    set STORE[GetUnitIndex(d.gadget)] = d
    call SetTimerData(d.t, d)
    call TimerStart(d.t, INTERVAL, true, function callback)
    
    set caster = null
endfunction

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

private function act takes nothing returns boolean
    local unit attacked = GetTriggerUnit()
    local data d
    local integer a
    local integer HITS
    set d = STORE[GetUnitIndex(attacked)]
        
    if d != null then
        set HITS = BASE_HITS + ((GetUnitAbilityLevel(d.caster, SPELL_ID) - 1) * HITS_PER_LEVEL)
        set d.hits = d.hits + 1
        
        if d.hits >= HITS then
            call d.destroy()
        else
            set STORE[GetUnitIndex(attacked)] = d
        endif
    endif
    
    set attacked = null
    return false
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local real aoe = TREE_CUT_AOE / 2
    
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function conditions))
    call TriggerAddAction(t, function actions)
    call TriggerAddCondition(Tr, Condition(function act))
    
    set R = Rect(-1 * aoe, -1 * aoe, aoe, aoe)
    
    //Preload
    call RemoveUnit(CreateUnit(Player(13), GADGET_DUMMY, 0., 0., 0.))
    call RemoveUnit(CreateUnit(Player(13), TURRET_DUMMY, 0., 0., 0.))
    set DUMMY = CreateUnit(Player(13), DUMMY_CASTER, 0., 0., 0.)
    
    set t = null
endfunction

endscope
BTW there are 3 other triggers in JASS like GU, AIDS and one more... called systems, when saving bilions errors too. Need you help and advice how to import.
 
Level 5
Joined
Nov 29, 2007
Messages
106
This program bugged my map, i just open that program, turns trigger on and save the map and then tried to test it, my map not work, it look like out of data (wrong patch)
 
Level 12
Joined
Jan 30, 2009
Messages
1,067
As in, you try to play it and it's all black? Nothing loads?

When NewGen opens your map, it's normal to get the "Is saved in a newer version of the editor" bug, since it's a hack program for the WE, it's not the same patch number but that shouldn't be causing issues.
 
Level 5
Joined
Nov 29, 2007
Messages
106
This program bugged my map, i just open that program, turns trigger on and save the map and then tried to test it, my map not work, it look like out of data (wrong patch)
Here is map, plz fix that spell - I really need it but can't use that program. Enery Field Trigger (Last Trigger)
 

Attachments

  • HoN~6.w3x
    8.7 MB · Views: 97
Level 12
Joined
Jan 30, 2009
Messages
1,067
Unfortunately, I don't have any clue about JASS. But, if the problem I described above (The map not loading; black screen) is what's happening, I'd REALLY love to know how to fix that as well, seeing as the same thing happens when I enable my FSI (Fullscreen Inventory) trigger in my map. With a fix I would be able to use it, :D
 
Level 12
Joined
Jan 30, 2009
Messages
1,067
Oh, I forgot about that. It's been well over a year since I Downloaded it, which may explain my issue, I suppose... Oh well, a problem for another day.

But yeah, Red, follow that, mate.
 
Level 5
Joined
Nov 29, 2007
Messages
106
Iv got JNGP - I changed all options like in that tutorial but when i saved map to test the map not work like it is not work properly on this patch. Any Ideas?
 
Level 12
Joined
Jan 30, 2009
Messages
1,067
I think the link I sent you was the latest version. I may be wrong, though... My version's bout 2 years old, I'll check to see if it's the version or not.

EDIT: btw, by that I meant if it is the version of NewGen causing the error.

Now, I opened it up, first thing I noticed is the filesize of almost 9MB. But, ignoring that, I tried to test it, it didn't auto test. So I searched for it, found it, and the players list doesn't show up. I had the same issue with my map before disabling a JASS trigger. The problem is somewhere within that trigger "Energy Field" and unfortunately, being unversed in JASS, I haven't the slightest clue what it is. Turning it off allows the map to load. Now, to the person who helps Red out in figuring this out, I'll give you +rep if the solution works for me as well, since that'll fix my FSI system!
 
Level 12
Joined
Jan 30, 2009
Messages
1,067
Unfortunately, if that is indeed the case, then my issue is a separate entity, and I don't think I can be of any more help.

GL, Red.
 
Level 5
Joined
Nov 29, 2007
Messages
106
I simply imported by JassWE GU, TU, AIDS, DUMMY, and turned on the trigger and it says: The trigger "GU" needs initialization function "InitTrig_GU", The trigger "AIDS" needs initialization function "InitTrig_AIDS", The trigger "TU" needs initialization function "InitTrig_TU".
 
Status
Not open for further replies.
Top