Jump to content

Home

[Scripting]: Setting A Specific Level? (XP points)


ChAiNz.2da

Recommended Posts

Greets all, yet another scripting question... ;)

 

Is there a way to award a PC/NPC a set Experience Level? or set the current amount of XP to a specific number? Not the amount awarded, but the actual total amount of XP a PC/NPC currently has... (or will have)

 

What I'd like to do is have/make/beg for, a script that will pretty much make a PC/NPC a specific level of their choosing...

 

The GiveXPToCreature is a little too 'random' and I can't find anyway to incorporate the addlevel # console cheat via script method... :fist: I have no clue what "addlevel #" is actually calling to??

 

Any way to go about doing this? or am I out of luck :giveup:

 

These are the table numbers (TSL) I assume I'll be working off of (exptable.2da):

[u]line#  Level   xp amount[/u]
0	1	0
1	2	1000
2	3	3000
3	4	6000
4	5	10000
5	6	15000
6	7	21000
7	8	28000
8	9	36000
9	10	45000
10	11	55000
11	12	66000
12	13	78000
13	14	91000
14	15	105000
15	16	120000
16	17	136000
17	18	153000
18	19	171000
19	20	190000
20	21	210000
21	22	231000
22	23	253000
23	24	276000
24	25	300000
25	26	325000
26	27	351000
27	28	378000
28	29	406000
29	30	435000
30	31	465000
31	32	496000
32	33	528000
33	34	561000
34	35	595000
35	36	630000
36	37	666000
37	38	703000
38	39	741000
39	40	780000
40	41	820000
41	42	861000
42	43	903000
43	44	946000
44	45	990000
45	46	1035000
46	47	1081000
47	48	1128000
48	49	1176000
49	50	1225000
50	51	0xFFFFFFFF

Link to comment
Share on other sites

To set the XP to a fixed amount, you can use the following function:

// 394: Sets oCreature's experience to nXpAmount.
void SetXP(object oCreature, int nXpAmount);

 

Example:

// 394: Sets oCreature's experience to nXpAmount.
void main()
{
SetXP(GetObjectByTag ( "object_tag_goes_here"), 250000);
}

Link to comment
Share on other sites

Hey chainz.2da if you take a look at the xp table there is a rather simple formula they use. (Current level * 1000) + (Previous levels xp) So using that example say I'm level 1 (0 XP) to get to level 2 I must earn (1000 XP) or in the formula it looks like this (1 * 1000) + (0) = 1000. Now let's go to level 3 it requires 3000 XP so our formula looks like this (2 * 1000) + (1000) = 3000.

 

So now that we have that principle down I'll use a really basic programming example.

 

void main()
{
int x;
int y;
int z;

x=GetCurrentLevel;
y=GetCurrentExperiencePoints;
z=(x * 1000) + y;
}

 

Now as I said this is Pseudo-code and not an actual script. I know there are scripting functions similiar to the one's I used in the example above but may be named slightly differently.

Link to comment
Share on other sites

What I'd like to do is have/make/beg for, a script that will pretty much make a PC/NPC a specific level of their choosing...

 

Here is a function from my utility include I've made for that purpose, perhaps it can be useful as an example:

 

void ST_SetExpForLevel(int nLevel, object oTarget=OBJECT_SELF) {
SetXP(oTarget, nLevel * (nLevel - 1) * 500);
}

 

Set the first parameter to the character level that should be reached, and optionally oTarget to who should have their exp changed.

Link to comment
Share on other sites

Here is a function from my utility include I've made for that purpose, perhaps it can be useful as an example:

 

void ST_SetExpForLevel(int nLevel, object oTarget=OBJECT_SELF) {
SetXP(oTarget, nLevel * (nLevel - 1) * 500);
}

 

Set the first parameter to the character level that should be reached, and optionally oTarget to who should have their exp changed.

well that sure simplifies the 'monster' of a script I just made... doh! hehehe...

 

I'd definitley want to keep the oTarget=OBJECT_SELF, but when you say set the parameter (P1), does that mean it will automatically search/use the exptable.2da line entries? Or do I need to define those?

 

Thanks stoffe! :D

 

this is my "beast code" I had done, but if you say that your script above would simplify this, I'd much rather use yours (with permission of course). And please excuse my clumsy & primitive attempts at scripting, I'm still learning.. hehehe :blush2:

 

However, I have to thank mrdefender. I really like how you laid out your scrips, very clean. Hope you don't mind me 'adopting' the format. Nice work! :D

 

void main ()
{
int nAmount = GetScriptParameter ( 1 );
{
 if ( nAmount == 1  ) { SetXP (OBJECT_SELF, 1       ); }
 if ( nAmount == 2  ) { SetXP (OBJECT_SELF, 1001    ); }
 if ( nAmount == 3  ) { SetXP (OBJECT_SELF, 3001    ); }
 if ( nAmount == 4  ) { SetXP (OBJECT_SELF, 6001    ); }
 if ( nAmount == 5  ) { SetXP (OBJECT_SELF, 10001   ); }
 if ( nAmount == 6  ) { SetXP (OBJECT_SELF, 15001   ); }
 if ( nAmount == 7  ) { SetXP (OBJECT_SELF, 21001   ); }
 if ( nAmount == 8  ) { SetXP (OBJECT_SELF, 28001   ); }
 if ( nAmount == 9  ) { SetXP (OBJECT_SELF, 36001   ); }
 if ( nAmount == 10 ) { SetXP (OBJECT_SELF, 45001   ); }
 if ( nAmount == 11 ) { SetXP (OBJECT_SELF, 55001   ); }
 if ( nAmount == 12 ) { SetXP (OBJECT_SELF, 66001   ); }
 if ( nAmount == 13 ) { SetXP (OBJECT_SELF, 78001   ); }
 if ( nAmount == 14 ) { SetXP (OBJECT_SELF, 91001   ); }
 if ( nAmount == 15 ) { SetXP (OBJECT_SELF, 105001  ); }
 if ( nAmount == 16 ) { SetXP (OBJECT_SELF, 120001  ); }
 if ( nAmount == 17 ) { SetXP (OBJECT_SELF, 136001  ); }
 if ( nAmount == 18 ) { SetXP (OBJECT_SELF, 153001  ); }
 if ( nAmount == 19 ) { SetXP (OBJECT_SELF, 171001  ); }
 if ( nAmount == 20 ) { SetXP (OBJECT_SELF, 190001  ); }
 if ( nAmount == 21 ) { SetXP (OBJECT_SELF, 210001  ); }
 if ( nAmount == 22 ) { SetXP (OBJECT_SELF, 231001  ); }
 if ( nAmount == 23 ) { SetXP (OBJECT_SELF, 253001  ); }
 if ( nAmount == 24 ) { SetXP (OBJECT_SELF, 276001  ); }
 if ( nAmount == 25 ) { SetXP (OBJECT_SELF, 300001  ); }
 if ( nAmount == 26 ) { SetXP (OBJECT_SELF, 325001  ); }
 if ( nAmount == 27 ) { SetXP (OBJECT_SELF, 351001  ); }
 if ( nAmount == 28 ) { SetXP (OBJECT_SELF, 378001  ); }
 if ( nAmount == 29 ) { SetXP (OBJECT_SELF, 406001  ); }
 if ( nAmount == 30 ) { SetXP (OBJECT_SELF, 435001  ); }
 if ( nAmount == 31 ) { SetXP (OBJECT_SELF, 465001  ); }
 if ( nAmount == 32 ) { SetXP (OBJECT_SELF, 496001  ); }
 if ( nAmount == 33 ) { SetXP (OBJECT_SELF, 528001  ); }
 if ( nAmount == 34 ) { SetXP (OBJECT_SELF, 561001  ); }
 if ( nAmount == 35 ) { SetXP (OBJECT_SELF, 595001  ); }
 if ( nAmount == 36 ) { SetXP (OBJECT_SELF, 630001  ); }
 if ( nAmount == 37 ) { SetXP (OBJECT_SELF, 666001  ); }
 if ( nAmount == 38 ) { SetXP (OBJECT_SELF, 703001  ); }
 if ( nAmount == 39 ) { SetXP (OBJECT_SELF, 741001  ); }
 if ( nAmount == 40 ) { SetXP (OBJECT_SELF, 780001  ); }
 if ( nAmount == 41 ) { SetXP (OBJECT_SELF, 820001  ); }
 if ( nAmount == 42 ) { SetXP (OBJECT_SELF, 861001  ); }
 if ( nAmount == 43 ) { SetXP (OBJECT_SELF, 903001  ); }
 if ( nAmount == 44 ) { SetXP (OBJECT_SELF, 990001  ); }
 if ( nAmount == 46 ) { SetXP (OBJECT_SELF, 1035001 ); }
 if ( nAmount == 47 ) { SetXP (OBJECT_SELF, 1081001 ); }
 if ( nAmount == 48 ) { SetXP (OBJECT_SELF, 1128001 ); }
 if ( nAmount == 49 ) { SetXP (OBJECT_SELF, 1176001 ); }
 if ( nAmount == 50 ) { SetXP (OBJECT_SELF, 1225001 ); }
}
} 

Link to comment
Share on other sites

I'd definitley want to keep the oTarget=OBJECT_SELF, but when you say set the parameter (P1), does that mean it will automatically search/use the exptable.2da line entries? Or do I need to define those?

(snip)

 

It was just a generic utility function usable by other scripts. If you want a complete script specifically for use as an action script in a dialog, this variant should work (I hope... untested since I just wrote it :) ):

 

void main() {
   int nLevel = GetScriptParameter(1);
   string sTag = GetScriptStringParameter();
   object oTarget = (sTag == "" ?  OBJECT_SELF : GetObjectByTag(sTag));

   SetXP(oTarget, nLevel * (nLevel - 1) * 500);
}

 

Set P1 to the level you want the creature to get enough Experience to reach. Leave the String Param blank if you want the creature running the script to get the Exp, or set it to the tag of the creature if you want to change the exp of another.

 

It doesn't look up anything in exptable.2da (since the 2DA lookup functions aren't present in KotOR's version of NWScript). It calculates the corresponding amount of exp needed instead, since the standard exptable.2da progression can be boiled down to a rather simple formula.

Link to comment
Share on other sites

Thanks stoffe! I'll give it a try and let you know how things go :D

 

If worse comes to worse (heaven forbid) my beast code worked. But I'd much rather have a nice 'tight' script rather than my "horse" of a one... :xp: hehehe...

 

Luckily, the way it's written, I won't have to change any P1 values *whew*

 

------------

 

@General Kenobi

Time will tell my friend ;)

 

It's ALIVE! It's ALIVE! ...The script works perfectly stoffe :D Thank You! :emodanc:

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...