Page 1 of 2
setResistances to remove resistances
Posted: Tue Apr 07, 2015 7:19 pm
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]
Re: setResistances to remove resistances
Posted: Wed Apr 08, 2015 12:07 am
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.
Re: setResistances to remove resistances
Posted: Wed Apr 08, 2015 1:02 am
by Emera Nova
so I could put the code
Code: Select all
setResistances = (
fire = "weak",
cold = "absorb",
),
and that would fix the problem?
Re: setResistances to remove resistances
Posted: Wed Apr 08, 2015 1:16 am
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.
Re: setResistances to remove resistances
Posted: Wed Apr 08, 2015 1:27 am
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.
Re: setResistances to remove resistances
Posted: Wed Apr 08, 2015 2:08 am
by minmay
No, you call it once and it changes the passed MonsterComponent's resistances. There's nothing to be filled in.
Re: setResistances to remove resistances
Posted: Wed Apr 08, 2015 2:28 am
by Emera Nova
How does it know what monster to be assigned to?
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.
Re: setResistances to remove resistances
Posted: Wed Apr 08, 2015 6:46 am
by minmay
Emera Nova wrote:How does it know what monster to be assigned to?

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.
Re: setResistances to remove resistances
Posted: Wed Apr 08, 2015 4:35 pm
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
Re: setResistances to remove resistances
Posted: Wed Apr 08, 2015 7:08 pm
by minmay
That's because you broke the script in about 500 different ways. Why didn't you just copy/paste it?