You could easily do that with the lightshy creature's ai script. Feel free to rip it apart and modify.
Basically all the lightshy system does is flag a PC with an integer so that certain creatures will not attack, and the flag has a value equivalent to how strong the light is. The value is a measure of how big the radius is. (value of 1 = 5 meters, 2 = 10 m etc...)
The flagging and deflagging of the PC occurs in the onequip and onunequip module events. This would work fine for you. (What you will probably not need is tracking whether the lightsource expires. I am using consumable lightsources - and I think I included that code in the lightshy scripts on the vault.)
One more thing that might not be of interest to you: it determines whether another creature which is not carrying the light, is within the light radius. The creatures will not target a creature within a light radius. You'd save some processing cycles by removing this. But it depends on how you want your aversion effect to work.
One bug with my code that may cause problems for you, is that sometimes creatures overcome their shyness, and I have not yet found the hole in my code that allows this. This could disrupt the other feature you want to add - that once a creature overcomes the "aura" of the necklace, they are no longer afraid. However it might function as you want as is. Typically the repulsion fails for a couple rounds when the PC attacks a lightshy NPC.
Some ways I have considered handling what you describe is to:
(1) Flag an NPC as immune to the necklace's effects under certain circumstances (when they have damaged the PC perhaps)
(2) Remove the repulsion flag from the PC if they attack one of the creatures which will enable all to attack.
(3) Flag all NPCs within 20 meters as immune to the effects if a PC attacks.
Modifié par henesua, 16 août 2011 - 10:09 .