Jaysyn904 04165202c0 Initial upload
Initial upload
2024-11-25 19:36:07 -05:00

202 lines
9.0 KiB
Plaintext

////////////////////////////////////////////////////////////////////////////////
// hos_onclient_e - On Client Enter - Version 2.0 by Deva Bryson Winblood
// and Jeremy Greene.
////////////////////////////////////////////////////////////////////////////////
#include "death_lock_h"
#include "header_sounds"
#include "hos_saveload_h"
#include "hos_pcsetup_h"
////////////////////////
// PROTOTYPES
////////////////////////
int fnLevelCount(object oPC);
void fnCreateGameSettingsTool(object oPC);
void fnAnnounceJoin(object oPC,int nOption=0);
void fnAnnounce(string sMsg="");
int fnCountPlayers();
void fnAddModuleJournals(object oPC);
int fnFindChatPosition();
/////////////////////////////////////////////////////////////////////// MAIN
void main()
{
object oPC=GetEnteringObject();
object oMod=GetModule();
int nMAX_PLAYERS;
int nInProgress=GetLocalInt(oMod,"nInProgress");
int nLevel=fnLevelCount(oPC);
object oInProgress=GetWaypointByTag("INPROGRESS_JOIN");
string sCDKEY=fnSLGetPCPublicCDKey(oPC)+fnSLGetPCPlayerName(oPC);
object oItem;
int nCL;
object oGoldThief=GetObjectByTag("GOLD_THIEF");
if (GetIsPossessedFamiliar(oPC)) { SendMessageToPC(oPC,"Client Enter ignored for possessed familiars."); return; } // do not run for possessed familiars
/// end variable declaration----------------------------------
PrintString("hos_onclient_ent: "+GetPCPlayerName(oPC)+"[Character:"+GetName(oPC)+"] CD-KEY:"+GetPCPublicCDKey(oPC)+" IP:"+GetPCIPAddress(oPC));
SendMessageToPC(oPC,"Connected: "+GetPCPlayerName(oPC)+"[Character:"+GetName(oPC)+"] CD-KEY:"+GetPCPublicCDKey(oPC)+" IP:"+GetPCIPAddress(oPC)+" Stored:"+sCDKEY);
DeleteLocalInt(oPC,"bSavePending"); // make sure not there in error after crash or link dead recovery
// We build the data for the module when the first player connects because,
// this provides a random seed that works well. If this is called from
// Load Module then the random #s always seem to be based off the same seed.
if (GetLocalInt(oMod,"RTSDATABUILT")!=TRUE) ExecuteScript("rts_build_data",OBJECT_SELF);
if (!GetIsObjectValid(GetLocalObject(oMod,"oFirstPlayer"))&&GetIsDM(oPC)==FALSE)
{
SetLocalInt(oPC,"nFirstPlayer",TRUE);
SetLocalObject(oMod,"oFirstPlayer",oPC);
DelayCommand(6.0,SendMessageToPC(oPC,"You are the GAME CONTROLLER."));
DelayCommand(6.0,SendMessageToPC(oPC,"Please use the Game Settings Control Panel to signify how you wish the game to play."));
AddJournalQuestEntry("STARTHELP",1,oPC,FALSE,FALSE);
}
// end call module build script
nMAX_PLAYERS=GetLocalInt(oMod,"nMaxPlayers");
if (nMAX_PLAYERS<4) nMAX_PLAYERS=20;
// end get vital variables
if (GetIsDM(oPC)!=TRUE&&sCDKEY!=(GetPCPublicCDKey(oPC)+GetPCPlayerName(oPC))&&fnCountPlayers()<=nMAX_PLAYERS)
{ // the pc is not a DM and I do not recognize this CDKEY and PLAYER and max players are not connected
fnSLSaveCDKEY(oPC);
fnSLSavePCPlayerName(oPC);
ExecuteScript("rts_save_player",oPC);
// the PC info has been saved so, it will remember that you connected before
fnRemoveAllInventory(oPC);
AssignCommand(oGoldThief,TakeGoldFromCreature(GetGold(oPC),oPC,TRUE));
fnAddModuleJournals(oPC);
DelayCommand(4.0,fnEquipStartingEquipment(oPC));
//SetXP(oPC,0);
fnAnnounceJoin(oPC);
if (!nInProgress)
{ // the game is NOT in progress<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
fnCreateGameSettingsTool(oPC);
} // the game is NOT in progress<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
else if(GetLocalInt(oMod,"nInProgressJoins")==TRUE)
{ // the game is in progress>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SetXP(oPC,0);
fnDeathLockBootPC(oPC);
DelayCommand(6.1,AssignCommand(oPC,JumpToObject(oInProgress)));
ExecuteScript("setupteam_tokens",oPC);
DelayCommand(6.5,AssignCommand(oPC,ActionStartConversation(oPC,"inprogress_join",TRUE,FALSE)));
} // the game is in progress>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
else
{ // in progress joins not allowed
AssignCommand(oPC,SpeakString("*This game is already in play and they have specified no in progress joins are allowed.*"));
fnAnnounce(GetName(oPC)+" tried to connect but, in progress joins are not allowed.");
DelayCommand(20.0,BootPC(oPC));
} // in progress joins not allowed
} // the pc is not a DM and I do not recognize this CDKEY and PLAYER and max players are not connected
else if (fnCountPlayers()>nMAX_PLAYERS)
{ // too many players-----------------------------------------------------------
AssignCommand(oPC,SpeakString("**WARNING: There are too many players connected. The max players is set to "+IntToString(nMAX_PLAYERS)+". You may have success if you try to connect later."));
fnAnnounce(GetName(oPC)+" tried to join the game but, maximum players has been reached.");
DelayCommand(20.0,BootPC(oPC));
} // too many players-----------------------------------------------------------
else if (GetIsDM(oPC)==TRUE)
{ // DUNGEON MASTER-------------------------------------------------------------
oItem=GetItemPossessedBy(oPC,"rts_dm_wand");
if (oItem==OBJECT_INVALID)
oItem=CreateItemOnObject("rts_dm_wand",oPC);
if (GetLocalInt(oPC,"nJoinedAlready")==FALSE)
{ // first join
fnAnnounce("Dungeon master "+GetName(oPC)+" played by "+GetPCPlayerName(oPC)+" has connected.");
SetLocalInt(oPC,"nJoinedAlready",TRUE);
} // first join
nCL=fnFindChatPosition();
SetLocalInt(GetModule(),"bChatLog"+IntToString(nCL),TRUE);
SetCustomToken(87000+nCL,"No chats have been logged yet.");
AddJournalQuestEntry("chatlog",nCL,oPC,FALSE,FALSE);
SetLocalInt(oPC,"nChatPosition",nCL);
SetLocalObject(GetModule(),"oChatLog"+IntToString(nCL),oPC);
} // DUNGEON MASTER-------------------------------------------------------------
else if (sCDKEY==(GetPCPublicCDKey(oPC)+GetPCPlayerName(oPC))&&!GetIsPossessedFamiliar(oPC))
{ // RECONNECTING PLAYER--------------------------------------------------------
SendMessageToPC(oPC,"WELCOME BACK!!");
//Qlippoth removed so no SaveLoadPC// fnSLLoadPlayer(oPC);
if (GetLocalInt(oPC,"nKicked")>3) BootPC(oPC);
fnAnnounce(GetName(oPC)+" has reconnected to the game.");
SendMessageToPC(oPC,"An announcement was sent that you reconnected.");
} // RECONNECTING PLAYER--------------------------------------------------------
DelayCommand(1.0,ExecuteScript("x3_mod_def_enter",OBJECT_SELF)); // horse support
} // main
/////////////////////////////////////////////////////////////////////// MAIN
/////////////////////////
// FUNCTIONS
/////////////////////////
int fnLevelCount(object oPC)
{ // return number of levels
int nRet=GetLevelByPosition(1,oPC);
nRet=nRet+GetLevelByPosition(2,oPC);
nRet=nRet+GetLevelByPosition(3,oPC);
return nRet;
} // fnLevelCount()
void fnCreateGameSettingsTool(object oPC)
{
object oItem;
if (GetItemPossessedBy(oPC,"rts_it_manual")==OBJECT_INVALID)
oItem=CreateItemOnObject("rts_it_manual",oPC,1);
} // fnCreateGameSettingsTool()
void fnAnnounceJoin(object oPC,int nOption=0)
{
object oNext=GetFirstPC();
if (GetLocalString(oNext,"sTeamID")!="")
SendMessageToPC(oNext,GetName(oPC)+" HAS CONNECTED TO THE GAME!");
while(oNext!=OBJECT_INVALID)
{ // message
if (nOption==0) AssignCommand(oNext,fnSoundAlert("as_cv_bell1"));
oNext=GetNextPC();
if (GetLocalString(oNext,"sTeamID")!="")
SendMessageToPC(oNext,GetName(oPC)+" HAS CONNECTED TO THE GAME!");
} // message
} // fnAnnounceJoin()
void fnAnnounce(string sMsg="")
{ // announce message to players
object oNext=GetFirstPC();
while(oNext!=OBJECT_INVALID)
{ // announce
SendMessageToPC(oNext,"ANNOUNCEMENT:"+sMsg);
AssignCommand(oNext,fnSoundAlert("as_cv_bell2"));
oNext=GetNextPC();
} // announce
} // fnAnnounce()
int fnCountPlayers()
{
int nRet=0;
object oPC=GetFirstPC();
while(oPC!=OBJECT_INVALID)
{
nRet++;
oPC=GetNextPC();
}
return nRet;
} // fnCountPlayers()
void fnAddModuleJournals(object oPC)
{
int nCL;
AddJournalQuestEntry("Introduction",1,oPC,FALSE,FALSE);
AddJournalQuestEntry("GeneralInfo",1,oPC,FALSE,FALSE);
AddJournalQuestEntry("TheStory",1,oPC,FALSE,FALSE);
AddJournalQuestEntry("voiceje",1,oPC,FALSE,FALSE);
nCL=fnFindChatPosition();
SetLocalInt(GetModule(),"bChatLog"+IntToString(nCL),TRUE);
SetCustomToken(87000+nCL,"No chats have been logged yet.");
AddJournalQuestEntry("chatlog",nCL,oPC,FALSE,FALSE);
SetLocalInt(oPC,"nChatPosition",nCL);
SetLocalObject(GetModule(),"oChatLog"+IntToString(nCL),oPC);
} // fnAddModuleJournals()
int fnFindChatPosition()
{
object oMod=GetModule();
int nN=1;
while((GetLocalInt(oMod,"bChatLog"+IntToString(nN))==TRUE&&GetLocalObject(oMod,"oChatLog"+IntToString(nN))!=OBJECT_INVALID)&&nN<65)
{ // find position
nN++;
} // find position
if (nN<65&&(GetLocalInt(oMod,"bChatLog"+IntToString(nN))==FALSE||GetLocalObject(oMod,"oChatLog"+IntToString(nN))==OBJECT_INVALID)) return nN;
return 0;
} // fnFindChatPosition()