Page 1 of 1

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

Posted: Thu Dec 18, 2014 4:29 am
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,
}

Re: [New Spell]Secret Detector

Posted: Thu Dec 18, 2014 4:31 am
by Grimfan
Just goes to show you that spam is good for something.

Nice work GoldenShadow. :)

Re: [New Spell]Secret Detector

Posted: Thu Dec 18, 2014 9:05 am
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 : ;)

Re: [New Spell]Secret Detector

Posted: Thu Dec 18, 2014 2:51 pm
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",
		},
	},
}

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

Posted: Fri Dec 19, 2014 9:24 pm
by GoldenShadowGS
Updated Topic with new script!

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

Posted: Fri Dec 19, 2014 11:05 pm
by Drakkan
wow, now thats quite powerfull tool for all secret seekers ! :) nice work.