alcove sound (item dropping)

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

alcove sound (item dropping)

Post by RayB »

Does anyone know if it is possible to create a silent alcove?

Defining a coin slot as a lock works fine if your game uses un-stackable coins. However if using stackable coins and the player accidently grabs 10 coins and clicks on the lock it eats them all. I discovered that by defining the coin slot as an alcove I can create a coin slot that only accepts one coin. Or I can define the coin slot to accept any number of coins and then, with the proper script, give change. However, I would like to click on the coin slot and here the 'click lock' sound. But because the coin slot is defined as an alcove you also here the item drop sound. I saw nothing in the definition info or the scripting reference to control the alcove sound. Is this even possible? Can anyone clue me in? I would to be able to do this.
User avatar
maneus
Posts: 246
Joined: Mon Jun 17, 2013 10:42 pm
Location: Switzerland

Re: alcove sound (item dropping)

Post by maneus »

You can make the coin slot not as an alcove but rather as a button and destroying the mouse object always you click on it. You can give the button the "click lock" sound
and if you wish that the player can see the coins behind (like a alcove did) then do a alcove behind and infront of the alcove a closed door with an empty texture.
Check by script your mouse item, destroy it from cursor and spawn it in the alcove behind the closed transparent door.

You can not change the alcove sound. As I know it is only possible for buttons and levers with a script done by Isaac.

Edit: My answer is only for LoG1 because your post is in the forum for it. No idea how to handle it in LoG2.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: alcove sound (item dropping)

Post by minmay »

The "alcove sound" is item_drop, just as the "lock sound" is key_lock.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: alcove sound (item dropping)

Post by Isaac »

RayB wrote:Does anyone know if it is possible to create a silent alcove?
SpoilerShow

Code: Select all

defineObject{
	name = "dungeon_silent_alcove",
	class = "Alcove",
	model = "assets/models/env/dungeon_wall_alcove.fbx",
	replacesWall = true,
	anchorPos = vec(0, 0.85, 0.2),
	targetPos = vec(0,1.3,0),
	targetSize = vec(0.6, 0.5, 0.6),
	placement = "wall",
	editorIcon = 8,
	onInsertItem = function(self, item) 
					self:addItem(item)
					setMouseItem()
					-- additional commands
					

					--
					return false
					end
}
*Not great [not at all], but it's silent, and you can use 'always activate' or manually add conditions and commands to the onInsertItem hook.
Defining a coin slot as a lock works fine if your game uses un-stackable coins. However if using stackable coins and the player accidently grabs 10 coins and clicks on the lock it eats them all.
SpoilerShow

Code: Select all

defineObject{
	name = "coin-slot",
	class = "Alcove",
	--model = "mod_assets/models/env/coin-slot.fbx",
	model = "assets/models/env/dungeon_secret_button_large.fbx",
	replacesWall = false,
	anchorPos = vec(0, 0.85, 0.2),
	targetPos = vec(0,1.7,0),
	targetSize = vec(0.2, 0.2, 0.2),
	placement = "wall",
	editorIcon = 20,
	onInsertItem = function(self, item)
					 
					 local function action()
					 		local number_of_coins = 3 -- set the price
					 		local count = item:getStackSize() --stacked coin check

					 		--optional tests to refuse coin(s) if desired. True means refuse.
					 		if dungeon_door_metal_2:isOpen() then 
					 			hudPrint("The door is already open!")
					 			playSound("party_move_overloaded")    -- refusal sound
					 			return false
					 		end

					 		if count < number_of_coins  then 
					 			hudPrint("You don\'t have enough coins! ["..number_of_coins.."]")
					 			playSound("party_move_overloaded")	-- refusal sound
					 			return false
					 		end

					 		--

					 		-- coin logic
					    		count = count - number_of_coins
					    	 	if count <1 then 
					    	 	--nothing left
					     			setMouseItem()
					      	 	 else 
					      	 	 --change left
					      	 	 	item:setStackSize(count)	
					     			setMouseItem(item)
					    		end	
							--	
							playSound("key_lock") 		--coin slot sound
					 		
					 		-- triggered actions
					 		dungeon_door_metal_2:open()
					 		


					 		--
					    end

				if item.name == "coin" then
					action() 	-- call triggered action
					return false
				 else
					return false
				end
			end,
}

	defineObject{
		name = "coin",
		class = "Item",
		uiName = "Coin",
		model = "assets/models/items/rock.fbx",
		skill = "throwing_weapons",
		ammoType = "coin",
		throwingWeapon = true,
		gfxIndex = 45,
		attackPower = .1,
		coolDownTime = 4,
		attackMethod = "throwAttack",
		attackSound = "swipe",
		impactSound = "impact_blunt",
		stackable = true,
		projectileRotationSpeed = 10,
		projectileRotationZ = -30,
		weight = 1.0,
	}
This works as a [basic] coin slot asset (that checks for stacked coins). You have to customize its triggered actions in the script, as it ignores the regular connectors.

*This script uses default model assets for the coin and slot; you will almost certainly want to change those to custom ones.

project file: https://www.dropbox.com/s/3xuvbizrsb42a ... t.zip?dl=0
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: To Isaac

Post by RayB »

Don't know why you said your first chunk of code was not great. As far as I'm concerned it worked just fine. I should have been more careful in wording my post. I stated 'alcove' because that was the class of my definition but actually I was defining a coin socket. I use a coin slot which is defined as a lock just for the model. It is set up to do nothing. I then add my coin socket to the same place and it does the work.

The socket definition (thanks to you)...
SpoilerShow

Code: Select all

defineObject{
	name = "socket_copper_coin",
	class = "Alcove",
	anchorPos = vec(-0.02, 1.89, -0.54),	--1.69 for reg slot, 1.89 for use with hi slot
	anchorRotation= vec(90,110,0),
	targetPos = vec(-0.02, 1.89, -0.54),
	targetSize = vec(0.07, 0.07, 0.07),
	placement = "wall",
	onInsertItem = function(self, item)
		if item.name == "coin_copper" then
			self:addItem(item)		--manually add item to alcove (socket)
			setMouseItem()			--get rid of mouse item
		end
		return false		--always returning false makes it silent
	end,
	editorIcon = 92,
}
The script I am using in my dungeon...
SpoilerShow

Code: Select all

function takeCoin(cs)
	local chg = 0
	playSound("key_lock")
	for i in cs:containedItems() do
		chg = i:getStackSize() - 1
		i:destroy()
	end
	
	playSound("item_drop")    --optional
	coinSlotAlc:addItem(spawn("bomb_ful"))
	if chg > 0 then
		playSound("coinDrop")
		coinSlotAlc:addItem(spawn("coin_copper"):setStackSize(chg))
		chg = 0
	end
end
This is currently set up to accept 'coin(s)', use only one and then deposit the item and change if needed into a nearby alcove. This script can be modified to accept coins, use more one (say 2 or 3) if the item costs more, and then give the proper change.

The main thing is my socket now sounds like a lock instead of an alcove!

Thank you much.

I am wondering one other thing though...
The definition adds an item to the socket (alcove) manually, sets the mouse item to nil, and then returns (a silent) false. The script then destroys the item I added to the socket but what about the original item that was in the mouse. Should I be destroying that too?
Post Reply