Author Topic: XP Giver - Hard Leveling  (Read 1441 times)

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
XP Giver - Hard Leveling
« Reply #45 on: July 18, 2014, 09:29:01 am »


               

well whizard, to solve it we can add this (line 142)


 




if((GetHitDice(oKiller) < GetHitDice(oObject))) iHD = GetHitDice(oObject);
else iHD = GetHitDice(oKiller);


and remove this condition (line 150)



if((GetHitDice(oKiller) < GetHitDice(oObject))) {}

I think that now it's all


Again a great by whizard. thank you very much  '^_^' 


               
               

               


                     Modifié par WhiteTiger, 18 juillet 2014 - 09:03 .
                     
                  


            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
XP Giver - Hard Leveling
« Reply #46 on: August 13, 2014, 10:17:22 pm »


               

Take a look to my finished code, Whizard and Shadooow.



//:://////////////////////////////////////////////////
//:: Code by WhiteTiger
//:: a_xp_giver
/*
  Script Padrao de recebimento de XP Amnesia
  Aplica dois tipos de penalidades no valor bruto.
 */
//:://////////////////////////////////////////////////

#include "amnesia_include"
#include "x2_inc_compon"
#include "x0_i0_spawncond"

int setPP(int iDN, int iNumParty)
{
    if(iNumParty == 2 && iDN >= 5) return 11;
    if(iNumParty == 2 && iDN == 4) return 13;
    if(iNumParty == 2 && iDN == 3) return 12;
    if(iNumParty == 2 && (iDN == 1 || iDN == 2)) return 14;
    if(iNumParty == 2 && (iDN == -1 || iDN == 0)) return 20;
    if(iNumParty == 2 && iDN == -2) return 25;
    if(iNumParty == 3 && iDN >= 5) return 14;
    if(iNumParty == 3 && iDN == 4) return 16;
    if(iNumParty == 3 && iDN == 3) return 15;
    if(iNumParty == 3 && iDN == 2) return 19;
    if(iNumParty == 3 && iDN == 1) return 20;
    if(iNumParty == 3 && iDN == 0) return 28;
    if(iNumParty == 3 && (iDN == -2 || iDN == -1)) return 25;
    if(iNumParty == 4 && iDN >= 5) return 16;
    if(iNumParty == 4 && (iDN == 3 || iDN == 4)) return 19;
    if(iNumParty == 4 && iDN == 2) return 23;
    if(iNumParty == 4 && iDN == 1) return 27;
    if(iNumParty == 4 && iDN == 0) return 37;
    if(iNumParty == 4 && iDN == -1) return 34;
    if(iNumParty == 4 && iDN == -2) return 25;

    return 10;
}

int setXP(int iDN)
{
    if (iDN >= 05) return 380;
    if (iDN == 04) return 330;
    if (iDN == 03) return 270;
    if (iDN == 02) return 220;
    if (iDN == 01) return 160;
    if (iDN == 00) return 110;
    if (iDN == -1) return 60;
    if (iDN == -2) return 40;
    if (iDN == -3) return 20;
    if (iDN == -4) return 10;

    return 1;
}

void main()
{
    object oKiller = GetLastKiller();

    //Set oKiller as a player
    if(GetAssociateType(oKiller) != ASSOCIATE_TYPE_NONE) oKiller = GetMaster(oKiller);

    //============== Starting Variables ===============
    int iNumParty;
    int iXP;
    float fXPPenalt;
    int iXPPenalt;
    int iNewXP;
    int iPenal;
    int iPenal2;
    int iCR = FloatToInt(GetChallengeRating(OBJECT_SELF));
    int iHD1 = GetHitDice(oKiller);
    int iHD2;
    int iDN1 = iCR - iHD1;
    int iDN2;
    object oAreaPC;

    //============== Starting Countdown ===========================
    object oArea = GetArea(OBJECT_SELF);
    object oObject = GetFirstObjectInArea(oArea);
    int iDead = GetIsDead (oObject);
    int iSameFaction = GetFactionEqual (oKiller, oObject);
    while (GetIsObjectValid(oObject))
    {
        if ((GetIsPC(oObject)) && (iSameFaction == TRUE) && (iDead == FALSE))
            {
                iNumParty = iNumParty + 1;
            }
        oObject = GetNextObjectInArea(oArea);
        iDead = GetIsDead (oObject);
        iSameFaction = GetFactionEqual (oKiller, oObject);
    }

    //========== Applying XP (oKiller) ====================================
            int iCurrentXP = GetXP(oKiller);
            int iXPMax = ((iHD1 * 1000) + (iHD1 * (iHD1 - 1) * 500));
            iDead = GetIsDead (oKiller);

            //Set the XP Proporcion
            iXP = setXP(iDN1);

            //Set the correct penalty according the XP
            iPenal = setPP(iDN1, iNumParty);

            //Set penalty if there is 5 players in party
            if(iNumParty >= 5) iXP = iXP/2;

                if  ((iDead == FALSE) && (iCurrentXP < iXPMax))
                {
                        if (!HasSanctuary(oKiller))
                        {
                            fXPPenalt = (iXP/10) * (iPenal/100.0);
                            iXPPenalt = FloatToInt(fXPPenalt); //Important Conversion.
                            iNewXP = iXP - (iXPPenalt*10);

                            if(((iCurrentXP + iNewXP) >= iXPMax))
                            {
                                SetXP(oKiller, (iXPMax));
                                ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(GetMaxHitPoints(oKiller) - GetCurrentHitPoints(oKiller)), oKiller);
                                SendMessageToPC(oKiller, "Level Up!");
                            } else
                            if(iNewXP <= 1)
                            {
                            iNewXP = 1;
                            SetXP(oKiller, (iCurrentXP + iNewXP));
                            } else GiveXPToCreature(oKiller, iNewXP);
                        }
                        else
                        {
                            FloatingTextStringOnCreature ("No XP in Sanctuary!", oKiller);
                        }
                } else
                if((iCurrentXP >= iXPMax) && (iCurrentXP < 780000))
                    {
                        FloatingTextStringOnCreature ("Level Up!", oKiller);
                    }

    //========== Applying XP (oObject) ====================================
    oObject = GetFirstPC();
    while (GetIsObjectValid(oObject))
    {
        iHD2 = GetHitDice(oObject);
        iDN2 = iCR - iHD2;

        //Extra Party Penalty
        iPenal2 = ((iHD1 - iHD2) - iDN1)*10;
        if(iPenal2 <= 0) iPenal2 = 0;

        iDead = GetIsDead (oObject);
        iSameFaction = GetFactionEqual (oKiller, oObject);
        oAreaPC = GetArea(oObject);
        if ((iSameFaction == TRUE) && (iDead == FALSE) && (oAreaPC == oArea) && (oObject != oKiller))
        {
            //Set the XP Proporcion
            iXP = setXP(iDN2);

            //Set the correct penalty according the XP
            iPenal = setPP(iDN2, iNumParty);

            //Set penalty if there is 5 players in party
            if(iNumParty >= 5) iXP = iXP/2;

            int iCurrentXP = GetXP(oObject);
            int iXPMax = ( (iHD2 * 1000) + (iHD2 * (iHD2 - 1) * 500) );
            if  (iCurrentXP < iXPMax)
            {
                    if (!HasSanctuary(oObject))
                    {
                        fXPPenalt = (iXP/10) * (iPenal/100.0);
                        iXPPenalt = FloatToInt(fXPPenalt); //Important conversion
                        iNewXP = (iXP - (iXPPenalt*10)) - iPenal2;

                        if(((iCurrentXP + iNewXP) >= iXPMax))
                            {
                                SetXP(oObject, (iXPMax));
                                ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(GetMaxHitPoints(oObject) - GetCurrentHitPoints(oObject)), oObject);
                                SendMessageToPC(oObject, "Level Up!");
                            } else
                        if(iNewXP <= 1)
                            {
                            iNewXP = 1;
                            SetXP(oObject, (iCurrentXP + iNewXP));
                            } else GiveXPToCreature(oObject, iNewXP);
                    }
                    else
                    {
                        FloatingTextStringOnCreature ("No XP in Sanctuary!", oObject);
                    }
            } else
            if((iCurrentXP >= iXPMax) && (iCurrentXP < 780000))
                    {
                        FloatingTextStringOnCreature ("Level Up!", oObject);
                    }
        }
    oObject = GetNextPC();
    }
}


               
               

               


                     Modifié par WhiteTiger, 16 août 2014 - 04:36 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
XP Giver - Hard Leveling
« Reply #47 on: August 13, 2014, 10:32:07 pm »


               

havent studied very deeply, but a small suggestion - learn to use and exploit "switch" statement


 


see this


 


int setXP(int iDN)
{
if (iDN >= 05) return 380; // 350, 340, 330, 320
if (iDN == 04) return 330; // 300, 290, 280, 270
if (iDN == 03) return 270; // 250, 240, 230, 220
if (iDN == 02) return 220; // 200, 190, 180, 170
if (iDN == 01) return 160; // 150, 140, 130, 120
if (iDN == 00) return 110; // 100, 090, 080, 070
if (iDN == -1) return 60; // 060, 050, 050, 040
if (iDN == -2) return 50; // 050, 040, 040, 030
if (iDN == -3) return 40; // 040, 040, 030
if (iDN == -4) return 20; // 020, 020, 020

return 1;
}


 


to


 


int setXP(int iDN)
{


 switch(iDN)


 {


 case 5: return 380;


 case 4: return 330;


 case 3: return 270;


 case 2: return 220;


 case 1: return 160;


 case 0: return 110;


 case -1: return 60;

 case -2: return 50;


 case -3: return 40;


 case -4: return 20;


 }
return 1;
}


 


especially useable it is if you would need to declare a variable like this


 


int n = GetLocalInt(something);


if(n == 2)


if(n == 6)


 


vs


 


switch(GetLocalInt(something))


{


 case 2:


 case 6:


}


 


More here.


 


EDIT: not saying your way is wrong, just offering an alternative and sometimes better way to do this.



               
               

               


                     Modifié par Shadooow, 13 août 2014 - 09:32 .
                     
                  


            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
XP Giver - Hard Leveling
« Reply #48 on: August 13, 2014, 10:41:26 pm »


               


int setXP(int iDN)


{


 switch(iDN)


 {


 case 5: return 380;


 case 4: return 330;


 case 3: return 270;


 case 2: return 220;


 case 1: return 160;


 case 0: return 110;


 case -1: return 60;

 case -2: return 50;


 case -3: return 40;


 case -4: return 20;


 }

return 1;

}




 


Good, haha... 


I have visited the link. And the default statement in switch? 


Is possible to set cases >4 = 380?  '<img'>



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
XP Giver - Hard Leveling
« Reply #49 on: August 13, 2014, 11:01:43 pm »


               


Good, haha... 


I have visited the link. And the default statement in switch? 


Is possible to set cases >4 = 380?  '<img'>




not directly but yes usign the default statement


basically you cover all other cases such as 0 1 2 3 (or negatives)


then the default is everything else than these cases which should be 4 5 6 7 and more


               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
XP Giver - Hard Leveling
« Reply #50 on: August 13, 2014, 11:09:36 pm »


               


not directly but yes usign the default statement


basically you cover all other cases such as 0 1 2 3 (or negatives)


then the default is everything else than these cases which should be 4 5 6 7 and more




 


I use return 1 to negatives cases <= 5 and 380 to positive cases >= 5. I have not thought of all possible chances, because I need the maximum value of CR (Challenge Rating) to calculate this 


               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
XP Giver - Hard Leveling
« Reply #51 on: August 13, 2014, 11:23:49 pm »


               

yea in this case, switch is not very effective