[JASS] Help in itemdrop system

Status
Not open for further replies.
Level 1
Joined
Jul 24, 2009
Messages
4
Hey guys , I need help to make this basic system efficient and I need suggestions to make it useful, it is similar to advanced \ Item Tables of WE.

The first problem I see is that it checks the condition every time a unit dies,
but I do not know how to remove the condition without creating a trigger for each unit registred.

Here is the code, requires AIDS by Jesus4Lyf
JASS:
library CIT initializer CITinit requires AIDS

globals
    
    integer CIT_lastCreatedItemTable = 0

    private itempool array IP
    private boolean array usedindex 
    private integer maxip = 1
    private integer RI = 0
endglobals

private struct CITdata extends array
    //! runtextmacro AIDS()
    integer ip
    real chanc
    boolean rl
    boolean dod
    boolean d
    boolean p
    integer pl
    boolean ivu
    integer ch
    integer ud
    string str
    
        private method AIDS_onCreate takes nothing returns nothing
            set this.ip = 0
        endmethod
    
        private static method AIDS_filter takes unit u returns boolean
            return GetUnitAbilityLevel(u, 'Aloc') == 0 and GetUnitAbilityLevel(u, 'Avul') == 0
        endmethod
endstruct

function RegDropRamdomItempoolEx takes unit u, integer ItempoolInstance, real chance, boolean removelater, boolean DropOnDeath, boolean Droppable, boolean Pawnable, integer toplayer, boolean Invulnerable, integer Charges, integer Custondata, string effectpath returns nothing
    local CITdata d = GetUnitUserData(u)
    if ItempoolInstance > 0 or usedindex[ItempoolInstance] == true then
        set d.ip = ItempoolInstance
        set d.chanc = chance
        set d.rl = removelater
        set d.dod = DropOnDeath
        set d.d = Droppable
        set d.p = Pawnable
        set d.pl = toplayer
        set d.ivu = Invulnerable
        set d.ch = Charges
        set d.ud = Custondata
        set d.str = effectpath
        else
        debug call BJDebugMsg("CustomItemTables: Invalid Instance")
    endif
endfunction

function RegDropRamdomItempool takes unit u, integer ItempoolInstance, real chance,string effectpath returns nothing
    call RegDropRamdomItempoolEx(u,ItempoolInstance, chance, false, false, true, true, 15, false, 0, 0, effectpath)
endfunction 

function CreateItempool takes nothing returns integer
    set RI = 0
    loop
        set RI = RI + 1
        exitwhen usedindex[RI] == false
    endloop
    if RI > maxip  then
        if maxip == 8192 then
            debug call BJDebugMsg("CustomItemTables: limit reached, return 0")
            return 0
            else
            set maxip = RI
        endif
    endif
    set IP[RI] = CreateItemPool()
    set usedindex[RI] = true
    set CIT_lastCreatedItemTable = RI
    return RI
endfunction

function DestroyItempool takes integer i returns nothing
    if i > 0 then
        call DestroyItemPool(IP[i])
        set usedindex[i] = false
    endif
endfunction

function ItempoolAddItemType takes integer i, integer itemId, real chance returns nothing
    if i > 0 then
        call ItemPoolAddItemType(IP[i], itemId, chance)
        else
    endif
endfunction

function ItempoolRemoveItemType takes integer i, integer ItemId returns nothing
    if i > 0 then
        call ItemPoolRemoveItemType(IP[i], ItemId)
    endif
endfunction

private function UnitDieDrop takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local CITdata d = GetUnitUserData(u)
    local item i
    if GetRandomInt(0,100) < d.chanc then
        set i = PlaceRandomItem(IP[d.ip], GetUnitX(u), GetUnitY(u))
        if d.rl then
            call ItempoolRemoveItemType(d.ip, GetItemTypeId(i))
        endif
        call SetItemDropOnDeath(i, d.dod)
        call SetItemDroppable(i, d.d)
        call SetItemPawnable(i, d.p)
        call SetItemPlayer(i, Player(d.pl), false)
        call SetItemInvulnerable(i, d.ivu)
        if d.ch > 0 then
            call SetItemCharges(i,d.ch)
        endif
        if d.ud > 0 then
            call SetItemUserData(i, d.ud)
        endif
        set i = null
    endif
    set u = null 
endfunction

private function condition  takes nothing returns boolean
    local CITdata d = GetUnitUserData(GetTriggerUnit())
    return d.ip > 0
endfunction

//===========================================================================
private function CITinit takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition(t, Condition( function condition))
    call TriggerAddAction(t, function UnitDieDrop )
endfunction

endlibrary
 
Status
Not open for further replies.
Top