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

[JASS] i need some help with this

Status
Not open for further replies.
Level 2
Joined
Oct 2, 2006
Messages
24
Hello,

im fairly new to this programming thing and im working on a converted GUI script.
The big idea is to create redlightning from a caster to a target and damaging it.
the script:

function Trig_StormofPain_Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'AEim' ) ) then
return false
endif
return true
endfunction

function Trig_StormofPain_Func004002003001001 takes nothing returns boolean
return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction

function Trig_StormofPain_Func004002003001002 takes nothing returns boolean
return ( GetFilterUnit() != udg_caster )
endfunction

function Trig_StormofPain_Func004002003001 takes nothing returns boolean
return GetBooleanAnd( Trig_StormofPain_Func004002003001001(), Trig_StormofPain_Func004002003001002() )
endfunction

function Trig_StormofPain_Func004002003002 takes nothing returns boolean
return ( IsUnitEnemy(GetFilterUnit(), udg_Mistressplayer) == true )
endfunction

function Trig_StormofPain_Func004002003 takes nothing returns boolean
return GetBooleanAnd( Trig_StormofPain_Func004002003001(), Trig_StormofPain_Func004002003002() )
endfunction

function Trig_StormofPain_Actions takes nothing returns nothing
local unit target
local location point
local location pointmax
local timer time
local effect E
local lightning L
local group G
local integer I
set udg_caster = gg_unit_Edem_0001
call StartTimerBJ( time, false, 30 )

loop
exitwhen I==30
set point = GetUnitLoc(udg_caster)
set G = GetUnitsInRangeOfLocMatching(500.00, point, Condition(function Trig_StormofPain_Func004002003))
set target = GroupPickRandomUnit(G)
set pointmax = GetUnitLoc(target)
call AddSpecialEffectLocBJ( pointmax, "Abilities\\Spells\\Demon\\DemonBoltImpact\\DemonBoltImpact.mdl" )
set E = GetLastCreatedEffectBJ()
call AddLightningLoc( "AFOD", point, pointmax )
set L = GetLastCreatedLightningBJ()
call TriggerSleepAction( 0.30 )
call DestroyLightningBJ( L )
call DestroyEffectBJ( E )
call UnitDamageTargetBJ( udg_caster, target, 500.00, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL )
set I = R2I(TimerGetElapsed(time))
set G = null
set target = null
set point = null
set pointmax = null
set E = null
set L = null
endloop
call DestroyTimer( time )
set time = null
endfunction

//===========================================================================
function InitTrig_StormofPain takes nothing returns nothing
set gg_trg_StormofPain = CreateTrigger( )
call TriggerRegisterUnitEvent( gg_trg_StormofPain, gg_unit_Edem_0001, EVENT_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_StormofPain, Condition( function Trig_StormofPain_Conditions ) )
call TriggerAddAction( gg_trg_StormofPain, function Trig_StormofPain_Actions )
endfunction

I've copied it to the trigger editor but it wont run. The WE doenst give any errors when i save the map with this, so i cant get any help from that.

Can someone help me out with this because im clueless at this point.
(oh, how do i get the colors for the code that the editor uses?)

Thanks,
frenksel
 
Level 5
Joined
May 22, 2006
Messages
150
Do not throw some parts to him and then let him starve. ^^

JASS:
function Trig_StormOfPain_Unitfilter takes nothing returns boolean 
  return GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE) <= 0 and GetFilterUnit() != udg_caster and IsUnitEnemy(GetFilterUnit(),udg_mistressplayer)
endfunction

function Trig_StormOfPain_Actions takes nothing returns nothing
  local effect E
  local filterfunc validTargets
  local group G
  local lightning L
  local real I
  local timer time
  local unit target
  if GetSpellAbilityId() == 'AEim' then
    set udg_caster = gg_unit_Edem_0001
    set validTargets = Filter(function Trig_StormOfPain_Unitfilter)
    set G = CreateGroup()
    set time = CreateTimer()
    call TimerStart(time,30,false,null)
    loop
      call GroupEnumUnitsInRange(G,GetUnitX(udg_caster),GetUnitY(udg_caster),500,validTargets)
      set target = GroupPickRandomUnit(G)
      set E = AddSpecialEffectTarget("Abilities\\Spells\\Demon\\DemonBoltImpact\\DemonBoltImpact.mdl",target,"origin")
      set L = AddLightningEx("AFOD",true,GetUnitX(udg_caster),GetUnitY(udg_caster),GetUnitFlyHeight(udg_caster),GetUnitX(target),GetUnitY(target),GetUnitFlyHeight(target))
      call TriggerSleepAction(0.3)
      call DestroyLightning(L)
      call DestroyEffect(E)
      call UnitDamageTarget(udg_caster,target,500,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS) 
      call GroupClear(G)
      set I = TimerGetElapsed(time)
      exitwhen I >= 30
    endloop
    call DestroyFilter(validTargets)
    call DestroyGroup(G)
    call DestroyTimer(time)
  endif
  set E = null
  set validTargets = null
  set G = null
  set L = null
  set time = null
  set target = null
endfunction

function InitTrig_StormOfPain takes nothing returns nothing
  set gg_trg_StormOfPain = CreateTrigger()
  call TriggerRegisterUnitEvent(gg_trg_StormOfPain,gg_unit_Edem_0001,EVENT_UNIT_SPELL_EFFECT)
  call TriggerAddAction(gg_trg_StormOfPain,function Trig_StormOfPain_Actions)
endfunction

It should work... I guess. ^^
Some things to think about:

If udg_mistressplayer == GetUnitOwner(udg_caster) then
remove "and GetFilterUnit() != udg_caster" from the filter function.

If you want to make this map be multiplayable, you should remove the line "call TriggerSleepAction(0.3)" from the main function and replace it with
JASS:
local timer notTime = CreateTimer()
to the other locals
JASS:
TimerStart(notTime,0.30,false,null)
loop
  call TriggerSleepAction(0.01)
  exitwhen TimerGetRemaining(notTime) <= 0
endloop
call DestroyTimer(notTime)
to the former place of "TriggerSleepAction(0.3)
JASS:
set notTime = null
to the other locals null-settings.

As you reset the value of "udg_caster" on every call of the main function, you may use a local variable instead to make the whole thing multiinstanceable.
(... and to save the little amount of memory, one variable takes, as long as the main function is not called or not called again.)
 
Level 2
Joined
Oct 2, 2006
Messages
24
back for more

Hello,

Thanks for not letting me starve. I've studied ur replie and it really helped me out. Made me a bit wiser.
However the WE, and JassShopPro now comes up with comilling errors. Here's the script:

JASS:
function Trig_StormOfPain_Unitfilter takes nothing returns boolean
    return GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE) <= 0 and IsUnitEnemy(GetFilterUnit(),udg_Mistressplayer)
endfunction

function Trig_StormOfPain_Actions takes nothing returns nothing 
local effect E
local filterfunc validTargets
local group G
local lightning L
local real I
local timer time
local unit target
local unit caster
local timer notTime = CreateTimer()
    if ( GetSpellAbilityId() == 'AEim' ) then
        set caster = GetSpellAbilityUnit()
        set validTargets = Filter(function Trig_StormOfPain_Unitfilter)
        set G = CreateGroup()
        set time = CreateTimer()
        call TimerStart(time,30,false,null)
        loop
            call GroupEnumUnitsInRange(G,GetUnitX(caster),GetUnitY(caster),500,validTargets)
            set target = GroupPickRandomUnit(G)
            set E = AddSpecialEffectTarget("Abilities\\Spells\\Demon\\DemonBoltImpact\\DemonBoltImpact.mdl",target,"origin")
            set L = AddLightningEx("AFOD",true,GetUnitX(caster),GetUnitY(caster),GetUnitFlyHeight(caster),GetUnitX(target),GetUnitY(target),GetUnitFlyHeight(target))
            call TimerStart(notTime,0.30,false,null)
            loop
                call TriggerSleepAction(0.01)
                exitwhen TimerGetRemaining(notTime) <= 0
            endloop
            call DestroyTimer(notTime)            
            call DestroyLightning (L)
            call DestroyEffect(E)
            call UnitDamageTarget(caster,target,500,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
            call GroupClear(G)
            set I = TimerGetElapsed(time)
            exitwhen I >=30
        endloop
    endif
    set E = null
    set validTargets = null
    set G = null
    set L = null
    set time = null
    set target = null
    set caster = null
    set notTime = null
endfunction

function InitTrig_StormOfPain takes nothing returns nothing
    set gg_trg_StormOfPain = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_StormOfPain,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(gg_trg_StormOfPain,function Trig_StormOfPain_Actions)
endfunction

I've made it not specificly for Edem_0001 but for a generic unit.
The JassShop tells me the gg_trg_StormOfPain is a unknown word, and that function StormOfPain Actions is never used, just like the inittrig. Once again im freaked out by Jass.

An other question:

What is the difference between my TriggerSleepAction 0.3 and the new line with the loop that waits 0.01 for 0.3 secs?

Thanks again,
Frenksel
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
What is the difference between my TriggerSleepAction 0.3 and the new line with the loop that waits 0.01 for 0.3 secs?

will take a helluva lot longer :D

(.01s is actually more like .27s in waits)

anyways...

i looked thru ur code, and couldnt c any errors, so i cheated a little and ran it thru JASSCraft, and the only errors it gave me were
expected a variable ( gg_trg_StormOfPain )
and
expected a variable ( w/e global u used went here )

which are both perfectly expected. this means that you problem is not directly with this trigger, its just the WE being stupid :?
 
Level 2
Joined
Oct 2, 2006
Messages
24
erhm :? .... grrr :x ...grmbl... :evil:
This aint the first time i had to edit some triggers for WE, wish i had know this sooner woulda saved me a helluva load on work.

Ah well,
Thanks,
frenksel
 
Level 5
Joined
May 22, 2006
Messages
150
What is the difference between my TriggerSleepAction 0.3 and the new line with the loop that waits 0.01 for 0.3 secs?

Well, just "it takes longer" is not the whole answer...
In case you want a map to be played by more than one player on more than one computer, the function "TriggerSleepAction" starts to behave odd:
Depending on the speed of the host computer in relation to the others, wait times become more or less long than they should be.

As this difference between "should-be" and "is" seems to be strictly procentual, it is a simple way of damage control:

Let us say, a delay of +30% of wait time is expected.
Now we have the simple function call and a loop:

JASS:
call TriggerSleepAction(50)
JASS:
call TimerStart(timer,50,false,null
loop
  call TriggerSleepAction(0.01)
  exitwhen TimerGetRemaining(timer) <= 0
endloop

First case: The trigger waits 65 seconds (+15 seconds)
Second case: The trigger waits 50.011 seconds (+0.011 seconds)

Of course, as purplePoot said: The loop (which is 3847 times executed in the example) needs more processing time and raises the game's possiblity to flag on lower level systems. ~~

... Just today I got an idea, how this may be eluded:
JASS:
function localWait takes nothing returns nothing
  if GetEnumPlayer == GetLocalPlayer then
    call TriggerSleepAction(50)
  endif
endfunction

call ForForce(bj_FORCE_ALL_PLAYERS,function localWait)
I have no idea if it does, but at least it may work. ^^
 
Level 2
Joined
Oct 2, 2006
Messages
24
the WE problem is over, no idea why so thats just fine. But now something else occured.

The loop doesnt loop...

It creates 1 redlighting for about 30s and then its over.

JASS:
function Trig_StormOfPain_Unitfilter takes nothing returns boolean
    return GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE) <= 0 and IsUnitEnemy(GetFilterUnit(),udg_Mistressplayer)
endfunction

function Trig_StormOfPain_Actions takes nothing returns nothing 
local effect E
local filterfunc validTargets
local group G
local lightning L
local real I
local timer time
local unit target
local unit caster
local timer notTime = CreateTimer()
    if ( GetSpellAbilityId() == 'AEim' ) then
        set caster = GetSpellAbilityUnit()
        set validTargets = Filter(function Trig_StormOfPain_Unitfilter)
        set G = CreateGroup()
        set time = CreateTimer()
        call TimerStart(time,30,false,null)
        loop
            call GroupEnumUnitsInRange(G,GetUnitX(caster),GetUnitY(caster),500,validTargets)
            set target = GroupPickRandomUnit(G)
            set E = AddSpecialEffectTarget("Abilities\\Spells\\Demon\\DemonBoltImpact\\DemonBoltImpact.mdl",target,"overhead")
            set L = AddLightningEx("AFOD",true,GetUnitX(caster),GetUnitY(caster),GetUnitFlyHeight(caster),GetUnitX(target),GetUnitY(target),GetUnitFlyHeight(target))
            call TimerStart(notTime,0.30,false,null)
            loop
                call TriggerSleepAction(0.01)
                exitwhen TimerGetRemaining(notTime) <= 0
            endloop
            call DestroyTimer(notTime)            
            call DestroyLightning (L)
            call DestroyEffect(E)
            call UnitDamageTarget(caster,target,500,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
            call GroupClear(G)
            set I = TimerGetElapsed(time)
            exitwhen I >= 30
        endloop
    endif
    set E = null
    set validTargets = null
    set G = null
    set L = null
    set time = null
    set target = null
    set caster = null
    set notTime = null
endfunction

function InitTrig_StormOfPain takes nothing returns nothing
    set gg_trg_StormOfPain = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_StormOfPain,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(gg_trg_StormOfPain,function Trig_StormOfPain_Actions)
endfunction
im clueless once again.







JASS:
function Trig_StormOfPain_Unitfilter takes nothing returns boolean
    return GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE) <= 0 and IsUnitEnemy(GetFilterUnit(),udg_Mistressplayer)
endfunction

function Trig_StormOfPain_Actions takes nothing returns nothing 
local effect E
local filterfunc validTargets
local group G
local lightning L
local real I
local timer time
local unit target
local unit caster
local timer notTime = CreateTimer()
    if ( GetSpellAbilityId() == 'AEim' ) then
        set caster = GetSpellAbilityUnit()
        set validTargets = Filter(function Trig_StormOfPain_Unitfilter)
        set G = CreateGroup()
        set time = CreateTimer()
        call TimerStart(time,30,false,null)
        loop
            call GroupEnumUnitsInRange(G,GetUnitX(caster),GetUnitY(caster),500,validTargets)
            set target = GroupPickRandomUnit(G)
            set E = AddSpecialEffectTarget("Abilities\\Spells\\Demon\\DemonBoltImpact\\DemonBoltImpact.mdl",target,"overhead")
            set L = AddLightningEx("AFOD",true,GetUnitX(caster),GetUnitY(caster),GetUnitFlyHeight(caster),GetUnitX(target),GetUnitY(target),GetUnitFlyHeight(target))
            call TimerStart(notTime,0.30,false,null)
            loop
                call TriggerSleepAction(0.01)
                exitwhen TimerGetRemaining(notTime) <= 0
            endloop
            call DestroyTimer(notTime)            
            call DestroyLightning (L)
            call DestroyEffect(E)
            call UnitDamageTarget(caster,target,500,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
            call GroupClear(G)
            set I = TimerGetElapsed(time)
            exitwhen I >= 30
        endloop
    endif
    set E = null
    set validTargets = null
    set G = null
    set L = null
    set time = null
    set target = null
    set caster = null
    set notTime = null
endfunction

function InitTrig_StormOfPain takes nothing returns nothing
    set gg_trg_StormOfPain = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_StormOfPain,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(gg_trg_StormOfPain,function Trig_StormOfPain_Actions)
endfunction
 
Level 5
Joined
May 22, 2006
Messages
150
@purplePoot:

Did you forget our pretty long discussion about this problem?

Originally it was you, who told me, that "TriggerSleepAction" is not exact, while "TimerGetRemaining(timer)" is.

Yet I am a little confused, as I reacted to that by replacing all my "TriggerSleepAction"-calls with these loop constructions - and now you tell me, that is is useless!?

... Mmh... Please explain.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
TriggerSleepAction is horribly innaccurate, meaning that the TriggerSleepAction( 0.01 ) will be ACTUALLY what would be in an ideal version of the func TriggerSleepAction( 0.27 )

since by the time this ended the timer would have .03s left, it would do that again, meaning it would wait .54 seconds.

HOWEVER, knowing TriggerSleepAction is innaccurate, TriggerSleepAction( .54 ) would be more like an ideal TriggerSleepAction( .7 ), so the actual value of the wait in terms of this function would be around TriggerSleepAction( .35 )
 
Level 5
Joined
May 22, 2006
Messages
150
Were did you get this from...

More important:
What is the value, you are examining the real wait time with?

I remember to have read something about processor speed, so that "TriggerSleepAction(x)" means a wait of x * y
with y being directly proportional to the difference between the host computer's speed and the fastest/slowest one's one.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
.27 is approx

the reason we know that TriggerSleepAction is innaccurate is this: we use handle variables

if it was accurate, we could just do a loop, and the handle vars would be comletely obsolete and pointless for almost all cases. However, seeing as TriggerSleepAction is so innaccurate, you can easily see this by trying to do exactly what logically SHOULD work.
 
Level 2
Joined
Oct 2, 2006
Messages
24
Is there a way around WE to get jass in a map?? The WE gives errors on lines that i left blank...
I got a few scripts but i cant get them to action cos of WE.

And my loop still wont loop, and that doesnt make much sense to me.

frenksel
 
Status
Not open for further replies.
Top