[SOLVED] Equip Items to Remove Conditions

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!
Post Reply
User avatar
Willigamer
Posts: 16
Joined: Sat Jan 07, 2017 6:06 pm
Contact:

[SOLVED] Equip Items to Remove Conditions

Post by Willigamer »

hi modders,
That's it, as very few people are aware, I'm creating a mod that stays pretty big with a certain number of components. It will be 3 years that I try to finish it (at least try to get it out :lol: ) and it will also be 3 years that I discovered the script, because at the base, I knew absolutely nothing about it, so it was a total discovery for me. I thank the developers, Skuggasveinn and other players/modders who allowed me to learn more and improve on the editors and scripts... :)


But in short, this is not the subject of the day (or not yet... ;) ), I am exploiting most of the functions of the game and it's been a while since I'm stuck with a particular function.

To put it simply, when the party receives the negative condition "cold", they must be equipped with light or heavy armor to remove the condition. I thought that the function will be rather simple and oddly, when I do it rightly, nothing happens and the condition has still not been removed from the party.

Code: Select all

defineObject{
	name = "party",
	baseObject = "party",
	components = {
		{
			class = "Party",
			onReceiveCondition = function(self, champion, condition)
				local helmet = champion:getItem(ItemSlot.Head)
				local cuirass = champion:getItem(ItemSlot.Chest)
				local cuisse = champion:getItem(ItemSlot.Legs)
				local greaves = champion:getItem(ItemSlot.Feet)
				if condition == "cold" then
					if (helmet and helmet:hasTrait("light_armor")) and 
					(cuirass and cuirass:hasTrait("light_armor")) and 
					(cuisse and cuisse:hasTrait("light_armor")) and 
					(greaves and greaves:hasTrait("light_armor")) then
						champion:removeCondition("cold")
					end
				end
			end,
		},
	},
	editorIcon = 32,
	placement = "floor",
}
For the moment, I'm just trying to make it work with light armors, but no need to go further, if I can not even get it working! What puzzles me is that all light armor logically have the feature "light_armor" and therefore should make it work...

Someone has an explanation or answer due to this problem? :?
Last edited by Willigamer on Sun Jan 13, 2019 12:42 pm, edited 1 time in total.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Equip Items to Remove Conditions

Post by Isaac »

Offhand, I'd say that it is because as-is, the test only (ever) happens at the moment they receive a condition. They would have to have all of that equipment already equipped to have the condition removed... and in that case, you'd never see that they had ever had the condition in the first place.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Equip Items to Remove Conditions

Post by AndakRainor »

aren't you supposed to return false instead of use champion:removeCondition("cold") ?
User avatar
Willigamer
Posts: 16
Joined: Sat Jan 07, 2017 6:06 pm
Contact:

Re: Equip Items to Remove Conditions

Post by Willigamer »

Thank you for your quick answers :)
Isaac wrote:Offhand, I'd say that it is because as-is, the test only (ever) happens at the moment they receive a condition. They would have to have all of that equipment already equipped to have the condition removed... and in that case, you'd never see that they had ever had the condition in the first place.
I understand better now. I have just tried, but even with all the equipments equipped before the condition, nothing is happening.
AndakRainor wrote:aren't you supposed to return false instead of use champion:removeCondition("cold") ?
It seems to work perfectly! :o But I don't understand, I often use the returns true/false but I thought that "removeCondition" would have the same context as if I used return false. Because... the two come back to the same result no?
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Equip Items to Remove Conditions

Post by Isaac »

Returning false from the onReceive event... cancels the event.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Equip Items to Remove Conditions

Post by AndakRainor »

The thing is onReceiveCondition is called before the condition is actually received to give you the opportunity to cancel it with return false ;)
So what you did is remove the condition just before it was actually received; you did nothing! (unless you believe in time travel)
User avatar
Willigamer
Posts: 16
Joined: Sat Jan 07, 2017 6:06 pm
Contact:

Re: Equip Items to Remove Conditions

Post by Willigamer »

Wow, I would never have been able to see it this way, but it looks so stupid said like that... I was persuaded to have written my part "hasTrait" and that my mistake was inside...
Anyway, thank you Isaac & AndakRainor :D
It's nice to see it work and think about something else now...
Post Reply