need help cleaning up a piece of code for abil

jig7c

Stop reading me...-statement
Reaction score
123
i need help cleaning out this code...

what i need is this ability (Illusion) to give the Hero, 10/15/20% chance to create an illusion of the attacked unit at the attacked unit's location... the Clone function is working fine(thanks to Sevion) i just need help setting up the chance and the globals... please help

Code:
scope Illusion initializer Init
    globals
        unit hero = GetAttacker()
        unit target = GetTriggerUnit()
        location l = GetUnitLoc(target)
    endglobals
    
private function Conditions takes nothing returns boolean
    local boolean b = false
    local unit u = GetTriggerUnit()
    set b = GetUnitTypeId(GetAttacker()) == 'Ekgg' and not (IsUnitType(u, UNIT_TYPE_HERO) and IsUnitType(u, UNIT_TYPE_PEON) and IsUnitType(u, UNIT_TYPE_STRUCTURE) and IsUnitType(u, UNIT_TYPE_MECHANICAL))
    set u = null
    return b
endfunction


function Level1 takes nothing returns boolean
    return (GetUnitAbilityLevel(hero, 'A028') ==1) and (GetRandomInt(1, 100) <= 10 )
endfunction

function Level2 takes nothing returns boolean
    return (GetUnitAbilityLevel(hero, 'A028') ==2) and (GetRandomInt(1, 100) <= 15 )
endfunction

function Level3 takes nothing returns boolean
   return (GetUnitAbilityLevel(hero, 'A028') ==3) and (GetRandomInt(1, 100) <= 20 )
endfunction

function Actions takes nothing returns nothing
 local unit u
 local real r = GetUnitState(target, UNIT_STATE_LIFE)
 
    if ( Level1() ) then
        call CloneUnit( target, l )
        set u = GetLastCreatedUnit ()
        call SetUnitState( u, UNIT_STATE_LIFE,r )
        call SetUnitOwner( u, GetOwningPlayer(hero), true )
        call SetUnitVertexColor( u, GetRandomInt(0, 100), GetRandomInt(0, 100), GetRandomInt(0, 100), 50 )
        call IssueTargetOrder ( u, "attack", target )
        call UnitApplyTimedLife (u,'BFig' ,5.00)
        call CreateTextTagManaBurn( GetUnitName(target), l )
        call RemoveLocation(l)
    else
    endif
    if ( Level2() ) then
        call CloneUnit( target, l )
        set u = GetLastCreatedUnit()
        call SetUnitState ( u,UNIT_STATE_LIFE, r )
        call SetUnitOwner( u, GetOwningPlayer(hero), true )
        call SetUnitVertexColor( u, GetRandomInt(0, 100), GetRandomInt(0, 100), GetRandomInt(0, 100), 50 )
        call IssueTargetOrder( u, "attack", target )
        call UnitApplyTimedLife (u,'BFig' ,7.00)
        call CreateTextTagManaBurn( GetUnitName(target), l )
        call RemoveLocation(l)
    else
    endif
    if ( Level3() )then
        call CloneUnit( target, l )
        set u = GetLastCreatedUnit()
        call SetUnitState( u, UNIT_STATE_LIFE, r)
        call SetUnitOwner( u, GetOwningPlayer(hero), true )
        call SetUnitVertexColor( u, GetRandomInt(0, 100), GetRandomInt(0, 100), GetRandomInt(0, 100), 50 )
        call IssueTargetOrder (u, "attack", target )
        call UnitApplyTimedLife (u,'BFig', 9.00)
        call CreateTextTagManaBurn( GetUnitName(target), l )
        call RemoveLocation(l)
    else
    endif
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger i = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( i, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( i, Condition( function Conditions ) )
    call TriggerAddAction( i, function Actions )
endfunction
endscope
 

Ayanami

칼리
Reaction score
288
I suggest you use JASS tags rather than CODE tags.

You could do it this way:

JASS:

private function GetChance takes integer level returns real
    return 5 + (5 * level)
endfunction

private function GetDuration takes integer level returns real
    return 3 + (2 * level)
endfunction


Then, in your actions code:

JASS:

function Actions takes nothing returns nothing
    local unit u = GetAttacker()
    local unit t = GetTriggerUnit()
    local unit d
    local location l = GetUnitLoc(t)
    local integer level = GetUnitAbilityLevel(u, &#039;A028&#039;)

    if GetRandomInt(0, 100) &lt;= GetChance(level) then
        call CloneUnit(t, l)
        set d = GetLastCreatedUnit ()
        call SetWidgetLife(d, GetWidgetLife(t))
        call SetUnitOwner( d, GetOwningPlayer(u), true )
        call SetUnitVertexColor( d, GetRandomInt(0, 100), GetRandomInt(0, 100), GetRandomInt(0, 100), 50 )
        call IssueTargetOrder ( d, &quot;attack&quot;, t )
        call UnitApplyTimedLife (d,&#039;BFig&#039; ,GetDuration(level))
        call CreateTextTagManaBurn( GetUnitName(t), l )
        call RemoveLocation(l)
    endif
 
    set u = null
    set t = null
    set d = null
    set l = null
endfunction


I'm pretty sure that the way you use your global is wrong. You can't directly set the variables to [ljass]GetTriggerUnit()[/ljass] and [ljass]GetAttacker()[/ljass] when you declare them.
 

jig7c

Stop reading me...-statement
Reaction score
123
i can't seem to find the jass tags..i been looking and looking.. im forced to use code tags...

thanks glenphir

can i set

global
integer level = GetUnitAbilityLevel (u, 'A028')
endglobal

then getchance
then getduration
then action...

since level is being used in each function??
 

Ayanami

칼리
Reaction score
288
i can't seem to find the jass tags..i been looking and looking.. im forced to use code tags...

thanks glenphir

can i set

global
integer level = GetUnitAbilityLevel (u, 'A028')
endglobal

then getchance
then getduration
then action...

since level is being used in each function??

You can't. If you do that, the global variable will not know what "u" is. You need to understand that globals cannot be used that way. Globals are not set every time the trigger runs. They are set to their initial value only on initialization. You can't set a global to [ljass]GetAttacker()[/ljass] directly. [ljass]GetAttacker()[/ljass] is only defined by the event. Same for [ljass]GetUnitAbilityLevel()[/ljass]. The system won't know what unit "u" is, you have to define it on every "Actions" function.
 

chobibo

Level 1 Crypt Lord
Reaction score
48
Hello guys.
JASS:

scope Clone initializer Init
    
    globals
        private constant integer    SPELL_ID                =   &#039;A028&#039;
        private constant integer    SPELL_UNIT_TYPE         =   &#039;Ekgg&#039;
    
    
        private constant integer    SPELL_BASE_DURATION     =   5
        private constant integer    SPELL_CONSTANT_FACTOR   =   2
        private constant integer    SPELL_CHANCE_BASE       =   10
        private constant integer    CHANCE_CONSTANT_FACTOR  =   5
        
        private location tempLoc                            =   Location(0,0)
    endglobals
    
    private function Conditions takes nothing returns boolean
        local boolean b = false
        local unit u = GetTriggerUnit()
        set b = GetUnitTypeId(GetAttacker()) == SPELL_UNIT_TYPE  and not (IsUnitType(u, UNIT_TYPE_HERO) and IsUnitType(u, UNIT_TYPE_PEON) and IsUnitType(u, UNIT_TYPE_STRUCTURE) and IsUnitType(u, UNIT_TYPE_MECHANICAL)) and GetUnitAbilityLevel(GetAttacker(), SPELL_ID) &gt; 0
        set u = null
        return b
    endfunction

    function Actions takes nothing returns nothing
        local integer   level       =   GetUnitAbilityLevel(GetAttacker(), SPELL_ID)-1
        local boolean   lucky       =   GetRandomInt(1, 100) &lt;= SPELL_CHANCE_BASE + CHANCE_CONSTANT_FACTOR * level
        
        local integer   duration    =   0
        local real      newHP       =   0
        
        local unit      attacker    =   null
        local unit      attacked    =   null
        local unit      illusion    =   null
        
        if lucky then

            set attacker    =   GetAttacker()
            set attacked    =   GetTriggerUnit()
            call MoveLocation( tempLoc, GetUnitX(attacked), GetUnitY(attacked) )
            set illusion    =   CreateUnitAtLoc(GetOwningPlayer(attacker), GetUnitTypeId(attacked), tempLoc, 0)
            
            set duration    =   SPELL_BASE_DURATION + SPELL_CONSTANT_FACTOR * level
            set newHP       =   GetUnitState(attacked, UNIT_STATE_LIFE)

            call SetUnitState( illusion, UNIT_STATE_LIFE, newHP )
            call SetUnitVertexColor( illusion, 255, 255/2, 255, 255 )
            call IssueTargetOrder ( illusion, &quot;attack&quot;, attacked )
            call UnitApplyTimedLife ( illusion, &#039;BFig&#039; , I2R(duration) )
            call CreateTextTagManaBurn( GetUnitName(attacked), tempLoc )

            set attacker    =   null
            set attacked    =   null
            set illusion    =   null
            
        endif
        
    endfunction

    //===========================================================================
    private function Init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_ATTACKED )
        call TriggerAddCondition( trig, Condition( function Conditions ) )
        call TriggerAddAction( trig, function Actions )
    endfunction
    
endscope


EDIT: Fixed it already, I switched the ABILITY ID with the UNIT TYPE ID, that's why it wasn't working. Sorry dude.
 

jig7c

Stop reading me...-statement
Reaction score
123
the above code doesn't work...
it doesn't make no illusions at any level...
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top