I might be mistaken (not at home right now), but I don't think you can use primary heir as a trigger inside any_child, it only works as a content switch.
If you rewrite your trigger as follows it should work:
Code:
condition = { type = primary_heir
condition = { type = not value = { type = trait value = bastard } }
condition = { type = save_target }
}
condition = { type = has_target }
The event is slightly bugged by the way, since you have it fire for the ruler, but it sets the trait on the primary heir. You ought to add the following check inside the primary_heir check to prevent it from firing for the same character more than once:
Code:
condition = { type = not value = { type = trait value = user_defined_a } }
I'd also add the following trigger, to prevent it from firing for republics, bishoprics, or knight orders:
Code:
condition = { type = form_of_goverment value = feudal }
This eliminates the need to check and exclude the Papacy:
Code:
condition = { type = not value = { type = title value = PAPA } }
Keep in mind that primary heir means primary heir according to the succession laws of the realm, this is not necessarily a ruler child. You can use the is_receiver trigger inside the primary heir check to make sure this fires for the right person:
Code:
condition = { type = primary_heir
condition = { type = not value = { type = trait value = bastard } }
condition = { type = not value = { type = trait value = user_defined_a } }
condition = { type = father
condition = { type = is_receiver }
}
condition = { type = save_target }
}
condition = { type = has_target }
Of course this means that there is a chance that the king's son may not get the trait if the realm is using elective law, and the son is not the most powerful vassal. To take care of this requires more rewriting than I can do now for you.
Hope this helps. I'll try to check this later from home if I find the time, there's a few other suggestions I can make.