Aller au contenu

Photo

give XP script [ ga_give_quest_xp_2 ]


  • Veuillez vous connecter pour répondre
2 réponses à ce sujet

#1
kevL

kevL
  • Members
  • 4 075 messages
Andy's musings inspired me to work up the following script. I don't expect anyone to use it (except perhaps its author) for it's likely really complicated to understand at the gitgo.

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 )
  • andysks aime ceci

#2
andysks

andysks
  • Members
  • 1 655 messages
Will certainly look at this when I get home later :)

#3
kevL

kevL
  • Members
  • 4 075 messages

:)  good luck. I wrote the extensive documentation at the top, because i know that after a week I wouldn't have a clue how to use it ...

 

[ add ]

Examples.

 

To award XP like the stock script:

ga_give_quest_xp_2("quest_tag", -1, 0, 0, 0, 0)


To prevent PC greater than level 10, and if so party members of any level, from getting XP:

ga_give_quest_xp_2("quest_tag", 10, 0, 0, 0, 0)


To give XP only to party members level 10 or lower:

ga_give_quest_xp_2("quest_tag", 10, 0, 0, 1, 0)


To divide XP among party members and give a portion only to those level 10 or lower:

ga_give_quest_xp_2("quest_tag", 10, 0, 0, 3, 0)


To give unrestricted full XP, but to the PC only:

ga_give_quest_xp_2("quest_tag", -1, 0, 0, -1, 0)


To give full XP restricted to level 10 or below, to the PC only:

ga_give_quest_xp_2("quest_tag", 10, 0, 0, -1, 0)


To reduce awarded XP by 50 XP per pip of average party level over level 10, and award that amount only to party members level 10 or below:

ga_give_quest_xp_2("quest_tag", 10, -1, 50, 3, 1)


To increase awarded XP by 50 XP per pip of average party level over level 10, and award that amount to all party members:

ga_give_quest_xp_2("quest_tag", 10, 1, 50, 0, 1)


To decrease awarded XP by 50 XP per pip of PC level over level 10, and award that amount only to PC:

ga_give_quest_xp_2("quest_tag", 10, -1, 50, -1, 0)


To multiply XP by PC level:

ga_give_quest_xp_2("quest_tag", 0, 0, 1, 0, 0)


To divide XP by average party level:

ga_give_quest_xp_2("quest_tag", 0, 0, -1, 0, 1)


To give 100 XP to all party:

ga_give_quest_xp_2("100", 0, 0, 0, 0, 0)



/may contain mistakes.