Author Topic: Trouble installing an Exp bank into module.  (Read 2304 times)

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #15 on: June 22, 2011, 11:01:06 am »


               Thank you Alex, that is good to know. I will proceed then, and report back what happens...
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #16 on: June 22, 2011, 06:39:19 pm »


               Your xp_inc should look like this:

#include "aps_include"
/*
XP Bank by uhmm TheGrimReefer, yay..
This Bank is a way for people to transfer Experience points from an old character
to a new one, so they dont have to deal with those tedious first levels.

Obviously there would be a penalty, this is represented by the Int "Penalty", go figure.

*/////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/*//////////////////////*/    int Penalty = 25;    /////////////////////////////
//The magic number, this is a percent of the XP taken that is actually stored \\\\
//in the bank. Ex, if they deposit 100 XP, only 25 XP is stored for withdraw. \\\\
////////////////////////////////////////////////////////////////////////////////
int fraction = 100/Penalty; // just a divider, to send the % to the other scripts,ignore.

// OK now, this I just threw in at the last second, if enabled, it will stop
// people from withdrawing after they reach a certain amount of XP.

int WithdrawCap = FALSE; // set as 'TRUE' if you want to stop them from withdrawing after a certain lvl
int XPcap = 190000; //this is the number to have them stop at, 190k = lvl 20
string slvlcap = "I am sorry, but you currently have too many experience points for me to help you.";
// and that's the happy message you tell them. ^^
/////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/*
//
//
//
*/
// These next lines just prevents ppl from dumping thier XP if thier below a designated lvl
// I believe there is a reason I did those, aside from making slackers hit lvl 10 or so,
// but you can probly jut set it to 1, and it'll turn this feature off
int lvl = 10; // meaning u have to be lvl 10 or higher to dump ALL your XP into bank.
string slvl = IntToString(lvl);
string sNO = "Sorry, but you need to be at least level "+slvl+" to deposit all your experience.";


Kato
               
               

               


                     Modifié par Kato_Yang, 22 juin 2011 - 05:54 .
                     
                  


            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #17 on: June 24, 2011, 07:20:06 am »


               Ok, sorry about the delay Kato, had to spend some time with a lady friend, and then been getting bogged down with just trying to get the module up and functioning correctly prior to making major customizations.

So I have followed you up to the point of swaping out the campaign integers. When I do that I get the error:
6/24/2011 1:16:43 AM: Error. 'xp_deposit_100k' did not compile.
xp_deposit_100k.nss(11): ERROR: DECLARATION DOES NOT MATCH PARAMETERS

pointing to line 11 which I have as:
int fXP = GetPersistentInt( "XP", sCDKey) + DepositXP;

Just so you can see if I set this up as per your example here is one of the scripts that is throwing this error:
#include "xp_inc"
void main()
{
object oPC =GetPCSpeaker();
 if (GetHitDice(oPC) >= 20)
  {
  int DepositXP = 100000/fraction;
  string sDepositXP = IntToString(DepositXP);
  string sCDKey = GetPCPublicCDKey( oPC);
  int fXP = GetPersistentInt( "XP", sCDKey) + DepositXP;
  int XP = GetXP(oPC) - 100000;
   SetPersistentInt( "XP", sCDKey, fXP);
   SetXP(oPC, XP);
   SpeakString ("You have deposited "+ sDepositXP +" XP.");
  }
else
   {
    SpeakString ("Sorry, but you need to be at least level 40 to use this feature.");
   }
}

So, I have the error, but not sure what to do about it.
Laz
P.S. I did change it from level 10 to level 40 in the xp_inc script in case you were wondering why it says lvl 40.
               
               

               


                     Modifié par Lazarus Magni, 24 juin 2011 - 06:22 .
                     
                  


            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #18 on: June 24, 2011, 07:41:32 am »


               Take a look at the example a few posts above this one, it's exactly with the same function you just posted. If you follow the instructions given with the example for all the scripts wich call database functions in your system, you should have no trouble.

Kato
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #19 on: June 24, 2011, 07:53:38 am »


               So your saying just ignore the error?

Edit:
Well I tried this (testing locally, but connected to a MySQL database), but now it is removing exp, and not saving it apparently. When I had tried it previously just using it out of the package so to speak, it actually worked fine, except for the fact that when I would go to withdraw exp, I could keep withdrawing it beyond what I had stored in the bank. So now I am really confused.... Seems like we have made some progress but still not quite working right.
               
               

               


                     Modifié par Lazarus Magni, 24 juin 2011 - 07:21 .
                     
                  


            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #20 on: June 24, 2011, 09:00:29 am »


               So alternatively to this whole system mentioned above, something Ghost said gave me an idea. I looked at the scripts for our persistant gold bank, and our releveler. I am wondering if I can use them modified to just make new exp bank scripts? As an example, some of the gold scripts are:

#include "aps_include"

// Used to deposit gold in the bank. oPC is the character depositing gold
// and iGold is the amount to deposit
void DepositGold(object oPC, int iGold);

// Used to withdraw gold from the bank. oPC is the character withdrawing gold
// and iGold is the amount to withdraw
void WithdrawGold(object oPC, int iGold);

// Returns the amount of gold the player has in the bank
int GetBankGold(object oPC);

void DepositGold(object oPC, int iGold)
{
int iMaxGold = 200000000; //Maximum gold that can be stored in the bank
int iBankGold;
string sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oPC));
string sSQL = "SELECT gold FROM bankvault WHERE player='" + sPlayer + "'";
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_SUCCESS)
{
iBankGold = StringToInt(SQLGetData(1));
if ((iBankGold + iGold) > iMaxGold)
{
iGold = iMaxGold - iBankGold;
SendMessageToPC(oPC, "The maximum amount of gold you can store is "
+ IntToString(iMaxGold));
}
sSQL = "UPDATE bankvault SET gold=" + IntToString(iBankGold + iGold)
+ " WHERE player='" + sPlayer + "'";
SQLExecDirect(sSQL);
TakeGoldFromCreature(iGold, oPC, TRUE);
}
else
{
if (iGold > iMaxGold)
{
iGold = iMaxGold;
SendMessageToPC(oPC, "The maximum amount of gold you can store is "
+ IntToString(iMaxGold));
}
sSQL = "INSERT INTO bankvault (player,gold) VALUES ('" + sPlayer + "',"
+ IntToString(iGold) + ")";
SQLExecDirect(sSQL);
TakeGoldFromCreature(iGold, oPC, TRUE);
}
}

int GetBankGold(object oPC)
{
int iBankGold = 0;
string sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oPC));
string sSQL = "SELECT gold FROM bankvault WHERE player='" + sPlayer + "'";
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_SUCCESS)
{
iBankGold = StringToInt(SQLGetData(1));
}
else
{
sSQL = "INSERT INTO bankvault (player,gold) VALUES ('" + sPlayer + "',0)";
SQLExecDirect(sSQL);
}
return iBankGold;
}

void WithdrawGold(object oPC, int iGold)
{
int iBankGold = GetBankGold(oPC);
string sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oPC));
string sSQL = "UPDATE bankvault SET gold=" + IntToString(iBankGold - iGold)
+ " WHERE player='" + sPlayer + "'";
SQLExecDirect(sSQL);
GiveGoldToCreature(oPC, iGold);
}

and than an example of a deposit amount script:

#include "jk_inc_bank"

void main()
{
object oPC = GetPCSpeaker();
int iGold = 10000;
DepositGold(oPC, iGold);
ExportSingleCharacter(oPC);
}

And also in case any sort of interger information, and translation (gp to xp) might be needed here is an example of one of the releveler scripts:
#include "conf_module"

void main( )
{
object oPC = GetPCSpeaker( );

int nXP = GetXP( oPC );
int nXPAfter = FloatToInt(IntToFloat(nXP) * IntToFloat(RELEVEL_XP_PENALTY) / 100.00);
SetXP( oPC, 10000 );
SetXP( oPC, nXPAfter );
}
               
               

               


                     Modifié par Lazarus Magni, 24 juin 2011 - 08:02 .
                     
                  


            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #21 on: June 24, 2011, 09:45:11 am »


               Specifically what I am thinking is something along these lines:
#include "aps_include"

// Used to deposit Experience in the bank. oPC is the character depositing gold
// and iXP is the amount to deposit
void DepositGold(object oPC, int iXP);

// Used to withdraw Experience from the bank. oPC is the character withdrawing gold
// and iXP is the amount to withdraw
void WithdrawGold(object oPC, int iXP);

// Returns the amount of Experience the player has in the bank
int GetBankXP(object oPC);

void DepositXP(object oPC, int iXP)
{
int iMaxXP = 200000000; //Maximum Experience that can be stored in the bank
int iBankXP;
string sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oPC));
string sSQL = "SELECT Experience FROM bankvault WHERE player='" + sPlayer + "'";
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_SUCCESS)
{
iBankXP = StringToInt(SQLGetData(1));
if ((iBankXP + iXP) > iMaxXP)
{
iXP = iMaxXP - iBankXP;
SendMessageToPC(oPC, "The maximum amount of Experience you can store is "
+ IntToString(iMaxXP));
}
sSQL = "UPDATE bankvault SET Experience=" + IntToString(iBankXP + iXP)
+ " WHERE player='" + sPlayer + "'";
SQLExecDirect(sSQL);
TakeExperienceFromCreature(iXP, oPC, TRUE);
}
else
{
if (iXP > iMaxXP)
{
iXP = iMaxXP;
SendMessageToPC(oPC, "The maximum amount of Experience you can store is "
+ IntToString(iMaxXP));
}
sSQL = "INSERT INTO bankvault (player,Experience) VALUES ('" + sPlayer + "',"
+ IntToString(iXP) + ")";
SQLExecDirect(sSQL);
TakeExperienceFromCreature(iXP, oPC, TRUE);
}
}

int GetBankXP(object oPC)
{
int iBankXP = 0;
string sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oPC));
string sSQL = "SELECT Experience FROM bankvault WHERE player='" + sPlayer + "'";
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_SUCCESS)
{
iBankXP = StringToInt(SQLGetData(1));
}
else
{
sSQL = "INSERT INTO bankvault (player,Experience) VALUES ('" + sPlayer + "',0)";
SQLExecDirect(sSQL);
}
return iBankXP;
}

void WithdrawExperience(object oPC, int iXP)
{
int iBankExperience = GetBankExperience(oPC);
string sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oPC));
string sSQL = "UPDATE bankvault SET Experience=" + IntToString(iBankXP - iXO)
+ " WHERE player='" + sPlayer + "'";
SQLExecDirect(sSQL);
GiveExperienceToCreature(oPC, iXP);
}

Except I do that I get the error message:
6/24/2011 3:38:59 AM: Error. 'laz_inc_xpbank' did not compile.
laz_inc_xpbank.nss(33): ERROR: UNDEFINED IDENTIFIER (TakeExperienceFromCreature)

So perhaps using some of the integers from the releveler scripts like:
int nXP = GetXP( oPC );
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #22 on: June 24, 2011, 05:50:02 pm »


               Now that's a different system... Not a problem, but I'll pm/email you instead of continuing online, I would not want to overload the forums.

Kato
               
               

               


                     Modifié par Kato_Yang, 24 juin 2011 - 04:51 .
                     
                  


            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #23 on: June 24, 2011, 08:06:53 pm »


               Sounds good Kato. I merely presented that as a possible alternative if I can't get the vault one to work with my mod. Honestly whichever is easiest to implement would be my preferance since I have a ton of other stuff I am trying to work on too.