Page 168 of 400

Re: Ask a simple question, get a simple answer

Posted: Tue Nov 22, 2016 12:06 am
by bongobeat
thanks!

Re: Ask a simple question, get a simple answer

Posted: Wed Nov 23, 2016 10:21 pm
by Isaac
Is there any context that would allow drawing over top of a playing video in LoG2?

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 4:47 am
by Mysterious
RE: Lock Problem.

Hi all. The below code works fine but when the correct key is used in the lock, the key falls to the ground. I want the key to be destroy not to be reused.

The idea is that the player has to use (lvl1thom_door_key_1) to open the lock which then opens the door etc.... Any help as to where I'm going wrong here Thank You.

PS: When the key is used by the way the Lock Socket is connected to a script which allows me to do things eg Open door maybe bad or good.

Code: Select all

-----------
--- Key ---
-----------
defineObject{
	name = "lvl1thom_door_key_1",
	baseObject = "base_item",
	tags = { "my_quest_keys" },
	components = {
		{
			class = "Model",
			model = "assets/models/items/key_iron.fbx",
		},
		{
			class = "Item",
			uiName = "Thomadars Key",
			gfxIndex = 22,
			weight = 0.2,
			traits = { "key" },
		},
		{
			class = "Particle",
			particleSystem = "glitter_gold",
		},
	},
}
------------------
--- Key Lock ---
------------------
defineObject{
	name = "thom_base_lock_1",
	components = {
		{
			class = "Model",
			model = "assets/models/env/wall_lock_round.fbx",
			offset = vec(0, 1.375, 0),
			staticShadow = true,
		},
		{
			class = "Clickable",
			offset = vec(0, 1.38, -0.16),
			size = vec(0.1, 0.1, 0.15),
			debugDraw = true,
		},
		{
			class = "Socket",
			offset = vec(0, 0, 0), --(-0.42, 1.18, 0),--
			--offset = vec(0, 0, 0),
			rotation = vec(0, 0, -3),
			onAcceptItem = function(self, item)
			if item.go.name ~= "lvl1thom_door_key_1" then
			hudPrint("You will need Thomadar's key to open the door.")
				return false
				else
				playSound("key_lock")
				return true
				end
			end,
		},
	},
	placement = "wall",
	editorIcon = 92,
	tags = { "my_quest_keys" },
}

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 5:12 am
by zimberzimber
You're using a socket component instead of a lock component.
Socket component doesn't destroy the item it accepts, and keeps it on display wherever it is defined to.
Lock component accepts only the item it is defined to accepts without any additional checkers, and automatically destroys it upon accepting it.
Try looking at some lock definitions inside the asset pack to get a better idea.

Also, instead of defining a new object, you could use one of the already present locks and attach it to the door.

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 6:58 am
by minmay
zimberzimber wrote:Lock component accepts only the item it is defined to accepts without any additional checkers, and automatically destroys it upon accepting it.
LockComponent doesn't actually destroy the item, it just removes the mouse item. The item still exists afterwards, but since it is not on a map you can only reach it by having a preexisting reference to it. For example, this is a lock that immediately puts the key item back into the mouse item slot:

Code: Select all

-- The mirror "lock" should not consume the item used to open it; in Dungeon
-- Master, using the Mirror of Dawn on it doesn't destroy the mirror. We do
-- this by simply setting the mouse item back to the key after it is used. The
-- ItemComponent reference here is removed before the end of the frame so it
-- cannot cause a serialization error.
defineObject{
	name = "dm_lock_mirror_slot",
	baseObject = "lock",
	components = {
		{
			class = "Model",
			model = "mod_assets/dmcsb_pack/models/env/dm_mirror_slot.fbx",
			offset = vec(0, 1.74, 0),
			staticShadow = true,
		},
		{
			class = "Clickable",
			offset = vec(0, 1.74, 0),
			size = vec(0.5, 0.4, 0.4),
			onClick = function(self)
				if self.go.lock:isEnabled() and getMouseItem() and getMouseItem().go.name == self.go.lock:getOpenedBy() then
					GameMode.dm_tempLockItem = getMouseItem()
				end
			end,
		},
		{
			class = "Lock",
			sound = "key_lock",
			openedBy = "dm_mirror_of_dawn",
			onActivate = function(self)
				setMouseItem(GameMode.dm_tempLockItem)
				GameMode.dm_tempLockItem = nil
			end,
		},
	},
	tags = {"dm","dm_user"},
}

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 3:05 pm
by zimberzimber
I see... That reminds me.
Is there a safe way of getting rid of an item for good?
Currently I'm using the 'add-it-to-a-surface-and-remove-the-surface-component' method and it works, but I really don't like it.
I need it because I have to return the item from a surface, and since there is no removeItem function, I had to settle for this.

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 3:37 pm
by AndakRainor
You can use GameObject:destroy() on an item added to a SurfaceComponent. You can check it; after this command, SurfaceComponent:count() will return the correct updated value. The real problem with SurfaceComponent is when you want to remove an item from it but not destroy it, that is where the scripting interface is lacking a function.

In my mod I use this in a script entity named "utils":

Code: Select all

self.go:createComponent("Surface")
self.go.surface:setSize(vec(1.5, 1.5))

function destroyItem(item)
  if not item then return end
  if not item.go.map then self.go.surface:addItem(item) end
  item.go:destroy()
end

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 5:35 pm
by zimberzimber
Yup, my problem is unlikning the item from the surface instead of deleting it.
Maybe someone has a better solution in mind for this instead of removing and re-adding the surface component?
Here is the script I'm using:

Code: Select all

for v,i in enchanterAltar.surface:contents() do
	if i and i.go.item then
		for c = 1,4 do
			local champion = party.party:getChampion(c)
			if champion then 
				for invSlot = 13, 32 do
					if champion:getItem(invSlot) == nil then
						champion:insertItem(invSlot, i)
						mi.data.gfxIndex = 0.5
						mi.data.size = {0, 0}
						enchanterAltar:removeComponent("surface")
						enchanterAltar:createComponent("Surface")
						enchanterAltar.surface:setSize(vec(1,1))
						return
					end
				end
			end
		end
		hudPrint("Inventory is full")
		playSound("dispel_launch")
		return
	end
end

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 5:43 pm
by Isaac
Minmay has a script [somewhere] ~IIRC, that adds the item to an invisible monster's inventory, then kills it; and so it drops on the map.

Re: Ask a simple question, get a simple answer

Posted: Fri Nov 25, 2016 6:14 pm
by zimberzimber
I tried that, but it didn't unlink the item from the surface.