domingo, 13 de fevereiro de 2011

Add Life v1.1

Esse system é bem simples e util. Para você adicionar HP (hit points) a uma unidade ao ponto que ela fique com hp completo, você deve adicionar uma habilidade que almenta a quantidade de hp dela. Para não ter o trabalho de cria aquelas functions que adicionam e removem essa habilidade, eu fiz esse system.

O system só tem uma function principal:
function UnitAddLife takes unit whichUnit, real amount returns nothing
Essa function adiciona uma quantidade de hp (amount) a unidade desejada (whichUnit). Simples!

Script do Sistema:
library AddLife
// Add Life System
// Criado por "Bills"
// Versão: 1.2
//=====================================
// Como implementar:
// Crie uma nova trigger,
// converta ela para custom script,
// salve seu mapa,
// feche-o,
// reabra-o
// e apague o ! da linha abaixo.
//! external ObjectMerger w3a AIlz ALBA anam "Life Bonus" ansf "(Bills's AddLife System)" Ilif 1 500000 aite 0
//=====================================================================
//Caso ja tenha essa native declarada, "comenta" a linha abaixo
native UnitAlive takes unit whichUnit returns boolean

private struct AL extends array // struct array não possui method create/destroy
    private static constant integer LIFE_BONUS_ABIL = 'ALBA'
    private static unit array tempUnit
    private static integer index
    private static timer timerFunc
   
    private static method removeLifeBonus takes nothing returns nothing
        loop
            exitwhen (index==0)
            call UnitRemoveAbility(tempUnit[index],LIFE_BONUS_ABIL)
            if (UnitAlive(tempUnit[index])) then
                call SetWidgetLife(tempUnit[index],GetWidgetLife(tempUnit[index]))
            endif
            set index=index-1
        endloop
    endmethod
   
    static method unitAddLife takes unit u, real amount returns nothing
        set amount=GetWidgetLife(u)+amount
        call SetWidgetLife(u,amount)
        if (GetWidgetLife(u)<amount) then
            call UnitAddAbility(u,LIFE_BONUS_ABIL)
            call SetWidgetLife(u,amount)
            set index=index+1
            set tempUnit[index]=u
            call ResumeTimer(timerFunc)
        endif
    endmethod
   
    private static method onInit takes nothing returns nothing
        set index=0
        set timerFunc=CreateTimer()
        call TimerStart(timerFunc,0.00,false,function thistype.removeLifeBonus)
    endmethod
endstruct

 function UnitAddLife takes unit u, real amount returns nothing // por compatibilidade
    call AL.unitAddLife(u,amount)
 endfunction

endlibrary

Nenhum comentário:

Postar um comentário