• 🏆 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] How to make loot droped depending on unit?

Status
Not open for further replies.
Level 2
Joined
Apr 15, 2011
Messages
14
So i need a trigger, that makes loot random, but still organized depending on how powerfull a unit is.
I need to divide loot in 4 categories(small, medium, big and epic).
A way to divide my creeps in to 4 categories, so the loot is random but still you can get small items from small creeps only e.t.c.
I also need a way to make the loot drop chance to be % based.
For example, there only is 10% chance to get an epic item from an epic boss.
30 % chance to get big item from a big creep etc.

How do i do that?
 
It depends :p
You need to have criteria to help you decide what is an Epic boss, what is a big unit, what is a weak creep, etc...

Here:
You need JNGP for this.
It's written in vJass, but can be used easily in GUI.

You need to create 4 groups:
WeakUnits
MediumUnits
BigUnits
EpicUnits

And you should add the units that go in each group :)

JASS:
library Looting
    // Configurables
    globals
        // The number of items:
        private constant integer EPIC_COUNT = 2
        private constant integer BIG_COUNT = 2
        private constant integer MED_COUNT = 3
        private constant integer WEAK_COUNT = 4
        // The chances to get each item:
        private constant real EPIC_CH = 15.0
        private constant real BIG_CH = 20.0
        private constant real MED_CH = 25.0
        private constant real WEAK_CH = 30.0
    endglobals
    
    // Your item lists
    globals
        private integer array EPIC_ITEMS
        private integer array BIG_ITEMS
        private integer array MED_ITEMS
        private integer array WEAK_ITEMS
    endglobals
    
    private function Config takes nothing returns nothing
        set EPIC_ITEMS[1] = 'I000'
        set EPIC_ITEMS[2] = 'I001'
        
        set BIG_ITEMS[1] = 'I002'
        set BIG_ITEMS[2] = 'I003'
        
        set MED_ITEMS[1] = 'I004'
        set MED_ITEMS[2] = 'I005'
        set MED_ITEMS[3] = 'I006'
        
        set WEAK_ITEMS[1] = 'I007'
        set WEAK_ITEMS[2] = 'I008'
        set WEAK_ITEMS[3] = 'I009'
        set WEAK_ITEMS[4] = 'I00A'
    endfunction
    
    private function Actions takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local real r = GetRandomReal(0,100.0)
        if IsUnitInGroup(u,udg_WeakUnits) and r<=WEAK_CH then
            call CreateItem(WEAK_ITEMS[GetRandomInt(1,WEAK_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_MediumUnits) and r<=MED_CH then
            call CreateItem(MED_ITEMS[GetRandomInt(1,MED_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_BigUnits) and r<=BIG_CH then
            call CreateItem(BIG_ITEMS[GetRandomInt(1,BIG_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_EpicUnits) and r<=EPIC_CH then
            call CreateItem(EPIC_ITEMS[GetRandomInt(1,EPIC_COUNT)],GetUnitX(u),GetUnitY(u))
        endif
        set u = null
        return false
    endfunction
    
    private module Init
        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_DEATH)
            call TriggerAddCondition(t,Condition(function Actions))
            call Config()
            set t = null
        endmethod
    endmodule
    private struct Inits extends array
        implement Init
    endstruct
endlibrary

You should edit the variables in this jass trigger in the first "globals" block, and you should edit the IDs in the Config function :)

Happy Mapping ^^
 
Last edited:
Level 2
Joined
Apr 15, 2011
Messages
14
Found where to put the code.

How do i add units to a group?
And how do i group them?

I'm new to JASS so this is quite tricky for me :/
 
Last edited:
Level 2
Joined
Apr 15, 2011
Messages
14
You don't have to use jass to add units to a group :p
You could do it in GUI :p

  • Untitled Trigger 002
    • Events
    • Conditions
    • Actions
      • Unit Group - Add (Triggering unit) to WeakUnits

Wait, so WeakUnits is a unit itself?
Or do i make this group somehow?
And can i group items in this way also, or do i just add the items to JASS like so:
JASS:
globals
        private integer array Archimnds Hearth, Jaws of Mannaroth
        private integer array Keg of Beer
        private integer array Shield of Defence +5
        private integer array Blades of Attack +3, Potion of Health
    endglobals
 
WeakUnits is a unit group o.o
Also, items are supposed to be set like this:

In the function Config:
JASS:
private function Config takes nothing returns nothing
        set EPIC_ITEMS[1] = 'I000'
        set EPIC_ITEMS[2] = 'I001'
        
        set BIG_ITEMS[1] = 'I002'
        set BIG_ITEMS[2] = 'I003'
        
        set MED_ITEMS[1] = 'I004'
        set MED_ITEMS[2] = 'I005'
        set MED_ITEMS[3] = 'I006'
        
        set WEAK_ITEMS[1] = 'I007'
        set WEAK_ITEMS[2] = 'I008'
        set WEAK_ITEMS[3] = 'I009'
        set WEAK_ITEMS[4] = 'I00A'
    endfunction

'I000','I001','I002', etc... are just examples of item ids.
If you want to get the id of an item, in the object editor, press Ctrl+D and they'll appear :)


For example, if the Keg of Beer and the Shield of Defence were items that drop from weak units ans:
Keg of Beer -> 'I003'
Shield of Defence -> 'I005'

Then:

JASS:
set WEAK_ITEMS[1] = 'I003'
set WEAK_ITEMS[2] = 'I005'

Get it? :)
 
Level 2
Joined
Apr 15, 2011
Messages
14
WeakUnits is a unit group o.o
Also, items are supposed to be set like this:

In the function Config:
JASS:
private function Config takes nothing returns nothing
        set EPIC_ITEMS[1] = 'I000'
        set EPIC_ITEMS[2] = 'I001'
        
        set BIG_ITEMS[1] = 'I002'
        set BIG_ITEMS[2] = 'I003'
        
        set MED_ITEMS[1] = 'I004'
        set MED_ITEMS[2] = 'I005'
        set MED_ITEMS[3] = 'I006'
        
        set WEAK_ITEMS[1] = 'I007'
        set WEAK_ITEMS[2] = 'I008'
        set WEAK_ITEMS[3] = 'I009'
        set WEAK_ITEMS[4] = 'I00A'
    endfunction

'I000','I001','I002', etc... are just examples of item ids.
If you want to get the id of an item, in the object editor, press Ctrl+D and they'll appear :)


For example, if the Keg of Beer and the Shield of Defence were items that drop from weak units ans:
Keg of Beer -> 'I003'
Shield of Defence -> 'I005'

Then:

JASS:
set WEAK_ITEMS[1] = 'I003'
set WEAK_ITEMS[2] = 'I005'

Get it? :)

Ok, now i understand about the items :)
But what puzles me is unit groups :
Unit like ''lvl 1 satyr'' is the whole group of units right? Lets say it's the WeakUnits group. But there are also many other lvl 1 units that i want to be in WeakUnits, that share the same loot drop etc.
So what is the unit group and how to make one?
Unit group = unit type, or not?
 
Press control B in the Trigger editor.
In the Variable Type line, scroll down and click on "Unit Group"
A unit group is a group of actual units on the map.
You can add a unit to a group.
You can remove a unit from a group.
You can do actions for every unit in a group
You can add a bunch of units to a group at once.
etc...
 
Level 2
Joined
Apr 15, 2011
Messages
14
Press control B in the Trigger editor.
In the Variable Type line, scroll down and click on "Unit Group"
A unit group is a group of actual units on the map.
You can add a unit to a group.
You can remove a unit from a group.
You can do actions for every unit in a group
You can add a bunch of units to a group at once.
etc...

Excellent, thats what i was looking for. ^^
Just in case i want to add more unit groups (like SpecialUnits) in your JASS trigger, what do i need to add for it to be operational? As well as make a item group for special_items, so i will know how to make it in the future?
 
Level 2
Joined
Apr 15, 2011
Messages
14
By item group you mean array right?
If you want to add something like SPECIAL_ITEMS:

In the "globals":
Add this:
JASS:
globals
    private integer array SPECIAL_ITEMS
endglobals

If you want special units, you're going to have to edit the entire system :p
In the future, if you want a change, just ask me ;)
Ok. Got new Request.
I need some extra unit groups in the code:

Civilians
HumanWeak
HumanMedium
HumanBig
Undead
WaveDemons

If you can, then add
Also add items groups for them with % chances.
I will edit the rest myself :)
 
I'm on it :)

edit

Done!

JASS:
library Looting
    // Configurables
    globals
        // The number of items:
        private constant integer EPIC_COUNT = 2 // Epic Unit Items
        private constant integer BIG_COUNT = 2 // Big Unit Items
        private constant integer MED_COUNT = 3  // Medium Unit Items
        private constant integer WEAK_COUNT = 4 // Weak Unit Items
        private constant integer CIVI_COUNT = 3 // Civilian Items
        private constant integer HWEAK_COUNT = 3 // Human Weak Items
        private constant integer HMED_COUNT = 3 // Human Medium Items
        private constant integer HBIG_COUNT = 3 // Human Big Items
        private constant integer UNDD_COUNT = 2 // Undead Items
        private constant integer WVDM_COUNT = 2 // WaveDemon Items
        // The chances to get each item:
        private constant real EPIC_CH = 15.0
        private constant real BIG_CH = 20.0
        private constant real MED_CH = 25.0
        private constant real WEAK_CH = 30.0
        private constant real CIVI_CH = 20.0
        private constant real HWEAK_CH = 25.0
        private constant real HMED_CH = 20.0
        private constant real HBIG_CH = 10.0
        private constant real UNDD_CH = 15.0
        private constant real WVDM_CH = 20.0
    endglobals
    
    // Your item lists
    globals
        private integer array EPIC_ITEMS
        private integer array BIG_ITEMS
        private integer array MED_ITEMS
        private integer array WEAK_ITEMS
        private integer array CIVI_ITEMS
        private integer array HWEAK_ITEMS
        private integer array HMED_ITEMS
        private integer array HBIG_ITEMS
        private integer array UNDD_ITEMS
        private integer array WVDM_ITEMS
    endglobals
    
    private function Config takes nothing returns nothing
        set EPIC_ITEMS[1] = 'I000'
        set EPIC_ITEMS[2] = 'I001'
        
        set BIG_ITEMS[1] = 'I002'
        set BIG_ITEMS[2] = 'I003'
        
        set MED_ITEMS[1] = 'I004'
        set MED_ITEMS[2] = 'I005'
        set MED_ITEMS[3] = 'I006'
        
        set WEAK_ITEMS[1] = 'I007'
        set WEAK_ITEMS[2] = 'I008'
        set WEAK_ITEMS[3] = 'I009'
        set WEAK_ITEMS[4] = 'I00A'
        
        set CIVI_ITEMS[1] = 'I00B'
        set CIVI_ITEMS[2] = 'I00C'
        set CIVI_ITEMS[3] = 'I00D'
        
        set HWEAK_ITEMS[1] = 'I00E'
        set HWEAK_ITEMS[2] = 'I00F'
        set HWEAK_ITEMS[3] = 'I00G'
        
        set HMED_ITEMS[1] = 'I00H'
        set HMED_ITEMS[2] = 'I00I'
        set HMED_ITEMS[3] = 'I00J'
        
        set HBIG_ITEMS[1] = 'I00K'
        set HBIG_ITEMS[2] = 'I00L'
        set HBIG_ITEMS[3] = 'I00M'
        
        set UNDD_ITEMS[1] = 'I00N'
        set UNDD_ITEMS[2] = 'I00O'
        
        set WVDM_ITEMS[1] = 'I00P'
        set WVDM_ITEMS[2] = 'I00Q'
    endfunction
    
    private function Actions takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local real r = GetRandomReal(0,100.0)
        if IsUnitInGroup(u,udg_WeakUnits) and r<=WEAK_CH then
            call CreateItem(WEAK_ITEMS[GetRandomInt(1,WEAK_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_MediumUnits) and r<=MED_CH then
            call CreateItem(MED_ITEMS[GetRandomInt(1,MED_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_BigUnits) and r<=BIG_CH then
            call CreateItem(BIG_ITEMS[GetRandomInt(1,BIG_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_EpicUnits) and r<=EPIC_CH then
            call CreateItem(EPIC_ITEMS[GetRandomInt(1,EPIC_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_Civilians) and r<=CIVI_CH then
            call CreateItem(CIVI_ITEMS[GetRandomInt(1,CIVI_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_HumanWeak) and r<=HWEAK_CH then
            call CreateItem(HWEAK_ITEMS[GetRandomInt(1,HWEAK_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_HumanMedium) and r<=HMED_CH then
            call CreateItem(HMED_ITEMS[GetRandomInt(1,HMED_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_HumanBig) and r<=HBIG_CH then
            call CreateItem(HBIG_ITEMS[GetRandomInt(1,HBIG_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_Undead) and r<=UNDD_CH then
            call CreateItem(UNDD_ITEMS[GetRandomInt(1,UNDD_COUNT)],GetUnitX(u),GetUnitY(u))
        elseif IsUnitInGroup(u,udg_WaveDemons) and r<=WVDM_CH then
            call CreateItem(WVDM_ITEMS[GetRandomInt(1,WVDM_COUNT)],GetUnitX(u),GetUnitY(u))
        endif
        set u = null
        return false
    endfunction
    
    private module Init
        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_DEATH)
            call TriggerAddCondition(t,Condition(function Actions))
            call Config()
            set t = null
        endmethod
    endmodule
    private struct Inits extends array
        implement Init
    endstruct
endlibrary

The new group names are:

Civilians
HumanWeak
HumanMedium
HumanBig
Undead
WaveDemons
 
Level 2
Joined
Apr 15, 2011
Messages
14
I've encountered an error whenever i try to test my map:
errorwi.jpg
 
Level 2
Joined
Apr 15, 2011
Messages
14
Thats cause your anti virus or something has blocked it from running only way to run the map is if you disable everything i.e anti virus, re install World Editor than try.

I heard that i have to ''Reinvent the craft'', but i don't have that kind of option in my newgen we. And yes, i do have v.5.D.
 
Status
Not open for further replies.
Top