Warcraft III resources & community, 2003–2006 · archived

Unit Drops an item

5 posts
#1

Unit Drops an item

Currently I made a system that would make an creep drop a random item. Those items are linked to some array variables ( item-types).
Initialization from the GUI variables :
 
Start Init
    Events
        Map initialization
    Conditions
    Actions
        -------- Items --------
        Set CreepDropItem[1] = Leather
        Set CreepDropItem[2] = Potion of Healing
        Set CreepDropItem[3] = Wooden Stick
        Set CreepDropItem[4] = Broken Buckler
              Wait 5.00 seconds
        Custom script:   call DestroyTrigger(GetTriggeringTrigger())




So CreepDropItem equals to an Item-type variable.
The next trigger I made was in JASS, giving a chance that a creep drops something.
But I think I did something wrong since a creep never dropped an item.
Code:
function Trig_Dropping_Copy_Conditions takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetDyingUnit()) == Player(PLAYER_NEUTRAL_AGGRESSIVE) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Dropping_Copy_Func003C takes nothing returns boolean
    if ( not ( 'c' == 12 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Dropping_Copy_Actions takes nothing returns nothing
    local integer c = GetRandomInt(1, 15)
    if ( Trig_Dropping_Copy_Func003C() ) then
        call CreateItemLoc( udg_CreepDropItem[GetRandomInt(1, 4)], GetUnitLoc(GetDyingUnit()) )
    else
        call DoNothing(  )
    endif
endfunction

//===========================================================================
function InitTrig_Dropping takes nothing returns nothing
    set gg_trg_Dropping = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Dropping, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Dropping, Condition( function Trig_Dropping_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Dropping, function Trig_Dropping_Copy_Actions )
endfunction




Can someone help me to find the answer? thanks ...
#2
ok why dont you just use the table that is for drops off of creeps? and your trigger is just setting variables to items? or what?
#3
First of all: Creeps respawn / are created every .. seconds when one has died.
Second :
yes , those VARIABLES are the item-types.
The creeps doesn't need to constantly drop an item, but must have kinda 10-30% chance to drop one.
#4
first of all, you should optimize the tigger like this

function Trig_Dropping_Copy_Conditions takes nothing returns boolean
    return GetOwningPlayer(GetTriggerUnit()) == Player(PLAYER_NEUTRAL_AGGRESSIVE) 
endfunction
 
function Trig_Dropping_Copy_Actions takes nothing returns nothing
    local integer c = GetRandomInt(1, 15)
    local location loc = GetUnitLoc(GetTriggerUnit())
    if c == 1 then
        call CreateItemLoc( udg_CreepDropItem[GetRandomInt(1, 4)], loc)
    endif
    call RemoveLocation(loc)
    set loc = null
endfunction
 
//===========================================================================
function InitTrig_Dropping takes nothing returns nothing
    set gg_trg_Dropping = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Dropping, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Dropping, Condition( function Trig_Dropping_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Dropping, function Trig_Dropping_Copy_Actions )
endfunction


i think u must use sime kind of conversation like ItemType2Int (not sure this exists)

but the best would be to create an integer variable, and write a function in jass like this:

function InitItems takes nothing returns nothing
    set udg_ItemInt[1] = '0000' 
    set udg_ItemInt[2] = '0000' 
    set udg_ItemInt[3] = '0000' 
    set udg_ItemInt[4] = '0000'
    //Replace '0000' with the items' raw codes.
endfunction

at map initialization, just call this function in a custom script:
call InitItems()

if you want 10-30% than
set c = GetRandomInt(1, GetRandomInt(3, 10))

hope this helps.
#5
It helped me indeed.
Thanks man, I thought nobody would replay! :)
U made my day :D