[Script] Magic Platform Spell

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

[Script] Magic Platform Spell

Post by GoldenShadowGS »

edit~IMPROVED version below a few posts down~


paste this into your spells.lua

Code: Select all

defineSpell{
	name = "magic_bridge_spell",
	uiName = "Magic Platform",
	skill = "air_magic",
	requirements = {"air_magic", 4, "concentration", 2},
	gesture = 3214563,
	manaCost = 120,
	icon = 14,
	spellIcon = 13,
	description = "Conjure a magical platform for a brief time in front of the party.",
    onCast = function(champion, x, y, direction, elevation, skillLevel)
		--myx and myy are the coordinates where the magic platform will spawn. 
		--Starts with the party's coordinates and modifies it base on their direction.
		local myx = x
		local myy = y
		if direction == 0 then
			myy = y - 1
		end
		if direction == 1 then
			myx = x + 1
		end
		if direction == 2 then
			myy = y + 1
		end
		if direction == 3 then
			myx = x - 1
		end
		--Makes sure only one magic platform exists at a time. The game will crash if two entities with the same ID exist.
		if findEntity("magic_spell_bridge") == nil then
			local bridgeelevation = party.map:getElevation(myx,myy)
			local bridgeceiling = party.map:getCeilingElevation(myx,myy)
			local hasbridge = false
			--Checks for existing platforms by name
			for i in party.map:entitiesAt(myx,myy) do
				--Only considers platforms at the same elevation as the party.
				if i.elevation == elevation then	
					--If you have any new platform entities in your mod, add them to this list.
					if i.name == "forest_bridge" or i.name == "castle_bridge" or i.name == "castle_bridge_grating" or i.name == "mine_bridge_01" or i.name == "invisible_platform" then
						hasbridge = true
					end
					if i.name == "magic_bridge" then
						if i.platform:isEnabled() then
							hasbridge = true
						end
					end
				end
			end
			--Makes sure the tile where the magic platform will appear has a lower floor and a higher ceiling than the tile the party is standing on. 
			--Also makes sure no other platforms exist there and that the party has line of sight, so it will work through wall grating, but not secret doors.
			--This prevents the magic platform from appearing inside of a floor or an existing bridge, which looks bad.
			if bridgeelevation < elevation and bridgeceiling > elevation and hasbridge == false and party.map:checkLineOfSight(x,y,myx,myy,elevation) then
				spawn("magic_bridge",party.level,myx,myy,direction,elevation,"magic_spell_bridge")
				delayedCall("bridge_remover_script",3,"removebridge")
				playSound("generic_spell")
			else
				hudPrint("You can not create a magic platform here.")
				playSound("spell_fizzle")
				champion:regainEnergy(110)
			end
		else
				hudPrint("You can only create one magic platform at a time.")
				playSound("spell_fizzle")
				champion:regainEnergy(110)
		end
	end,
}
IMPORTANT: create a script entity in your dungeon and name it exactly:"bridge_remover_script"
paste the following into the script of "bridge_remover_script"

Code: Select all

function removebridge()
	if findEntity("magic_spell_bridge") ~= nil then
		magic_spell_bridge:destroy()
	end
end
This works in 99% of my test cases except over pits that are at -7 elevation. In such a case, you will just get the message that you can not put a magic platform there.

edit: tweaked it so you can cast the magic platform over deactivated light bridges.
Last edited by GoldenShadowGS on Tue Nov 25, 2014 10:16 pm, edited 1 time in total.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: [Script] Magic Platform Spell

Post by Drakkan »

this spell could be quite break-trough in many dungeons, but still nice coding, thanks for sharing.
Breath from the unpromising waters.
Eye of the Atlantis
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: [Script] Magic Platform Spell

Post by GoldenShadowGS »

My dungeon is very non linear, almost like a Metroid game. So, I gotta have something to enable sequence breaks :)
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: [Script] Magic Platform Spell

Post by GoldenShadowGS »

I've made some alterations to the code. Now the platform drains a small amount of energy constantly if nothing is standing on it. Drains a lot of energy if the party or a monster is standing on it, will automatically disappear when you or a monster steps off of it or you run out of energy, which ever happens first.

spells.lua:

Code: Select all

defineSpell{
	name = "magic_bridge_spell",
	uiName = "Magic Platform",
	skill = "air_magic",
	requirements = {"air_magic", 2, "concentration", 2},
	gesture = 3214563,
	manaCost = 10,
	icon = 14,
	spellIcon = 13,
	description = "Conjure a magical platform for a brief time in front of the party.",
    onCast = function(champion, x, y, direction, elevation, skillLevel)
		--myx and myy are the coordinates where the magic platform will spawn. 
		--Starts with the party's coordinates and modifies it base on their direction.
		local myx = x
		local myy = y
		if direction == 0 then
			myy = y - 1
		end
		if direction == 1 then
			myx = x + 1
		end
		if direction == 2 then
			myy = y + 1
		end
		if direction == 3 then
			myx = x - 1
		end
		--Makes sure only one magic platform exists at a time. The game will crash if two entities with the same ID exist.
		if findEntity("magic_spell_bridge") == nil then
			local bridgeelevation = party.map:getElevation(myx,myy)
			local bridgeceiling = party.map:getCeilingElevation(myx,myy)
			local hasbridge = false
			--Checks for existing platforms by name
			for i in party.map:entitiesAt(myx,myy) do
				--Only considers platforms at the same elevation as the party.
				if i.elevation == elevation then	
					--If you have any new platform entities in your mod, add them to this list.
					if i.name == "forest_bridge" or i.name == "castle_bridge" or i.name == "castle_bridge_grating" or i.name == "mine_bridge_01" or i.name == "invisible_platform" then
						hasbridge = true
					end
					if i.name == "magic_bridge" then
						if i.platform:isEnabled() then
							hasbridge = true
						end
					end
				end
			end
			--Makes sure the tile where the magic platform will appear has a lower floor and a higher ceiling than the tile the party is standing on. 
			--Also makes sure no other platforms exist there and that the party has line of sight, so it will work through wall grating, but not secret doors.
			--This prevents the magic platform from appearing inside of a floor or an existing bridge, which looks bad.
			if bridgeelevation < elevation and bridgeceiling > elevation and hasbridge == false and party.map:checkLineOfSight(x,y,myx,myy,elevation) then
				spawn("magic_bridge",party.level,myx,myy,direction,elevation,"magic_spell_bridge")
				spawn("floor_trigger",party.level,myx,myy,direction,elevation,"magic_spell_bridge_trigger")
				magic_spell_bridge_trigger.floortrigger:setTriggeredByDigging(false)
				magic_spell_bridge_trigger.floortrigger:setTriggeredByItem(false)
				magic_spell_bridge_trigger.floortrigger:setTriggeredByMonster(true)
				magic_spell_bridge_trigger.floortrigger:setTriggeredByParty(true)
				magic_spell_bridge_trigger.floortrigger:addConnector("onDeactivate", "bridge_remover_script", "removebridge")
				delayedCall("bridge_remover_script",0.1,"checkbridge", champion:getOrdinal())
				playSound("generic_spell")
			else
				hudPrint("You can not create a magic platform here.")
				playSound("spell_fizzle")
				champion:regainEnergy(5)
			end
		else
				hudPrint("You can only create one magic platform at a time.")
				playSound("spell_fizzle")
				champion:regainEnergy(5)
		end
	end,
}
Like before, put a script entity in your dungeon named "bridge_remover_script" and paste this into it:

Code: Select all


function removebridge()
	if magic_spell_bridge ~= nil then
		magic_spell_bridge:destroyDelayed(.01)
		playSound("spell_expires")
	end
	if magic_spell_bridge_trigger ~= nil then
		magic_spell_bridge_trigger:destroyDelayed(.01)
	end
end

function checkbridge(caster)
	if magic_spell_bridge ~= nil then
		if party.party:getChampion(caster):getEnergy() >= 5 then
			if magic_spell_bridge_trigger.floortrigger:isActivated() then
				delayedCall("bridge_remover_script",0.1,"checkbridge", caster)
				party.party:getChampion(caster):regainEnergy(-5)
			else
				delayedCall("bridge_remover_script",0.1,"checkbridge", caster)
				party.party:getChampion(caster):regainEnergy(-1)
			end
		else
			removebridge()
		end
	end
end

Jackard
Posts: 59
Joined: Thu Oct 30, 2014 7:32 pm

Re: [Script] Magic Platform Spell

Post by Jackard »

Has anyone included this in their mod yet? Sounds neat.
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: [Script] Magic Platform Spell

Post by GoldenShadowGS »

Mine has it, but I'm not releasing for a while.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: [Script] Magic Platform Spell

Post by Drakkan »

I am afraid this spell could spoil majority of puzzles in lots of mods :) it is almost the same like levitation spell...
Breath from the unpromising waters.
Eye of the Atlantis
Jackard
Posts: 59
Joined: Thu Oct 30, 2014 7:32 pm

Re: [Script] Magic Platform Spell

Post by Jackard »

Think I'm gonna try it out for Meskia
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: [Script] Magic Platform Spell

Post by GoldenShadowGS »

Being the way I designed it, It can only allow the party to cross 1 tile wide gaps/chasms, etc... you can not make a 2nd platform while the first one is still in existence.
cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

Re: [Script] Magic Platform Spell

Post by cameronC »

This spell is fairly balanced, given what it does, and someone obviously shouldnt just drop it in their dungeon if it would break any aspect of it. A spell like this being available in a dungeon needs to take its existence into account when being designed, is all. I like this a lot.
Writer and sometimes artist of the very slightly acclaimed comic series Scrambled Circuits. A comic series about a robot written by a human.

Grimrock 2 socketSystem: viewtopic.php?f=22&t=8546 / Github
Post Reply