Disabling specific Spells Help

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!
Echoplex
Posts: 63
Joined: Tue Nov 04, 2014 10:59 pm

Disabling specific Spells Help

Post by Echoplex »

So I'm trying to give special attention to the ambiance and lighting in levels. Id really like if folks couldn't just run around with light spell on 100% through the campaign. Is there anyway to disable a spell(specifcally the light spell) using a script that I could just copy and paste into each level?
OGDA
Posts: 115
Joined: Tue Oct 28, 2014 5:07 pm

Re: Disabling specific Spells Help

Post by OGDA »

Hi,

I'm searching for a way to check if the spell light is active or cast darkness on the party, too.
It seems that they cannot be cast by spawners. I managed to check if the party is holding a torch, but with the spells I have no clue for now.

So... push. :)

Kind regards,
Joerg
OGDA
Posts: 115
Joined: Tue Oct 28, 2014 5:07 pm

Re: Disabling specific Spells Help

Post by OGDA »

Hi,

I still have not solved this problem, so if anyone can help...

Here is what I do so far:

In \mod_assets\scripts\init.lua I check if the spell "light" is cast, and if this happens, the script and function script_entity_88.script:darknesscast() are called.

Code: Select all

defineObject{
	name = "party",
	baseObject = "party",
	components = {
		{
		class = "Party",  
		onCastSpell = function(party,champion,spellName)
			if spellName == "light" then
				--hudPrint(spellName)
				script_entity_88.script:darknesscast()
			end		  
		end
		}
	},
}
I noticed, that a character who casts the spells light or darkness has the Traits "Darkness" and/or "Light" in his trait window together with other traits like "Aura", "Meditation" and so on.

However, when I check with an extra script for these traits, I get no result:

Code: Select all

for i = 1,4 do
  if party.party:getChampion(i):hasTrait("Aura") then
    hudPrint("found")
  end
end
It doesn't matter if I search with hasTrait for Aura, Meditation, Light, Darkness... they are never found.
Also when I try to set or remote traits with addTrait(string) or removeTrait it doesn't work.

Has anyone an idea what's up with the trait functions?

They are from the Champion-class, setFood(number) from the same class for example works without problems:
for i = 1,4 do
party.party:getChampion(i):setFood(400)
end

Code: Select all

class Champion
    setEnabled(boolean)
    setName(string)
    setRace(string)
    setSex(string)
    setClass(string)
    setHealth(number)
    getEnabled
    getName
    getRace
    getSex
    getClass
    getDualClass
    getLevel
    getOrdinal
    setPortrait(string)
    isAlive
    gainExp(number)
    levelUp
    getSkillPoints
    addSkillPoints(number)
    getSkillLevel(string)
    trainSkill(number,string,string)
    addTrait(string)
    removeTrait
    hasTrait(string)
    setFood(number)
    getFood
    consumeFood(number)
    modifyFood(number)
    setCondition(string)
    removeCondition(string)
    hasCondition(string)
    setConditionValue(number,string,string)
    getConditionValue
    damage(string,number)
    playDamageSound(string)
    playSound
    showAttackResult(string,any)
    setBaseStat(number,string)
    modifyBaseStat(number,string)
    upgradeBaseStat(number,string)
    addStatModifier(number,string,string)
    getBaseStat(string)
    getCurrentStat(number)
    regainHealth(number)
    regainEnergy(number)
    getHealth
    getMaxHealth
    getEnergy
    getMaxEnergy
    getProtection
    getEvasion(string)
    getResistance
    getLoad
    getMaxLoad(string)
    getArmorSetPiecesEquipped(string)
    isArmorSetEquipped
    insertItem(ItemComponent,number,ItemComponent)
    removeItem(number)
    removeItemFromSlot(number)
    getItem(number)
    getOtherHandItem
    playHealingIndicator

Kind regards,
Joerg
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Disabling specific Spells Help

Post by minmay »

Can't you just redefine the light spell with defineSpell{} to have a nil gesture so it's uncastable like blob? Or if that doesn't work anymore in LoG2, redefine it and give it impossible requirements (e.g. concentration skill 500).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
OGDA
Posts: 115
Joined: Tue Oct 28, 2014 5:07 pm

Re: Disabling specific Spells Help

Post by OGDA »

Hi,

I don't want to disable the light spell, because I think that general disabling of function is not a good design.
I want do temporarily make light unavailable in certain level areas because of the level design.

When the player casts light before he enters that area, he could get around this.
So I need to remove the light-spell/trait when he enters the area and if he casts light in the area he gets punished for it because of lore.

The punish-part is possible as I can check if light is cast and then use a normal script to check the area and do other things.

What I haven't found out is how to remove the light-trait when entering that area so that the player really has no own light in that part of the dungeon.
Or how to overwrite light with casting a darkness spell.

Kind regards,
Joerg
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Disabling specific Spells Help

Post by JKos »

Try

Code: Select all

      onCastSpell = function(party,champion,spellName)
         if spellName == "light" then
            return false
         end       
      end
IIRC this worked in LoG1.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
OGDA
Posts: 115
Joined: Tue Oct 28, 2014 5:07 pm

Re: Disabling specific Spells Help

Post by OGDA »

Hello JKos,

thank you for your answer, but unfortunately this is not the desired behaviour as I don't want do disable the light spell.
I need to remove the light trait or cast a darkness spell (see posts above).

It might however be the solution for Echoplex.

Kind regards,
Joerg
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Disabling specific Spells Help

Post by JKos »

How about this?

Code: Select all

      onCastSpell = function(party,champion,spellName)
         if party.level == 2 and spellName == "light" then
            hudPrint("Light spell doesn't seem to have effect in here...blablabla")
            return false
         end       
      end
Disables light spell on level 2 only.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
OGDA
Posts: 115
Joined: Tue Oct 28, 2014 5:07 pm

Re: Disabling specific Spells Help

Post by OGDA »

The problem is that the duration of the light spell is really long:

The party can cast the light spell on the stairs of level 1 and proceed to level 2.
They could have light through the whole level 2.
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Disabling specific Spells Help

Post by JKos »

one possible solution is that you create your own "light spell" and implement it so that it can be turned off. You can for example try to add LightComponent to the party and then in onCastSpell you can do something like this:

Code: Select all

      onCastSpell = function(party,champion,spellName)
         if spellName == "light" then
		    --activate party.light. Don't know if it works this way.
			party.light.setDisable(false) 
			return false
         end       
      end

then you can disable it any time you want by calling party.light.setDisable(true)
This code isn't tested, and probably doesn't work, but I hope you got the idea.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
Post Reply