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

Custom Aura JASS

Status
Not open for further replies.

FLW

FLW

Level 2
Joined
Apr 17, 2009
Messages
19
Iam creating an custom aura, that this make invulnerable to units near of 500 AOE of loc of the spell, only to allies of caster. but, this not work, here is the code:

JASS:
function CdI_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A001'
endfunction

function CdI_2_1 takes nothing returns boolean // agrega a todas
    local timer t = GetExpiredTimer()
    //local unit pick = GetFilterUnit()
    local unit caster = GetHandleUnit(t,"caster")
    local unit dummy = GetHandleUnit(t,"dummy")
    call BJDebugMsg("hola mundo cruel")
    if DistanceBetweenPoints(GetUnitLoc(GetFilterUnit()),GetUnitLoc(dummy)) < 750 and IsUnitAlly(GetFilterUnit(),GetOwningPlayer(caster)) == true then
        call BJDebugMsg("eres invul " + GetUnitName(GetFilterUnit()))
        call UnitAddAbility(GetFilterUnit(),'ACmi')
        call SetUnitInvulnerable(GetFilterUnit(),true)
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Brilliance\\Brilliance.mdl",GetFilterUnit(),"origin"))
        //call GroupRemoveUnit(udg_gg,pick)
        //call KillUnit(pick)
    endif
    if DistanceBetweenPoints(GetUnitLoc(GetFilterUnit()),GetUnitLoc(dummy)) > 755 and GetUnitAbilityLevel(GetFilterUnit(),'ACmi')>0 then
        call SetUnitInvulnerable(GetFilterUnit(),false)
        call UnitRemoveAbility(GetFilterUnit(),'ACmi')
        call BJDebugMsg("ya no eres invul " + GetUnitName(GetFilterUnit()))
        call SetUnitInvulnerable(GetFilterUnit(),false)
        //call KillUnit(pick)
    endif
return false
endfunction

function CdI_2 takes nothing returns nothing // agrega a todas
    local timer t = GetExpiredTimer()
    local unit caster = GetHandleUnit(t,"caster")
    local unit dummy = GetHandleUnit(t,"dummy")
    local group g = GetHandleGroup(t,"g")
    local real locx = GetHandleReal(t,"locx")
    local real locy = GetHandleReal(t,"locy")
    call SetHandleHandle(t,"dummy",dummy)
    call SetHandleHandle(t,"caster",caster)
    call GroupEnumUnitsInRange(g,locx,locy,750,Filter( function CdI_2_1))
    //call GroupEnumUnitsInRangeOfLoc(g,GetUnitLoc(dummy),750,Filter( function CdI_2_1))
endfunction

function CdI_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local group g = CreateGroup()
    local timer t = CreateTimer()
    local unit dummy = CreateUnit(GetTriggerPlayer(),'hsor',GetLocationX(GetSpellTargetLoc()),GetLocationY(GetSpellTargetLoc()),0)
    call SetHandleHandle(t, "caster",caster)
    call SetHandleHandle(t, "dummy",dummy)
    call SetHandleHandle(t, "g",g)
    call SetHandleReal(t, "locx",GetLocationX(GetSpellTargetLoc()))
    call SetHandleReal(t, "locy",GetLocationY(GetSpellTargetLoc()))
    call TimerStart(t,.05,true,function CdI_2)
    //set caster = null
    //set t = null
endfunction
//===========================================================================
function InitTrig_Campo_de_Inmunidad takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function CdI_Conditions ) )
    call TriggerAddAction( t, function CdI_Actions )
endfunction

someone can help me please!

P.S: i will remove leaks when it will be finished :goblin_boom:

ty community :grin:
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
It might be wise to ask questions related to why your trigger is not functioning inside the Triggers & Scripts section on the hive workshop.

Wild guess: It might not work because function CdI_2_1 is not a timer callback but a groupEnum callback and therefore can not use GetExpiredTimer().

A transition workaround for the GroupEnum would be:
making the timer a global array that is attached to the handle id of the casting unit - 0x100000.
Or use a unit indexer. This way it stays MUI. Or just use vJass structs ofcourse.
Another approach is setting the caster and dummy to a global temp var since it's single threaded (easiest approach).
Just make sure to null your handle variables, you seem to forget that.
Use a global block in this case. This way you can reference caster and dummy directly without the ugly udg_.
JASS:
globals 
    unit caster
    unit dummy
endglobals
As long as the thread will not sleep, this will work fine.

Also, please set FilterUnit() to a local variable, I hate to see so many wasted function calls :(
If it's called more then once while it doesn't have to it's a waste of execution time.
Little performance tip: put all your actions inside the conditions callback of your trigger. It's faster ;)
Just do everything you want inside the conditions and return false at the end. (Only use this when you're not threading with TSA's)

This is because apparently trigger actions are executed slower then trigger conditions.

EDIT: note that rulerofiron99 has a pretty solid statement there.
 
Last edited:
Level 14
Joined
Apr 20, 2009
Messages
1,543
i don't know vjass sry, my knowledge are standard

As I said: your problem is that GetExpiredTimer() can not be used inside function CdI_2_1 because it's not a callback for a timer but for a GroupEnum.
It's not vJass, just set a global variable for dummy and caster and reference those instead. (Since warcraft 3 is single threaded and if you haven't used any waits inside your code, this will work just fine)
Global blocks are vJass but as I showed above they are really, really easy to use. Even easier then GUI variables...

Do you want me to make an example for you?
(I could also make an optimized version for you if you want to...)

JASS:
globals
    unit globalDummy
    unit globalCaster
endglobals

function CdI_Conditions takes nothing returns boolean    
    return GetSpellAbilityId() == 'A001' 
endfunction 

function CdI_2_1 takes nothing returns boolean    
    local unit pick = GetFilterUnit()  
    call BJDebugMsg("hola mundo cruel")     
    if DistanceBetweenPoints(GetUnitLoc(GetFilterUnit()),GetUnitLoc(globalDummy)) < 750 and IsUnitAlly(GetFilterUnit(),GetOwningPlayer(globalCaster)) == true then
        call BJDebugMsg("eres invul " + GetUnitName(GetFilterUnit()))         
        call UnitAddAbility(GetFilterUnit(),'ACmi')         
        call SetUnitInvulnerable(GetFilterUnit(),true)         
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Brilliance\\Brilliance.mdl",GetFilterUnit(),"origin"))         //
        call GroupRemoveUnit(udg_gg,pick)
        call KillUnit(pick)    
    endif     
    if DistanceBetweenPoints(GetUnitLoc(GetFilterUnit()),GetUnitLoc(globalDummy)) > 755 and GetUnitAbilityLevel(GetFilterUnit(),'ACmi')>0 then         
        call SetUnitInvulnerable(GetFilterUnit(),false)         
        call UnitRemoveAbility(GetFilterUnit(),'ACmi')         
        call BJDebugMsg("ya no eres invul " + GetUnitName(GetFilterUnit()))         
        call SetUnitInvulnerable(GetFilterUnit(),false)
        call KillUnit(pick)     
    endif 
    set pick = null
    set globalDummy = null
    set globalCaster = null
    return false 
endfunction 

function CdI_2 takes nothing returns nothing 
    local timer t = GetExpiredTimer()        
    local group g = GetHandleGroup(t,"g")     
    local real locx = GetHandleReal(t,"locx")     
    local real locy = GetHandleReal(t,"locy")   
    set globalDummy = GetHandleUnit(t,"dummy")
    set globalCaster = GetHandleUnit(t, "caster")
    call GroupEnumUnitsInRange(g,locx,locy,750,Filter( function CdI_2_1))
    call GroupEnumUnitsInRangeOfLoc(g,GetUnitLoc(globalDummy),750,Filter( function CdI_2_1)) 
endfunction 

function CdI_Actions takes nothing returns nothing        
    local group g = CreateGroup()     
    local timer t = CreateTimer()
    local unit caster = GetTriggerUnit()
    local unit dummy = CreateUnit(GetTriggerPlayer(),'hsor',GetLocationX(GetSpellTargetLoc()),GetLocationY(GetSpellTargetLoc()),0)       
    call SetHandleHandle(t, "caster",caster)
    call SetHandleHandle(t, "dummy",dummy)
    call SetHandleHandle(t, "g",g)     
    call SetHandleReal(t, "locx",GetLocationX(GetSpellTargetLoc()))     
    call SetHandleReal(t, "locy",GetLocationY(GetSpellTargetLoc()))   
    call TimerStart(t,.05,true,function CdI_2)
    set caster = null
    set dummy = null
    set t = null 
endfunction 

function InitTrig_Campo_de_Inmunidad takes nothing returns nothing     
    local trigger t = CreateTrigger(  )     
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )     
    call TriggerAddCondition( t, Condition( function CdI_Conditions ) )     
    call TriggerAddAction( t, function CdI_Actions ) 
endfunction
 
Last edited:

FLW

FLW

Level 2
Joined
Apr 17, 2009
Messages
19
Big fails, the DistanceBeetwen 2 points work inverse, i was trying and check that if ur hero or ur workers walk since the mid to the left this work properily, but if u walk since the left to the right this don't work, and the system isnt remove the ability.

Maybe the big error is here:?

JASS:
DistanceBetweenPoints(GetUnitLoc(GetFilterUnit()),GetUnitLoc(globalDummy))

since the init, i would use IsUnitRange, but with this function u can not check if the unit is inside or out of range.

could be that DistanceBetweenPoints also check if the unit took is in her degree? :goblin_cry:
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Well... This is what DistanceBetweenPoints does exactly:
(Yes BJ's tend to inverse the parameters for unexplainable blizzard GUI reasons -,-)

JASS:
function DistanceBetweenPoints takes location locA, location locB returns real
    local real dx = GetLocationX(locB) - GetLocationX(locA)
    local real dy = GetLocationY(locB) - GetLocationY(locA)
    return SquareRoot(dx * dx + dy * dy)
endfunction

FLW said:
since the init, i would use IsUnitRange, but with this function u can not check if the unit is inside or out of range.

You could indeed always use:
JASS:
constant native IsUnitInRange       takes unit whichUnit, unit otherUnit, real distance returns boolean
This will return true if the unit is in a specified range of the other unit. And should work in your case.
I don't see how that could go wrong really :/...
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
JASS:
if IsUnitInRange(GetFilterUnit(), globalDummy, 750) and IsUnitAlly(GetFilterUnit(),GetOwningPlayer(globalCaster)) == true then

It's as simple as that.

If you want to check if it's not in range do:

JASS:
if not(IsUnitInRange(GetFilterUnit(), globalDummy, 755)) and GetUnitAbilityLevel(GetFilterUnit(),'ACmi')>0 then

If that still doesn't work you might want to check your and conditions.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
not work..

do you try it in game? ¬¬

Yes I tried using IsUnitInRange in a new map and it does work.
If it for some reason doesn't work for you then it must have something to do with your trigger, not with using IsUnitInRange.

I can't test your code because I don't have the SetHandle library you are using .
If you could either send me the map through PM or an example map with the system that needs to be fixed I'll take a look at it when I get home.
Or just link me to the library if this code doesn't take any input from outside.

Hell, I'd probably recreate the entire thing to make it more efficient.
If you want even more efficiency I can make a vJass version too.
 

FLW

FLW

Level 2
Joined
Apr 17, 2009
Messages
19
library:

JASS:
function SetHandleHandle takes handle subject, string name, agent value returns nothing
      call SaveAgentHandle(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleInt takes handle subject, string name, integer value returns nothing
      call SaveInteger(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
      call SaveBoolean(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleReal takes handle subject, string name, real value returns nothing
      call SaveReal(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleString takes handle subject, string name, string value returns nothing
      call SaveStr(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleLightning takes handle subject, string name, lightning value returns nothing
      call SaveLightningHandle(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleTA takes handle subject, string name, triggeraction value returns nothing
      call SaveTriggerActionHandle(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleTextTag takes handle subject, string name, texttag value returns nothing
      call SaveTextTagHandle(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction

    function GetHandleInt takes handle subject, string name returns integer
      return LoadInteger(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleBoolean takes handle subject, string name returns boolean
      return LoadBoolean(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleReal takes handle subject, string name returns real
      return LoadReal(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleString takes handle subject, string name returns string
      return LoadStr(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleUnit takes handle subject, string name returns unit
      return LoadUnitHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleItem takes handle subject, string name returns item
      return LoadItemHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleTimer takes handle subject, string name returns timer
      return LoadTimerHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleTrigger takes handle subject, string name returns trigger
      return LoadTriggerHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleTA takes handle subject, string name returns triggeraction
      return LoadTriggerActionHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleEffect takes handle subject, string name returns effect
      return LoadEffectHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleGroup takes handle subject, string name returns group
      return LoadGroupHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleLightning takes handle subject, string name returns lightning
      return LoadLightningHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleWidget takes handle subject, string name returns widget
      return LoadWidgetHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleLocation takes handle subject, string name returns location
      return LoadLocationHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandlePlayer takes handle subject, string name returns player
      return LoadPlayerHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleRegion takes handle subject, string name returns region
      return LoadRegionHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleRect takes handle subject, string name returns rect
      return LoadRectHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleForce takes handle subject, string name returns force
      return LoadForceHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleFogmodifier takes handle subject, string name returns fogmodifier
      return LoadFogModifierHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleTimerDialog takes handle subject, string name returns timerdialog
      return LoadTimerDialogHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleTextTag takes handle subject, string name returns texttag
      return LoadTextTagHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction

    function HaveHandleHandle takes handle subject, string name returns boolean
      return HaveSavedHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function HaveHandleInt takes handle subject, string name returns boolean
      return HaveSavedInteger(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function HaveHandleReal takes handle subject, string name returns boolean
      return HaveSavedReal(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function HaveHandleString takes handle subject, string name returns boolean
      return HaveSavedString(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function HaveHandleBoolean takes handle subject, string name returns boolean
      return HaveSavedBoolean(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction

    function RemoveHandle takes handle subject, string name returns nothing
      call SaveAgentHandle(udg_HashTable,GetHandleId(subject),StringHash(name), null)
      call RemoveSavedHandle(udg_HashTable,GetHandleId(subject),StringHash(name))
    endfunction
    function RemoveInt takes handle subject, string name returns nothing
      call SaveInteger(udg_HashTable,GetHandleId(subject),StringHash(name), 0)
      call RemoveSavedInteger(udg_HashTable,GetHandleId(subject),StringHash(name))
    endfunction
    function RemoveReal takes handle subject, string name returns nothing
      call SaveReal(udg_HashTable,GetHandleId(subject),StringHash(name), 0.0)
      call RemoveSavedReal(udg_HashTable,GetHandleId(subject),StringHash(name))
    endfunction
    function RemoveBoolean takes handle subject, string name returns nothing
      call SaveBoolean(udg_HashTable,GetHandleId(subject),StringHash(name), false)
      call RemoveSavedBoolean(udg_HashTable,GetHandleId(subject),StringHash(name))
    endfunction
    function RemoveStr takes handle subject, string name returns nothing
      call SaveStr(udg_HashTable,GetHandleId(subject),StringHash(name), null)
      call RemoveSavedString(udg_HashTable,GetHandleId(subject),StringHash(name))
    endfunction

    function FlushHandleLocals takes handle subject returns nothing
      call FlushChildHashtable(udg_HashTable, GetHandleId(subject) )
    endfunction

u 're a pro :D

ty man, if u get fix it, i have another code that i was trying yesterday(the same system), that i need that u check it if it is usefull.

ps: only jass, vjass i need more time to learn it
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
library:

JASS:
function SetHandleHandle takes handle subject, string name, agent value returns nothing
      call SaveAgentHandle(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleInt takes handle subject, string name, integer value returns nothing
      call SaveInteger(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
      call SaveBoolean(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleReal takes handle subject, string name, real value returns nothing
      call SaveReal(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleString takes handle subject, string name, string value returns nothing
      call SaveStr(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleLightning takes handle subject, string name, lightning value returns nothing
      call SaveLightningHandle(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleTA takes handle subject, string name, triggeraction value returns nothing
      call SaveTriggerActionHandle(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction
    function SetHandleTextTag takes handle subject, string name, texttag value returns nothing
      call SaveTextTagHandle(udg_HashTable, GetHandleId(subject), StringHash(name), value)
    endfunction

    function GetHandleInt takes handle subject, string name returns integer
      return LoadInteger(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleBoolean takes handle subject, string name returns boolean
      return LoadBoolean(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleReal takes handle subject, string name returns real
      return LoadReal(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleString takes handle subject, string name returns string
      return LoadStr(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleUnit takes handle subject, string name returns unit
      return LoadUnitHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleItem takes handle subject, string name returns item
      return LoadItemHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleTimer takes handle subject, string name returns timer
      return LoadTimerHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleTrigger takes handle subject, string name returns trigger
      return LoadTriggerHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleTA takes handle subject, string name returns triggeraction
      return LoadTriggerActionHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleEffect takes handle subject, string name returns effect
      return LoadEffectHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleGroup takes handle subject, string name returns group
      return LoadGroupHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleLightning takes handle subject, string name returns lightning
      return LoadLightningHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleWidget takes handle subject, string name returns widget
      return LoadWidgetHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleLocation takes handle subject, string name returns location
      return LoadLocationHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandlePlayer takes handle subject, string name returns player
      return LoadPlayerHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleRegion takes handle subject, string name returns region
      return LoadRegionHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleRect takes handle subject, string name returns rect
      return LoadRectHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleForce takes handle subject, string name returns force
      return LoadForceHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleFogmodifier takes handle subject, string name returns fogmodifier
      return LoadFogModifierHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleTimerDialog takes handle subject, string name returns timerdialog
      return LoadTimerDialogHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function GetHandleTextTag takes handle subject, string name returns texttag
      return LoadTextTagHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction

    function HaveHandleHandle takes handle subject, string name returns boolean
      return HaveSavedHandle(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function HaveHandleInt takes handle subject, string name returns boolean
      return HaveSavedInteger(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function HaveHandleReal takes handle subject, string name returns boolean
      return HaveSavedReal(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function HaveHandleString takes handle subject, string name returns boolean
      return HaveSavedString(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction
    function HaveHandleBoolean takes handle subject, string name returns boolean
      return HaveSavedBoolean(udg_HashTable, GetHandleId(subject), StringHash(name))
    endfunction

    function RemoveHandle takes handle subject, string name returns nothing
      call SaveAgentHandle(udg_HashTable,GetHandleId(subject),StringHash(name), null)
      call RemoveSavedHandle(udg_HashTable,GetHandleId(subject),StringHash(name))
    endfunction
    function RemoveInt takes handle subject, string name returns nothing
      call SaveInteger(udg_HashTable,GetHandleId(subject),StringHash(name), 0)
      call RemoveSavedInteger(udg_HashTable,GetHandleId(subject),StringHash(name))
    endfunction
    function RemoveReal takes handle subject, string name returns nothing
      call SaveReal(udg_HashTable,GetHandleId(subject),StringHash(name), 0.0)
      call RemoveSavedReal(udg_HashTable,GetHandleId(subject),StringHash(name))
    endfunction
    function RemoveBoolean takes handle subject, string name returns nothing
      call SaveBoolean(udg_HashTable,GetHandleId(subject),StringHash(name), false)
      call RemoveSavedBoolean(udg_HashTable,GetHandleId(subject),StringHash(name))
    endfunction
    function RemoveStr takes handle subject, string name returns nothing
      call SaveStr(udg_HashTable,GetHandleId(subject),StringHash(name), null)
      call RemoveSavedString(udg_HashTable,GetHandleId(subject),StringHash(name))
    endfunction

    function FlushHandleLocals takes handle subject returns nothing
      call FlushChildHashtable(udg_HashTable, GetHandleId(subject) )
    endfunction

Oh lol it's all saved inside a simple hashtable.
u 're a pro :D
Why thank you, but I'd like to stay humble to the real vJass pro's out there. They are probably lots better then I am :p

ty man, if u get fix it, i have another code that i was trying yesterday(the same system), that i need that u check it if it is usefull.

ps: only jass, vjass i need more time to learn it

Is it okay if I make one in jass and one in vJass so that you can decide what to do with it yourself?

Also: it will have to wait since I'm still at work, it'll probably take some time before I can start working on this.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Tell me what exactly you want the ability to do, because as of now I've fixed it but what it does looks really stupid to me :/...

It adds a ability to units within 750 range of the target of the casted spell then that unit gets killed afterwards (including the caster)?

And this is done in a continous timer that runs every 0.05 seconds after the spell is cast repeatedly infinitly because...?

I think you should not pick all the units in range but simply use IsUnitInRange within the timer callback if that is what you where aiming for.
That would probably solve some of your problems, but still I'd like to know what exactly you are planning to do here so that I can fix the entire trigger the way you want it to be.

I'm not trying to be a logic nazi here, I'm just trying to help you solve these problems for your spell ;)
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
BUMP: sorry for the double post guys :(

I didn't have that much time to work on it but here it is:

JASS:
//This trigger is almost fully in Jass except for the globals block.
//a globals block is as simple as defining GUI variables: instead of udg_HashTable you can now use HashTable
//what constant means is explained underneath...

globals
    hashtable HashTable = InitHashtable()//I could make it faster by only using arrays with HandleId offsets, but I'm too lazy to do it right now, you could do it yourself.
    //just look at how I used unitsInRange, it's not that difficult...
    group array unitsInRange
    integer tempId
    //constant variables are vJass variables which constantly exist. They can not be changed inside functions, they can only be used. Not altered
    //these constants can be changed to your prefference in the globals block
    //this way it's easier to change the settings of your spell inside the entire trigger without having to go through all of them inside the trigger by yourself.
    constant real AOE = 500 //the amount of AOE range the field has
    constant real DURATION = 5 //the amount of seconds the AOE field exists
    constant real INTERVAL = 0.25 //the interval to check if a unit left the field, making this too low will result in slowdowns of your trigger. lololol ForGroup()
    constant integer DUMMY_RAW = 'h000' //RAW code of the dummy. Look inside the object editor, he uses a model to display the field right now
    constant integer ABILITY_RAW = 'A000' //RAW code of the casted ability
    constant integer ADD_ABILITY_RAW = 'ACvp' //Vampirism aura RAW is added to the units.
endglobals

function destroyGroup takes nothing returns nothing
    local unit u = GetEnumUnit()
    local integer trig = LoadInteger(HashTable, tempId, StringHash("trigger")) - 0x100000
    call UnitRemoveAbility(u, ADD_ABILITY_RAW)
    call SetUnitInvulnerable(u, false)
    call GroupRemoveUnit(unitsInRange[trig], u)
endfunction

function checkRange takes nothing returns nothing
    local unit u = GetEnumUnit()
    local real locX = LoadReal(HashTable, tempId, StringHash("locx"))
    local real locY = LoadReal(HashTable, tempId, StringHash("locy"))
    local integer trig = LoadInteger(HashTable, tempId, StringHash("trigger")) - 0x100000
    if not(IsUnitInRangeXY(u, locX, locY, AOE)) then //if the unit is not inside the range of the field, do some stuff...
        call UnitRemoveAbility(u, ADD_ABILITY_RAW)
        call SetUnitInvulnerable(u,false)
        call GroupRemoveUnit(unitsInRange[trig], u)
    endif
endfunction

function CdI_2 takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer timerId = GetHandleId(t)
    local integer trig = LoadInteger(HashTable, timerId, StringHash("trigger")) - 0x100000
    local real time = LoadReal(HashTable, trig, StringHash("time"))
    local unit dummy = LoadUnitHandle(HashTable, timerId, StringHash("dummy"))
    set tempId = timerId //set a global tempId to the handle ID of the timer so that it can be used in the callback inside ForGroup()
    call SaveReal(HashTable, trig, StringHash("time"), time - INTERVAL)
    if (time <= 0) then
        //remove abilities, set units back to normal and remove group.
        call ForGroup(unitsInRange[trig], function destroyGroup) //slow function call :(
        call DestroyGroup(unitsInRange[trig])
        call RemoveUnit(dummy)
        call PauseTimer(t)
        call DestroyTimer(t)
    else
        call ForGroup(unitsInRange[trig], function checkRange) //this thing makes the entire trigger slow, I know... It's a really slow function call unfortunately :(
        //it's the reason why the interval shouldn't be that low... 0.25 works okay I guess, you can make it higher for more efficiency.
        //I guess I could've avoided this by using linked arrays, but I'm just too lazy to create a unit heap in Jass for this spell :P
    endif
    set tempId = 0 //let's just do this...
endfunction

function CdI_actions_2 takes nothing returns boolean //same story
    local unit enteringUnit = GetTriggerUnit()
    local integer trig = GetHandleId(GetTriggeringTrigger()) - 0x100000 //get the handle Id of the trigger with offset (for example handle id = 125)
    local real time = LoadReal(HashTable, trig, StringHash("time")) //load the time through the handle id of the trigger
    if (time <= 0) then //if time is less then or equal to 0, destroy this trigger
        call DestroyTrigger(GetTriggeringTrigger())
    else
        if not(IsUnitInGroup(enteringUnit, unitsInRange[trig])) then //if the unit is not already in the global unit group, add the unit and the abilities, and make it invulnerable
            call GroupAddUnit(unitsInRange[trig], enteringUnit)
            call UnitAddAbility(enteringUnit, ADD_ABILITY_RAW)
            call SetUnitInvulnerable(enteringUnit,true)
        endif
    endif
    return false //return bullshit again
endfunction

function CdI_Actions takes nothing returns boolean //returns boolean because well yeah... it's a condition :/
    local timer t
    local unit dummy
    local trigger trig
    local real locx
    local real locy
    local group g = CreateGroup()
    local unit u
    local unit caster = GetTriggerUnit()
    local integer timerId
    local integer trigId
    if (GetSpellAbilityId() == ABILITY_RAW) then
        set t = CreateTimer()
        set timerId = GetHandleId(t)
        set locx = GetSpellTargetX()
        set locy = GetSpellTargetY()
        set trig = CreateTrigger()//here I create a trigger inside my actions
        set trigId = GetHandleId(trig)
        set dummy = CreateUnit(Player(13), DUMMY_RAW, GetSpellTargetX(), GetSpellTargetY(), 0.00)//create a dummy unit that is used for checking within range
        call TriggerRegisterUnitInRange(trig, dummy, AOE, null)//I add the dummy unit to the event of the trigger for whenever someone comes in range of the dummy
        call TriggerAddCondition(trig, Condition(function CdI_actions_2))//I add the actions to the trigger
        set unitsInRange[trigId - 0x100000] = CreateGroup()//create a global unit group attached to the handle if of the trigger
        //what is this 0x100000 that I'm seeing? It's the offset from any handle ID, if you substract it from the handle ID you can use the Handle ID as a standard number inside arrays (index won't be too long)
        call GroupEnumUnitsInRange(g,locx,locy,AOE, null)//filters are slow, we are going to create our filter inside this function. Pay close attention.
        loop
            set u = FirstOfGroup(g) //local unit u is the first unit of the group
            exitwhen u == null //stop the loop when the first unit of the group is empty
            call GroupAddUnit(unitsInRange[trigId - 0x100000], u) //add the unit to the global unit group
            if IsUnitAlly(u, GetOwningPlayer(caster)) then //if its an ally of caster
                call UnitAddAbility(u, ADD_ABILITY_RAW)//add ability to unit
                call SetUnitInvulnerable(u,true)//make unit invulnerable
            endif
            call GroupRemoveUnit(g, u) //remove u from the current unit group
        endloop
        //instead of using these deprecated functions, why not use the actual hashtable natives directly? They are just as simple and makes your trigger faster
        //because not only will it be called only once, but also some of those functions you used where outdated and didn't work at all... SaveHandleHandle didn't work for example.
        call SaveUnitHandle(HashTable, timerId, StringHash("dummy"), dummy) //save the dummy on the id of the timer
        call SaveInteger(HashTable, timerId, StringHash("trigger"), trigId) //save the trigger handle ID on the id of the timer
        call SaveReal(HashTable, timerId, StringHash("locx"), locx) //save the cast loc x on the id of the timer
        call SaveReal(HashTable, timerId, StringHash("locy"), locy) //save the cast loc y on the id of the timer
        call SaveReal(HashTable, trigId - 0x100000, StringHash("time"), DURATION) //save the duration on the id of the trigger, this is because the trigger can then use the time
        call TimerStart(t, INTERVAL, true, function CdI_2) //start the timer
        //??? what is this ??? I dunno rlly ¯(°_o)/¯
        set caster = null
        set dummy = null
        call DestroyGroup(g)
        set g = null
        set trig = null
    endif
    return false //return false, because we already did all the stuff we wanna do, this is just to make sure that something is returned from our "condition" ^.^
endfunction


function InitTrig_New_approach takes nothing returns nothing     
    local trigger t = CreateTrigger()     
    //little optimization instead of using the BJ, use what is inside the BJ for 1 less function call.
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
    endloop
    call TriggerAddCondition( t, Condition( function CdI_Actions) )//apparently trigger conditions are faster then trigger actions. Actions should not be used, do this instead.
    set t = null
endfunction

Ow yeah and the trigger name = New_approach

(also I'm not sure if tempId is MUI, but I think it is. Check it out just to be sure...)

hehe, would've looked much prettier in vJass ^.^
 

Attachments

  • test.w3x
    20.5 KB · Views: 49
Last edited:
Status
Not open for further replies.
Top