Magic Dead Zone
Magic Dead Zone
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
- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: Magic Dead Zone
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).
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.
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,
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.
Re: Magic Dead Zone
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,
}
Puzzle Frameworks - http://www.grimrock.net/forum/viewtopic.php?f=14&t=4564
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: Magic Dead Zone
@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.
Re: Magic Dead Zone
Thank you John and Grimwold. I will give this a shoot when I start to build out my first dungeon.
Re: Magic Dead Zone
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:
After this, simply add a Lua script entity and name it checkAntiMagic (note the capitalization), and copy-paste in this code:
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!
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",
}
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
Hope that helps!
Try my Mordor: Depths of Dejenol LoG-ification. Feedback much appreciated!
Re: Magic Dead Zone
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
Puzzle Frameworks - http://www.grimrock.net/forum/viewtopic.php?f=14&t=4564
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Re: Magic Dead Zone
@Grimwold
Duh, yes. That's obviously a lot easier and faster. Use that solution instead!
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!
Re: Magic Dead Zone
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.
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.
Re: Magic Dead Zone
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.