setResistances to remove resistances

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!
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

setResistances to remove resistances

Post by Emera Nova »

I'd Like to be able to remove a resistance from an enemy mid battle and replace it with another one. So say going from resist to fire and weak against shock to weak against fire and resist to shock.

IS it possible with setResistance? because what ever I just tossed in broke it hard xD monstername.monster:setResistances (fire ~= false) <--- thats what I put in, not really sure what I told it to do tho x]
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: setResistances to remove resistances

Post by minmay »

Resistances are a table in which the keys are the damage types (fire, cold, poison, shock, physical, dispel) and the values are "weak" (increased damage, red text), "vulnerable" (increased damage, red text, not sure if it is different from weak), "resist" (reduced damage, normal text), "immune" (no damage, normal text), "absorb" (damage converted to healing, green text). If a field is not present then the monster takes normal damage.

For example, ice guardians have:

Code: Select all

			resistances = {
				fire = "weak",
				cold = "absorb",
			},
Note that dispel damage won't hit the monster in the first place if the monster doesn't have the "elemental" trait.
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.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: setResistances to remove resistances

Post by Emera Nova »

so I could put the code

Code: Select all

  setResistances = (
            fire = "weak",
            cold = "absorb",
         ),
and that would fix the problem?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: setResistances to remove resistances

Post by minmay »

No, that syntax won't even compile...setResistances is a function that takes a table (of resistances) as its only parameter.
If you want to replace certain resistances while keeping the rest, you should make a function like this:

Code: Select all

function changeResistances(monster,newResistances)
  local damageTypes = {"fire","cold","shock","poison","physical","dispel"}
  local resists = {}
  for _,type in ipairs(damageTypes) do
    resists[type] = newResistances[type] or monster:getResistance(type)
  end
  monster:setResistances(resists)
end
Then to do the substitution you mentioned in your original post, you'd make this call:

Code: Select all

changeResistances(monstername.monster,{fire = "weak", shock = "resist"})
This will overwrite the monster's fire and shock resistances with weak and resist, respectively, and leave all of its other resistances the same.
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.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: setResistances to remove resistances

Post by Emera Nova »

Code: Select all

function changeResistances(monster,newResistances)
  local damageTypes = {"fire","cold","shock","poison","physical","dispel"}
  local resists = {}
  for _,type in ipairs(damageTypes) do
    resists[type] = newResistances[type] or monster:getResistance(type)
  end
  monster:setResistances(resists)
end
So do I run this under a timer that just keeps calling the function? and is this script completed or is there stuff that still needs filled in to make it work.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: setResistances to remove resistances

Post by minmay »

No, you call it once and it changes the passed MonsterComponent's resistances. There's nothing to be filled in.
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.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: setResistances to remove resistances

Post by Emera Nova »

How does it know what monster to be assigned to? :o

Sorry about all teh questions xD I know literally nothing programming wise so I don't understand it all I just come up with ideas I think should work.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: setResistances to remove resistances

Post by minmay »

Emera Nova wrote:How does it know what monster to be assigned to? :o
The first parameter is the MonsterComponent to give the resistances to.
Emera Nova wrote:Sorry about all teh questions xD I know literally nothing programming wise so I don't understand it all I just come up with ideas I think should work.
This is highly unlikely to work, it would be much faster to learn some basic programming concepts first.
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.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: setResistances to remove resistances

Post by Emera Nova »

I put this in as a script that gets trigged by a pressure plate and when I stepped on the pressureplate it made my game go nonresponsive o-o which is different from it just ending the play test and saying something is broken.

Code: Select all

function changeResistances(mummy_2,newResistances)
  local damageTypes = {"fire","cold","shock","poison","physical","dispel"}
  local resists = {}
  for _,type in ipairs({fire = "resist", shock = "shock"}) do
    resists[fire] = newResistances[fire] or monster:getResistance(fire)
  end
  monster:setResistances(fire)
end
function resist()
changeResistances(mummy_2.monster,{fire = "resist", shock = "shock"})
end
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: setResistances to remove resistances

Post by minmay »

That's because you broke the script in about 500 different ways. Why didn't you just copy/paste it?
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.
Post Reply