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

[vJASS] function take integer question

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Hi,
when i have a function which take integer...
call function(integer)

function A takes integer x returns nothing
local integer y
display x
wait 1.00
set y = x +2
endfunction

my question is what kind of integer variable is x?
is it local integer? so if i have wait (triggersleepaction) and the function is long,
it will never be over written by other call?
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
Hi,
when i have a function which take integer...
call function(integer)

function A takes integer x returns nothing
local integer y
display x
wait 1.00
set y = x +2
endfunction

my question is what kind of integer variable is x?
is it local integer? so if i have wait (triggersleepaction) and the function is long,
it will never be over written by other call?

It's a function parameter, so it's a local. Thus, no overwriting is possible unless you do it on purpose.
 
Level 4
Joined
Jan 27, 2010
Messages
133
if i have wait (triggersleepaction) and the function is long

Just to clarify, you never want to use long waits (and some people would even tell you never to use waits at all). If the game is paused by triggers, or paused by "waiting for players", then waits happily continue the count-down.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
well the wait i use in the trigger isn't timed wait...
it is just a wait to help computer breath between code processing...
each time i do many loop or many coding goes on, i put some wait between so it has time to process...

i fear that some player would disconnect if too many operation goes on without so pausing in the code.
so it doesn't matter if the code continue while people pause the game.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
it is just a wait to help computer breath between code processing...
each time i do many loop or many coding goes on, i put some wait between so it has time to process...

i fear that some player would disconnect if too many operation goes on without so pausing in the code.
so it doesn't matter if the code continue while people pause the game.

that idea is wrong. You can use Waits to deal with the op-limit, but jass commands inside of one thread are getting executed in strict sequential order.
This means: The computer always takes one piece of code and executes it. After it is done executing that command it will start with the next command. He will never start executing a piece of code before the previous one hasnt finished execution.
You dont really have to give the computer "time to rest".
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
well let's say i have 1000 of operation in the same trigger
and i don't care if it takes 1 or 3 sec to execute them as long as they are done
and these are periodic OP
so you say it is bad to separate some of them with 3 to 4 little wait 0.10 ?
wait won't help people computer to synchronise?
wait shouldn't be a very heavy operation, basically it equal do nothing
it am not expert, but doing nothing and increasing the length time for trigger execution, should help computer wich lag behind a little, no?

it is same thing as creating 1000 of units, it will lag...
if create a few, wait with timer real 0.01 or 0.1 and repeat OP multiple time will decrease lag by a hell lot.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Hum, so wait are bad.....
but how can i use timer to replace wait in this library?
the function CheckPlayer in the library is runned every 3 sec 12 times (one for each players)
how can i improve it and make it better without wait?
also the wait 0.5 in the coma section is very important...because the dummy unit created cannot see the target if he doesn't wait 0.5 sec, because vision ability to see invi on a just created unit take 0.5 sec to activate.

[Jass=]
library BioSupport

private function arcanum takes unit u returns boolean
local integer i = 1
loop
exitwhen i > 6
if GetItemTypeId(UnitItemInSlot(u, i)) == 'I060' then
return true
endif
set i = i +1
endloop
return false
endfunction

public function CheckPlayer takes integer p returns nothing
local unit dummy
local real x
local real y
// ===== Water Wet Effect =====
set x = GetUnitX(udg_Hero_Troll)
set y = GetUnitY(udg_Hero_Troll)
if IsTerrainPathable( x, y, PATHING_TYPE_FLOATABILITY) == false then
if udg_ProtectWater == false then
set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
call UnitAddAbility( dummy, 'ACcs' )
if udg_ProtectSlip == false then
if udg_Slippery == false then
set udg_Slippery = true
set udg_Crit_power = ( udg_Crit_power - 1 )
endif
else
call SetUnitAbilityLevel( dummy, 'ACcs', 2 )
endif
call IssueTargetOrder( dummy, "curse", udg_Hero_Troll )
set dummy =null
endif
elseif GetUnitAbilityLevel(udg_Hero_Troll, 'BUfa') == 0 and GetUnitAbilityLevel(udg_Hero_Troll, 'Bapl') == 0 and udg_Rain == true then
if udg_ProtectRain == false then
set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
call UnitAddAbility( dummy, 'ACcs' )
if udg_ProtectSlip == false then
if udg_Slippery == false then
set udg_Slippery = true
set udg_Crit_power = ( udg_Crit_power - 1 )
endif
else
call SetUnitAbilityLevel( dummy, 'ACcs', 2 )
endif
call IssueTargetOrder( dummy, "curse", udg_Hero_Troll )
set dummy =null
endif
endif
call TriggerSleepAction( 0.10 ) // un-needed wait use to give more time to process
if GetUnitAbilityLevel(udg_Hero_Troll, 'BUfa') == 0 then
if udg_Slippery == true then
set udg_Slippery = false
set udg_Crit_power = ( udg_Crit_power + 1 )
endif
else
if GetUnitAbilityLevel(udg_Hero_Troll, 'Bapl') == 0 then
set udg_WetEffect = 2
else
set udg_WetEffect = 1
endif
endif
// ===== Frozen by Cold =====
if GetPlayerState(Player(p-1), PLAYER_STATE_RESOURCE_LUMBER) <= 0 and udg_Frozen == false then
set udg_MB_Frozen = "Yes"
set udg_Frozen = true
call UnitAddAbility( udg_Hero_Troll, 'A00P' )
endif
if udg_Frozen == true then
if udg_Boat == true then
call UnitAddAbility( udg_BoatLoaded, 'A00P' )
call SetUnitAbilityLevel( udg_BoatLoaded, 'A00P', 2 )
endif
endif
if GetPlayerState(Player(p-1), PLAYER_STATE_RESOURCE_LUMBER) <= 0 and GetRandomInt(1, 10) == 1 and GetUnitAbilityLevel(udg_Hero_Troll, 'Brej') == 0 then
set x = GetUnitX(udg_Hero_Troll)
set y = GetUnitY(udg_Hero_Troll)
set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
call UnitAddAbility( dummy, 'ACff' )
call IssueTargetOrder( dummy, "faeriefire", udg_Hero_Troll )
set dummy =null
endif
// ===== Unfrozen by Heat =====
if GetPlayerState(Player(p-1), PLAYER_STATE_RESOURCE_LUMBER) >= 50 and udg_Frozen == true then
set udg_MB_Frozen = "No"
set udg_Frozen = false
call UnitRemoveAbility( udg_Hero_Troll, 'A00P' )
call UnitRemoveAbility( udg_BoatLoaded, 'A00P' )
endif
call TriggerSleepAction( 0.10 ) // un-needed wait use to give more time to process
// ===== Coma Energy is 0 =====
if udg_Sleeping == false and udg_Coma == false and udg_Eaten == false and GetUnitState( udg_Hero_Troll, UNIT_STATE_MANA) <= 0.00 then
call SetUnitState(udg_Basic_Crafting, UNIT_STATE_MANA, 200.)
set udg_Coma = true
set udg_MB_Coma = "Yes"
call UnitRemoveBuffBJ( 'Binv', udg_Hero_Troll )
call UnitRemoveBuffBJ( 'BOwk', udg_Hero_Troll )
set x = GetUnitX(udg_Hero_Troll)
set y = GetUnitY(udg_Hero_Troll)
set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
call UnitAddAbility( dummy, 'A0MA' )
call TriggerSleepAction( 0.50 ) //very important cannot target unless 0.5sec has passed after unit was created
call IssueTargetOrder( dummy, "creepthunderbolt", udg_Hero_Troll )
set dummy =null
call UnitAddAbility( udg_Hero_Troll, 'A00B' )
set udg_Sleep_Troll = 'A00B'
call TriggerSleepAction( 0.10 ) // un-needed wait use to give more time to process
call SetUnitAnimation( udg_Hero_Troll, "death" )
endif
// ===== Starving =====
if GetPlayerState(Player(p-1), PLAYER_STATE_RESOURCE_GOLD) <= 0 then
if udg_Starving == false then
set udg_MB_Starving = "Yes"
call UnitAddAbility( udg_Hero_Troll, 'A00M' )
set udg_Starving = true
endif
else
if udg_Starving == true then
set udg_MB_Starving = "No"
call UnitRemoveAbility( udg_Hero_Troll, 'A00M' )
set udg_Starving = false
endif
endif
// ========== SLEEP BONUS ==========
if GetUnitAbilityLevel(udg_Hero_Troll, 'A04F') > 0 or GetUnitAbilityLevel(udg_Hero_Troll, 'A04S') > 0 or GetUnitAbilityLevel(udg_Hero_Troll, 'A04L') > 0 or GetUnitAbilityLevel(udg_Hero_Troll, 'A04R') > 0 or GetUnitAbilityLevel(udg_Hero_Troll, 'A0HF') > 0 or GetUnitAbilityLevel(udg_Hero_Troll, 'A0HX') > 0 or GetUnitAbilityLevel(udg_Hero_Troll, 'A0HW') > 0 then then
call SetPlayerState( Player(p-1), PLAYER_STATE_RESOURCE_GOLD, ( 5 - udg_GameDiff ) )
endif
// ========== INVISIBILITY BONUS ==========
if arcanum(udg_Hero_Troll) and GetRandomInt(1, 4) == 1 then
if GetUnitAbilityLevel(udg_Hero_Troll, 'A0DY') == 0 then
call UnitAddAbility( udg_Hero_Troll, 'A0DY' )
endif
else
call UnitRemoveAbility( udg_Hero_Troll, 'A0DY' )
endif
if GetUnitAbilityLevel(udg_Hero_Troll, 'B01R') > 0 then
if GetUnitAbilityLevel(udg_Hero_Troll, 'A0DY') == 0 then
call UnitAddAbility( udg_Hero_Troll, 'A0DY' )
endif
else
call UnitRemoveAbility( udg_Hero_Troll, 'A0DY' )
endif
endfunction
endlibrary
[/code]
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Try to cut down on the calling functions like getunitabilitylvl store them as a local integer. Anything tht u call more than once set it as a local integer and use the I integer. Also I noticed a couple if blocks tht did the same thing if they have to be in both spots the make a new function and do a function call to make the code shorter. The .1 second waits u can take all of them out they aren't needed. The .5 second wait I've never heard of the time limit for targeting hopefully someone else will know. As for the rest I can't really look at it sry hopefully someone helps u in the meantime
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
ok here the thing reworked with deathismyfriend suggestion.

[Jass=]
library BioSupport

private function arcanum takes unit u returns boolean
local integer i = 1
loop
exitwhen i > 6
if GetItemTypeId(UnitItemInSlot(u, i)) == 'I060' then
return true
endif
set i = i +1
endloop
return false
endfunction

public function CheckPlayer takes integer p returns nothing
local unit dummy
local real x = GetUnitX(udg_Hero_Troll)
local real y = GetUnitY(udg_Hero_Troll)
local integer wetbuff = GetUnitAbilityLevel(udg_Hero_Troll, 'BUfa')
local integer heatbuff = GetUnitAbilityLevel(udg_Hero_Troll, 'Bapl')
local integer springbuff = GetUnitAbilityLevel(udg_Hero_Troll, 'BHab')
local integer feverbuff = GetUnitAbilityLevel(udg_Hero_Troll, 'Brej')
local integer shelterbuff = GetUnitAbilityLevel(udg_Hero_Troll, 'B01R')
local integer bear = GetUnitAbilityLevel(udg_Hero_Troll, 'A04F')
local integer pig = GetUnitAbilityLevel(udg_Hero_Troll, 'A04S')
local integer hutt = GetUnitAbilityLevel(udg_Hero_Troll, 'A04L')
local integer saber = GetUnitAbilityLevel(udg_Hero_Troll, 'A04R')
local integer hunter = GetUnitAbilityLevel(udg_Hero_Troll, 'A0HF')
local integer other = GetUnitAbilityLevel(udg_Hero_Troll, 'A0HX')
local integer shaman = GetUnitAbilityLevel(udg_Hero_Troll, 'A0HW')
local integer invi = GetUnitAbilityLevel(udg_Hero_Troll, 'A0DY')
local integer heroheat = GetPlayerState(Player(p-1), PLAYER_STATE_RESOURCE_LUMBER)
local integer herohunger = GetPlayerState(Player(p-1), PLAYER_STATE_RESOURCE_GOLD)
// ===== Water Wet Effect =====
if IsTerrainPathable( x, y, PATHING_TYPE_FLOATABILITY) == false then
if udg_ProtectWater == false then
set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
call UnitAddAbility( dummy, 'ACcs' )
if udg_ProtectSlip == false then
if udg_Slippery == false then
set udg_Slippery = true
set udg_Crit_power = ( udg_Crit_power - 1 )
endif
else
call SetUnitAbilityLevel( dummy, 'ACcs', 2 )
endif
call IssueTargetOrder( dummy, "curse", udg_Hero_Troll )
set dummy =null
endif
elseif wetbuff == 0 and heatbuff == 0 and udg_Rain == true then
if udg_ProtectRain == false then
set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
call UnitAddAbility( dummy, 'ACcs' )
if udg_ProtectSlip == false then
if udg_Slippery == false then
set udg_Slippery = true
set udg_Crit_power = ( udg_Crit_power - 1 )
endif
else
call SetUnitAbilityLevel( dummy, 'ACcs', 2 )
endif
call IssueTargetOrder( dummy, "curse", udg_Hero_Troll )
set dummy =null
endif
endif
if wetbuff == 0 then
if udg_Slippery == true then
set udg_Slippery = false
set udg_Crit_power = ( udg_Crit_power + 1 )
endif
else
if springbuff == 0 then
set udg_WetEffect = 2
else
set udg_WetEffect = 1
endif
endif
// ===== Frozen by Cold =====
if heroheat <= 0 and udg_Frozen == false then
set udg_MB_Frozen = "Yes"
set udg_Frozen = true
call UnitAddAbility( udg_Hero_Troll, 'A00P' )
endif
if udg_Frozen == true then
if udg_Boat == true then
call UnitAddAbility( udg_BoatLoaded, 'A00P' )
call SetUnitAbilityLevel( udg_BoatLoaded, 'A00P', 2 )
endif
endif
if heroheat <= 0 and GetRandomInt(1, 10) == 1 and feverbuff == 0 then
set x = GetUnitX(udg_Hero_Troll)
set y = GetUnitY(udg_Hero_Troll)
set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
call UnitAddAbility( dummy, 'ACff' )
call IssueTargetOrder( dummy, "faeriefire", udg_Hero_Troll )
set dummy =null
endif
// ===== Unfrozen by Heat =====
if heroheat >= 50 and udg_Frozen == true then
set udg_MB_Frozen = "No"
set udg_Frozen = false
call UnitRemoveAbility( udg_Hero_Troll, 'A00P' )
call UnitRemoveAbility( udg_BoatLoaded, 'A00P' )
endif
// ===== Starving =====
if herohunger <= 0 then
if udg_Starving == false then
set udg_MB_Starving = "Yes"
call UnitAddAbility( udg_Hero_Troll, 'A00M' )
set udg_Starving = true
endif
else
if udg_Starving == true then
set udg_MB_Starving = "No"
call UnitRemoveAbility( udg_Hero_Troll, 'A00M' )
set udg_Starving = false
endif
endif
// ========== SLEEP BONUS ==========
if hutt > 0 or bear > 0 or saber > 0 or pig > 0 or hunter > 0 or shaman > 0 or other > 0 then
call SetPlayerState( Player(p-1), PLAYER_STATE_RESOURCE_GOLD, herohunger + ( 5 - udg_GameDiff ) ))
endif
// ========== INVISIBILITY BONUS ==========
if arcanum(udg_Hero_Troll) and GetRandomInt(1, 4) == 1 then
if invi == 0 then
call UnitAddAbility( udg_Hero_Troll, 'A0DY' )
endif
else
call UnitRemoveAbility( udg_Hero_Troll, 'A0DY' )
endif
if shelterbuff > 0 then
if invi == 0 then
call UnitAddAbility( udg_Hero_Troll, 'A0DY' )
endif
else
call UnitRemoveAbility( udg_Hero_Troll, 'A0DY' )
endif
// ===== Coma Energy is 0 =====
if udg_Sleeping == false and udg_Coma == false and udg_Eaten == false and GetUnitState( udg_Hero_Troll, UNIT_STATE_MANA) <= 0.00 then
call SetUnitState(udg_Basic_Crafting, UNIT_STATE_MANA, 200.)
set udg_Coma = true
set udg_MB_Coma = "Yes"
call UnitRemoveBuffBJ( 'Binv', udg_Hero_Troll )
call UnitRemoveBuffBJ( 'BOwk', udg_Hero_Troll )
set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
call UnitAddAbility( dummy, 'A0MA' )
call TriggerSleepAction( 0.50 )
call IssueTargetOrder( dummy, "creepthunderbolt", udg_Hero_Troll )
set dummy =null
call UnitAddAbility( udg_Hero_Troll, 'A00B' )
set udg_Sleep_Troll = 'A00B'
call SetUnitAnimation( udg_Hero_Troll, "death" )
endif
endfunction
endlibrary
[/code]

about the 0.50 sec...
i have done intensive testing...
if you create a unit, from the time it appear in game and the time it can get an order, it is instant...so you can target anything.
but if the target is invi and the unit has no vision, the targeting will fail....
so to prevent that we add the ability vision (detect invi) to the caster...
the problem is the vision ability need 0.50 sec wait in order to really function and really give vision to the caster (whether you add vision in editor or ingame is same).
upon creation the unit will need 0.50 sec...
i didn't tested on a allready there unit and adding vision to see if there is also a delay.

the only way around is A) a unit created in advance, B) a unit created owned by same player of target... (if both units (target, caster) share same vision it works) C) else need 0.50 sec...
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
one other thing i noticed is the removebuffbj change them to. full trigger is at bottom. also since ur using jass/vjass u should change over from all the udg's. do not forget to remove the dummy unit either. u have to remove it then set it to null
JASS:
call UnitRemoveAbility( udg_Hero_Troll, 'Binv' )
call UnitRemoveAbility( udg_Hero_Troll, 'BOwk' )

and for ur .5 second timer y not make a dummy in the object editor tht already has tht ability then u create tht dummy when u need him so he can see the invi units as soon as he is placed on the map this way u dont have to add the ability to the dummy unit also.

edit: this code can be shortened like this also. shorten this piece of code
JASS:
if udg_ProtectWater == false then
                set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
                call UnitAddAbility( dummy, 'ACcs' )
                if udg_ProtectSlip == false then
                    if udg_Slippery == false then
                        set udg_Slippery = true
                        set udg_Crit_power = ( udg_Crit_power - 1 )
                    endif
                else
                    call SetUnitAbilityLevel( dummy, 'ACcs', 2 )
                endif
                call IssueTargetOrder( dummy, "curse", udg_Hero_Troll )
                set dummy =null
            endif
        elseif  wetbuff == 0 and heatbuff == 0 and udg_Rain == true then
            if udg_ProtectRain == false then
                set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
                call UnitAddAbility( dummy, 'ACcs' )
                if udg_ProtectSlip == false then
                    if udg_Slippery == false then
                        set udg_Slippery = true
                        set udg_Crit_power = ( udg_Crit_power - 1 )
                    endif
                else
                    call SetUnitAbilityLevel( dummy, 'ACcs', 2 )
                endif
                call IssueTargetOrder( dummy, "curse", udg_Hero_Troll )
                set dummy =null
            endif

to this
JASS:
function slipperyFalse takes integer p, unit dummy returns nothing
    set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
    call UnitAddAbility( dummy, 'ACcs' )
    if udg_ProtectSlip == false then
        if udg_Slippery == false then
            set udg_Slippery = true
            set udg_Crit_power = ( udg_Crit_power - 1 )
        endif
    else
        call SetUnitAbilityLevel( dummy, 'ACcs', 2 )
    endif
    call IssueTargetOrder( dummy, "curse", udg_Hero_Troll )
    set dummy =null
endfunction

        if udg_ProtectWater == false then
            call slipperyFalse(p, dummy)
        elseif  wetbuff == 0 and heatbuff == 0 and udg_Rain == true then
            call slipperyFalse(p, dummy)
        endif

edit: heres the full trig i changed one other thing
JASS:
library BioSupport    
    
    private function arcanum takes unit u returns boolean
        local integer i = 1
        loop
            exitwhen i > 6
            if GetItemTypeId(UnitItemInSlot(u, i)) == 'I060' then
            return true
            endif
            set i = i +1
        endloop
        return false
    endfunction
    
    private function inviZero takes integer p returns nothing
        if invi == 0 then
            call UnitAddAbility( udg_Hero_Troll, 'A0DY' )
        endif
    endfunction
    
    private function slipperyFalse takes integer p, unit dummy returns nothing
        set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
        call UnitAddAbility( dummy, 'ACcs' )
        if udg_ProtectSlip == false then
            if udg_Slippery == false then
                set udg_Slippery = true
                set udg_Crit_power = ( udg_Crit_power - 1 )
            endif
        else
            call SetUnitAbilityLevel( dummy, 'ACcs', 2 )
        endif
        call IssueTargetOrder( dummy, "curse", udg_Hero_Troll )
        call RemoveUnit( dummy)  // do not forget this line if u do the game will lag overtime only other option is timed life for unit
        set dummy =null
    endfunction
    
    public function CheckPlayer takes integer p returns nothing
        local unit dummy
        local real x = GetUnitX(udg_Hero_Troll)
        local real y = GetUnitY(udg_Hero_Troll)
        local integer wetbuff = GetUnitAbilityLevel(udg_Hero_Troll, 'BUfa')
        local integer heatbuff = GetUnitAbilityLevel(udg_Hero_Troll, 'Bapl')
        local integer springbuff = GetUnitAbilityLevel(udg_Hero_Troll, 'BHab')
        local integer feverbuff = GetUnitAbilityLevel(udg_Hero_Troll, 'Brej')
        local integer shelterbuff = GetUnitAbilityLevel(udg_Hero_Troll, 'B01R')
        local integer bear = GetUnitAbilityLevel(udg_Hero_Troll, 'A04F')
        local integer pig = GetUnitAbilityLevel(udg_Hero_Troll, 'A04S')
        local integer hutt = GetUnitAbilityLevel(udg_Hero_Troll, 'A04L')
        local integer saber = GetUnitAbilityLevel(udg_Hero_Troll, 'A04R')
        local integer hunter = GetUnitAbilityLevel(udg_Hero_Troll, 'A0HF')
        local integer other = GetUnitAbilityLevel(udg_Hero_Troll, 'A0HX')
        local integer shaman = GetUnitAbilityLevel(udg_Hero_Troll, 'A0HW')
        local integer invi = GetUnitAbilityLevel(udg_Hero_Troll, 'A0DY')
        local integer heroheat = GetPlayerState(Player(p-1), PLAYER_STATE_RESOURCE_LUMBER)
        local integer herohunger = GetPlayerState(Player(p-1), PLAYER_STATE_RESOURCE_GOLD)
        // ===== Water Wet Effect =====
        if IsTerrainPathable( x, y, PATHING_TYPE_FLOATABILITY) == false then
            if udg_ProtectWater == false then
                call slipperyFalse(p, dummy)
            elseif  wetbuff == 0 and heatbuff == 0 and udg_Rain == true then
                call slipperyFalse(p, dummy)
            endif
        endif
        if wetbuff == 0 then
            if udg_Slippery == true then
                set udg_Slippery = false
                set udg_Crit_power = ( udg_Crit_power + 1 )
            endif
        else
            if springbuff == 0 then
                set udg_WetEffect = 2
            else
                set udg_WetEffect = 1
            endif
        endif
        // ===== Frozen by Cold =====
        if heroheat <= 0 and udg_Frozen == false then
            set udg_MB_Frozen = "Yes"
            set udg_Frozen = true
            call UnitAddAbility( udg_Hero_Troll, 'A00P' )
        endif
        if udg_Frozen == true then
            if udg_Boat == true then
                call UnitAddAbility( udg_BoatLoaded, 'A00P' )
                call SetUnitAbilityLevel( udg_BoatLoaded, 'A00P', 2 )
            endif
        endif
        if heroheat <= 0 and GetRandomInt(1, 10) == 1 and feverbuff == 0 then
            set x = GetUnitX(udg_Hero_Troll)
            set y = GetUnitY(udg_Hero_Troll)
            set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
            call UnitAddAbility( dummy, 'ACff' )
            call IssueTargetOrder( dummy, "faeriefire", udg_Hero_Troll )
            call RemoveUnit( dummy)  // do not forget this line if u do the game will lag overtime only other option is timed life for unit
            set dummy =null
        endif
        // ===== Unfrozen by Heat =====
        if heroheat >= 50 and udg_Frozen == true then
            set udg_MB_Frozen = "No"
            set udg_Frozen = false
            call UnitRemoveAbility( udg_Hero_Troll, 'A00P' )
            call UnitRemoveAbility( udg_BoatLoaded, 'A00P' )
        endif
        // ===== Starving =====
        if herohunger <= 0 and udg_Starving == false then
            set udg_MB_Starving = "Yes"
            call UnitAddAbility( udg_Hero_Troll, 'A00M' )
            set udg_Starving = true
        else //if udg_Starving == true 
            set udg_MB_Starving = "No"
            call UnitRemoveAbility( udg_Hero_Troll, 'A00M' )
            set udg_Starving = false
        endif
        // ==========  SLEEP BONUS  ==========
        if hutt > 0 or bear > 0 or saber > 0 or pig > 0 or hunter > 0 or shaman > 0 or other > 0 then
            call SetPlayerState( Player(p-1), PLAYER_STATE_RESOURCE_GOLD, herohunger + ( 5 - udg_GameDiff ) ))
        endif
        // ==========  INVISIBILITY BONUS  ==========
        if arcanum(udg_Hero_Troll) and GetRandomInt(1, 4) == 1 then
            inviZero(p)
        else
            call UnitRemoveAbility( udg_Hero_Troll, 'A0DY' )
        endif
        if shelterbuff > 0 then
            inviZero(p)
        else
            call UnitRemoveAbility( udg_Hero_Troll, 'A0DY' )
        endif
        // ===== Coma Energy is 0 =====
        if udg_Sleeping == false and udg_Coma == false and udg_Eaten == false and GetUnitState( udg_Hero_Troll, UNIT_STATE_MANA) <= 0.00 then
            call SetUnitState(udg_Basic_Crafting, UNIT_STATE_MANA, 200.)
            set udg_Coma = true
            set udg_MB_Coma = "Yes"
            call UnitRemoveAbility( udg_Hero_Troll, 'Binv' )
            call UnitRemoveAbility( udg_Hero_Troll, 'BOwk' )
            set dummy = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'ndwm', x, y, bj_UNIT_FACING )
            call UnitAddAbility( dummy, 'A0MA' )
            call TriggerSleepAction( 0.50 )
            call IssueTargetOrder( dummy, "creepthunderbolt", udg_Hero_Troll )
            call RemoveUnit( dummy)  // do not forget this line if u do the game will lag overtime only other option is timed life for unit
            set dummy =null
            call UnitAddAbility( udg_Hero_Troll, 'A00B' )
            set udg_Sleep_Troll = 'A00B'
            call SetUnitAnimation( udg_Hero_Troll, "death" )
        endif
    endfunction
endlibrary
 
Last edited:

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
wow, thanks a lot for your help deathismyfriend
about the dummy unit (it has 2 hp and a negative regen)
so as soon as it appears on the map it die 2 sec later.
when it die a trigger remove it from the game.
so i guess i can set dummy = null without calling unit remove?

also about unit remove.
when i order a dummy to cast a spell and remove the dummy without wait does he have time to cast the spell before he is removed? i mean begin and finish casting (casting time 0, cooldown 0)


[Jass=]
if arcanum(udg_Hero_Troll) and GetRandomInt(1, 4) == 1 then
inviZero(p)
else
call UnitRemoveAbility( udg_Hero_Troll, 'A0DY' )
endif
if shelterbuff > 0 then
inviZero(p)
else
call UnitRemoveAbility( udg_Hero_Troll, 'A0DY' )
endif
[/code]
the inviZero(p) is a function inside the library... don't we need use "call"
call inviZero(p) ?
 
Status
Not open for further replies.
Top