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

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« on: June 19, 2011, 10:43:10 am »


               Disclaimer: I am not sure where the best place to post this is since there is no Dev forum, but seeing as a bunch of scripts are involved I thought I would try here.

I am trying to install an XP Bank by TheGrimReefer from the vault into a module.
http://nwvault.ign.c....Detail&id=2866

I am able to get it to work, however when I go to withdraw exp, I can continue to do so beyond what I have deposited into the bank.

In the script description it says this was intended for "standard bioware DB calls" however the module is using MySQL. Anyone know if this is the problem, and how to fix it?
               
               

               


                     Modifié par Lazarus Magni, 19 juin 2011 - 10:44 .
                     
                  


            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #1 on: June 20, 2011, 08:57:17 pm »


               The system uses BioWare DB calls, indeed. MySQL usually(sorry if there are other ways I don't know of) interacts with NWN via NWNX-ODBC. If this is already set, then you simply have to replace some function calls, in order to properly interact with MySQL. For instance, SetCampaignInt can be replaced by SetPersistentInt, and so on. You'll find the functions you need for MySQL in the script "aps_include". I'll be happy to help you with the "conversion" if you need.

Kato
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #2 on: June 21, 2011, 04:13:38 am »


               Hi Kato, thanks for the response. I certainly would welcome your help.
               
               

               
            

Legacy_Lazarus Magni

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


               Ok so I just opened the fist of those scripts and I replaced SetCampaignIn  with SetPersistentInt. I then saved and complied, and got this error message:

6/20/2011 10:53:42 PM: Error. 'xp_deposit_1000k' did not compile.
xp_deposit_1000k.nss(13): ERROR: UNDEFINED IDENTIFIER (SetPersistentInt)

I am assuming that means it is not working?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #4 on: June 21, 2011, 05:03:16 am »


               The script from NWNX called "aps_include" needs to be in your module. Then in your script, just above the void main(), put the line: #include "aps_include"

Also be aware that the SetPersistentInt function has different parameters. Instead of a string for a database name you will need to put in some object.

This is an example of a gold deposit script. It might give you and idea. You can use the player character as the object as well. I just didn't cause I want all characters the player uses to have access to the same gold.


///////////////////////
//Deposit 1,000 gold.//
///////////////////////
#include "aps_include"
void main()
{
object oPC = GetPCSpeaker();
object oBankDBObject = GetNearestObjectByTag("BANK_DB_OBJECT", oPC);
int nDeposit = 1000;
string sCDKey = GetPCPublicCDKey(oPC);
//int nBalance = GetCampaignInt("AURYN_BANK", sCDKey);
int nBalance = GetPersistentInt(oBankDBObject, sCDKey, "pwdata");
int nAmount = (nDeposit + nBalance);
int nGold = GetGold(oPC);

if (nGold >= 1000)
    {
    TakeGoldFromCreature(nDeposit, oPC, TRUE);
    //SetCampaignInt("AURYN_BANK", sCDKey, nAmount, oPC);
    SetPersistentInt(oBankDBObject, sCDKey, nAmount, 0, "pwdata");
    SpeakString("Thank You.", TALKVOLUME_TALK);
    }
else
    {
    SpeakString("I'm sorry but you do not have enought gold to deposit that amount.");
    }
}
               
               

               


                     Modifié par GhostOfGod, 21 juin 2011 - 04:11 .
                     
                  


            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #5 on: June 21, 2011, 05:44:12 am »


               Hi Ghost, thanks for the respons.
I do have aps_include in the module. By in your script I assume you mean all the scripts that the bank erf added? (there were a dozen or so) I will try and add #include "aps_include" to each, and see what happens. I assume I also change GetCampaignInt to SetPersistentInt as Kato mentioned?

On the first one I tried this with I am still getting this compile error:
6/20/2011 11:46:37 PM: Error. 'xp_deposit_1000k' did not compile.
xp_deposit_1000k.nss(12): ERROR: DECLARATION DOES NOT MATCH PARAMETERS

I am not sure what you mean by this "Instead of a string for a database name you will need to put in some object."? Can you explain that a bit?
               
               

               


                     Modifié par Lazarus Magni, 21 juin 2011 - 04:47 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #6 on: June 21, 2011, 06:00:56 am »


               If you take a look at the script I posted above you will see that I was also useing GetCampaignInt but then commented it out and replaced it with GetPersistentInt(I also did the same thing with the SetPersistentInt).

//int nBalance = GetCampaignInt("AURYN_BANK", sCDKey);
int nBalance = GetPersistentInt(oBankDBObject, sCDKey, "pwdata");

The parameters for these two functions are not the same. In the standard GetCampaignInt function. the first parameter requires that you entet a string for the database name. In the case above my database name was "AURYN_BANK".
Now with the NWNX function, GetPersitentInt, the first parameter is not asking for a string for a database name. It is asking for the object that the persistent int is stored on. You will need to define your object and then pass that into the first parameter. The other parameters in the Get/SetPersistent functions are also different . Except for the second one, variable name.
               
               

               
            

Legacy_Lazarus Magni

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


               Honestly you have totally lost me. Really I am not a scripter at all. I just make sad attempts at tweaking them out of neccesity when the need arises.

As you can see above I replaced GetCampaignInt with SetPersistentInt when it prolly should have been GetPersistentInt? I will try that now, however I don't really understand "It is asking for the object that the persistent int is stored on. You will need to define your object and then pass that into the first parameter."?
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #8 on: June 21, 2011, 11:10:33 am »


               Okay. First, you need to put the line: #include "aps_include" in 3 of the system's scripts, at the very beginning of the script: xp_inc, xp_sc_10k and xp_sc_50k. The rest of the scripts include xp_inc, so you don't need to add the line to them.

Next, as mentioned by GhostOfGod, you must of course pass the correct parameters to the aps_include functions. In all the system's scripts where either GetCampaignInt or SetCampaignInt is called, the object "tied" to the bank account is retrieved with GetPCSpeaker() and named oPC. This is the object you need to pass to GetPersistentInt and SetPersistentInt. Next comes the name of the variable you wish to store or retrieve, wich is the second parameter of the aforementioned functions. In the system you're using, this parameter is the cd key of oPC, retrieved with GetPCPublicCDKey(), and named sCDKey. Next comes the value(or banked xp) you want to set in SetPersistentInt() followed by the table name. So, the infos you need to pass to the new functions are already present in the system you're using, you only need to pass them in a different order in the new function calls.

For instance, let's say you want to "update" the script: xp_deposit_100k.

#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 = GetCampaignInt( "XP", sCDKey) + DepositXP;
 int XP = GetXP(oPC) - 100000;
  SetCampaignInt( "XP", sCDKey, fXP);
  SetXP(oPC, XP);
  SpeakString ("You have deposited "+ sDepositXP +" XP.");
 }
else
  {
   SpeakString ("Sorry, but you need to be at least level 20 to use this feature.");
  }
}


Would become:


#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(oPC, sCDKey) + DepositXP;
 int XP = GetXP(oPC) - 100000;
  SetPersistentInt(oPC, sCDKey, fXP);
  SetXP(oPC, XP);
  SpeakString ("You have deposited "+ sDepositXP +" XP.");
 }
else
  {
   SpeakString ("Sorry, but you need to be at least level 20 to use this feature.");
  }
}

This is taken from one of the system's scripts, for informational purposes, I'm not saying that the code is debugged and secure, it's only "converted" to use aps_include, with the aforementioned functions.

Using MySQL offers you a great deal of flexibility and speed, so you might want to eventually create your own table(s) and write some SQL queries, or even simply test your current queries, so I would advise you use MySQL Query Browser, a very simple and free tool wich will allow you to do all this and more.

Finally, I'm currently using several banking systems in my PW(xp, gold, objects), all custom and under MySQL, so I'd be happy to share some code snippets with you, yet I would not want to disrespect the builder of your current system...

Good luck!

Kato
               
               

               


                     Modifié par Kato_Yang, 24 juin 2011 - 06:40 .
                     
                  


            

Legacy_Lazarus Magni

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


               Hi Kato,
Ok first of all, when I go to add #include "aps_include" at the beginning of those scripts I get the error message:
There was no "void main ()" function in the script.
Would you like to compile the script as a conditional script instead?
And I get 2 options yes or no... Not sure which to choose... Or if I should go back and put in the line void main () at the beginning?

I will start working my way through the rest of your instructions once I get past this first one...

I have MySQL workbench, and also downloaded that stand alone program you mentioned, but I think that will be down the road, before I get into any of that.

The module does already have a persistant banking system for gold and items, using MySQL. I would not worry about disrespecting anyone, as the mod was released on the vault a year and a half ago or more, when the first host shut down, for anyone to do with as they please, and the version I have now after the most recent host shut down a week and a half ago or so, has received another years worth of development of which I was a big part of (I think I did more work on it than anyone other than the host, and a previous dev who stoped working on it in December), so I feel quite justified continuing to work on it, and also am at this point the only person developing my version of it, however I am hoping to put a team together, but would hope they could all worth together. It also has community development as a part of it's legacy, which is an aspect I am hoping to continue. There is someone else who has picked up hosting this same mod base now (as of a week ago), however he has made it clear I am not welcome to continue working on it with him at the helm, and that my vision for it is not what he wants, which is why I am persuing my own path with it now, and hoping others will join me along the way who like the direction I am taking it.
               
               

               


                     Modifié par Lazarus Magni, 22 juin 2011 - 01:34 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #10 on: June 22, 2011, 02:47:26 am »


               My advice which is a bit contradictory to what Kato suggested. Do not put the #include "aps_include" line at the top of those three system scripts and only add that line to the top other the other script like "xp_deposit_100k". You are probably having some looping include problems. Unless you know for sure that your not doubling up on your includes somewhere it's but to keep em separated.

So keep your script the way that Kato fixed it, to work with NWNX, but add the line #include "aps_include" to the top of it as well. And keep that line off those three system scripts that Kato mentioned. See if that helps out.


#include "xp_inc"
#include "aps_include"

void main()
{
    object oPC =GetPCSpeaker();
    if (GetHitDice(oPC) >= 20)
    {
        int DepositXP = 100000/fraction;
        string sDepositXP = IntToString(DepositXP);
        string sCDKey = GetPCPublicCDKey( oPC);
        int fXP = GetPersistentInt(oPC, sCDKey) + DepositXP;
        int XP = GetXP(oPC) - 100000;
        SetPersistentInt(oPC, sCDKey, fXP);
        SetXP(oPC, XP);
        SpeakString ("You have deposited "+ sDepositXP +" XP.");
    }
    else
    {
        SpeakString ("Sorry, but you need to be at least level 20 to use this feature.");
    }
}
               
               

               


                     Modifié par GhostOfGod, 22 juin 2011 - 01:51 .
                     
                  


            

Legacy_Lazarus Magni

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


               Well that's why multiple minds are better than one, you get different perspectives and ideas. I am guessing both approaches will work (unless I get the looping problem with Kato's approach, as you suggested is possible Ghost.)

I am still not sure what to do about the current error I am receiving? If I select no, I get a message saying:

6/21/2011 9:24:20 PM: Error. 'pf_portal_util' did not compile.
pf_portal_util.nss: ERROR: NO FUNCTION MAIN() IN SCRIPT

If I select yes I get a message saying:
6/21/2011 9:25:16 PM: Error. 'pf_portal_util' did not compile.
pf_portal_util.nss: ERROR: NO FUNCTION STARTINGCONDITIONAL() IN SCRIPT

Edit:
Sorry that was the same error message but when compiling a different script.

The one I get for the script I posted above is:
6/21/2011 9:32:54 PM: Error. 'xp_deposit_1000k' did not compile.
xp_deposit_1000k.nss(12): ERROR: DECLARATION DOES NOT MATCH PARAMETERS

But I can't remember if I chose yes or no '<img'>  (*looks foolish*)
               
               

               


                     Modifié par Lazarus Magni, 22 juin 2011 - 02:35 .
                     
                  


            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #12 on: June 22, 2011, 03:41:21 am »


               Okay let's clarify things a bit. I mentioned 3 scripts:
xp_inc: The main include. Included by all system scripts except the two listed below. Includes nothing, no aps_include function calls.
xp_sc_10k: Includes nothing, calls aps_include function.
xp_sc_50k: Includes nothing, calls aps_include function.
All other scripts: Include xp_inc, call aps_include functions.

So we can see that the two scripts including nothing could not possibly call functions from aps_include without including it. Moreover, since all other scripts include xp_inc, and considering that the very few lines of code this one contains do not conflict with aps_include, it seems cleaner to simply add the include line in xp_inc instead of adding it to all the scripts. I have just tested this setup and it perfectly compiled, as expected.

Concerning the question about compiling as conditional, you should answer no, and then on the displayed script, simply press spacebar + backspace, then save your script(simply recompiling). You will get an error message, but this time the message should be explicit enough for you to know where to look in your code. If you can't fix the bugged line(or instruction), I'll do my best to help you out.

Kato
               
               

               


                     Modifié par Kato_Yang, 22 juin 2011 - 07:22 .
                     
                  


            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #13 on: June 22, 2011, 09:34:02 am »


               As I mentioned in the e-mail I sent you...

"Ok so I am trying to follow the instructions you posted on the forums. I am starting off with xp_inc, when I save and compile I get the error I described. I selected no, and then got this error message:
6/21/2011 10:15:57 PM: Error. 'xp_inc' did not compile.
xp_inc.nss: ERROR: NO FUNCTION MAIN() IN SCRIPT
I then pressed spacebar + backspace, but it didn't seem to do anything?"

If you would perfer to work through this on the forums that's all good, whatever works best for you.

As I mentioned spacebar + backspace didn't seem to do anything, but I saved afterwards nonetheless, and still got the message:

Error. 'xp_inc' did not compile.
xp_inc.nss: ERROR: NO FUNCTION MAIN() IN SCRIPT

This may be explicit for you, but I have no idea what that means or how to fix it?
               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
Trouble installing an Exp bank into module.
« Reply #14 on: June 22, 2011, 09:59:58 am »


               You don't have to fix it ;p Include scripts don't compile. Just make sure that other scripts using this include compile.