Author Topic: Force Level up in PC  (Read 451 times)

Legacy_Eva_hop

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +0/-0
Force Level up in PC
« on: October 20, 2010, 11:20:54 pm »


               Hey all,

sorry if this has been asked before, but the search engine isn't working for me.
I was trying to make it so that in conversation you could choose to level up. Nothing complicated.
It seems there is no effect 'lvl up', so i would have to reward a different amount of xp varying on what level the PC is. How do I script this??
I can't seem to figure it out, also with using Lilac Soul's script generator.
Then again, I'm a total noob so...

Thanks very much for any help.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Force Level up in PC
« Reply #1 on: October 20, 2010, 11:53:19 pm »


               Here ya go:

void main()
{
object oPC = GetPCSpeaker();
int iLevel = GetHitDice(oPC);
int iXP = ((iLevel * (iLevel + 1)) / 2) * 1000;
SetXP(oPC, iXP);
}
               
               

               


                     Modifié par GhostOfGod, 21 octobre 2010 - 02:32 .
                     
                  


            

Legacy_Eva_hop

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +0/-0
Force Level up in PC
« Reply #2 on: October 21, 2010, 08:40:51 pm »


               Awesome! Thanks very much!
               
               

               
            

Legacy_AgedAlchemist

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Force Level up in PC
« Reply #3 on: October 24, 2010, 12:40:07 am »


               Using GetHitDice() without a check against the Player's current XP can result in the LOSS of XP, not gaining a level, if they have not completed the LevelUp process. 
That's not a concern when you use the Player's XP to determine their current level ...
void main()
{
object oPC = GetPCSpeaker();
int nLevel = FloatToInt(0.5 + sqrt(0.25 + IntToFloat(GetXP(oPC)) / 500));
SetXP(oPC, nLevel * (nLevel + 1) * 500);
}
               
               

               
            

Legacy_AgedAlchemist

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Force Level up in PC
« Reply #4 on: October 24, 2010, 12:40:56 am »


               Sorry, I duplicated the above.
               
               

               


                     Modifié par AgedAlchemist, 23 octobre 2010 - 11:48 .
                     
                  


            

Legacy_AgedAlchemist

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Force Level up in PC
« Reply #5 on: October 24, 2010, 12:45:37 am »


               How do I delete a duplicate post?
               
               

               


                     Modifié par AgedAlchemist, 23 octobre 2010 - 11:48 .
                     
                  


            

Legacy_Eva_hop

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +0/-0
Force Level up in PC
« Reply #6 on: October 24, 2010, 05:35:40 pm »


               I tested your script and what it does is test the amount of XP already owned by the PC and then add the recquired to level up. So this means that the amount of XP the PC already had is lost. This is not the case with GhostofGod's script, which allows the PC to keep the amount of XP already had, which is fine in the case of my module.

Thanks anyway this gives me more insight into nwn scripting!

               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Force Level up in PC
« Reply #7 on: October 25, 2010, 09:41:15 am »


               AgedAlchemist does bring up a good point though. I didn't figure in for players who still need to level and have more xp than required for leveling. If they trigger the above script it does in fact take the xp away.

However AgedAlchemists approach is slightly flawed as well. If someone is able to level their character and they repeatedly fire his script, they will keep getting 1,000 xp.

So a solution to both problems might be to do something like so:

void main()
{
object oPC = GetPCSpeaker();
int iLevel = GetHitDice(oPC);
int iXP = ((iLevel * (iLevel + 1)) / 2) * 1000;
if (iXP < GetXP(oPC))
SendMessageToPC(oPC, "You must first level up your character.");
else SetXP(oPC, iXP);
}

I think I thought it our right. ':whistle:'
               
               

               


                     Modifié par GhostOfGod, 25 octobre 2010 - 08:43 .
                     
                  


            

Legacy_Eva_hop

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +0/-0
Force Level up in PC
« Reply #8 on: October 25, 2010, 04:07:40 pm »


               I'm not exactly sure now anymore what the problem was with the first script? I tested it and it seemed to work fine. The PC wasn't getting anymore XP if he didn't levelup first...



I don't see how XP is 'lost'. Maybe you could explain that to me?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Force Level up in PC
« Reply #9 on: October 25, 2010, 04:18:09 pm »


               Example.   A pc is 1st level (has never leveled up) But has 3500Xp(this is enough xp for the pc to be level 3, If he would just level up,)  If the first script ran it would check his HD and find it to be level 1. Then it would calculate how much xp he needs to be level 2 (1000 xp) and set his xp to that amount.   The PC would have just went from having 3500xp to only having 1000xp. Loseing 1500xp because for some reason he did not want to level up when he was able to.
               
               

               
            

Legacy_Eva_hop

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +0/-0
Force Level up in PC
« Reply #10 on: October 25, 2010, 07:42:47 pm »


               Ah I see! Thanks for the explanation!