REO-EE/_module/nss/inc_letoscript.nss
Jaysyn904 f82740bbbd Initial commit
Initial commit
2024-02-22 13:22:03 -05:00

428 lines
11 KiB
Plaintext

//::Constants
//::---------------------------------------------------------------------------
const string SERVERVAULT = "/home/tyler/Desktop/NeverwinterNights/NWN/servervault";
//::Prototypes
//::---------------------------------------------------------------------------
//::Returns true if leto is online
int Leto_GetIsOnline( );
//::Returns the path to oPC's file
string Leto_GetBicPath( object oPC );
//::Executes a letoscript that will alter the character file
//::This function will boot the PC
//::NOTE This function should not run on the PC as (s)he'll's getting booted
//::Use the GenerateLetoScript* functions to setup a script
//::Example:
//::string sScript = GenerateLetoScriptSetAbility( ABILITY_CHARISMA, 10 );
//::sScript += GenerateLetoScriptAddFeat( FEAT_EPIC_DEVASTATING_CRITICAL_HANDAXE );
//::ExecuteFileWritingOperation(oPC, sScript );
//::Result: The PC is booted and when he logs in he'll have devcrit handaxe and 10 cha
void Leto_ExecuteFileWritingOperation( object oPC, string sScript, int nBoot = TRUE );
//::Executes a file reading leto script
//::This does not require booting
//::Fields:
//::------
//::FirstName
//::LastName
//::Description
//::DescriptionOverr
//::IsPC
//::IsDM
//::Tag
//::Conversation
//::Interuptable
//::Age
//::Gender
//::Race
//::Subrace
//::StartingPackage
//::Deity
//::MClassLevUpIn
//::willbonus
//::fortbonus
//::refbonus
//::Gold
//::BaseAttackBonus
//::RefSaveThrow
//::WillSaveThrow
//::FortSaveThrow
//::ArmorClass
//::OverrideBAB
//::Str
//::Dex
//::Int
//::Wis
//::Con
//::Cha
//::NeutralAC
//::SoundSetFile
//::FootstepType
//::Plot
//::NoPermaDeath
//::Disarmable
//::BodyBag
//::HitPoints
//::CurrentHitPoints
//::MaxHitPoints
//::PregameCurrent
//::Experiance
//::MovementRate
//::Portait
//::GoodEvil
//::LawfulChaotic
//::Color_Skin
//::Color_Hair
//::Color_Tattoo1
//::Color_Tattoo2
//::Phenotype
//::Appearance_Type
//::Appearance_Head
//::Tail_New
//::Wings_New
//::FactionID
//::ChallengeRating
//::BodyPart_Neck
//::BodyPart_Torso
//::BodyPart_Belt
//::BodyPart_Pelvis
//::BodyPart_LShoul
//::BodyPart_LBicep
//::BodyPart_LFArm
//::BodyPart_LHand
//::BodyPart_LThigh
//::BodyPart_LShin
//::BodyPart_LFoot
//::BodyPart_RShoul
//::BodyPart_RBicep
//::BodyPart_RFArm
//::BodyPart_RHand
//::BodyPart_RThigh
//::BodyPart_RShin
//::BodyPart_RFoot
//::CompanionType
//::CompanionName
//::SkillPoints
//::DetectMode
//::StealthMode
//::MasterID
//::CreatureSize
//::IsDestroyable
//::IsCommandable
//::IsImmortal
//::Lootable
//::BodyBagId
//::DecayTime
//::TemplateResRef
//::ScriptHeartBeat
//::ScriptOnNotice
//::SctiptSpellAt
//::ScriptAttacked
//::ScriptDamaged
//::ScriptDisturbed
//::ScriptEndRound
//::ScriptDialogue
//::ScriptSpawn
//::ScriptRested
//::ScriptDeath
//::ScriptUserDefine
//::ScriptOnBlocked
//::CombatRoundData
//::AreaId
//::SitObject
//::AmbientAnimState
//::CreatnScrtFird
//::CreatnScrptFird
//::PM_IsPolymorphed
//::Listening
//::XPosition
//::YPosition
//::ZPosition
//::XOrientation
//::YOrientation
//::ZOrientation
//::AnimationDay
//::AnimationTime
//::EncounterObject
string Leto_ExecuteFileReadingOperation( object oPC, string sFieldToRead );
//::Return letoscript code to change the racial on oPC
//::Use ExecuteFileWritingOperation() to execute the script
//::All strings GenerateLeto* functions returns are stackable
//::Fields:
//::------
//::FirstName
//::LastName
//::Description
//::DescriptionOverr
//::IsPC
//::IsDM
//::Tag
//::Conversation
//::Interuptable
//::Age
//::Gender
//::Race
//::Subrace
//::StartingPackage
//::Deity
//::MClassLevUpIn
//::willbonus
//::fortbonus
//::refbonus
//::Gold
//::BaseAttackBonus
//::RefSaveThrow
//::WillSaveThrow
//::FortSaveThrow
//::ArmorClass
//::OverrideBAB
//::Str
//::Dex
//::Int
//::Wis
//::Con
//::Cha
//::NeutralAC
//::SoundSetFile
//::FootstepType
//::Plot
//::NoPermaDeath
//::Disarmable
//::BodyBag
//::HitPoints
//::CurrentHitPoints
//::MaxHitPoints
//::PregameCurrent
//::Experiance
//::MovementRate
//::Portait
//::GoodEvil
//::LawfulChaotic
//::Color_Skin
//::Color_Hair
//::Color_Tattoo1
//::Color_Tattoo2
//::Phenotype
//::Appearance_Type
//::Appearance_Head
//::Tail_New
//::Wings_New
//::FactionID
//::ChallengeRating
//::BodyPart_Neck
//::BodyPart_Torso
//::BodyPart_Belt
//::BodyPart_Pelvis
//::BodyPart_LShoul
//::BodyPart_LBicep
//::BodyPart_LFArm
//::BodyPart_LHand
//::BodyPart_LThigh
//::BodyPart_LShin
//::BodyPart_LFoot
//::BodyPart_RShoul
//::BodyPart_RBicep
//::BodyPart_RFArm
//::BodyPart_RHand
//::BodyPart_RThigh
//::BodyPart_RShin
//::BodyPart_RFoot
//::CompanionType
//::CompanionName
//::SkillPoints
//::DetectMode
//::StealthMode
//::MasterID
//::CreatureSize
//::IsDestroyable
//::IsCommandable
//::IsImmortal
//::Lootable
//::BodyBagId
//::DecayTime
//::TemplateResRef
//::ScriptHeartBeat
//::ScriptOnNotice
//::SctiptSpellAt
//::ScriptAttacked
//::ScriptDamaged
//::ScriptDisturbed
//::ScriptEndRound
//::ScriptDialogue
//::ScriptSpawn
//::ScriptRested
//::ScriptDeath
//::ScriptUserDefine
//::ScriptOnBlocked
//::CombatRoundData
//::AreaId
//::SitObject
//::AmbientAnimState
//::CreatnScrtFird
//::CreatnScrptFird
//::PM_IsPolymorphed
//::Listening
//::XPosition
//::YPosition
//::ZPosition
//::XOrientation
//::YOrientation
//::ZOrientation
//::AnimationDay
//::AnimationTime
//::EncounterObject
string Leto_GenerateLetoScriptChangeBicField( string sBicField, string sValue );
//::Return letoscript code to modify a skill on oPC
//::Use ExecuteFileWritingOperation() to execute the script
//::All strings GenerateLeto* functions returns are stackable
//::nLevel determines which level in the bicfield the modification
//::should be linked to if that level is undone so is the letochange
//::if nLevel = -1 no levellist changing will happen
//::SKILL_* constants are used
string Leto_GenerateLetoScriptModifySkill( int nSkill, int nModify, int nLevel = -1 );
//::Return letoscript code to add nFeat to oPC
//::Use ExecuteFileWritingOperation() to execute the script
//::All strings GenerateLeto* functions returns are stackable
//::nLevel determines which level in the bicfield the modification
//::should be linked to if that level is undone so is the letochange
//::if nLevel = -1 no levellist changing will happen
string Leto_GenerateLetoScriptAddFeat( int nFeat, int nLevel = -1 );
//::Return letoscript code to remove nFeat from oPC
//::Use ExecuteFileWritingOperation() to execute the script
//::All strings GenerateLeto* functions returns are stackable
string Leto_GenerateLetoScriptRemoveFeat( int nFeat );
//::Return letoscript code to modify a ability score on oPC
//::Use ExecuteFileWritingOperation() to execute the script
//::All strings GenerateLeto* functions returns are stackable
//::ABILITY_* constants are used to determin ability
//::Note nwn handles its own races for example if you want a elf
//::to have 10 con you'd have to set nSet to 12 as nwn is subracting 2
string Leto_GenerateLetoScriptModifyAbility( int nAbility, int nSet );
//::Function definitions
//::---------------------------------------------------------------------------
string Leto_GenerateLetoScriptModifySkill( int nSkill, int nModify, int nLevel = -1 ){
if( nLevel == -1 )return "/SkillList/["+ IntToString( nSkill ) +"]/Rank = /SkillList/["+ IntToString( nSkill ) +"]/Rank +"+IntToString( nModify )+"; ";
nLevel--;
return "/SkillList/["+ IntToString( nSkill ) +"]/Rank = /SkillList/["+ IntToString( nSkill ) +"]/Rank +"+IntToString( nModify )+"; "+
"/LvlStatList/["+ IntToString( nLevel ) +"]/SkillList/["+ IntToString( nSkill ) +"]/Rank = "+IntToString( nModify )+"; ";
}
//::---------------------------------------------------------------------------
string Leto_GenerateLetoScriptChangeBicField( string sBicField, string sValue ){
return "/" + sBicField + "='" + sValue + "';";
}
//::---------------------------------------------------------------------------
string Leto_GenerateLetoScriptModifyAbility( int nAbility, int nMod ){
string sAbility;
switch( nAbility ){
case ABILITY_CHARISMA: sAbility = "Cha";break;
case ABILITY_CONSTITUTION: sAbility = "Con";break;
case ABILITY_DEXTERITY: sAbility = "Dex";break;
case ABILITY_INTELLIGENCE: sAbility = "Int";break;
case ABILITY_STRENGTH: sAbility = "Str";break;
case ABILITY_WISDOM: sAbility = "Wis";break;
default: return "";
}
return "/"+sAbility+" += '" +IntToString( nMod )+ "';";
}
//::---------------------------------------------------------------------------
string Leto_GenerateLetoScriptRemoveFeat( int nFeat ){
return "replace 'Feat', " + IntToString( nFeat ) + ", DeleteParent;";
}
//::---------------------------------------------------------------------------
string Leto_GenerateLetoScriptAddFeat( int nFeat, int nLevel = -1 ){
if( nLevel == -1 )return "add /FeatList/Feat, "+IntToString( nFeat )+", gffWord;";
nLevel--;
return "add /FeatList/Feat, "+IntToString( nFeat )+", gffWord;"+
"add /LvlStatList/["+ IntToString( nLevel ) +"]/FeatList/Feat, "+IntToString( nFeat )+", gffWord;";
}
//::---------------------------------------------------------------------------
string Leto_ExecuteFileReadingOperation( object oPC, string sFieldToRead ){
object oMod = GetModule();
string sPath = Leto_GetBicPath( oPC );
string sEXEScript =
"$RealFile = q<" + sPath + ">;" +
"$EditFile = $RealFile + '.utc';" +
"FileRename $RealFile, $EditFile;" +
"%bic = $EditFile or die;" +
"print /" + sFieldToRead + ";" +
"%bic = '>';" +
"close %bic;" +
"FileRename $EditFile, $RealFile;";
SetLocalString( oMod, "NWNX!LETO!SCRIPT", sEXEScript );
return GetLocalString( oMod, "NWNX!LETO!SCRIPT" );
}
//::---------------------------------------------------------------------------
void ExecuteLetoScript(string sScript) {
SetLocalString( GetModule( ), "NWNX!LETO!SCRIPT", sScript );
}
//::---------------------------------------------------------------------------
void Leto_ExecuteFileWritingOperation( object oPC, string sScript, int nBoot = TRUE ){
string sPath = Leto_GetBicPath( oPC );
if( nBoot )
BootPC( oPC );
string sEXEScript =
"$RealFile = q<" + sPath + ">;" +
"$EditFile = $RealFile + '.utc';" +
"FileRename $RealFile, $EditFile;" +
"%bic = $EditFile or die;" +
sScript +
"%bic = '>';" +
"close %bic;" +
"FileRename $EditFile, $RealFile;";
DelayCommand(1.0, ExecuteLetoScript(sEXEScript));
}
//::---------------------------------------------------------------------------
string Leto_GetBicPath( object oPC ){
ExportSingleCharacter( oPC );
object oMod = GetModule();
string sPath = SERVERVAULT + GetPCPlayerName( oPC ) + "/";
SetLocalString( oMod, "NWNX!LETO!SCRIPT", "print q<" + sPath + "> + FindNewestBic q<" + sPath + ">;" );
return GetLocalString( oMod, "NWNX!LETO!SCRIPT" );
}
//::---------------------------------------------------------------------------
int Leto_GetIsOnline( ){
SetLocalString( GetModule( ), "NWNX!LETO!SCRIPT", "print 'is_very_alive_today'" );
return ( GetLocalString( GetModule( ), "NWNX!LETO!SCRIPT" ) == "is_very_alive_today" ? TRUE: FALSE );
}
//::Main; uncomment for testing
//::---------------------------------------------------------------------------
//void main(){}