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.
  • 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 The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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