desto-git / sdv-mods

Mods for Stardew Valley

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when giving a disliked gift to an NPC whose friendship is 0

desto-git opened this issue · comments

commented

Determine who got a gift is not that easy. There is no method to check if an NPC already received a gift today from the player. Or I just can't for the life of me find it.

So instead, each time an item is removed from the player's inventory while they are in a dialog with someone, the mod will scan all NPCs in the same location and check if the friendship level got updated. If that is the case, they must have received a gift.

But if the friendship is at 0 and they recieve a disliked gift, and error is thrown and the gift won't become hated. Reason being that the mod did not find a change in the friendship level of any NPC and thus can't tell who received the gift.

To fix this, we can use Game1.player.giftedItems. It is a dictionary of how many of each item each NPC received in the format:

{
	NpcName<string>: {
		ItemID<string>: amount<int>
	}
}