• 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.

Items dropped on death?

Status
Not open for further replies.
Level 1
Joined
Jan 13, 2012
Messages
2
Is there a trigger to randomly make items drop on death for spawned units? I want random items to drop at random times when these units are killed. Help?
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
This is one of many triggers that can drop random number of items with random levels.

  • Random Item
    • Events
      • Unit - A unit Dies
    • Conditions
      • Add your conditions here
    • Actions
      • Set temp_Point = (Position of (Triggering unit))
      • For each (Integer A) from 1 to (Random integer number between 1 and 6), do (Actions)
        • Loop - Actions
          • Item - Create (Random level (Random integer number between 1 and 10) item-type) at temp_Point
      • Custom script: call RemoveLocation( udg_temp_Point )
 
Level 14
Joined
Nov 17, 2010
Messages
1,266
This trigger gives a level 1 creep a 3% chance to drop a level 1 Permanent item. You can change it however you'd like to adapt for creep level or different percentages

[trigger=Is this what you mean]ITEM DROP TRIGGER
Events
Unit - A unit Dies
Conditions
(Owner of (Dying unit)) Equal to (==) Neutral Hostile
(Level of (Dying unit)) Equal to (==) 1
Actions
Set Random_Integer = (Random integer number between 1 and 100)
Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Random_Integer Less than or equal to (<=) 3
Then - Actions
Set DisposablePoint = ((Position of (Dying unit)) offset by 50.00 towards (Random angle) degrees)
Item - Create (Random level 1 Permanent item-type) at DisposablePoint
Custom script: call RemoveLocation(udg_DisposablePoint)
Else - Actions
Do nothing[/trigger]

I haven't had a problem with 'Dying Unit' but Triggering Unit might be better
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
This trigger gives a level 1 creep a 3% chance to drop a level 1 Permanent item. You can change it however you'd like to adapt for creep level or different percentages

[trigger=Is this what you mean]ITEM DROP TRIGGER
Events
Unit - A unit Dies
Conditions
(Owner of (Dying unit)) Equal to (==) Neutral Hostile
(Level of (Dying unit)) Equal to (==) 1
Actions
Set Random_Integer = (Random integer number between 1 and 100)
Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Random_Integer Less than or equal to (<=) 3
Then - Actions
Set DisposablePoint = ((Position of (Dying unit)) offset by 50.00 towards (Random angle) degrees)
Item - Create (Random level 1 Permanent item-type) at DisposablePoint
Custom script: call RemoveLocation(udg_DisposablePoint)
Else - Actions
Do nothing[/trigger]

I haven't had a problem with 'Dying Unit' but Triggering Unit might be better
leaks a location
 
Level 14
Joined
Nov 17, 2010
Messages
1,266
you create the locationA (Position of Picked Unit)

you create another locationB (LocationA moved x up, y across)

you remove locationB

locationA is still there

Oh I see. So how do I remove them both? I guess there is no need to offset it, not sure why I did that in the first place. But to satisfy my curiosity what would you suggest I do?
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Oh I see. So how do I remove them both? I guess there is no need to offset it, not sure why I did that in the first place. But to satisfy my curiosity what would you suggest I do?

make a variable for Position of Picked Unit
make a second variableB for variableA offset #,#,#
remove the first variable
 
Level 14
Joined
Nov 17, 2010
Messages
1,266
Thanks for the tip, never knew I was doing it wrong all this time
Is this better?

[trigger=My Trigger]Level 1 to 2
Events
Unit - A unit Dies
Conditions
(Owner of (Dying unit)) Equal to (==) Neutral Hostile
((Dying unit) is A giant) Equal to (==) True
Multiple ConditionsOr - Any (Conditions) are true
Conditions
(Level of (Dying unit)) Equal to (==) 1
(Level of (Dying unit)) Equal to (==) 2
Actions
Set Random_Integer = (Random integer number between 1 and 100)
Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Random_Integer Less than or equal to (<=) 3
Then - Actions
Set TemporaryPoint[1] = (Position of (Dying unit))
Set TemporaryPoint[2] = (TemporaryPoint[1] offset by 50.00 towards (Random angle) degrees)
Item - Create (Random level 1 Permanent item-type) at TemporaryPoint[2]
Custom script: call RemoveLocation(udg_TemporaryPoint[1])
Custom script: call RemoveLocation(udg_TemporaryPoint[2])
Else - Actions
Do nothing[/trigger]
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I suggest using indexes 0 and 1, this way you waste 2 locations :D but thats just a little note and is not needed
I personally think there is nothing wrong in the GetDyingUnit(GUI Dying Unit), yes it must convert itself to GetTriggerUnit but it does in lower levels than Jass so its imo not problem
other than that, its leakless and should be bugless as you dont use any waits
 
Level 14
Joined
Nov 17, 2010
Messages
1,266
I suggest using indexes 0 and 1, this way you waste 2 locations :D but thats just a little note and is not needed
I personally think there is nothing wrong in the GetDyingUnit(GUI Dying Unit), yes it must convert itself to GetTriggerUnit but it does in lower levels than Jass so its imo not problem
other than that, its leakless and should be bugless as you dont use any waits

Thanks, I know I should use 0 and 1, but I've been doing it wrong for so long that it's hard to change haha. If I ever learn JASS (or any programming for that matter) I'll have to be sure to do it the right way.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Do Nothing literaly does nothing, it justs wastes space, remove it...

JASS:
 function DoNothing takes nothing returns nothing
endfunction

the only purpose for it is a one-line if-then-else statement where it will give u an error if u dont put anything in the Else block
 
Level 14
Joined
Nov 17, 2010
Messages
1,266
Do Nothing literaly does nothing, it justs wastes space, remove it...

JASS:
 function DoNothing takes nothing returns nothing
endfunction

the only purpose for it is a one-line if-then-else statement where it will give u an error if u dont put anything in the Else block

Good to know. Thanks
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I suggest it only because in Jass arrays are allocated in powers of 2(so you have 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 or 8192 variables allocated at the same time, dont worry, the null ones dont or should not eat up space because they point to 0 memory in ram) so if you use 0, 1 you will not allocate additional array size but if you use 1, 2 you will allocate indexes 2 and 3
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
I suggest it only because in Jass arrays are allocated in powers of 2(so you have 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 or 8192 variables allocated at the same time, dont worry, the null ones dont or should not eat up space because they point to 0 memory in ram) so if you use 0, 1 you will not allocate additional array size but if you use 1, 2 you will allocate indexes 2 and 3

in jass u dont allocate arrays...
 
Status
Not open for further replies.
Top