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

Polledwait or TriggerSleepAction in a loop?

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
You can, but neither of those actions are efficient. If you wait 1 second, it will wait a bit more or less than 1 second.

Also, all the actions after the loop with be stuck there until the loop finishes.

Loop is meant for instant processing, not periodic. For periodic processing you have timers and periodic triggers.

What effect do you want to achieve?
 
Level 11
Joined
Oct 11, 2012
Messages
711
You can, but neither of those actions are efficient. If you wait 1 second, it will wait a bit more or less than 1 second.

Also, all the actions after the loop with be stuck there until the loop finishes.

Loop is meant for instant processing, not periodic. For periodic processing you have timers and periodic triggers.

What effect do you want to achieve?
Thank you for the advice.
I want to make an ability that when the hero use it, there will be dummies casting war stomp around the hero every 0.7 second.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
a counter is something used to count passes in time. like say after 1 second i want to deal damage in a spell. Its a normal spell with .03 loop.
i cant just order unit to attack as it will damage the unit after .03 seconds so instead i use a counter.
to get one second from .03 u divide 1 by .03 and u get about 33
so i use a counter to count up 33 times then i use an ITE below the counter to see if that counter is at 33. when it hits 33 i do the damage.

also plz dont double post instead hit the edit on ur last post
 
Level 11
Joined
Oct 11, 2012
Messages
711
u can describe it here so many ppl can help. i would show u how but best i can do is tell u how to do it.

Alright, here is what I want to do. I want to make a spell that can do the following:
1. the hero cast the spell, which is a modified version of warstomp.
2. at the same time, "step 1" triggers the trigger. Creating a dummy to cast warstomp (not the same one as the hero's warstomp) at a random location within 500 range of the hero.
3. repeat "step 2" every 0.5 sec for a duration of 3 seconds. Loop without pause is too fast, all the dummies nearly appear at the same time.

PS: if I edit my last post, can you receive notice that I edit it?
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
No. You editions doesn't notify.

You'll find this done in the morning.

Download JNGP and Jasshelper from my signature, you'll need it.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
1- Create a trigger
2- Conver it to Custom Text (Edit -> Convert to custom text)
3- Replace everything inside with the script below
4- Rename your trigger to whatever you want (I called this Stomp Rush)
5- Check the Globals Configurables and adjust the values as you desire
6- Save, test, and ejoy.

This doesn't create a dummy unit for every stomp, it just moves the same dummy from one position to the next one. Dummy castpoint and backswing must be lower than the interval (0 is better for instant cast). There are some tutorials an guides around that explains how to properly configure a Dummy Unit.

JASS:
globals
    // Start Configurations //
    // Note: Press CTRL+D on the Object Editor to see objects Id's
    
    integer StompRush_Id = 'xxxx'    // ID of your StompRush ability (The one that triggers everything)
    integer StompRush_Dummy = 'zzzz' // ID of your Dummy Stomper
    string StompRush_Order = "stomp" // Order of the Dummy Stomp Ability
    real StompRush_Interval = 0.5    // Every *this interval* a dummy will stun
    real StompRush_Duration = 3      // The duration of the effect
    real StompRush_AoE = 500         // AoE of the ability
    
    // End Configurations //
    
    hashtable StompRush_Hash = InitHashtable()
endglobals

function StompRush_TimerFunc takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer id = GetHandleId(t)
    local integer duration = LoadInteger(StompRush_Hash, id, 1)
    local unit dummy
    local unit caster
    local real x
    local real y
    
    if duration >= StompRush_Interval then
        call SaveReal(StompRush_Hash, id, 1, duration-StompRush_Interval)
        set dummy = LoadUnitHandle(StompRush_Hash, id, 0)
        set caster = LoadUnitHandle(StompRush_Hash, id, 2)
        set x = GetUnitX(caster) + GetRandomReal(0, StompRush_AoE)
        set y = GetUnitY(caster) + GetRandomReal(0, StompRush_AoE)
        call SetUnitX(dummy, x)
        call SetUnitY(dummy, y)
        call IssueImmediateOrder(dummy, StompRush_Order)
        set dummy = null
        set caster = null
    else
        call PauseTimer(t)
        call DestroyTimer(t)
        call KillUnit(dummy)
        call RemoveUnit(dummy)
        call FlushChildHashtable(StompRush_Hash, id)
    endif
    
    set t = null
endfunction

function Trig_Stomp_Rush_Conditions takes nothing returns boolean
    local unit caster
    local unit dummy
    local timer t
    local real ux
    local real uy
    local integer id
    
    if GetSpellAbilityId() == StompRush_Id then
        set caster = GetTriggerUnit()
        set ux = GetUnitX(caster)
        set uy = GetUnitY(caster)
        set dummy = CreateUnit(GetTriggerPlayer(), StompRush_Dummy, ux, uy, 0)
        set t = CreateTimer()
        set id = GetHandleId(t)
        
        call SaveUnitHandle(StompRush_Hash, id, 0, dummy)
        call SaveReal(StompRush_Hash, id, 1, StompRush_Duration)
        call SaveUnitHandle(StompRush_Hash, id, 2, caster)
    
        // Null Locals - Clear leaks
        set t = null
        set dummy = null
        set caster = null
    endif

    return false
endfunction

//===========================================================================
function InitTrig_Stomp_Rush takes nothing returns nothing
    set gg_trg_Stomp_Rush = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stomp_Rush, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Stomp_Rush, Condition( function Trig_Stomp_Rush_Conditions ) )
endfunction

I didn't test it, but it should work.
 
Level 11
Joined
Oct 11, 2012
Messages
711
1- Create a trigger
2- Conver it to Custom Text (Edit -> Convert to custom text)
3- Replace everything inside with the script below
4- Rename your trigger to whatever you want (I called this Stomp Rush)
5- Check the Globals Configurables and adjust the values as you desire
6- Save, test, and ejoy.

This doesn't create a dummy unit for every stomp, it just moves the same dummy from one position to the next one. Dummy castpoint and backswing must be lower than the interval (0 is better for instant cast). There are some tutorials an guides around that explains how to properly configure a Dummy Unit.

JASS:
globals
    // Start Configurations //
    // Note: Press CTRL+D on the Object Editor to see objects Id's
    
    integer StompRush_Id = 'xxxx'    // ID of your StompRush ability (The one that triggers everything)
    integer StompRush_Dummy = 'zzzz' // ID of your Dummy Stomper
    string StompRush_Order = "stomp" // Order of the Dummy Stomp Ability
    real StompRush_Interval = 0.5    // Every *this interval* a dummy will stun
    real StompRush_Duration = 3      // The duration of the effect
    real StompRush_AoE = 500         // AoE of the ability
    
    // End Configurations //
    
    hashtable StompRush_Hash = InitHashtable()
endglobals

function StompRush_TimerFunc takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer id = GetHandleId(t)
    local integer duration = LoadInteger(StompRush_Hash, id, 1)
    local unit dummy
    local unit caster
    local real x
    local real y
    
    if duration >= StompRush_Interval then
        call SaveReal(StompRush_Hash, id, 1, duration-StompRush_Interval)
        set dummy = LoadUnitHandle(StompRush_Hash, id, 0)
        set caster = LoadUnitHandle(StompRush_Hash, id, 2)
        set x = GetUnitX(caster) + GetRandomReal(0, StompRush_AoE)
        set y = GetUnitY(caster) + GetRandomReal(0, StompRush_AoE)
        call SetUnitX(dummy, x)
        call SetUnitY(dummy, y)
        call IssueImmediateOrder(dummy, StompRush_Order)
        set dummy = null
        set caster = null
    else
        call PauseTimer(t)
        call DestroyTimer(t)
        call KillUnit(dummy)
        call RemoveUnit(dummy)
        call FlushChildHashtable(StompRush_Hash, id)
    endif
    
    set t = null
endfunction

function Trig_Stomp_Rush_Conditions takes nothing returns boolean
    local unit caster
    local unit dummy
    local timer t
    local real ux
    local real uy
    local integer id
    
    if GetSpellAbilityId() == StompRush_Id then
        set caster = GetTriggerUnit()
        set ux = GetUnitX(caster)
        set uy = GetUnitY(caster)
        set dummy = CreateUnit(GetTriggerPlayer(), StompRush_Dummy, ux, uy, 0)
        set t = CreateTimer()
        set id = GetHandleId(t)
        
        call SaveUnitHandle(StompRush_Hash, id, 0, dummy)
        call SaveReal(StompRush_Hash, id, 1, StompRush_Duration)
        call SaveUnitHandle(StompRush_Hash, id, 2, caster)
    
        // Null Locals - Clear leaks
        set t = null
        set dummy = null
        set caster = null
    endif

    return false
endfunction

//===========================================================================
function InitTrig_Stomp_Rush takes nothing returns nothing
    set gg_trg_Stomp_Rush = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Stomp_Rush, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Stomp_Rush, Condition( function Trig_Stomp_Rush_Conditions ) )
endfunction

I didn't test it, but it should work.

Thanks a lot lot lot lot for your time. I am gonna use it right away and gives you credit for it.

Don't know how to express my appreciation, thanks really !!!

++REP
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
First of all.. did it work? xD

Let me know if you wanna modify something or add some new feature like special effects
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
The action part is included in the Condition.

What isn't working? Did you adjust the ID of the Dummy and the Ability that triggers everything? Does it compile when you save?
 
Level 11
Joined
Oct 11, 2012
Messages
711
The action part is included in the Condition.

What isn't working? Did you adjust the ID of the Dummy and the Ability that triggers everything? Does it compile when you save?

" if GetSpellAbilityId() == StompRush_Id then"
Jasshelper detected the error of this line, is it?

Edit: wait, let me import again. I might have done something wrong.

Edit:the name of the trigger is "gg_trg_Stomp_Rush", right? And, yes, I have changed the ID of the dummy and the ability. :)
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Rename the trigger to whatever you want, the system will adjust the trigger script part automatically. I named the trigger "Stomp Rush"

" if GetSpellAbilityId() == StompRush_Id then"
Jasshelper detected the error of this line, is it?

What error?

Remember the ID's are 4 letters inside single quotes

'sadf'
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Well... "Copy/paste" doesn't seem really as a complex "importing" process :p If you don't manage to solve this yourself, Copy/Paste here the JassHelper error log.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Not actually dimf. As far a I know locals with no data reference doesn't need to be nulled; they just have to be nulled when they hold some kind of information; else, you would null already "null" variables wasting like 0.0000000001 memory in the process xD
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
Not actually dimf. As far a I know locals with no data reference doesn't need to be nulled; they just have to be nulled when they hold some kind of information; else, you would null already "null" variables wasting like 0.0000000001 memory in the process xD
That does not make any sense...
If you null something already nulled all you are doing is wasting time as you are changing a memory location from null to... well... null. No more or less memory is used as null is a constant and so there is no underlying object creation.

The whole reason you have to null local defined local handle variables is because there is a bug that at the end of the function (end of variable life) they do not decrement the reference counter of the handle they last pointed at so the handle can never be recycled as it thinks some variable is always referencing it. Argument defined locals do not suffer from this fault and so do not need to be nulled at the end of a function.

Some handle values are never recycled so do not need to be nulled. Player is the most commonly known one as even after destruction the player still exists.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Not actually dimf. As far a I know locals with no data reference doesn't need to be nulled; they just have to be nulled when they hold some kind of information; else, you would null already "null" variables wasting like 0.0000000001 memory in the process xD

ur right lol sry i thought u set them when u declared them lol.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Sorry Dr. Super Good, I don't know that much about computing words (my native language is spanish) I just wanted to say that there's no need to null "null" locals (locals with no assigned/allocated value)
 
Level 11
Joined
Oct 11, 2012
Messages
711
Sorry Dr. Super Good, I don't know that much about computing words (my native language is spanish) I just wanted to say that there's no need to null "null" locals (locals with no assigned/allocated value)

It works perfectly, :). Thank you Spartipilo for your great work and time. Sorry that I am a noob and dont even know how to import correctly in the first time. I wish I can give you Rep but the forum system does not allow me, :(

@ deathismyfriend
Also thank you for your advice. :)
 
Status
Not open for further replies.
Top