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.
 

aggro

New Member
Reaction score
0
thanks for advice. i converted BJs into natives.

so any advice about "internal cooldown" "buff ends" functions?
 

Bribe

vJass errors are legion
Reaction score
67
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.
 

hgkjfhfdsj

Active Member
Reaction score
55
- 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
 

aggro

New Member
Reaction score
0
- 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.
 

hgkjfhfdsj

Active Member
Reaction score
55
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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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