So here is the code. The reason I was using +sResearchType+ was that I’m trying to make this into a template system that gets the variables from the items instead of having to have each research type coded into its own bespoke script. I’m still undecided on which ones will be made at this point.
I’m aware that writing variables to a PC in a multiplayer environment isn’t a good idea, this is still a prototyping script and it’ll be pointing at a database item on the PC in the future. This script is called very rarely.
void main()
{
object oPC = GetItemActivator();
object oItem = GetItemActivated();
string sResearchType = GetLocalString(oItem, "ResearchType");
string sStationBlueprint = GetLocalString(oItem, "StationBlueprint");
string sBlueprintDescription = GetLocalString(oItem, "BlueprintDescription");
int iActiveResearch = GetLocalInt(oPC, "ActiveResearch");
int iBasicResearchComplete = GetLocalInt(oPC, "BasicResearch"+sResearchType+"Complete");
int iStatModifier = GetAbilityModifier(ABILITY_INTELLIGENCE, oPC)+GetAbilityModifier(ABILITY_WISDOM, oPC)/2;
int iXPGain = GetLocalInt(oItem, "XP Gain")*iStatModifier;
int iXPRequired = GetLocalInt(oItem, "XP Required");
int iCurrentSkill = GetLocalInt(oPC, ""+sResearchType+"");
//Check to make sure we only have the one research project going.
if (iActiveResearch != 0 && sResearchType != GetLocalString(oPC, "ActiveResearchType"))
{
SendMessageToPC(oPC, "You are currently researching " +sResearchType+" and will have to complete the basics to start a new field of study.");
return;
}
//I would like a more elborate message here.
SendMessageToPC(oPC, "Your XP mod is: " +IntToString(iStatModifier)+".");
SendMessageToPC(oPC, "XP gain from this item is: " +IntToString(iXPGain)+".");
SendMessageToPC(oPC, "DEBUGGING: Your current XP level is: " +IntToString(iCurrentSkill)+".");
//Once we begin reading the book we set variables and things.
switch (GetLocalInt(oPC, "ActiveResearch"))
{
case 0:
//Perform first time use actions.
SetLocalInt(oPC, "ActiveResearch", 1);
SetLocalString(oPC, "ActiveResearchType", ""+sResearchType+"");
SetLocalInt(oPC, ""+sResearchType+"", iXPGain);
SendMessageToPC(oPC, "You begin to study the basics of " +sResearchType+".");
break;
case 1:
SendMessageToPC(oPC, "You continue to study the basics of " +sResearchType+".");
SetLocalInt(oPC, ""+sResearchType+"", iCurrentSkill+iXPGain);
if (iCurrentSkill >= iXPRequired)
{
SendMessageToPC(oPC, ""+sBlueprintDescription+"");
CreateItemOnObject(""+sStationBlueprint+"", oPC, 1, "research_station_"+sResearchType+"");
SetLocalInt(oPC, "BasicResearch"+sResearchType+"Complete", 1);
SetLocalInt(oPC, "ActiveResearch", 0);
SetLocalString(oPC, "ActiveResearchType", "");
return;
}
break;
}
}