This is the updated object. It places the item models, and has limited support for distance checking and item stacking.
*This version does require facing == 0; and it aligns itself on init. If the offsets are wrong, they should be adjustable to suit.
I have a version of it with support for arbitrary facing [0-3], but it has a bug that I don't understand yet.
Code: Select all
defineObject{
name = "river_sockets",
baseObject = "base_floor_decoration",
components = {
{
class = "Null",
onInit = function(self) self.go:setPosition(self.go.x, self.go.y, 0, self.go.elevation, self.go.level)
self.go.script:setSource([[
function distanceCheck(self, offset, target)
local range = 2.5
local partyX, null ,partyY = unpack(party:getWorldPosition()) null = nil --party X/Y world position
local worldX, null ,worldY = unpack(self.go:getWorldPosition()) null = nil --object X/Y world position
local modelX, modelY = worldX + offset[1] ,worldY + offset[3]
if target then
range = .5
partyX, null ,partyY = unpack(target:getWorldPosition()) null = nil --item X/Y world position
end
local distance = math.sqrt((partyX-modelX)^2 + (partyY-modelY)^2)
if distance < range then
return true
end
end
function stackCheck(self, item)
local itemCount = 1
local stackable = false
for each in self.go.map:entitiesAt(self.go.x, self.go.y) do
if each.name == item then
if each.item:getStackable() then
stackable = true
if self.go.script:distanceCheck(self.go[item]:getOffset(), each) then
itemCount = itemCount + each.item:getStackSize()
each:destroy()
end
end
end
end
item = spawn(item)
if stackable then
item.item:setStackSize(itemCount)
end
return item.item
end
]])
end,
},
{
class = "Script",
},
{
class = "Model", --"crystal_flower"
name = "s1",
offset = vec(0.35, 0, 1.49),
model = "assets/models/items/crystal_flower.fbx",
},
{
class = "Clickable",
name = "crystal_flower",
offset = vec(0.35, 0, 1.49),
size = vec(.2,.2,.2),
frontFacing = false,
--debugDraw = true,
maxDistance = 1,
onClick = function(self) if not getMouseItem() then
if self.go.script:distanceCheck(self.go.s1:getOffset()) then
self.go.s1:disable() self.go[self:getName()]:disable() setMouseItem(self.go.script:stackCheck(self:getName()))
end
end
end,
},
{
class = "Model", --"blooddrop_cap"
name = "s2",
offset = vec(-0.35, 0, 1.1),
model = "assets/models/items/blooddrop_cap.fbx",
},
{
class = "Clickable",
name = "blooddrop_cap",
offset = vec(-0.35, 0, 1.1),
size = vec(.2,.2,.2),
frontFacing = false,
--debugDraw = true,
maxDistance = 1,
onClick = function(self) if not getMouseItem() then
if self.go.script:distanceCheck(self.go.s2:getOffset()) then
self.go.s2:disable() self.go[self:getName()]:disable() setMouseItem(self.go.script:stackCheck(self:getName()))
end
end
end,
},
{
class = "Model", --"etherweed"
name = "s3",
offset = vec(-0.35, 0, 0.4),
model = "assets/models/items/milkreed.fbx",
},
{
class = "Clickable",
name = "etherweed",
offset = vec(-0.35, 0, 0.4),
size = vec(.2,.8,.2),
frontFacing = false,
--debugDraw = true,
maxDistance = 1,
onClick = function(self) if not getMouseItem() then
if self.go.script:distanceCheck(self.go.s3:getOffset()) then
self.go.s3:disable() self.go[self:getName()]:disable() setMouseItem(self.go.script:stackCheck(self:getName()))
end
end
end,
},
{
class = "Model", --"brass_key"
name = "s4",
offset = vec(0.8, -0.05, 0.55),
model = "assets/models/items/key_brass.fbx",
},
{
class = "Clickable",
name = "brass_key",
offset = vec(0.8, -0.05, 0.55),
size = vec(.2,.2,.2),
frontFacing = false,
--debugDraw = true,
maxDistance = 1,
onClick = function(self) if not getMouseItem() then
if self.go.script:distanceCheck(self.go.s4:getOffset()) then
self.go.s4:disable() self.go[self:getName()]:disable() setMouseItem(self.go.script:stackCheck(self:getName()))
end
end
end,
},
{
class = "Model", --"skull"
name = "s5",
offset = vec(-0.5, 0, -0.85),
model = "assets/models/items/skull.fbx",
},
{
class = "Clickable",
name = "skull",
offset = vec(-0.5, 0, -0.85),
size = vec(.2,.3,.2),
frontFacing = false,
--debugDraw = true,
maxDistance = 1,
onClick = function(self) if not getMouseItem() then
if self.go.script:distanceCheck(self.go.s5:getOffset()) then
self.go.s5:disable() self.go[self:getName()]:disable() setMouseItem(self.go.script:stackCheck(self:getName()))
end
end
end,
},
},
placement = "floor",
editorIcon = 104,
}