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

[Solved] Looting System

Status
Not open for further replies.
Level 6
Joined
Apr 1, 2009
Messages
201
I'm in development of a looting system for a map I am making. When a unit dies it gets removed from the game and another unit of that type is placed where the unit died (Acting as a corpse). When I cast the "Loot" ability on the corpse it doesn't do what I want it to. It is supposed to create items at the looting players inventory region and when cast it doesn't do anything. The part of the system I am working on is in 3 triggers (For now). The first trigger is storing my integer values. The second trigger is when the player casts the ability "Loot". The third trigger is the chance of which item will drop and then puts it into the owner of the casting units inventory region. I think the problem is with the third trigger, where it doesn't create any items. I've modified the trigger so no matter what the chance, an item will be created. Also, I added in text messages to try and figure out where the problem is. What was displayed was 1,2,3,4,10. I've been looking at it for awhile now and have had no luck in figuring out what is wrong. I'm not that good at triggering but I try my best. I have already looked through some tutorials but have had no luck :/.

  • Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Player and Player's Inventory --------
      • Set LootingPlayer[1] = Player 1 (Red)
      • Set PlayerInventory[1] = Player 1 Inventory <gen>
      • Set LootingPlayer[2] = Player 2 (Blue)
      • Set PlayerInventory[2] = Player 2 Inventory <gen>
      • Set LootingPlayer[3] = Player 3 (Teal)
      • Set PlayerInventory[3] = Player 3 Inventory <gen>
      • Set LootingPlayer[4] = Player 4 (Purple)
      • Set PlayerInventory[4] = Player 4 Inventory <gen>
      • Set LootingPlayer[5] = Player 5 (Yellow)
      • Set PlayerInventory[5] = Player 5 Inventory <gen>
      • Set LootingPlayer[6] = Player 6 (Orange)
      • Set PlayerInventory[6] = Player 6 Inventory <gen>
      • Set LootingPlayer[7] = Player 7 (Green)
      • Set PlayerInventory[7] = Player 7 Inventory <gen>
      • Set LootingPlayer[8] = Player 8 (Pink)
      • Set PlayerInventory[8] = Player 8 Inventory <gen>
      • -------- Unit Loot And Unit Trigger --------
      • Set TriggerLootUnitType[1] = Wolf (Loot)
      • Set TriggerLootType[1] = Wolf <gen>
  • Loot
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Loot
    • Actions
      • For each (Integer TriggerUnitLootInt) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Target unit of ability being cast)) Equal to TriggerLootUnitType[TriggerUnitLootInt]
            • Then - Actions
              • Game - Display to (All players) the text: 1
              • Unit - Make (Target unit of ability being cast) Invulnerable
              • Game - Display to (All players) the text: 2
              • Trigger - Run TriggerLootType[TriggerUnitLootInt] (checking conditions)
            • Else - Actions
  • Wolf
    • Events
    • Conditions
    • Actions
      • Set DropChanceInt = (Random integer number between 0 and 100)
      • Game - Display to (All players) the text: 3
      • For each (Integer LootingInt) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Triggering unit)) Equal to LootingPlayer[LootingInt]
            • Then - Actions
              • Game - Display to (All players) the text: 4
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DropChanceInt Equal to 0
                  • DropChanceInt Less than or equal to 14
                • Then - Actions
                  • Game - Display to (All players) the text: 5
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DropChanceInt Equal to 15
                  • DropChanceInt Less than or equal to 19
                • Then - Actions
                  • Game - Display to (All players) the text: 6
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DropChanceInt Equal to 20
                  • DropChanceInt Less than or equal to 29
                • Then - Actions
                  • Game - Display to (All players) the text: 7
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DropChanceInt Equal to 30
                  • DropChanceInt Less than or equal to 49
                • Then - Actions
                  • Game - Display to (All players) the text: 8
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DropChanceInt Equal to 50
                  • DropChanceInt Less than or equal to 100
                • Then - Actions
                  • Game - Display to (All players) the text: 9
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at (Center of PlayerInventory[LootingInt])
                • Else - Actions
            • Else - Actions
              • Game - Display to (All players) the text: 10
 
Level 6
Joined
Apr 1, 2009
Messages
201
The conditions for drop chances say that the int must be equal to x and less than equal to y-z. As x < y-z, then the conditions are true only when int = x.

You want to remove the equal to x conditions, and leave the less than or equal to.

Ahhhh there's my problem, how could I not have seen that :/ +rep Although now that items are dropping I fear there may be some leaks in my trigger when I loot the corpse 10 is displayed at least 6 times. I thought it shouldn't go to the else actions in the last trigger if my condition is true?

I thinking on this trigger why it use loop only 2? Or this example for 2 player? Tell me Plz.

What do you mean?
 
Last edited:
Level 6
Joined
Apr 1, 2009
Messages
201
You can add Skip remaining actions after you have created the items.

Read about leaks: Things That Leak
All those Center of... are leaking.

I've read through the tutorial and fixed my leaks and have one last question. Do I need to put custom script after each item that is placed at the location or will one work after all the items have been placed at that location?
 
Level 6
Joined
Apr 1, 2009
Messages
201
Okay thank you, I fixed the leak but now the trigger isn't working for other players and trigger 3 is still skipping the then actions going to the else actions then back to then actions. It is really confusing.
 
Level 6
Joined
Apr 1, 2009
Messages
201
  • Loot
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Loot
    • Actions
      • Set LootCaster = (Owner of (Triggering unit))
      • For each (Integer TriggerUnitLootInt) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Target unit of ability being cast)) Equal to TriggerLootUnitType[TriggerUnitLootInt]
            • Then - Actions
              • Game - Display to (All players) the text: 1
              • Unit - Make (Target unit of ability being cast) Invulnerable
              • Game - Display to (All players) the text: 2
              • Trigger - Run TriggerLootType[TriggerUnitLootInt] (checking conditions)
            • Else - Actions
  • Wolf
    • Events
    • Conditions
    • Actions
      • Set DropChanceInt = (Random integer number between 0 and 100)
      • Game - Display to (All players) the text: 3
      • For each (Integer LootingInt) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • LootCaster Equal to LootingPlayer[LootingInt]
            • Then - Actions
              • Game - Display to (All players) the text: 4
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DropChanceInt Greater than or equal to 0
                  • DropChanceInt Less than or equal to 14
                • Then - Actions
                  • Game - Display to (All players) the text: 5
                  • Set PlayerInventoryRegion = (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Custom script: call RemoveLocation(udg_PlayerInventoryRegion)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DropChanceInt Greater than or equal to 15
                  • DropChanceInt Less than or equal to 19
                • Then - Actions
                  • Game - Display to (All players) the text: 6
                  • Set PlayerInventoryRegion = (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Custom script: call RemoveLocation(udg_PlayerInventoryRegion)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DropChanceInt Greater than or equal to 20
                  • DropChanceInt Less than or equal to 29
                • Then - Actions
                  • Game - Display to (All players) the text: 7
                  • Set PlayerInventoryRegion = (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Custom script: call RemoveLocation(udg_PlayerInventoryRegion)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DropChanceInt Greater than or equal to 30
                  • DropChanceInt Less than or equal to 49
                • Then - Actions
                  • Game - Display to (All players) the text: 8
                  • Set PlayerInventoryRegion = (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Custom script: call RemoveLocation(udg_PlayerInventoryRegion)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DropChanceInt Greater than or equal to 50
                  • DropChanceInt Less than or equal to 100
                • Then - Actions
                  • Game - Display to (All players) the text: 9
                  • Set PlayerInventoryRegion = (Center of PlayerInventory[LootingInt])
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Item - Create Wolf Fur at PlayerInventoryRegion
                  • Custom script: call RemoveLocation(udg_PlayerInventoryRegion)
                • Else - Actions
            • Else - Actions
              • Game - Display to (All players) the text: 10
I don't use any events for the wolf trigger I just run the wolf trigger from the previous trigger.
 
Level 6
Joined
Apr 1, 2009
Messages
201
Now it works for every player, but will the loop that doesn't meet the player conditions cause any problems?
Also I just ran into another problem with my system where I remove the unit and replace it with the corpse unit. The problem is I used last created unit to remove the corpse and if I kill one unit then a second unit it will remove the second unit, leaving the first unit. I can't do an expiration timer either because when the regular unit dies a loot unit is created in its place and the loot unit's death animation is played. If I add an expiration timer, the loot unit gets up and then dies again. Is there any way to fix that?

  • Unit Dies
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
    • Actions
      • For each (Integer UnitLootInt) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to UnitType[UnitLootInt]
            • Then - Actions
              • Set UnitPoint = (Position of (Triggering unit))
              • Unit - Remove (Triggering unit) from the game
              • Unit - Create 1 UnitLootType[UnitLootInt] for Neutral Passive at UnitPoint facing (Facing of (Dying unit)) degrees
              • Custom script: call RemoveLocation( udg_UnitPoint )
              • Animation - Play (Last created unit)'s death animation
              • Wait 10.00 seconds
              • Unit - Remove (Last created unit) from the game
            • Else - Actions
Edit: I figured out how to do fix this trigger, I'm just going to remove the corpse when you loot it. Thank you for your help +rep.
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,240
The loops won't cause problems.

  • Unit Dies
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
    • Actions
      • Custom script: local unit u
      • For each (Integer UnitLootInt) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to UnitType[UnitLootInt]
            • Then - Actions
              • Set UnitPoint = (Position of (Triggering unit))
              • Unit - Remove (Triggering unit) from the game
              • Unit - Create 1 UnitLootType[UnitLootInt] for Neutral Passive at UnitPoint facing (Facing of (Dying unit)) degrees
              • Custom script: call RemoveLocation( udg_UnitPoint )
              • Animation - Play (Last created unit)'s death animation
              • Custom script: set u = bj_lastCreatedUnit
              • Wait 10.00 seconds
              • Custom script: call RemoveUnit(u)
            • Else - Actions
      • Custom script: set u = null
 
Level 5
Joined
Jan 4, 2009
Messages
118
You're looping from 1 to 2 so it only works for P1 and P2.

It will display "10" for every loop that doesn't meet the player condition.

Sorry for my language, I mean same Mr. Maker. your loop for Player 1 and Player 2?

The loops won't cause problems.

  • Unit Dies
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
    • Actions
      • Custom script: local unit u
      • For each (Integer UnitLootInt) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to UnitType[UnitLootInt]
            • Then - Actions
              • Set UnitPoint = (Position of (Triggering unit))
              • Unit - Remove (Triggering unit) from the game
              • Unit - Create 1 UnitLootType[UnitLootInt] for Neutral Passive at UnitPoint facing (Facing of (Dying unit)) degrees
              • Custom script: call RemoveLocation( udg_UnitPoint )
              • Animation - Play (Last created unit)'s death animation
              • Custom script: set u = bj_lastCreatedUnit
              • Wait 10.00 seconds
              • Custom script: call RemoveUnit(u)
            • Else - Actions
      • Custom script: set u = null

I ask Mr. Maker about "wait" on next time event is happening again old unit u will be deleted?
 
Last edited by a moderator:
Status
Not open for further replies.
Top