[New Spell]Secret Detector(New and Improved!)

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

[New Spell]Secret Detector(New and Improved!)

Post by GoldenShadowGS »

The Metal Detector thread got my gears spinning and I wanted to make this.


New and improved. Now it states the champion's name and tells you how far away the secret is. It also stops detecting secrets that have been triggered. It also takes into account the elevation of the secret when determining the distance. Only shows the distance to the closest secret instead of the first one it finds. Every point is Earth magic increases your detection range.

Code: Select all

defineSpell{
	name = "find_secret",
	uiName = "Find Secret",
	skill = "earth_magic",
	requirements = {"concentration", 1},
	gesture = 8,
	manaCost = 5,
	icon = 14,
	spellIcon = 13,
	description = "Reveals if a secret is nearby. Every point is Earth Magic increases your maximum detection range.",
	onCast = function(champion, x, y, direction, elevation, skillLevel)
		local secretfound = false
		local count = 3 + skillLevel
		local dist = -1 
		for fx = x - count, x + count do
			for fy = y - count, y + count do
				for i in party.map:entitiesAt(fx,fy) do
					if i:getComponent("secret") then
						if i.secret:isEnabled() then
							--convert tile distance into meters by multiplying by 3
							local xdist = (x - i.x) * 3
							local ydist = (y - i.y) * 3
							local zdist = (elevation - i.elevation) * 3
							local sdist = math.floor(0.5 + math.sqrt(xdist^2 + ydist^2 + zdist^2))
							--Only keeps the lowest distance
							if sdist < dist or dist == -1 then
								dist = sdist
							end
							secretfound = true
						end
					end
				end
			end
		end	
		if secretfound == true then
			playSound("generic_spell")
			if dist == 0 then
				--This part may never be seen if the secret is activated when the party stands on it, but added just in case.
				hudPrint("You are standing on a secret.")
			else
				hudPrint(champion:getName().." senses that the nearest secret is "..dist.." meters away.")
			end
		else
			hudPrint(champion:getName().." can not detect any secrets nearby.")
			playSound("spell_fizzle")
		end
	end,
}
Original, old script
SpoilerShow

Code: Select all

defineSpell{
	name = "find_secret",
	uiName = "Find Secret",
	skill = "earth_magic",
	requirements = {"concentration", 1},
	gesture = 8,
	manaCost = 5,
	icon = 14,
	spellIcon = 13,
	description = "Reveals if a secret is nearby.",
	onCast = function(champion, x, y, direction, elevation, skillLevel)
		local secretfound = false
		local count = 0
		repeat
			for fx = x - count, x + count do
				for fy = y - count, y + count do
					for i in party.map:entitiesAt(fx,fy) do
						if i:getComponent("secret") then
							secretfound = true
							playSoundAt("generic_spell", i.level, i.x, i.y)
							break
						end
					end
				end
			end	
			count = count + 1
		until secretfound == true or count >= 5
		if secretfound == true then
			if count == 1 then
				hudPrint("You are standing on a secret")
			else
				hudPrint("A secret is nearby.")
			end
		else
			hudPrint("You can not detect any secrets nearby.")
			playSound("spell_fizzle")
		end
	end,
}
Last edited by GoldenShadowGS on Fri Dec 19, 2014 9:43 pm, edited 9 times in total.
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: [New Spell]Secret Detector

Post by Grimfan »

Just goes to show you that spam is good for something.

Nice work GoldenShadow. :)
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: [New Spell]Secret Detector

Post by Drakkan »

haha cool. however I think that metal detector should work like some item, which onUse will tell if there is buried chest treasure on the square, so you do not need shoveling around like mad : ;)
Breath from the unpromising waters.
Eye of the Atlantis
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: [New Spell]Secret Detector

Post by bongobeat »

thanks for this code :D
my little contribution :oops:

the ancient apparatus converted into a secret detector item
in LOG1 gfxIndex, the number is 206, in LOG2 this number shows the meteor hammer special attack.
I don't know if the ancient icones are added to the new index?

I finally added it in a custom index.
SpoilerShow

Code: Select all

defineObject{
	name = "secret_apparatus",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
		model = "assets/models/items/ancient_apparatus.fbx",
		},
		{
			class = "Item",
			uiName = "Strange Apparatus",
			gfxAtlas = "mod_assets/textures/oliveitem.tga", -- custom index
			gfxIndex = 91, -- custom index
			weight = 0.7,
			description = "A strange apparatus used by the ninjas of the Khandar sect to detect secrets.",
			secondaryAction = "secret",
			impactSound = "impact_blunt",
		},
		{
			class = "CastSpell",
			name = "secret",
			uiName = "Detect Secret",
			energyCost = 30,
			spell = "find_secret",
			requirements = { "concentration", 1 },
		},
		{
			class = "Particle",
			particleSystem = "glitter_gold",
		},
	},
}
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: [New Spell]Secret Detector(New and Improved!)

Post by GoldenShadowGS »

Updated Topic with new script!
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: [New Spell]Secret Detector(New and Improved!)

Post by Drakkan »

wow, now thats quite powerfull tool for all secret seekers ! :) nice work.
Breath from the unpromising waters.
Eye of the Atlantis
Post Reply