09 Oct, 2013, Grieffels wrote in the 1st comment:
Votes: 0
I think I should post this here, but im not sure. If I am wrong, please excuse me and let me know. I won't make the same mistake twice.
First off, i've added in professions to my game and have given them 200 levels to be gained. I used the ROM gain_exp function and modified
it to fit what I needed. It's now going into the (-) exp and not gaining levels correctly. In my score sheet I have TNL setup as:
(ch->level + 1) * prof_tnl(ch) - ch->profexp[0]. I basically want this setup to be 2000 a level, every level for the professions. Can anyone
tell me where im going wrong with this?

the profession.c file looks like this:

void gain_profexp args( ( CHAR_DATA *ch, int prof_gain ) ); // Used as gain_profexp (ch,Xamount);
void gain_profexptwo args( ( CHAR_DATA *ch, int prof_gain ) ); // Used as gain_profexptwo (ch, Xamount);

// Profession [0]
void gain_profexp( CHAR_DATA *ch, int prof_gain )

if (ch->proflevel[0] >= MAX_PROF_LEVEL)

ch->profexp[0] = UMAX( prof_tnl(ch), ch->profexp[0] + prof_gain );

while ( ch->proflevel[0] < MAX_PROF_LEVEL && ch->profexp[0] >= prof_tnl(ch) * (ch->proflevel[0] + 1))
send_to_char( "You raise a level in your primary profession!", ch );
ch->proflevel[0] += 1;
sprintf(buf,"%s gained level %d",ch->name,ch->proflevel[0]);
sprintf(buf,"$N has attained level %d!",ch->proflevel[0]);


int prof_tnl(CHAR_DATA *ch)
int pexpl = 2000;

if (IS_NPC(ch))
return 2000;

// pexpl = 2000;
return pexpl;
09 Oct, 2013, Nathan wrote in the 2nd comment:
Votes: 0
Just to make sure I understand what you're saying:

I'm guessing by the functions gain_profexp(…) and gain_profexptwo(…) that a player can have two professions that you have a separate function for increasing experience in each?
* As an aside, if that's true, it might make a bit more sense to have one function that increases for a specified profession so as to only have to debug one function.

prof_tnl(ch) just returns the experience to the next level for the character, which in your case is always 2000, yes?

From the very top paragraph:

"(ch->level + 1) * prof_tnl(ch) - ch->profexp[0]"

So for a character of profession level 5 (I assume that you mean the profession level there) who has exactly 10k exp, where prof_tnl(ch) is always 2000:

(5 + 1) * 2000 - 10000 == 2000
12000 - 2000 = 2000?

You'd need 2000 exp to get from level 5 to level 6 in that profession, yes?


In this bit:

character->profexp[0] = UMAX( prof_tnl(character), character->profexp[0] + prof_gain );

What exactly is being checked and assigned to the experience for the first profession?

In the code given in the post there doesn't seem to be an obvious error. Perhaps there is something wrong with the input to the function (the incoming value of prof_gain)? Assuming nothing else is going wrong, a negative experience value will never be valid in the check to see whether the experience is sufficient to gain/have gained a level.


You may want to provide example data for the exp value before going up a level (i.e. experience less than 'next level * 2000') and the exp value after going up a level. That way we can presumably see the results of the gain exp function. If you have a convenient means of debug, you might insert some output about the before and after experience values around and/or in the call to gain_profexp(…)
09 Oct, 2013, Grieffels wrote in the 3rd comment:
Votes: 0
The exp it gives is correct. I set it to give 1999 exp and gave me that. It's once it passes 2000, it turns it into going negative.

gain_profexp(ch, 1999);
Which gives the reward of exp.
09 Oct, 2013, Grieffels wrote in the 4th comment:
Votes: 0
Sorry, I tried to edit the last post but couldn't due to it being older than one hour. Basically, to sum everything up…
I want it to be 2000 per level. Level 1-100 will all cost 2000 exp to level. There are two professions, [0] and [1]. Which
can be any of the 6 professions available. The exp that is sending to the character is the correct amount. It's after it reaches 2000 that it goes negative for each it gives over. Say you have 100 exp tnl and it gives 1900, you will go negative 1800.
10 Oct, 2013, Nathan wrote in the 5th comment:
Votes: 0
Since I'm not familiar with the codebase I'm using the code on here for rom24 as a reference since your statement implied that you are using ROM or a derivative of it.

ch->profexp[0] = UMAX( prof_tnl(ch), ch->profexp[0] + prof_gain );

From merc.h:

#define UMAX(a, b)		((a) > (b) ? (a) : (b))


if( prof_tnl(ch) >  ch->profexp[0] + prof_gain ) return prof_tnl(ch) : return (ch->profexp[0] + prof_gain);

So, if the experience to the next level is greater than the current experience + gain in experience then the experience is set to 2000?
In any case, prof_tnl(ch) will only ever return 2000 that I can see. Unless I miss something this would make any experience gains at level 0 that resulted in less than 2000 exp jumping you to the first level. That seems like weird behavior and it will be irrelevant check past that point, yes?

Why not just the following:

ch->profexp[0] += prof_gain;

The pieces you post from your file 'profession.c' otherwise look fine to me. If you don't have another way to look at profession experience than 'score' (do_score(…) ?), which I take to be what you mean by "in my score sheet", maybe you should check that the calculation performed there is correct?
10 Oct, 2013, Grieffels wrote in the 6th comment:
Votes: 0
Yeah, I removed the UMAX long before the second response hoping to fix my problem.
I made it a bit further and still couldnt get why it wasnt working after I found UMAX
was show a > b etc..and the way prof_tnl(ch), etc.. was written didnt even fit that.
I finally got the rest straightened out and it was literally that one line. Even after
removing UMAX, I still for some reason was trying to do profexp[0] = prof_gain + prof_exp[0]
which was giving a print of something wrong. I'm sorry I took up your time on that and thank
you VERY much for helping me. What you through out with += prof_gain; worked like a
charm. Thanks again Nathan.