But if anyone wants to run it through their mill, test for bugs, or just figure it out here it is:
// 'ga_give_quest_xp_2'
//
// Grant experience.
// Experience goes to PCs and/or Companions & PlayerCreated characters.
// but never to Associates
//
// A rather lengthy adaptation of the stock 'ga_give_quest_xp' script, this
// permits giving experience to the PC exclusively. And other stuff. A very
// simple overview is: Think of iLevel as the cutoff, iBoost as whether to
// increase or decrease awarded experience pts, and iFactor as by how much.
//
// kL.2014.3.16
//
// sQuest: tag of the journal quest.
// note! If this is a purely numeric string
// -- without letters, an underscore, leading zeros, etc. --
// sQuest will be used to input XP directly.
//
// iLevel: -1 = turns iBoost & iFactor OFF. Use QuestXP directly!!!
// also bypasses bAverage and alters aspects of iDivide.
// if iBoost & iFactor == 0: iLevel acts as a hardcap, no XP
// awarded if (iLevel > charLevel).
// if iBoost != 0: iLevel acts as a boundary. iFactor qty is
// added to/subtracted from QuestXP based on the
// difference in levels between iLevel & charLevel.
// iBoost: 1 = increase awarded XP by addition.
// 0 = if iFactor == 0, use iLevel as a hardcap.
// if iFactor != 0, iFactor becomes the amount by which
// (iLevel - charLevel) is multiplied before addition
// or subtraction from QuestXP.
// -1 = decrease awarded XP by subtraction.
// iFactor: if iBoost == 0, this becomes a factor by which QuestXP is
// multiplied or divided by charLevel. Otherwise this is the
// amount by which (iLevel - charLevel) is multiplied before
// addition or subtraction from QuestXP.
// NOTE: Can be negative for division or subraction; that is,
// whether the resulting XP has been increased or decreased
// is determined by iBoost, iFactor, & iLevel together.
//
// iDivide: This assigns how the XP is apportioned.
// -1 = grant XP to PC only.
// 0 = grant XP to all Faction.
// 1 = grant XP to Faction that are at or below iLevel.
// if iLevel == -1, grant QuestXP to PC only.
// 2 = divide XP among all Faction.
// 3 = divide XP among Faction that are at or below iLevel.
// if iLevel == -1, divide QuestXP but grant to PC only.
// bAverage: 0 = use PC level against iLevel, iff applicable.
// 1 = use average partyLevel rather than PC level.
//
// note: it is NOT possible to award negative XP with this script.
// ________________
// ** Prototype ***
// ----------------
// Returns the PC object of oCreature's faction
// - oCreature must be PC-faction. else, returns OBJECT_INVALID
object kL_GetPC(object oCreature);
// ___________
// ** MAIN ***
// -----------
void main(string sQuest, int iLevel, int iBoost, int iFactor, int iDivide, int bAverage)
{
object oPC = GetIsObjectValid(GetPCSpeaker())? GetPCSpeaker(): OBJECT_SELF;
oPC = kL_GetPC(oPC);
if (GetIsObjectValid(oPC))
{
int iReward = 0;
if (sQuest != "")
{
iReward = StringToInt(sQuest);
if (sQuest != IntToString(iReward))
iReward = GetJournalQuestExperience(sQuest);
if (iReward < 1)
{
SendMessageToPC(GetFirstPC(FALSE), "error: ( ga_give_quest_xp_2 ) no reward for JournalTag : " + sQuest);
return;
}
}
else
{
SendMessageToPC(GetFirstPC(FALSE), "error: ( ga_give_quest_xp_2 ) sQuest not specified.");
return;
}
// debug:
//SendMessageToPC(GetFirstPC(FALSE), "\n. QuestXP = " + IntToString(iReward));
if (iLevel > -1)
{
int iCharLevel = bAverage? GetFactionAverageLevel(oPC): GetTotalLevels(oPC, FALSE);
if (iCharLevel < 1)
iCharLevel = 1;
// debug:
//SendMessageToPC(GetFirstPC(FALSE), ". iCharLevel = " + IntToString(iCharLevel));
if (iCharLevel > iLevel
&& iBoost == 0
&& iFactor == 0)
{
iReward = 0;
}
else if (iBoost != 0)
{
if (iBoost > 0)
iReward += (iLevel - iCharLevel) * iFactor;
else
iReward -= (iLevel - iCharLevel) * iFactor;
}
else if (iFactor != 0)
{
if (iFactor > 0)
iReward *= iCharLevel;
else
iReward /= iCharLevel;
}
}
if (iReward < 1)
{
SendMessageToPC(GetFirstPC(FALSE), "Your PC level is too high for this.");
return;
}
// debug:
//SendMessageToPC(GetFirstPC(FALSE), ". iReward (pre-divide) = " + IntToString(iReward));
if (iDivide > 1)
{
int i = 0;
object oFM = GetFirstFactionMember(oPC, FALSE);
while (GetIsObjectValid(oFM))
{
if (GetAssociateType(oFM) == ASSOCIATE_TYPE_NONE)
++i;
oFM = GetNextFactionMember(oPC, FALSE);
}
if (i) iReward /= i;
}
// debug:
//SendMessageToPC(GetFirstPC(FALSE), ". iReward (post-divide) = " + IntToString(iReward));
if (iDivide < 0
|| (iLevel < 0
&& (iDivide == 1 || iDivide == 3)))
{
// debug:
//SendMessageToPC(GetFirstPC(FALSE), ". . reward " + GetName(oPC));
SetXP(oPC, GetXP(oPC) + iReward);
}
else
{
// debug:
//SendMessageToPC(GetFirstPC(FALSE), ". . check Party");
object oFM = GetFirstFactionMember(oPC, FALSE);
while (GetIsObjectValid(oFM))
{
if (GetAssociateType(oFM) == ASSOCIATE_TYPE_NONE
&& (iLevel < 0
|| iDivide == 0 || iDivide == 2
|| GetTotalLevels(oFM, FALSE) <= iLevel))
{
// debug:
//SendMessageToPC(GetFirstPC(FALSE), ". . reward " + GetName(oFM));
SetXP(oFM, GetXP(oFM) + iReward);
}
// debug
//else SendMessageToPC(GetFirstPC(FALSE), ". . skip " + GetName(oFM));
oFM = GetNextFactionMember(oPC, FALSE);
}
}
}
else
{
SendMessageToPC(GetFirstPC(FALSE), "error: ( ga_give_quest_xp_2 ) oPC is not PC faction");
}
}
//________________
// ** Function ***
// ---------------
// Returns the PC object of oCreature's faction
// - oCreature must be PC-faction. else, returns OBJECT_INVALID
object kL_GetPC(object oCreature)
{
object oMaster = GetMaster(oCreature);
while (GetIsObjectValid(oMaster))
{
oCreature = oMaster;
oMaster = GetMaster(oMaster);
}
if (GetIsOwnedByPlayer(oCreature))
{
return oCreature;
}
else if (GetIsRosterMember(oCreature))
{
oCreature = GetFactionLeader(oCreature);
oCreature = GetOwnedCharacter(oCreature);
return oCreature;
}
return OBJECT_INVALID;
}ideas:- use GetTarget() 'ginc_param_const'
- use PCLevel as iLevel ( ie. bring lower level companions up closer to PC )





Retour en haut






