Page 1 of 1

[SOLVED] Equip Items to Remove Conditions

Posted: Fri May 11, 2018 6:04 pm
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? :?

Re: Equip Items to Remove Conditions

Posted: Fri May 11, 2018 7:21 pm
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.

Re: Equip Items to Remove Conditions

Posted: Fri May 11, 2018 10:45 pm
by AndakRainor
aren't you supposed to return false instead of use champion:removeCondition("cold") ?

Re: Equip Items to Remove Conditions

Posted: Sat May 12, 2018 12:23 am
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?

Re: Equip Items to Remove Conditions

Posted: Sat May 12, 2018 12:33 am
by Isaac
Returning false from the onReceive event... cancels the event.

Re: Equip Items to Remove Conditions

Posted: Sat May 12, 2018 12:34 am
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)

Re: Equip Items to Remove Conditions

Posted: Sat May 12, 2018 12:56 am
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...