Magic Dead Zone

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Delak
Posts: 2
Joined: Mon Oct 08, 2012 12:44 am

Magic Dead Zone

Post by Delak »

:?:

Is their away to script a magic dead zone where no champion can cast a spell? Just a point in the right direction would be good so I can learn more.

thanks
Delak
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: Magic Dead Zone

Post by JohnWordsworth »

I don't know exactly where you would place this, but I think you can override / hook into some of the Party actions by 'cloning' the Party object in a lua script that is imported in your mod's init.lia script.

A completely untested stab at this would be...

In party.lua (add import 'mod_assets/scripts/party.lua' to mod_assets/scripts/init.lua if it doesn't exist).
SpoilerShow

Code: Select all


cloneObject{
  name = "party",
  baseObject = "party",
  onCastSpell = function(self, champion, spellName)
    if party.level = 1 and party.x > 3 and party.x < 8 and party.y > 3 and party.y < 8 then
      hudPrint("Your magic fails to work here...");
      return false;
    end

    return true;
  end,
This manually checks to see if the party is on level one and in any spaces in the square (4,4) to (7,7). If so, it prints a message to the screen and returns false (so the spell is not cast).

You could obviously check for anything in that function - if they are carrying a certain item, if they are on a given floor, etc.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Magic Dead Zone

Post by Grimwold »

Just tested John's method and it seems to work well... (with a couple of very minor corrections)

Code: Select all

cloneObject{
  name = "party",
  baseObject = "party",
  onCastSpell = function(self, champion, spellName)
    if party.level == 1 and party.x > 3 and party.x < 8 and party.y > 3 and party.y < 8 then
      hudPrint("Your magic fails to work here...");
      return false;
    end

  return true;
  end,
}
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: Magic Dead Zone

Post by JohnWordsworth »

@Grimwold: Good spot on the equals. I bashed that out on my iPad, and the autocorrect plays havoc when typing out lua code!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Delak
Posts: 2
Joined: Mon Oct 08, 2012 12:44 am

Re: Magic Dead Zone

Post by Delak »

Thank you John and Grimwold. I will give this a shoot when I start to build out my first dungeon.
User avatar
Wolfrug
Posts: 55
Joined: Wed Oct 03, 2012 6:56 pm

Re: Magic Dead Zone

Post by Wolfrug »

Heya Delak,

I've actually done this myself, so you can just copy-paste my solution. It's based on two things: a lua script from the onCastSpell hook, and a custom object. Here're the entries for objects.lua:

Code: Select all

-- Add the onCastSpell hook and have it run a script called antimagic inside a Lua script entity called checkAntiMagic
cloneObject{
   name = "party",
   baseObject = "party",

   onCastSpell = function(self, spell)
	   local returnValue = checkAntiMagic.antimagic()
       return returnValue
	end,
}

-- Make a custom object that denotes the location of the anti-magic zone: you can use anything, but I used an invisible pressure plate

cloneObject{
	name = "antimagic_zone",
	baseObject = "pressure_plate_hidden",
}
After this, simply add a Lua script entity and name it checkAntiMagic (note the capitalization), and copy-paste in this code:

Code: Select all

function antimagic()
-- Set here the number of levels you want to check for the presence of antimagic_zone objects
local LevelAmount = 5

local returnValue = true
for l=1,LevelAmount do
	for i in allEntities(l) do
		if i.name == "antimagic_zone" then
      		if party.x == i.x and party.y == i.y and party.level == i.level then
				returnValue = false
				hudPrint ("Your spell fizzles! You are standing on an anti-magic zone!")
				break
			end
		end
	end
end
return returnValue
Now you can simply put down the antimagic_zone objects (which are invisible). If the party stands on any such object, all spells will fail to cast. Note that this does not prevent monsters from casting spells - I'm not entirely sure if they are considered to 'cast spells' or more precisely make attacks, so I haven't tried, but presumably something similar could be arranged for them!

Hope that helps!
Try my Mordor: Depths of Dejenol LoG-ification. Feedback much appreciated!
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Magic Dead Zone

Post by Grimwold »

I really liked your idea of antimagic_zone objects, Wolfrug, so I've been working on this a little myself... I thought checking several levels for antimagic zones and checking if the party is there was a bit much though, so I've written a script to use entitiesAt(), to check the parties grid location for an antimagic zone.

Code: Select all

function antimagic(caster,spell)
  for i in entitiesAt(party.level,party.x,party.y) do
    -- hudPrint(i.name .. " with id = " .. i.id)
    if i.name == "antimagic_zone"
    then
      hudPrint(caster:getName() .. "'s spell fizzles! You are standing on an anti-magic zone!")
      return false
    end
  end
  return true
end
User avatar
Wolfrug
Posts: 55
Joined: Wed Oct 03, 2012 6:56 pm

Re: Magic Dead Zone

Post by Wolfrug »

@Grimwold

Duh, yes. That's obviously a lot easier and faster. Use that solution instead!
Try my Mordor: Depths of Dejenol LoG-ification. Feedback much appreciated!
User avatar
strangely
Posts: 25
Joined: Mon Oct 29, 2012 2:28 am
Location: Tucson, AZ

Re: Magic Dead Zone

Post by strangely »

Very useful information. Thanks.

Are there other hooks on the party object that can be overriden like onCastSpell?
I want to create a sword that calls some custom lua code every time a player swings it at a monster.
I can't override onUseItem on a cloned object because that isn't called when the player has the sword in their hand and they swing it at a monster.
nichg
Posts: 48
Joined: Thu Oct 11, 2012 12:38 pm

Re: Magic Dead Zone

Post by nichg »

You can use onAttack for that. It gives you the attacker and their weapon, which you could check against the name of the item you want to do something weird.
Post Reply