• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Random item or itempool?

Status
Not open for further replies.
Level 5
Joined
Sep 19, 2006
Messages
152
I'm just starting out in JASS, and patience isn't really my strong point. At any rate, I'm working on a one-time self-destroying trigger to create any one of six items at a select location. Originally I used an array to define these 6 items, such as SpecialItem[1] - SpecialItem[6], but it seems an overkill use of an array. Now I've trying building an itempool then selecting an item from this group, but there seems to exist some confusion between "item" and "item-type". I've written "INSERT VARIABLE HERE" to indicate where this value should be, but I can find no information on it. Any help would be much appreciated.

On a side-note, I've just used "0" in place of the "item weight" portion of the item pool functions, simply because I don't really know what it's asking for.



function CreepsDeath_Event01 takes nothing returns boolean
if ( not ( GetRandomInt(1, 100) == 1 ) ) then
return false
endif
return true
endfunction

function CreepsDeath_Condition01 takes nothing returns boolean
if ( not CreepsDeath_Event01() ) then
return false
endif
return true
endfunction

function CreepsDeath_Action01 takes nothing returns nothing
local itempool UniqueItemGroup
call ItemPoolAddItemType(UniqueItemGroup,shea,0)
call ItemPoolAddItemType(UniqueItemGroup,rwiz,0)
call ItemPoolAddItemType(UniqueItemGroup,I04N,0)
call ItemPoolAddItemType(UniqueItemGroup,rpsh,0)
call ItemPoolAddItemType(UniqueItemGroup,fwss,0)
call ItemPoolAddItemType(UniqueItemGroup,skul,0)
endfunction

function CreepsDeath_Action02 takes nothing returns nothing
local unit DyingUnit = GetDyingUnit()
local location DyingUnitPoint = GetUnitLoc(DyingUnit)
call CreateItemLoc ---- INSERT VARIABLE HERE ----, DyingUnitPoint)
call RemoveLocation (DyingUnitPoint)
set DyingUnit = null
call DestroyTrigger (gg_trg_CreepsDeathUnique )
endfunction

//====================================================
function InitTrig_CreepsDeathUnique takes nothing returns nothing
set gg_trg_CreepsDeathUnique = CreateTrigger( )
call DisableTrigger (gg_trg_CreepsDeathUnique)
call TriggerRegisterPlayerUnitEventSimple(gg_trg_CreepsDeathUnique, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition (gg_trg_CreepsDeathUnique, Condition( function CreepsDeath_Condition01) )
call TriggerAddAction (gg_trg_CreepsDeathUnique, function CreepsDeath_Action01)
call TriggerAddAction (gg_trg_CreepsDeathUnique, function CreepsDeath_Action02)
endfunction
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Aight, there are a few problems ><. Also, please use the JASS forums, and post in [*JASS*] tags. (without the *s)

First, Weight means the chance. Eg. if there was a Boots of Speed (bspd) with weight 50 and a Gold Coins (gold) with weight 25, the Boots of Speed would come 2 out of 3 times, statistically. Note: this is NOT out of 100.

Second, you've made numerous code errors ><

first, those should be in one actions func. Second, the conditions can be compressed, third, Item-types are integers, eg 'bspd', not just bspd, in JASS. Finally, you have to create itempools.

The first way to do this would be;

JASS:
function CreapsDeathsUniqueConds takes nothing returns boolean
    return GetRandomInt(1, 100) == 1
endfunction

function CreepsDeathUnique takes nothing returns nothing
    local itempool pool = CreateItemPool()
    call ItemPoolAddType(pool, 'shea', <chance>)
    call ItemPoolAddType(pool, 'rwiz', <chance>)
    call ItemPoolAddType(pool, 'I04N', <chance>)
    call ItemPoolAddType(pool, 'rpsh', <chance>)
    call ItemPoolAddType(pool, 'fwss', <chance>)
    call ItemPoolAddType(pool, 'skul', <chance>)
    call PlaceRandomItem(pool, GetUnitX( GetTriggerUnit() ), GetUnitY( GetTriggerUnit())
    call DestroyItemPool( pool )
    set pool = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function InitTrig_CreepsDeathUnique takes nothing returns nothing
    set gg_trg_CreepsDeathUnique = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(gg_trg_CreepsDeathUnique, Player(12), EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddCondition( gg_trg_CreepsDeathUnique, Condition( function CreepsDeathUniqueConds ) )
    call TriggerAddAction( gg_trg_CreepsDeathUnique, function CreepsDeathUnique )
endfunction

or, with vJass,

JASS:
globals
    itempool CreepDeathUniqueItemPool
endglobals

function CreapsDeathsUniqueConds takes nothing returns boolean
    return GetRandomInt(1, 100) == 1
endfunction

function CreepsDeathUnique takes nothing returns nothing
    call PlaceRandomItem(CreepDeathUniqueItemPool, GetUnitX( GetTriggerUnit() ), GetUnitY( GetTriggerUnit())
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function InitTrig_CreepsDeathUnique takes nothing returns nothing
    set gg_trg_CreepsDeathUnique = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(gg_trg_CreepsDeathUnique, Player(12), EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddCondition(gg_trg_CreepsDeathUnique, Condition( function CreepsDeathUniqueConds ))
    call TriggerAddAction(gg_trg_CreepsDeathUnique, function CreepsDeathUnique)
    set CreepDeathUniqueItemPool = CreateItemPool()
     call ItemPoolAddType(CreepDeathUniqueItemPool, 'shea', <chance>)
     call ItemPoolAddType(CreepDeathUniqueItemPool, 'rwiz', <chance>)
      call ItemPoolAddType(CreepDeathUniqueItemPool, 'I04N', <chance>)
      call ItemPoolAddType(CreepDeathUniqueItemPool, 'rpsh', <chance>)
      call ItemPoolAddType(CreepDeathUniqueItemPool, 'fwss', <chance>)
      call ItemPoolAddType(CreepDeathUniqueItemPool, 'skul', <chance>)
endfunction
 
Level 5
Joined
Sep 19, 2006
Messages
152
Sorry about posting in the wrong place. I'll be more careful in the future.

I did have a few questions, however:
1) If this is a one-time trigger, why is CreepDeathUniqueItemPool listed as a global in the second sample solution?
2) You used a "12" to define "Neutral-Aggressive". In JASS, are the numeric values of the players reduced by 1?
3) Where can I find information to better understand the "function DoNothingEx takes code DoNothingCodeFunc returns nothing" code you suppplied at the bottom? I really don't get that part.

Thank you for your patience, guys!
 
Level 8
Joined
Jan 18, 2007
Messages
331
Haha, i dont understand how you can even know jass=) but the 3.rd question:"Where can I find information to better understand the "function DoNothingEx takes code DoNothingCodeFunc returns nothing" code you suppplied at the bottom? I really don't get that part." thats probably not even a working jass, Becous thats heis SIGNATURE=)) hehe, great work men!
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
-Player values are 0-11. 12 is Neutral Hostile, 13 is Neutral Victim, 14 is Neutral Extra, and 15 is Neutral Passive.

-Whoops, I didn't notice that DestroyTrigger(). Guess you can remove that global with the second one, and just add a DestroyTrigger to the first one (I was a little tired when I did that)

-That's my signature. It's a joke. the
"_________________"

divides your signature and your text
 
Level 5
Joined
Sep 19, 2006
Messages
152
Sonkan1, did you see the part where I wrote "I'm just starting out in JASS"? Ok then. I'm pretty sure you weren't BORN with the knowledge of this stuff either, so have a little tolerance of those of us who are learning.
 
Status
Not open for further replies.
Top