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

[General] Creating a Loot System for RPGs

Status
Not open for further replies.
Level 4
Joined
Jul 5, 2015
Messages
75
What I am trying to figure out is if there is a way to create a random item from an item list, like random loot from bosses or high level enemies, but make it where the item is created in a separated area and isn't actually dropped from the boss/enemy.

Item List 1: Sword, Curiass, Cloak, Boots

--> Boss/Enemy Dies
--> Killing unit ported to player's specific lootzone
--> (This is what I need to know HOW to do) Random piece of loot from Item List 1 is dropped within the lootzone/region
 
Level 4
Joined
Jul 26, 2016
Messages
88
Well, I guess you could make an item-type array,

set ItemArray[0] = Sword
set ItemArray[1] = Cuirass
set ItemArray[2] = Cloak
set ItemArray[3] = Boots

then

Unit Dies:

if unit-type of triggering unit = somemonster

create 1 item of type ItemArray[random integer between 0 and 3] at desired_position

I'm not sure if there is a random integer function in the GUI, but you could as well get a random number converting a Real to an int, maybe use floors and ceilings, I'm pretty sure you can find some creative way of getting a random integer anyways
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
The functionality is already integrated into the game in the form of itempool objects.

JASS:
type itempool  extends  handle
native  SaveItemPoolHandle				takes hashtable table, integer parentKey, integer childKey, itempool whichItempool returns boolean
native  LoadItemPoolHandle			takes hashtable table, integer parentKey, integer childKey returns itempool
native CreateItemPool           takes nothing returns itempool
native DestroyItemPool          takes itempool whichItemPool returns nothing
native ItemPoolAddItemType      takes itempool whichItemPool, integer itemId, real weight returns nothing
native ItemPoolRemoveItemType   takes itempool whichItemPool, integer itemId returns nothing
native PlaceRandomItem          takes itempool whichItemPool, real x, real y returns item
Basically create itempool, add item types to pool, then place from the pool when you need an item. This functionality is used by creeps to drop items in melee maps.

You may need to use JNGP with vJASS in order to create a itempool global variable or array due to how usless GUI is.
 
Level 4
Joined
Jul 5, 2015
Messages
75
@Dr Super Good I don't understand enough about JASS to know what you've added means. Sure I can understand it, after enough blind staring, but Im just going to stick with GUI until I ABSOLUTELY need JASS. As I get better as a map maker, I will end up switching over to JASS, but yeah.

@Bitchmoon Ill see if that works on a separate map, basically, it needs to be RNG for the array position. So whenever the specific unit dies it'll generate a random number (integer only) and spawn said item for whomever was in the immediate area.

@Chaosy I'll check it out.
 
Level 4
Joined
Jul 26, 2016
Messages
88
@Tzalksar well, you can go even simpler: for any event where you want random branching, you can use nested if/then/else:

if random real between 0.00 and 1.00 < 0.4
then spawn item1
else (
if random real between 0.00 and 1.00 < 0.7
then spawn item2
else (
spawn item3 ))​

The probabilities for the events are not evenly distributed, you can pretty much control them like so:

Probability for item1 to spawn is 40% chance, else,

now the probability for item1 not to spawn (60%) AND item2 to spawn (70% after item1 not spawning) is 0.6*0.7=0.42 or 42%

item3 will spawn when item1 doesnt spawn (60%) and item2 doesnt (30% after item1 not spawning) : 0.6*0.3=0.18 or 18%.

Though, if you have a lot of events you want to happen with a certain probability, this might end up really messy with the large amount of nesting.
 
Level 4
Joined
Jul 5, 2015
Messages
75
@Bitchmoon is there a way to do percentages where item A has 20% chance to spawn, Item B has a 75% chance to spawn and item C only has 5% chance to spawn, without nesting? (This is actually more likely what I'm after)

So Essentially:
Unit X dies
Loot[0] = Sword
Loot[0] has 20% chance to spawn in Region Y

As soon as I get the loot system done, I should basically be ready to release the first version of the map I'm working on, and of course I need to make a godly amount of items (ugh)

@Chaosy I did a quick search via forum search for IPool, your post is the only relevant thing to it. Does it perhaps go by a different name or what?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
@Bitchmoon is there a way to do percentages where item A has 20% chance to spawn, Item B has a 75% chance to spawn and item C only has 5% chance to spawn, without nesting? (This is actually more likely what I'm after)
Item pools, as I said. It will spawn 1 item out of all the weights you provide. How melee maps spawn items.

Otherwise you roll a random number and test if the spawn chance is less than that number. If it is then spawn that item, otherwise subtract the spawn chance from the number and check the next item. Continue until out of items (which would be no spawn).
 
Level 4
Joined
Jul 5, 2015
Messages
75
Alright, Super Good, but could you please give me an example of how your above code works? I realize what each function you have there does, I just don't know how to use the specifics.
 
Level 4
Joined
Jul 26, 2016
Messages
88
@Tzalksar For your previous post, yes, quite simply.

Your create a real variable, say realRandomizer

Now every time you want to spawn a random item, you do, for example, set realRandomizer = random number between 0.00 and 100.00

Then you just do 3 (not nested, simply side-by-side) if then else, like so


Actions:

set realRandomizer = random number between 0.00 and 100.00

if realRandomizer is between 0.00 and 20.00 spawn item A
else ()

if realRandomizer is between 20.00 and 95.00 spawn item B
else ()

if realRandomizer is between 95.00 and 100.00 spawn item C
else ()



The only thing to be careful of is if you have for example something like

...
if realRandomizer is between 20.00 and 65.00 spawn item B
else ()

if realRandomizer is between 60.00 and 100.00 spawn item C
else ()
...

as you can see, if the random value gets anywhere between 60.00 and 65.00, you will spawn both items, so it's your job to make sure the conditions are mutually exclusive (one cannot happen if the other does)

Cheers!
 

EdgeOfChaos

E

EdgeOfChaos

Here's an example of an itempool use (it's vJASS, you will need newgen world editor to compile this)

It will drop a random item from 5 default items when the user types -go. Look specifically at the ItemPoolAddItemType and PlaceRandomItem to see its use.
JASS:
scope ItemDrop initializer onInit

  globals
  private itempool ip = CreateItemPool()
  endglobals
  
  /**
  *  Drop an item from the item pool
  *  when player 1 writes -go
  */
  private function onDrop takes nothing returns nothing
  local real x = 60
  local real y = -10
  call PlaceRandomItem(ip,x,y)
  endfunction

  /**
  *  Generate an item pool
  *  Create a trigger to spawn
  *  an item when player types -go
  */
  private function onInit takes nothing returns nothing
  local trigger t = CreateTrigger()
  //make the item drop pool
  call ItemPoolAddItemType(ip,'afac',20) //aleria's flute, 20%
  call ItemPoolAddItemType(ip,'spsh',10) //amulet, 10%
  call ItemPoolAddItemType(ip,'ajen',40) //jamgo, 40%
  call ItemPoolAddItemType(ip,'bgst',25) //belt, 25%
  call ItemPoolAddItemType(ip,'belv',5) //boots, 5%
  //item drop trigger
  call TriggerRegisterPlayerChatEvent(t,Player(0),"-go",true)
  call TriggerAddAction(t,function onDrop)
  endfunction
endscope

You can use itempools in regular JASS (but regular JASS sucks). Unfortunately you cannot use it at all in GUI, so if you want to use itempools, now's the time to learn!
 

Attachments

  • ItemPoolTest.w3x
    16.4 KB · Views: 36
Level 4
Joined
Jul 5, 2015
Messages
75
'kay....
Since I'm obviously still a newbie, could you explain how to create specific unit death event, and have the item spawn in multiple locations, dependent on # of players in a given region?
 

EdgeOfChaos

E

EdgeOfChaos

I don't have much time now so I'll be brief

1: A trigger with EVENT_PLAYER_UNIT_DEATH event
(i.e. call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_DEATH)
Then in condition, check what unit it is
(add a condition: call TriggerAddCondition(t,Condition(function check))
(then compare unit:if(GetUnitTypeId(GetTriggerUnit())=='u000'))

2. Count units in region and then use an if statement? There's probably a better way but I can't tell you without knowing exactly what you want to do.

If you tell me exactly what you want, I can make a demo after work.
 
Status
Not open for further replies.
Top