• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Unit Drops an item

Status
Not open for further replies.
Level 4
Joined
Jul 3, 2006
Messages
61
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 :
Code:
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:
JASS:
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 ...
 
Level 7
Joined
Dec 8, 2005
Messages
319
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?
 
Level 4
Joined
Jul 3, 2006
Messages
61
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.
 
Level 11
Joined
Jul 12, 2005
Messages
764
first of all, you should optimize the tigger like this
JASS:
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:
JASS:
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.
 
Status
Not open for further replies.
Top