//Script Name: oncliententer
////////////////////////////////////////
//Created by Genisys / Guile
//Created On: 6/14/08 (Updated 8/10/08)
////////////////////////////////////////
/*
This my premier OnClientEnter Module Event Script for all my modules
(click edit / module properties to select this script for the event)

*/
/////////////////////////////////////////////////////////////////
/*
This script does multiple things, it checks to see if...
If the PC is immortal or level 40 (apply special effects)
If the character they have has been banned. (not a total bann)
If they logged out while dead, if so make them dead instantly!!! ;)
If the player is playing a legal character or not...read below..
And if the Player themself have been banned from the module or not..
*/
//////////////////////////////////////////////////////////////////////

//Redundant Variables Declared
effect eEffect;
int nInt;
object oItem;
object aTarget;
location bTarget;

#include "x3_inc_horse"

//Required Include For Color Messages(Read include to learn more)
#include "gen_inc_color"

//PROTOTYPE DECLARED
void SendMessageToAllPC(string sMessage);

//Main Script
void main()
{
   

//Declare Major Variables..
object oPC;
oPC = GetEnteringObject();
object oTarget;
oTarget = oPC;
object oPlayer = oPC;
object oPP = oPC;
string sCDKey = GetPCPublicCDKey(oPC, FALSE);

   AddJournalQuestEntry("xprules", 1, oPC, FALSE, FALSE, FALSE);
   AddJournalQuestEntry("lvl_adj", 1, oPC, FALSE, FALSE, FALSE);

//Only for PCs!
if(GetIsDM(oPC))
{
    AddJournalQuestEntry("dmrules", 1, oPC, FALSE, FALSE);

return;
}

//If changed here you must open the script "kopcwand" and adjust it there!
object oNap = GetItemPossessedBy(oPC, "napper");
 if(oNap !=OBJECT_INVALID)
 {
  //Only on PCs!
  if(GetIsPC(oPC) && !GetIsDM(oPC) && !GetIsDMPossessed(oPC))
  {
   //Start the nap all over again!   (the 15 = minutes of nap!)
   SetLocalInt(oTarget, "NAP_TIME", 15); //set 15 to your taste
   //Allow them to actually enter the module...
   DelayCommand(12.0, ExecuteScript("naptime", oPC));
   return;
  }
 }

//Higher Ground's Legendary leveler
string Script = GetLocalString(oPC, "LetoScript");
    if( Script != "" )
    {
        SetLocalString(oPC, "LetoScript", "");
    }

//Please leave the credits to the module within the message.

//Colorful Server Message sent to all PCs when they enter the module..
string sMessage;
sMessage = GetRGB(1,7,7); //The color (See above)
sMessage +=  "Welcome ";  //The text to be colorized by the above color.
sMessage += GetRGB(15,15,1);//The next color.
sMessage +=  "to  "; //The next text to be colorized by the above color.
sMessage += GetRGB(15,1,1);//etc..
sMessage +=  "the ";
sMessage += GetRGB(7,7,15);
sMessage +=  "CEP 2.1 ";
sMessage += GetRGB(1,15,1);
sMessage +=  "UNDERWORLD ";
sMessage += GetRGB(13,9,13);
sMessage +=  "Created ";
sMessage += GetRGB(12,10,7);
sMessage +=  "Designed & ";
sMessage += GetRGB();
sMessage +=  "Scripted by: ";
sMessage += GetRGB(15,5,1);
sMessage +=  "Genisys (Guile) ";
sMessage += GetRGB(12,10,7);
sMessage += "from 3/20/07 to 8/29/10.";

string sNewb = GetRGB(1,15,1) + "Be sure to read your journal frequently (press J).";
string sNewb2 = GetRGB(1,15,1) + "Be sure to examine the Rest Menu carefully.";

string sEnter = GetName(oPC) + " / " + GetPCPlayerName(oPC) + " / " + GetPCPublicCDKey(oPC) + " / " + GetPCIPAddress(oPC) + " Entered." ;
SendMessageToAllDMs(sEnter);

string sEnter2 = GetRGB(15,5,1) + GetName(oPC) + " / " + GetPCPlayerName(oPC) + " / " + GetPCPublicCDKey(oPC) + " / " + GetPCIPAddress(oPC) + "Has Entered." ;
SendMessageToAllPC(sEnter2);

AssignCommand(oPC, ActionSpeakString("Greetings everyone!", TALKVOLUME_SHOUT));

//Float welcome message by..
DelayCommand(14.3, FloatingTextStringOnCreature(sMessage, oPC, FALSE));

if(GetHitDice(oPC)<=6)
{
DelayCommand(17.3, FloatingTextStringOnCreature(sNewb, oPC, FALSE));
DelayCommand(27.3, FloatingTextStringOnCreature(sNewb2, oPC, FALSE));
}


object oTag;
location lTag;

//This part is about verifying the Player's name..
//A player must have at least a 2 character name or they are going to
//return with an error!  If they have spaces in their name it will return
//with an error as well, including alt code!
string sPCNM = GetName(oPP);
string sPCNMR = GetStringRight(sPCNM, 2);
string sNC1; string sNC2; string sRNC1; string sRNC2;
int nBad;

//Find the second character of the players name..
sNC1 = GetSubString(sPCNM, 0, 1);
//Find the second character of the players name..
sNC2 = GetSubString(sPCNM, 0, 2);
//Find the last letter in the player's name.
sRNC1 = GetSubString(sPCNMR, 0, 1);
//Find the next to the last letter in the player's name.
sRNC2 = GetSubString(sPCNMR, 0, 2);

/////////////////////////IMPORTANT//////////////////////////////////
//You must make all the "" below into " " to check for legal names
//I turned it off because a lot of my characters have bad names!
//Simply put the cursor between "" and hit the space bar for "" to " "
if(sNC1 =="")
{ nBad =1; }
else if(sNC2 =="")
{ nBad =1; }
else if(sRNC1 =="")
{ nBad =1; }
else if(sRNC2 =="")
{ nBad =1; }
else { nBad = 0; }

//See below to activate this system..
////////////////////////////////////////////////////////////////////////////

//This is for the rest of the script, if it's not a PC stop here!
if(!GetIsPC(oPC))return;


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

//These function add journal entries by the tag names below
//If you wish to create more, just copy / paste and change
//The tagname which is in "here", and the entry # remains 1 only!

//AddJournalQuestEntry("here", 1, oPC, FALSE, FALSE);

  AddJournalQuestEntry("important", 1, oPC, FALSE, FALSE);
  AddJournalQuestEntry("sockets", 1, oPC, FALSE, FALSE);
  AddJournalQuestEntry("requirements", 1, oPC, FALSE, FALSE);
  AddJournalQuestEntry("legendarylevels", 1, oPC, FALSE, FALSE);
  AddJournalQuestEntry("godlevels", 1, oPC, FALSE, FALSE);
  AddJournalQuestEntry("specialitems", 1, oPC, FALSE, FALSE);



/////////////////////////////////////////////////////////////////////////////
//If level 40 lets do some cool stuff to them :) (optional of course)
//If you do not wish to use this options you will need to delete the // below
                        //                      /* <<(don't touch this part)

    if(GetHitDice(oPC) == 40 || GetItemPossessedBy(oPC, "gen_token")!=OBJECT_INVALID)
    {
    //Lets make the concealed 40%
    eEffect = EffectConcealment(40);
    eEffect = SupernaturalEffect(eEffect);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, eEffect, oPC);

    //Lets make the look like a ghost.. :)
    //To activate, simply delete the // below this line
    //ApplyEffectToObject(DURATION_TYPE_PERMANENT, SupernaturalEffect(EffectVisualEffect(VFX_DUR_GLOW_WHITE)), oPC);

    }

// don't touch this line */
//////////////////////////////////////////////////////////////////////////////

//This is the immortal option, you must utilize the "makeimmortal" script
//to make players immortal (please read that script.)
if(GetItemPossessedBy(oPC, "immotoken") != OBJECT_INVALID)
{
 //Run this script on the player (See script to configure settings)
 ExecuteScript("powerimmortal", oPC);
}

//////////////////////////////////////////////////////////////////////////////
//If a player has been found with an illegal character they will have this item.
//It will prevent them from logging onto your server with that character.
//Note this will only work if you have activated the Anti-Cheat option above!
if (GetItemPossessedBy(oPC, "banned")!= OBJECT_INVALID)
   {
   AssignCommand(oPC, ClearAllActions());

   SetCutsceneMode(oPC, TRUE);

   SetCameraMode(oPC, CAMERA_MODE_CHASE_CAMERA);

   DelayCommand(4.0, FloatingTextStringOnCreature("You have an illegal character which is not allowed on this server.", oPC));

   DelayCommand(5.0, SetCutsceneMode(oPC, FALSE));

   DelayCommand(6.0, BootPC(oPC));

   }
// */
////////////////////////////////////////////////////////////////////////////

//Since the player was dead when they logged, kill them!
if (GetItemPossessedBy(oPC, "death") != OBJECT_INVALID)
   {
    effect eEffect;
    eEffect = EffectDamage(999, DAMAGE_TYPE_POSITIVE, DAMAGE_POWER_ENERGY);
    eEffect = SupernaturalEffect(eEffect);
    DelayCommand(5.8, ApplyEffectToObject(DURATION_TYPE_INSTANT, eEffect, oPC));
    DelayCommand(5.9, ApplyEffectToObject(DURATION_TYPE_INSTANT, eEffect, oPC));
    SendMessageToPC(oPC, "You died because you were dead when you logged out.");
   }

///////////////////////////////////////////////////////////////////
//Bioware Scripting For Handing Horses
/*
    ExecuteScript("x3_mod_pre_enter",OBJECT_SELF); // Override for other skin systems

    if ((GetIsPC(oPC)||GetIsDM(oPC))&&!GetHasFeat(FEAT_HORSE_MENU,oPC))
    { // add horse menu
        HorseAddHorseMenu(oPC);
        if (GetLocalInt(GetModule(),"X3_ENABLE_MOUNT_DB"))
        { // restore PC horse status from database
            DelayCommand(2.0,HorseReloadFromDatabase(oPC,X3_HORSE_DATABASE));
        } // restore PC horse status from database
    } // add horse menu
    if (GetIsPC(oPC))
    { // more details
        // restore appearance in case you export your character in mounted form, etc.
        if (!GetSkinInt(oPC,"bX3_IS_MOUNTED")) HorseIfNotDefaultAppearanceChange(oPC);
        // pre-cache horse animations for player as attaching a tail to the model
        HorsePreloadAnimations(oPC);
        DelayCommand(3.0,HorseRestoreHenchmenLocations(oPC));
    } // more details
*/
//////////////////////////////////////////////////////////////////

//End Script
}


//PROTOTYPE DEFINED
void SendMessageToAllPC(string sMessage)
{
   object oPC = GetFirstPC();
   while(GetIsObjectValid(oPC))
   {
      FloatingTextStringOnCreature(sMessage, oPC);
      oPC = GetNextPC();
   }
}