• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Sell all ability

Status
Not open for further replies.
Level 5
Joined
Jul 15, 2018
Messages
111
My RPG map has buildings that auto collect resources over time, I would like to give pack horse units the ability to sell their entire inventory to help streamline the process. What would be the best way to go about that?

Ideally I would like to integrate an ability like that into a system where the pack animal automates the selling process by picking up items from the targeted building and travel to a shop to sell, rinse and repeat.
 
Anyway, so this should be a (mostly) working 'sell all items' ability, but not an entire auto-pickup items and auto-sell items.

Trigger 1
  • sell all items ability
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Sell all Items
      • (Level of Select Hero for (Target unit of ability being cast)) Equal to 1
    • Actions
      • set unit1 = (Triggering Unit)
      • set unit2 = (Target unit of ability being cast)
      • set playerVar = (Triggering player)
      • set playerIndex = (Player number of playerVar)
      • set itemsNum[playerIndex] = 0
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item carried by unit1 in slot (Integer A)) Not equal to No item
            • Then - Actions
              • Set itemsNum[playerIndex] = itemsNum[playerIndex] + 1)
              • Set item1 = (Item carried by unit1 in slot (Integer A))
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • itemsNum[playerIndex] Greater than 0
        • Then - Actions
          • Custom script: call UnitDropItemTarget(udg_unit1, udg_item1, udg_unit2)
        • Else - Actions
Trigger 2
  • sell all items sell
    • Events
      • Unit - A unit Pawns an item (to shop)
    • Conditions
      • itemsNum[(Player number of (Triggering player))] Greater than 0
    • Actions
      • set unit1 = (Triggering unit)
      • set unit2 = (Buying unit)
      • set playerVar = (Triggering player)
      • set playerIndex = (Player number of playerVar)
      • Set itemsNum[playerIndex] = itemsNum[playerIndex] - 1
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • itemsNum[playerIndex] Greater than 0
        • Then - Actions
          • set item1 = (Item carried by unit1 in slot (Integer A))
          • For each (Integer A) from 1 to 6, do (Actions)
            • Loop - Actions
              • set item1 = (Item carried by unit1 in slot (Integer A))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • item1 Not equal to No item
                    • Then - Actions
                      • Custom script: call UnitDropItemTarget(udg_unit1, udg_item1, udg_unit2)
                    • Else - Actions
I messed up the formatting a bit on the 2nd trigger, but eh should be fine. Anyway, I made it so it's just 1 per player, so it's not mui, but it should be easy enough to change... It might not actually work either as I wrote most of it right here in the post, but it should give you an idea at least.
 
Last edited:
Death Adder has a good start, but it definitely needs to be MUI for this to even be viable. In my opinion this is best done with a spellbook on each packhorse that allows you to set a target shop, a source building, and turn on/off auto-repeat. You'll need some sort of a Unit Indexer in your map (there are many varieties, or this whole thing can be done with a hashtable too), two unit arrays to store the current source building and the destination shop, and a boolean array to store whether or not it the pack horse should sell all and repeat. Then 3 abilities: choose source, choose target, stop, and start (stop/start replace each other so you only see 3 at a time) which you can all base on Channel so they have no art/casting time/effects/etc.

Used this as a source: [Solved] - Order unit to sell item to unit

  • Events
    • Unit - A Unit starts the effect of an ability
  • Conditions
    • (Ability being cast) equal to SET_SOURCE
  • Actions
    • Set PACK_source[(Custom value of (Triggering Unit))] = (Target unit of ability being cast)
  • Events
    • Unit - A Unit starts the effect of an ability
  • Conditions
    • (Ability being cast) equal to SET_TARGET
  • Actions
    • Set PACK_target[(Custom value of (Triggering Unit))] = (Target unit of ability being cast)
  • Events
    • Unit - A Unit starts the effect of an ability
  • Conditions
    • (Ability being cast) equal to STOP
  • Actions
    • Unit - Remove STOP from (triggering unit)
    • Unit - Add START to (triggering unit)
    • Set PACK_active[(Custom value of (Triggering Unit))] = false
    • Unit - Order (triggering unit) to stop
  • Events
    • Unit - A Unit starts the effect of an ability
  • Conditions
    • (Ability being cast) equal to START
  • Actions
    • Unit - Remove START from (triggering unit)
    • Unit - Add STOP to (triggering unit)
    • Set PACK_active[(Custom value of (Triggering Unit))] = true
    • For each (Integer ITEM_LOOP) from 1 to 6 do (Actions)
      • Loop - Actions
        • Set ITEM = (Item carried by (Triggering Unit) in slot ITEM_LOOP)
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • ITEM not equal to (no item)
          • Then - Actions
            • Custom script: call UnitDropItemTarget(GetTriggerUnit(), udg_ITEM, udg_PACK_target[GetUnitUserData(GetTriggerUnit())]) //change the variable names here to match your variables, but keep the udg_ before each one
            • Skip remaining actions
          • Else - Actions
  • Events
    • Unit - A Unit pawns an item (to shop)
  • Conditions
    • Pack_active[Custom Value of (Triggering Unit)] equal to true //optional line, only enables full inventory sell if active
    • (Unit-type of (Triggering Unit)) equal to Pack Horse //if you don't have the above line use this instead to restrict autosell only to pack horses
  • Actions
    • For each (Integer ITEM_LOOP) from 1 to 6 do (Actions)
      • Loop - Actions
        • Set ITEM = (Item carried by (Triggering Unit) in slot ITEM_LOOP)
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • ITEM not equal to (no item)
          • Then - Actions
            • Custom script: call UnitDropItemTarget(GetTriggerUnit(), udg_ITEM, udg_PACK_target[GetUnitUserData(GetTriggerUnit())]) //change the variable names here to match your variables, but keep the udg_ before each one
            • Skip remaining Actions
          • Else - Actions
    • -------- If we got all the way here the packhorse inventory is now empty and it can turn around and go back to get more resources --------
    • -------- This is now a problem for the next trigger, so I'll leave this bit blank for now though something WILL go here --------
So the above 5 triggers set the source, target, and 'autosell' variables; and when the unit sells one item it continues to sell everything in its inventory until it's full, then it does <something> to start the process over again. What the <something> is depends really on how you want to get the items from the source building into the pack horse's inventory. Another factor is how the source building stores them anyway-- are they items in its inventory? Are they added to the shop stock via triggers at the right time? Are they units or items that auto-generate more stock every X seconds? This is important because there is no "order unit to buy item from shop" or "order shop to sell item to unit" action you can use, and that is kinda a roadblock to the simplest solution (effectively what I was able to do with looping the item pawn until no items are left).

I think the best solution would be to make the shops populate their own literal 6-slot inventory and then order them to give it to the packhorses when necessary to transfer. You can still stack items there but only 6 different items could be produced at one time. The next best solution is detecting when pack horses get near a shop they're currently targeting as a source and then filling their inventory with triggers immediately while reducing the source shop's stock. This requires a few triggers with "Unit - A unit comes within <distance> range of <specific unit>" events (which you have to add manually for every source shop on your map) or putting all the packhorses into a unit group and checking if they're near their currently selected source building on a reasonable timeout, like every 1.00 seconds. If you can give more specifics about the way you want to approach this I will be happy to flesh out the trigger more, but for now this is about all I can do.

Finally why not automatically pick the closest shop to sell their items to? Well, you could have a situation where the closest shop (straight line distance) is on a cliff with the ramp very far away, or cut off from the pack horse by a wall of trees, or something else entirely may make it an undesirable location (maybe it's near an un-killed creep camp). IMO it's better to give players control.
 
Last edited:
Status
Not open for further replies.
Back
Top