/*--------------------------------------------------------

Script Name: onplayerlevelup
----------------------------------------------------------
Created By: Genisys(Guile)
Created On: 3/03/09
----------------------------------------------------------

Intergrated SimTools to the OnPlayerLevelUp Event

----------------------------------------------------------*/

//Required Include for SimTools
//#include "fky_chat_inc"

void SendMessageToAllPC(string sMessage)
{
   object oPC = GetFirstPC();
   while(GetIsObjectValid(oPC))
   {
      SendMessageToPC(oPC, sMessage);
      oPC = GetNextPC();
   }
}

void main()
{
ExecuteScript("prc_levelup", OBJECT_SELF);
   object oPC = GetPCLevellingUp();
   int nHD = GetHitDice(oPC);
   location lSaved = GetLocation(oPC);
   int MULTI_PLAYER = GetLocalInt(GetModule(), "multi");
///////LOCATION SAVING OPTION////////

//Delete the /* above to activate

//If in the guild only!
//If they are in the guild...
if(GetItemPossessedBy(oPC, "guildpass")!=OBJECT_INVALID)
{
if(GetArea(GetAreaFromLocation(lSaved))!=OBJECT_INVALID)
{
  object oGuild = GetItemPossessedBy(oPC, "guildstone");

     //Store the PC's location, so they can come back here after relogging
     SetCampaignLocation("LOCATIONS", GetName(oGuild), lSaved, oPC);

      //Tell the PC thier location was saved..
      SendMessageToPC(oPC, "Location Saved.");
}
}

// (DO NOT TOUCH THIS LINE!) */

/////////////////////////////////////////

///Character Auto Save (Single Character / safe save)

if(MULTI_PLAYER)
{
 //DelayCommand(3.0, ExportSingleCharacter(oPC));
}
else
{
 //DelayCommand(2.0, DoSinglePlayerAutoSave());
}

   if(nHD == 5  || nHD == 10 || nHD == 15 || nHD == 20 ||
      nHD == 25 || nHD == 30 || nHD == 35 || nHD == 40)
   {
       SendMessageToAllPC(GetName(oPC) + " has reached level " + IntToString(nHD)
       + " Congratulations!");
       if(nHD == 40)
          ApplyEffectToObject(DURATION_TYPE_PERMANENT,
             SupernaturalEffect(EffectVisualEffect(VFX_DUR_GLOW_WHITE)), oPC);

   }



   {

object oPC = GetPCLevellingUp();
if (!GetIsPC(oPC)) return;

object oTarget;
oTarget = oPC;


int nInt;
nInt = GetObjectType(oTarget);

if (nInt != OBJECT_TYPE_WAYPOINT) ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_KNOCK), oTarget);
else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_KNOCK), GetLocation(oTarget));

   }

/////////////////////////CHARACTER SCANNING OPTIONS////////////////////////

//This function scans the PC who just leveled up to see if they are playing
//a legal character or not, just delete the // below to use
//DelayCommand(2.0, ExecuteScript("cheatercheck4", oPC));


//////////////////////////////////////////////////////////////////////////
//SimTools Languages (DISABLED)
////////////////////////////////////////////////////////////
/*
if (ENABLE_LANGUAGES)//check to see if they gained a level in a language class, and if so, add that language
    {
        object oPC = GetPCLevellingUp();
        if (USING_NWNX_DB)
        {
            if ((GetLevelByClass(CLASS_TYPE_RANGER, oPC) || GetLevelByClass(CLASS_TYPE_DRUID, oPC)) && (!GetLocalInt(oPC, "FKY_CHAT_LANG37")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG37", TRUE);
                SetPersistentInt(oPC, "FKY_CHAT_LANG37", TRUE);
            }
            if (GetLevelByClass(CLASS_TYPE_ROGUE, oPC) && (!GetLocalInt(oPC, "FKY_CHAT_LANG44")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG44", TRUE);
                SetPersistentInt(oPC, "FKY_CHAT_LANG44", TRUE);
            }
            if (GetLevelByClass(CLASS_TYPE_ASSASSIN, oPC) && (!GetLocalInt(oPC, "FKY_CHAT_LANG5")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG5", TRUE);
                SetPersistentInt(oPC, "FKY_CHAT_LANG5", TRUE);
            }
            if (GetLevelByClass(CLASS_TYPE_DRUID, oPC) && (!GetLocalInt(oPC, "FKY_CHAT_LANG14")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG14", TRUE);
                SetPersistentInt(oPC, "FKY_CHAT_LANG14", TRUE);
            }
            if ((GetLevelByClass(CLASS_TYPE_WIZARD, oPC) || GetLevelByClass(CLASS_TYPE_SORCERER, oPC) || GetLevelByClass(CLASS_TYPE_PALEMASTER, oPC)) && (!GetLocalInt(oPC, "FKY_CHAT_LANG71")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG71", TRUE);
                SetPersistentInt(oPC, "FKY_CHAT_LANG71", TRUE);
            }
            if (GetLevelByClass(CLASS_TYPE_PALEMASTER, oPC) && (!GetLocalInt(oPC, "FKY_CHAT_LANG80")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG80", TRUE);
                SetPersistentInt(oPC, "FKY_CHAT_LANG80", TRUE);
            }
        }
        else
        {
            object oStorage = GetItemPossessedBy(oPC, TAG_OF_LANGUAGE_STORAGE_OBJECT);
            if ((GetLevelByClass(CLASS_TYPE_RANGER, oPC) || GetLevelByClass(CLASS_TYPE_DRUID, oPC)) && (!GetLocalInt(oPC, "FKY_CHAT_LANG37")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG37", TRUE);
                SetLocalInt(oStorage, "FKY_CHAT_LANG37", TRUE);
            }
            if (GetLevelByClass(CLASS_TYPE_ROGUE, oPC) && (!GetLocalInt(oPC, "FKY_CHAT_LANG44")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG44", TRUE);
                SetLocalInt(oStorage, "FKY_CHAT_LANG44", TRUE);
            }
            if (GetLevelByClass(CLASS_TYPE_ASSASSIN, oPC) && (!GetLocalInt(oPC, "FKY_CHAT_LANG5")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG5", TRUE);
                SetLocalInt(oStorage, "FKY_CHAT_LANG5", TRUE);
            }
            if (GetLevelByClass(CLASS_TYPE_DRUID, oPC) && (!GetLocalInt(oPC, "FKY_CHAT_LANG14")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG14", TRUE);
                SetLocalInt(oStorage, "FKY_CHAT_LANG14", TRUE);
            }
            if ((GetLevelByClass(CLASS_TYPE_WIZARD, oPC) || GetLevelByClass(CLASS_TYPE_SORCERER, oPC) || GetLevelByClass(CLASS_TYPE_PALEMASTER, oPC)) && (!GetLocalInt(oPC, "FKY_CHAT_LANG71")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG71", TRUE);
                SetLocalInt(oStorage, "FKY_CHAT_LANG71", TRUE);
            }
            if (GetLevelByClass(CLASS_TYPE_PALEMASTER, oPC) && (!GetLocalInt(oPC, "FKY_CHAT_LANG80")))
            {
                SetLocalInt(oPC, "FKY_CHAT_LANG80", TRUE);
                SetLocalInt(oStorage, "FKY_CHAT_LANG80", TRUE);
            }
        }
    }
// */
/////////////////////////////////////////////////////////////////////////

}