// returns TRUE if the player has the wolf effect, else returns FALSE
int iswolf();
// removes the werewolf effect
void removewolf();
// turns the PC into a werewolf
void makewolf();
// main werewolfscript
void dowolf();

void dowolf()
{

int nNight=GetIsNight();
if (!nNight)
 {
 SpeakString("It is day");
   if (iswolf())
   {
    removewolf();
   }
  return;
 }
else
 {
  SpeakString("It is night");
 }
// so it is night and we carry on from here

if (!iswolf())
  {
  makewolf();
  }

object oPlayer=GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC,OBJECT_SELF,1,CREATURE_TYPE_PERCEPTION,PERCEPTION_SEEN);
if (GetIsObjectValid(oPlayer))
 {
  ActionAttack(oPlayer);
 }



}


int iswolf()
{
   object oPC=OBJECT_SELF;

   effect eEffect=GetFirstEffect(oPC);
   int nWolf=FALSE;
   while (GetIsEffectValid(eEffect))
   {
    if ((GetEffectType(eEffect)==EFFECT_TYPE_POLYMORPH)&&(GetEffectSubType(eEffect)==POLYMORPH_TYPE_WEREWOLF))
    {
     nWolf=1;
    }
   eEffect=GetNextEffect(oPC);
   }

return (nWolf);
}


void removewolf()
{
   object oPC=OBJECT_SELF;

   effect eEffect=GetFirstEffect(oPC);
   int nWolf=FALSE;
   while (GetIsEffectValid(eEffect)&&nWolf==0)
   {
    if ((GetEffectType(eEffect)==EFFECT_TYPE_POLYMORPH)&&(GetEffectSubType(eEffect)==POLYMORPH_TYPE_WEREWOLF))
    {
     RemoveEffect(oPC,eEffect);
     nWolf=1;
    }
   eEffect=GetNextEffect(oPC);
   }
}

void makewolf()
{
 object oPC=OBJECT_SELF;
 effect eEffect=EffectPolymorph(POLYMORPH_TYPE_WEREWOLF);
 eEffect=ExtraordinaryEffect(eEffect);
 ApplyEffectToObject(DURATION_TYPE_PERMANENT,eEffect,OBJECT_SELF);
}