Scripted Shop Spawning

A feature commonly asked about is how to dynamically create shops. Turns out it's actually quite easy! Here's what to do.

Step 1

You need to create the triggering area for your shop in hammer. Use the block tool (ctrl+b) to draw the triggering area you want for the shop, you can change the shape in the block tool to whatever you need.

Draw the area somewhere off the map. You don't want players randomly stumbling across it.

Step 2.

Turn the block into a entity by selecting it and pressing ctrl+t. Change the entity class to trigger_shop and give it a name. Also filter materials and find the trigger material, drag it onto the block. Finally set the shop type at the bottom. It should now look like this ShopInHammer. When that's done rebuild the map.

Step 3.

Now simply add the following code to create a shop at your desired location! I added this to OnConstructionCompleted in building helper.

local shopEnt = Entities:FindByName(nil, "my_new_shop") -- entity name in hammer
local newshop = SpawnEntityFromTableSynchronous('trigger_shop', {origin = unit:GetAbsOrigin(), shoptype = 1, model=shopEnt:GetModelName()}) -- shoptype is 0 for a "home" shop, 1 for a side shop and 2 for a secret shop

Example:

Recommended reading: Creating a custom shop in Dota 2

Comments

  • edited April 2015 Posts: 2

    For what it's worth, I've gotta say SpawnEntityFromTableSynchronous is by far one of the most underrated lua functions. It doesn't really matter what you set in hammer as this creates a new entity with the args passed to it. All it needs from hammer is the box with a trigger material. You could use a similar technique to create 1x1 gridnav blocks or vision blockers I suspect.

  • edited April 2015 Posts: 1,670

    Nice! I certainly haven't used SpawnSynchronous enough, how do you discover the shoptype and model parameters? Could we script a trigger spawning with it? (As in, the actual trigger box entity of Hammer without having to draw its size)

    Edit: I just realized the existence of CreateTrigger and CreateTriggerRadiusApproximate function, nevermind that :sweat_smile:

    The concept of Modding Community doesn't go well together with Competitive Business
    My Project Page || My GitHub Profile ||

  • DunDun
    Posts: 123

    This might shed a light on dynamic shop system, thanks

  • Posts: 6

    @Noya If you change the view on Object Properties to "Raw Edit Mode" you can see what parameters to pass.

    enter image description here

  • Posts: 184

    Well I'd be damned.

    Treat everyday as if you are a student, not a master. The student learns, grows and sees beauty. The master becomes bitter, resentful, and stagnates.