Skip to content

Shop functions

add_item_to_shop

source

function remove_from_shop(ent_uid)
local ent = get_entity(ent_uid)
if ent then
-- technically this function is all you need
ent:liberate_from_shop(true)
end
-- Be aware that removing all the items with the method below will grant you the "Big Spender" quest
-- removing items from the owned_items is not required
-- game only does it when you buy from the store and not when items are destroyed or shop disabled by aggro
state.room_owners.owned_items:erase(ent_uid)
end
function add_item_to_shop(item_uid: integer, shop_owner_uid: integer)
item_uid: integer
shop_owner_uid: integer

Adds entity as shop item, has to be of Purchasable type, check the entity hierarchy list to find all the Purchasable entity types. Adding other entities will result in not obtainable items or game crash, if item already is in StateMemory.room_owners.owned_items then it will just re-parent it

is_inside_active_shop_room

source

function is_inside_active_shop_room(x: number, y: number, layer: LAYER): boolean
x: number
y: number
layer: LAYER

Returns boolean

Checks whether a coordinate is inside a room containing an active shop. This function checks whether the shopkeeper is still alive.

is_inside_shop_zone

source

function is_inside_shop_zone(x: number, y: number, layer: LAYER): boolean
x: number
y: number
layer: LAYER

Returns boolean

Checks whether a coordinate is inside a shop zone, the rectangle where the camera zooms in a bit. Does not check if the shop is still active!

spawn_shopkeeper

documented onlysource

-- spawns a shopkeeper selling a shotgun next to you
-- converts the current room to a ROOM_TEMPLATE.SHOP with shop music and zoom effect
local x, y, l = get_position(get_player(1).uid)
local owner = spawn_shopkeeper(x+1, y, l)
add_item_to_shop(spawn_on_floor(ENT_TYPE.ITEM_SHOTGUN, x-1, y, l), owner)
-- spawns a shopkeeper selling a puppy next to you
-- also converts the room to a shop, but after the shopkeeper is spawned
-- this enables the safe zone for moving items, but disables shop music and zoom for whatever reason
local x, y, l = get_position(get_player(1).uid)
local owner = spawn_shopkeeper(x+1, y, l, ROOM_TEMPLATE.SIDE)
add_item_to_shop(spawn_on_floor(ENT_TYPE.MONS_PET_DOG, x-1, y, l), owner)
local ctx = PostRoomGenerationContext:new()
local rx, ry = get_room_index(x, y)
ctx:set_room_template(rx, ry, l, ROOM_TEMPLATE.SHOP)
function spawn_shopkeeper(x: number, y: number, layer: LAYER, room_template?: ROOM_TEMPLATE): integer
x: number
y: number
layer: LAYER
room_template?: ROOM_TEMPLATEoptional

Returns integer

Spawn a Shopkeeper in the coordinates and make the room their shop. Returns the Shopkeeper uid. Also see spawn_roomowner.