Turning a Jass Hero Spell to a Unit Spell

Kommando

New Member
Reaction score
1
So i have this ability called Camouflage i found in wc3c, but currently it only works for heroes, and i need it to work on a regular unit. thanks to anyone who can help.
 

Attachments

  • Camouflageorg.w3x
    105.7 KB · Views: 159

Summoned

New Member
Reaction score
51
Edit: Actually, wrong thread. :p Sorry.

Try this:
JASS:
// Camouflage
// Coded by Zerzax as per Fulla's Request in Pyrogasm's Spell Request Thread
// Uses: Table

scope Camouflage initializer init

    // Configuration Section

    globals
        private constant integer ABILITY_ID = 'A002'
        private constant integer INVIS_ID = 'A001'
        private constant integer PRELOAD_ID = 'h000'
        // Timer Interval. Keep it large to minimize processing burdens.
        private constant real INTERVAL = 0.10
    endglobals

    // Range of trees.

    private function Range takes integer level returns real
        return 100.00 + level * 55.00
    endfunction
    
    // How many times the timer must run while the unit is out of range.
    
    private function FadeOut takes integer level returns integer
        return 7 + R2I( 3.3 * level )
    endfunction
    
    // Acceptable destructable types (that are trees)
    
    private function TreeTypes takes integer id returns boolean
        return id == 'ATtr' or id == 'BTtw' or id == 'KTtw' or id == 'YTft' or id == 'JTct' or id == 'YTst' or id == 'YTct' or id == 'YTwt' or id == 'JTwt' or id == 'JTwt' or id == 'FTtw' or id == 'CTtr' or id == 'ITtw' or id == 'NTtw' or id == 'OTtw' or id == 'ZTtw' or id == 'WTst' or id == 'LTlt' or id == 'GTsh' or id == 'Xtlt' or id == 'WTtw' or id == 'Attc' or id == 'BTtc' or id == 'CTtc' or id == 'ITtc' or id == 'NTtc' or id == 'ZTtc'
    endfunction
    
    // End of config. No Touchie!
    
    globals
        private group Camouflaged = CreateGroup()
        private rect TreeFinder = null
        private HandleTable FadeCounter
        private boolexpr TreeFilter = null
        private boolean FoundTrees = false
    endglobals
    
    private function FindTree takes nothing returns boolean
        return TreeTypes(GetDestructableTypeId(GetFilterDestructable()))
    endfunction
    
    private function FoundTree takes nothing returns nothing
        set FoundTrees = true
    endfunction
    
    private function Enum takes nothing returns nothing
        local unit camouflaged = GetEnumUnit()
        local real cX = GetUnitX(camouflaged)
        local real cY = GetUnitY(camouflaged)
        local integer lvl = GetUnitAbilityLevel(camouflaged, ABILITY_ID)
        local real range = Range(lvl)
        
        call SetRect(TreeFinder, cX - range, cY - range, cX + range, cY + range) 
        call EnumDestructablesInRect(TreeFinder, TreeFilter, function FoundTree) // Enumerate.
        
        if FoundTrees then // Then the current unit is in range.
            set FoundTrees = false
            if GetUnitAbilityLevel(camouflaged, INVIS_ID) == 0 then
                call UnitAddAbility(camouflaged, INVIS_ID) // Add so he can fade in.
                call SetUnitAbilityLevel(camouflaged, INVIS_ID, lvl)
            else
                set FadeCounter[camouflaged] = 0 // Restart fade-out process
            endif
        elseif GetUnitAbilityLevel(camouflaged, INVIS_ID) > 0 then // Start the fade proccess.
            set FadeCounter[camouflaged] = FadeCounter[camouflaged] + 1
            if FadeCounter[camouflaged] >= FadeOut(lvl) then 
                call UnitRemoveAbility(camouflaged, INVIS_ID) // Fully faded.
                set FadeCounter[camouflaged] = 0
            endif
        endif
        
        set camouflaged = null
    endfunction
    
    private function GroupEnum takes nothing returns nothing
        call ForGroup(Camouflaged, function Enum) // Perform enum action on all learned units.
    endfunction
    
    private function LearnCondition2 takes nothing returns boolean
        return (GetUnitAbilityLevel(GetEnumUnit(), ABILITY_ID) > 0)
    endfunction

    private function LearnCondition takes nothing returns boolean
        return (GetUnitAbilityLevel(GetTriggerUnit(), ABILITY_ID) > 0)
    endfunction
    
    private function OnLearn2 takes nothing returns nothing
        set FadeCounter[GetEnumUnit()] = 0
    endfunction
    
    private function OnLearn takes nothing returns nothing
        local unit learn = GetTriggerUnit() // The hero has learned the ability.
        if GetUnitAbilityLevel(learn, ABILITY_ID) > 0 then
            call GroupAddUnit(Camouflaged, learn)
            set FadeCounter[learn] = 0
        endif
        set learn = null
    endfunction

    private function init takes nothing returns nothing // Preload, trigger creation, handle creation.
        local unit preload = CreateUnit(Player(15), PRELOAD_ID, 0,0,0)
        local trigger t = CreateTrigger()
        call TriggerRegisterEnterRectSimple(t, bj_mapInitialPlayableArea)
        call TriggerAddAction(t, function OnLearn)
        call TriggerAddCondition(t, Condition(function LearnCondition))
        
        call GroupEnumUnitsInRect(Camouflaged, bj_mapInitialPlayableArea, Condition(function LearnCondition2))
        call ForGroup(Camouflaged, function OnLearn2)
        
        set FadeCounter = HandleTable.create()
        set TreeFinder = Rect(0,0,0,0)
        set TreeFilter = Filter(function FindTree)
        set Camouflaged = CreateGroup()
        call TimerStart(CreateTimer(), INTERVAL, true, function GroupEnum)
            
        call UnitAddAbility(preload, ABILITY_ID)
        call UnitAddAbility(preload, INVIS_ID)
        call UnitRemoveAbility(preload, ABILITY_ID)
        call UnitRemoveAbility(preload, INVIS_ID)
        
        call RemoveUnit(preload)
        set preload = null
    endfunction

endscope
 

Kommando

New Member
Reaction score
1
would it be possible if you could make it so it checks if ability is enabled? like i want camouflage only to usable if you've researched somethin. also make it usable if a unit is preplaced.
 

Summoned

New Member
Reaction score
51
About the pre-placed. That's my fault for putting the GroupEnum before the group is even created. :banghead:

Fill in the research id at the top, see if it works now:

EDIT: Typos.
JASS:
// Camouflage
// Coded by Zerzax as per Fulla's Request in Pyrogasm's Spell Request Thread
// Uses: Table

scope Camouflage initializer init

    // Configuration Section

    globals
        private constant integer ABILITY_ID = 'A002'
        private constant integer INVIS_ID = 'A001'
        private constant integer PRELOAD_ID = 'h000'
        private constant integer RESEARCH_ID = 'R000'
        // Timer Interval. Keep it large to minimize processing burdens.
        private constant real INTERVAL = 0.10
    endglobals

    // Range of trees.

    private function Range takes integer level returns real
        return 100.00 + level * 55.00
    endfunction
    
    // How many times the timer must run while the unit is out of range.
    
    private function FadeOut takes integer level returns integer
        return 7 + R2I( 3.3 * level )
    endfunction
    
    // Acceptable destructable types (that are trees)
    
    private function TreeTypes takes integer id returns boolean
        return id == 'ATtr' or id == 'BTtw' or id == 'KTtw' or id == 'YTft' or id == 'JTct' or id == 'YTst' or id == 'YTct' or id == 'YTwt' or id == 'JTwt' or id == 'JTwt' or id == 'FTtw' or id == 'CTtr' or id == 'ITtw' or id == 'NTtw' or id == 'OTtw' or id == 'ZTtw' or id == 'WTst' or id == 'LTlt' or id == 'GTsh' or id == 'Xtlt' or id == 'WTtw' or id == 'Attc' or id == 'BTtc' or id == 'CTtc' or id == 'ITtc' or id == 'NTtc' or id == 'ZTtc'
    endfunction
    
    // End of config. No Touchie!
    
    globals
        private group Camouflaged = CreateGroup()
        private rect TreeFinder = null
        private HandleTable FadeCounter
        private boolexpr TreeFilter = null
        private boolean FoundTrees = false
    endglobals
    
    private function FindTree takes nothing returns boolean
        return TreeTypes(GetDestructableTypeId(GetFilterDestructable()))
    endfunction
    
    private function FoundTree takes nothing returns nothing
        set FoundTrees = true
    endfunction
    
    private function Enum takes nothing returns nothing
        local unit camouflaged = GetEnumUnit()
        local real cX = GetUnitX(camouflaged)
        local real cY = GetUnitY(camouflaged)
        local integer lvl = GetUnitAbilityLevel(camouflaged, ABILITY_ID)
        local real range = Range(lvl)
        
        if (not GetPlayerTechResearched(GetOwningPlayer(GetEnumUnit()), RESEARCH_ID, true)) then
            set camouflaged = null
            return
        endif
        
        call SetRect(TreeFinder, cX - range, cY - range, cX + range, cY + range) 
        call EnumDestructablesInRect(TreeFinder, TreeFilter, function FoundTree) // Enumerate.
        
        if FoundTrees then // Then the current unit is in range.
            set FoundTrees = false
            if GetUnitAbilityLevel(camouflaged, INVIS_ID) == 0 then
                call UnitAddAbility(camouflaged, INVIS_ID) // Add so he can fade in.
                call SetUnitAbilityLevel(camouflaged, INVIS_ID, lvl)
            else
                set FadeCounter[camouflaged] = 0 // Restart fade-out process
            endif
        elseif GetUnitAbilityLevel(camouflaged, INVIS_ID) > 0 then // Start the fade proccess.
            set FadeCounter[camouflaged] = FadeCounter[camouflaged] + 1
            if FadeCounter[camouflaged] >= FadeOut(lvl) then 
                call UnitRemoveAbility(camouflaged, INVIS_ID) // Fully faded.
                set FadeCounter[camouflaged] = 0
            endif
        endif
        
        set camouflaged = null
    endfunction
    
    private function GroupEnum takes nothing returns nothing
        call ForGroup(Camouflaged, function Enum) // Perform enum action on all learned units.
    endfunction
    
    private function LearnCondition2 takes nothing returns boolean
        return (GetUnitAbilityLevel(GetEnumUnit(), ABILITY_ID) > 0)
    endfunction

    private function LearnCondition takes nothing returns boolean
        return (GetUnitAbilityLevel(GetTriggerUnit(), ABILITY_ID) > 0)
    endfunction
    
    private function OnLearn2 takes nothing returns nothing
        set FadeCounter[GetEnumUnit()] = 0
    endfunction
    
    private function OnLearn takes nothing returns nothing
        local unit learn = GetTriggerUnit() // The hero has learned the ability.
        if GetUnitAbilityLevel(learn, ABILITY_ID) > 0 then
            call GroupAddUnit(Camouflaged, learn)
            set FadeCounter[learn] = 0
        endif
        set learn = null
    endfunction

    private function init takes nothing returns nothing // Preload, trigger creation, handle creation.
        local unit preload = CreateUnit(Player(15), PRELOAD_ID, 0,0,0)
        local trigger t = CreateTrigger()
        call TriggerRegisterEnterRectSimple(t, bj_mapInitialPlayableArea)
        call TriggerAddAction(t, function OnLearn)
        call TriggerAddCondition(t, Condition(function LearnCondition))
        
        set FadeCounter = HandleTable.create()
        set TreeFinder = Rect(0,0,0,0)
        set TreeFilter = Filter(function FindTree)
        set Camouflaged = CreateGroup()
        call TimerStart(CreateTimer(), INTERVAL, true, function GroupEnum)
            
        call UnitAddAbility(preload, ABILITY_ID)
        call UnitAddAbility(preload, INVIS_ID)
        call UnitRemoveAbility(preload, ABILITY_ID)
        call UnitRemoveAbility(preload, INVIS_ID)
        
        call RemoveUnit(preload)
        set preload = null
        
        call GroupEnumUnitsInRect(Camouflaged, bj_mapInitialPlayableArea, Condition(function LearnCondition2))
        call ForGroup(Camouflaged, function OnLearn2)
    endfunction

endscope
 

Kommando

New Member
Reaction score
1
this is kinda optional, but could you add the option of choosing which integer of upgrade? like priest master training, shaman master training, etc.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top