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

[JASS] Simple Passive Spell...

Status
Not open for further replies.
Level 29
Joined
Mar 10, 2009
Messages
5,016
I have this code and it works just fine...
But I have some few questions...


JASS:
function Doppel takes nothing returns nothing
    local unit Attacked = GetTriggerUnit()
    local unit Attacker = GetAttacker()
    local unit Doppelganger
    local integer randomizer = GetRandomInt(1,100) 
    local integer abilityID = 'AHab' // <<< Can be customized
    local integer abilitylevel = GetUnitAbilityLevel(Attacked, abilityID)
    local integer castok = 5 * abilitylevel 
    local string SFX = "Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl"
    if randomizer <= castok and GetUnitAbilityLevel(Attacked, abilityID) >= 0 and IsUnitEnemy(Attacker, GetOwningPlayer(Attacked)) and IsUnitType(Attacked, UNIT_TYPE_HERO) then
       call DisplayTextToPlayer(Player(0), 0, 0, I2S(castok))
       set Doppelganger = CreateUnit(GetOwningPlayer(Attacked), GetUnitTypeId(Attacker), GetUnitX(Attacker), GetUnitY(Attacker), 0)  
       call DestroyEffect(AddSpecialEffect(SFX, GetUnitX(Doppelganger), GetUnitY(Doppelganger)))
       call UnitApplyTimedLife(Doppelganger, 'BTLF', 15.0)
    endif
    set Attacked = null
    set Attacker = null  
    set Doppelganger = null   
endfunction
 
//==== Init Trigger Doppelganger ====
 
function InitTrig_Doppelganger takes nothing returns nothing
    local trigger t                         = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ      (t, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddAction                   (t, function Doppel)
    set t = null        
endfunction
1. is there any way to shorten the "If randomizer blahhh and blahhh and blahhh..."

2. Can I use "filterfunc >>> Filter>>>Condition" for this? coz I've tried and I got an error...pls show me how to do it correctly...

3. I did this before and its not functioning well, why?...
JASS:
if randomizer <= castok and abilitylevel >= 0 .........
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
#1 [a] Store them in variables, at the expense of consuming more memory.
#1 Setup a triggercondition for the trigger.
#2 I'm not sure but I think boolexpr's can't be used like boolean variables or functions returning boolean.
#3 Enclose them in brackets; (abilitylevel >= 0)
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
OK perhaps my question was not so clear...

1. I mean, Shorten like this...
JASS:
if randomizer <= castok and
        GetUnitAbilityLevel(Attacked, abilityID) >= 0 and 
        IsUnitEnemy(Attacker, GetOwningPlayer(Attacked)) and
        IsUnitType(Attacked, UNIT_TYPE_HERO) then
endif

2. I use like this "local filterfunc cond = Filter(function sample)" but I dont
how to setup conditions to it except using triggercondition...

3. Ok I mean it also worked but it's getting the same results, castok is always 10...
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
Still error...

JASS:
  if randomizer <= castok and /*
       */ GetUnitAbilityLevel(Attacked, abilityID) >= 0 and /*
       */ IsUnitEnemy(Attacker, GetOwningPlayer(Attacked)) and /*
       */ IsUnitType(Attacked, UNIT_TYPE_HERO) then
            call DisplayTextToPlayer(Player(0), 0, 0, I2S(castok))
            set Doppelganger = CreateUnit(GetOwningPlayer(Attacked), GetUnitTypeId(Attacker), GetUnitX(Attacker), GetUnitY(Attacker), 0)  
            call DestroyEffect(AddSpecialEffect(SFX, GetUnitX(Doppelganger), GetUnitY(Doppelganger)))
            call UnitApplyTimedLife(Doppelganger, 'BTLF', 15.0)        
endif
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
JASS:
if randomizer <= castok and/*
        */ GetUnitAbilityLevel(Attacked, abilityID) >= 0 and/*
        */ IsUnitEnemy(Attacker, GetOwningPlayer(Attacked)) and/*
        */ IsUnitType(Attacked, UNIT_TYPE_HERO) then
endif

Shouldn't it be like this? Or, works for me. (In JNGP but whatever, should work with normal we too or?)

JASS:
if randomizer <= castok and /*
        */GetUnitAbilityLevel(Attacked, abilityID) >= 0 and /*
        */IsUnitEnemy(Attacker, GetOwningPlayer(Attacked)) and /*
        */IsUnitType(Attacked, UNIT_TYPE_HERO) then
endif
 
1. You can use seperate booleans, but it is less efficient. For example:
JASS:
    local boolean b1 = (randomizer <= castok)
    local boolean b2 = GetUnitAbilityLevel(Attacked, abilityID) >= 0
    local boolean b3 = IsUnitEnemy(Attacker, GetOwningPlayer(Attacked))
    local boolean b4 = IsUnitType(Attacked, UNIT_TYPE_HERO)
    if b1 and b2 and b3 and b4 then
        //...actions...
    endif

Otherwise, you can't really shorten it in plain JASS.

2. You can't evaluate boolexprs without using triggers/a group or some other variant. However, you can just create a function that returns boolean:
JASS:
    function cond takes integer r, integer c, unit attk, integer id, unit attacker returns boolean
        return (r <= c) and (GetUnitAbilityLevel(attk,id) >= 0) and IsUnitEnemy(attacker,GetOwningPlayer(attk)) and IsUnitType(attk,UNIT_TYPE_HERO)
    endfunction

And then just use:
JASS:
    if cond(randomizer, castok, Attacked, abilityID, Attacker) then

3. castok will always be 10 if the unit's ability level is 2.

@baassee: Comment delimiters are a vJASS feature. ;) Also, both of those two codes should have the same result.
 
Status
Not open for further replies.
Top