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

[JASS] Itempool help

Status
Not open for further replies.
Level 4
Joined
Jun 19, 2007
Messages
53
Im new to Jass. Im trying to make a simple trigger where when any unit owned by brown player dies it has a 20% chance to drop an item, of which can be one of the three stat increasing tome (tdex, tint, tstr). So I half GUI half Jass'd this:

JASS:
function Trig_ItemDrops_Conditions takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetDyingUnit()) == Player(11) ) ) then
        return false
    endif
    return true
endfunction

function Condtionz takes integer i returns boolean
    if i > 21 then
        return false
    endif
    return true
endfunction

function Trig_ItemDrops_Actions takes nothing returns nothing
    local itempool ip
    local item i
    local integer chance
    call ItemPoolAddItemType(ip, 'tdex', 1)
    call ItemPoolAddItemType(ip, 'tint', 1)
    call ItemPoolAddItemType(ip, 'tstr', 1)
    set chance = GetRandomInt(0, 100)
    if ( Condtionz(chance) ) then
        call PlaceRandomItem(ip, GetLocationX(GetUnitLoc(GetDyingUnit())), GetLocationY(GetUnitLoc(GetDyingUnit())))
    else
    endif
endfunction

//===========================================================================
function InitTrig_ItemDrops takes nothing returns nothing
    set gg_trg_ItemDrops = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ItemDrops, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_ItemDrops, Condition( function Trig_ItemDrops_Conditions ) )
    call TriggerAddAction( gg_trg_ItemDrops, function Trig_ItemDrops_Actions )
endfunction

So, uh, whats wrong with it.
 
Level 11
Joined
Apr 6, 2008
Messages
760
i would recommend using Vjass for this one using a globals itempool would be much much efficent

JASS:
library ItemDrops initializer init

globals
    itempool IP = CreateItemPool()
endglobals

private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local P = GetOwningPlayer(u)
    local integer chance
    
    if P == Player(11) then

        set chance = GetRandomInt(0, 100)

        if chance <= 20 then then
            call PlaceRandomItem(ip,GetUnitX(u),GetUnitY(u))
        endif

    endif

    set P = null
    set u = null
endfunction

//===========================================================================
private function init takes nothing returns nothing
    local trigger trig = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition(trig, Condition( function Actions ) )
    
    
    call ItemPoolAddItemType(IP, 'tdex', .33)
    call ItemPoolAddItemType(IP, 'tint', .33) //the total value of these much be 1 else it can create 0 items
    call ItemPoolAddItemType(IP, 'tstr', .34)

    set trig = null
endfunction

endlibrary
 
Status
Not open for further replies.
Top