Need help for my first spell with vJass

aggro

New Member
Reaction score
0
well, i decided to learn vJass. Im doing some practice by converting my old gui spells into vJass.

addsn.jpg


thats the spell. basically, its proc chance increases with every missing hp and although it's a passive spell, it has 25 sec internal cooldown. It means it can proc only once every 25 sec. btw these "type: attack" and "modifiers" things are about my own attribute system. thats not necessary here, ignore it please.

I'm using Damage-Event-AIDS, Caster System, TimerUtils, GroupUtils.

thats the code:

JASS:
scope Thirst initializer Starter

////////////////////////////////////////////////////////////////////////////////////////////

    globals
        private constant integer SPELL_ID = 'A02H'
        private timer cooldown
        private timer duration
        private trigger ta
        private trigger tb
        private trigger tc
        private real durationr = 8.00 + ( I2R(GetHeroStr(GetEventDamageSource(), true)) * 0.05 )
        private integer cooldownr = 0
    endglobals

////////////////////////////////////////////////////////////////////////////////////////////

    private function Actions takes nothing returns nothing
        local integer level = GetUnitAbilityLevel(GetEventDamageSource(), SPELL_ID )
        local integer roll = R2I(( ( ( GetUnitState(GetEventDamageSource(), UNIT_STATE_MAX_LIFE) - GetUnitState(GetEventDamageSource(), UNIT_STATE_LIFE) ) * 100.00 ) / GetUnitState(GetEventDamageSource(), UNIT_STATE_MAX_LIFE) ))
        local integer random = GetRandomInt(1, 100)
            if  ( random <= roll ) and ( GetUnitTypeId(GetEventDamageSource()) == 'U001' ) and (level>0) and (cooldownr==0) then
                call DisplayTimedTextToPlayer(GetOwningPlayer(GetEventDamageSource()),0,0,60,"test message")
                call CasterCastAbilityLevel( GetOwningPlayer(GetEventDamageSource()), 'A035', level, "unholyfrenzy", GetEventDamageSource(), true)
                call TimerStart(cooldown, 25.00, false, null)
                call TimerStart( duration, durationr, false, null )
                call TriggerSleepAction(durationr)
                call UnitRemoveAbility(GetEventDamageSource(), 'B006')
                set cooldownr = 25
                set cooldown=NewTimer()
                call SetTimerData(cooldown, cooldownr)
            endif
    endfunction

    private function Cooldown takes nothing returns nothing
        call EnableTrigger( ta )
    endfunction

    private function Duration takes nothing returns nothing
        call UnitRemoveAbility(GetEventDamageSource(), 'B006')
    endfunction

////////////////////////////////////////////////////////////////////////////////////////////

    private function Starter takes nothing returns nothing
        set ta=CreateTrigger()
        call TriggerAddAction(ta,function Actions)
        call Damage_RegisterEvent(ta)  
        
        set tb=CreateTrigger()
        call TriggerAddAction(tb,function Cooldown)
        call TriggerRegisterTimerExpireEvent( tb, cooldown ) 
        
        set tc=CreateTrigger()
        call TriggerAddAction(tc,function Duration)
        call TriggerRegisterTimerExpireEvent( tc, duration )  
    endfunction
endscope

(It's indented now.)

I'm stuck on making internal cooldown and buff ends(by the modifiers, buff duration is dynamic).

1. how to fix it?
2. how to make leakless and multi-doable this code?
3. is there anyway to optimize it? Because it looks very mess to me. :)

Thanks anyway.
 
thanks for advice. i converted BJs into natives.

so any advice about "internal cooldown" "buff ends" functions?
 
It helps to not name things by number (t1, t2, t3) because it shows a disconnect of multi-user compatibility. Your indentation is screwed up, badly.

JASS:
function foo takes nothing returns nothing
    //actions
    endfunction


You'd never get away with this kind of shit in real-world programming. I can't bother to read what your code is trying to do in its current state.
 
- for the indentation, you can dl a jass editor like jasscraft to auto indent your text
- function Actions–save GetEventDamageSource as local or global to avoid so many fn calls
- multi-doable?
- your triggers/timers arent initialized
- function Duration–GetEventDamageSource() is null, perhaps this is the source of your error?

as for the internal timer thing, you can either attach a timer to each unit with some unit indexing system or you can have 1 timer to manage all. 1 timer per unit should be used if reseting cooldown etc is frequently used in your map, otherwise 1 timer to manage all instances would be more efficient. extracted is a portion of 'Effect' by executor. i suggest you read up on this recycle idea (by vexorian?), and include it in your code. this will also make your spell mui–right now i see that youre using 1 timer for maximum of 1 instance.
JASS:
  //--
       private static method onRecycleTimer takes nothing returns nothing
         // recycle one instance and start the timer to recycle the next one ...
            local thistype this = .recycleStart
            set .recycleStart = .recycleStart.next
            call .destroy()
            if .recycleStart != 0 then
                call TimerStart(.recycleTimer,TimerGetRemaining(.NOW)-.recycleStart.schedule,false,function thistype.onRecycleTimer)
            else
                set .recycleEnd = 0
            endif
        endmethod
        private method recycle takes nothing returns nothing
            // add this instance to the recycle queue 
            call DestroyEffect(.sfx)
            set .sfx = null
            set .schedule   = TimerGetRemaining(.NOW)-RECYCLE_DELAY
            if .recycleStart == 0 then
                set .recycleStart  = this
                set .recycleEnd    = this
                set .next = 0
                call TimerStart(.recycleTimer,RECYCLE_DELAY,false,function thistype.onRecycleTimer)
            else
                set .recycleEnd.next    = this
                set .next               = 0
                set .recycleEnd         = this
            endif
        endmethod


EDIT: indented version...

JASS:
scope Thirst initializer Starter
////////////////////////////////////////////////////////////////////////////////////////////
globals
    private constant integer SPELL_ID = 'A02H'
    private timer cooldown
    private timer duration
    private trigger t1
    private trigger t2
    private trigger t3
endglobals
////////////////////////////////////////////////////////////////////////////////////////////
private function Actions takes nothing returns nothing
    local integer level = GetUnitAbilityLevel(GetEventDamageSource(), SPELL_ID )
    local real cooldownr
    local real durationr = 8.00 + ( I2R(GetHeroStr(GetEventDamageSource(), true)) * 0.05 )
    local integer roll = R2I(( ( ( GetUnitState(GetEventDamageSource(), UNIT_STATE_MAX_LIFE) - GetUnitState(GetEventDamageSource(), UNIT_STATE_LIFE) ) * 100.00 ) / GetUnitState(GetEventDamageSource(), UNIT_STATE_MAX_LIFE) ))
    local integer random = GetRandomInt(1, 100)
    if  ( random <= roll ) and ( GetUnitTypeId(GetEventDamageSource()) == 'U001' )  then   
        call DisplayTimedTextToPlayer(GetOwningPlayer(GetEventDamageSource()),0,0,60,"test message")
        call CasterCastAbilityLevel( GetOwningPlayer(GetEventDamageSource()), 'A035', level, "unholyfrenzy", GetEventDamageSource(), true)
        call TimerStart(cooldown, 25.00, false, null)
        call TimerStart( duration, durationr, false, null )
        call DisableTrigger( t1 )  
    endif
endfunction

private function Cooldown takes nothing returns nothing
    call EnableTrigger( t1 )
endfunction

private function Duration takes nothing returns nothing
    call UnitRemoveAbility(GetEventDamageSource(), 'B006')
endfunction
////////////////////////////////////////////////////////////////////////////////////////////

private function Starter takes nothing returns nothing
    set t1=CreateTrigger()
    call TriggerAddAction(t1,function Actions)
    call Damage_RegisterEvent(t1)

    set t2=CreateTrigger()
    call TriggerAddAction(t2,function Cooldown)
    call TriggerRegisterTimerExpireEvent( t2, cooldown )

    set t3=CreateTrigger()
    call TriggerAddAction(t3,function Duration)
    call TriggerRegisterTimerExpireEvent( t3, duration )
endfunction

endscope
 
- for the indentation, you can dl a jass editor like jasscraft to auto indent your text

-- I fixed the code indents.

- function Actions–save GetEventDamageSource as local or global to avoid so many fn calls

-- i'll do that.

- multi-doable?

-- i mean, for example, five players have the same hero which has that spell and they cast that spell anytime without any bugs.

- your triggers/timers arent initialized

-- Actually thats my question. How to initialize the timers? I mean, when "cooldown" is counting down "function actions" wont work till "cooldown" is zero.

- function Duration–GetEventDamageSource() is null, perhaps this is the source of your error?

-- Function Duration–GetEventDamageSource() is null?? I didnt write any like that function. It doesnt gives any error. I just couldnt make the timers work.
 
How to initialize the timers
JASS:
private trigger t1 = CreateTrigger()
private timer cooldown = NewTimer()[/ljass]
// OR
set t1 = CreateTrigger() 
set duration = NewTimer()
//etc

Function Duration–GetEventDamageSource() is null?? I didnt write any like that function. It doesnt gives any error. I just couldnt make the timers work.
JASS:
private function Duration takes nothing returns nothing
    call UnitRemoveAbility(GetEventDamageSource(), 'B006') //event response will not work.
endfunction

sorry, i meant that geteventdamagesource wont return anything--there is no event response for timer events, and as i was saying, attach 1 timer per unit that has the skill (if you dont want the schedule method). this will also make it mui/multi-doable

for fn duration to work properly, attach unit to timer and retrieve from that.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      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