logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
nwnx4 Set/Get persistent variables help

 
Post new topic   Reply to topic    nwnx.org Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
Will_Constantine



Joined: 12 Aug 2007
Posts: 9

PostPosted: Mon Jan 07, 2008 7:02    Post subject: nwnx4 Set/Get persistent variables help Reply with quote

Ive been trying to figure this out forever. and its high time i do it. I was hoping someone could post some example scripts i could use for reference to set and get persistent integers from the pwdata table im still not highly advanced at scripting but im no novice. but im not sure how to approach this problem. thanks in advance
Back to top
View user's profile Send private message Visit poster's website
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Mon Jan 07, 2008 11:04    Post subject: Reply with quote

The persistent functions are set up so that you can use them exactly like locals, you needn't specify expire (which is unused unless you add checks) or database (the default is pwdata).

SetLocalInt(oPC, "Quest1", 1);
SetPersistentInt(oPC, "Quest1", 1);

By contrast the Campaign ints for the bioware database are counterintuitive, because they jumble the order and add the 'campaign' name field:

void SetCampaignInt(string sCampaignName, string sVarName, int nInt, object oPlayer=OBJECT_INVALID)

If you are converting over from Campaign to Persistent with nwnx, you can simply combine the campaign name with the variable name in the campaign functions to get the Persistent Variable name. For Example:

SetCampaignInt("Bank", GetPCPublicCDKey(oPC), nGold);

is using the campaign int to create an int shared by all a players charcters and playernames under that cd key. You can achieve the same result in many ways with nwnx, because you aren't constrained to setting variables on objects, or to specific campaign names. You could make a 'bank' table, for example, or use the default pwdata table in nonstandard ways. When using the default aps_include functions, you'd probably want to do this:
SetPersistentInt(GetModule(), "Bank" + GetPCPublicCDKey(oPC), nGold);

You could also set it on the PC, it will just change the way you Get it.

The thing to understand about the pwdata tables is this: they are designed for highly generalized use, in concert with the default Persistent functions. You can input any object to store the int on, either player or nonplayer. The pwdata has 4 main fields you need to concern yourself with (you can safely ignore the expire and last columns for now):

Code:

mysql> describe pwdata;
+--------+-------------+------+-----+-------------------+-------+
| Field  | Type        | Null | Key | Default           | Extra |
+--------+-------------+------+-----+-------------------+-------+
| player | varchar(64) | NO   | PRI | ~                 |       |
| tag    | varchar(64) | NO   | PRI | ~                 |       |
| name   | varchar(64) | NO   | PRI | ~                 |       |
| val    | text        | YES  |     | NULL              |       |
| expire | int(11)     | NO   |     | 0                 |       |
| last   | timestamp   | NO   |     | CURRENT_TIMESTAMP |       |
+--------+-------------+------+-----+-------------------+-------+
6 rows in set (0.00 sec)

The data inpute wilil differ based on whether the object you are setting it on is a player or not. I said above that you do not need to set the variable on an object, but you DO need to pick an object if you are using the default aps_include functions. If you want one not specifically linked to the character, however, you can simply set it on the module, so this isn't a major constraint.

Anyway, if you set the persistent int on a player, the player field will be the playername (gamespy login), and the tag field will be the player name (characters don't have tags unless you leto them on). This is sufficient to uniquely identify any character, in most situations, since each player can only have one character of any given name. Complexities arise when players name subsequent characters the same name as old ones, but that's beyond the scope of this discussion.

If you set the persistent in on a nonplayer object, the player field will be the default tilde : ~ and the tag field will be the tag of the object.

The remaining two columns are name and val, which hold the name of the variable and the value of the variable.

Knowing these things, you should be easily able to convert all your Campaign functions to Persistent functions. If you want help with specific ones, just post em.

Here's a chunk of pwdata data from our server, just to give you some idea what it'll look like. Seeing that helped me to understand what was going on when I was just starting out:

Code:


mysql> select player, tag, name, val from pwdata limit 20;
+-------------------+-------------------------+----------------------------------+-----------+
| player            | tag                     | name                             | val       |
+-------------------+-------------------------+----------------------------------+-----------+
| Advazion Welfurth | Caldur Nuleltanocen     | demoName                         | testValue |
| jillywho          | Mae Hemm                | Accomplishments                  | 7         |
| leifus            | Akee Wellea Esthercoler | Accomplishments                  | 7         |
| surfer_me         | Celestial Glory         | bankQVRDVXDR                     | 0         |
| RPGamer99         | Alita                   | bankFTMCXDQF                     | 11612992  |
| mctigue           | Circe Jones             | Accomplishments                  | 2         |
| malday            | Malakai Meliadin        | Malakai Meliadinmaldaymalday     | 2         |
| talonsnow         | AngelStorm              | Accomplishments                  | 23        |
| malday            | Malakai Meliadin        | bankFFU97WED                     | 8604509   |
| Hells_Kitchen     | Herel Kley              | bankQCRHHCNN                     | 0         |
| Mister Bubbles    | Doc                     | bankQV6FJLM3                     | 11403217  |
| RPGamer99         | Klar Redblade           | bankFTMCXDQF                     | 0         |
| elband            | Elas Gall               | Accomplishments                  | 33554679  |
| Good_Reaper       | Kanthea Ryster          | Kanthea a RysterGood_Read_Reaper | 2         |
| tempest_204       | Bedros Ward             | Accomplishments                  | 6         |
| Phantanya         | Phannta                 | Accomplishments                  | 31        |
| Phantanya         | Nyna SparrowBlade       | bankQCR9MCVF                     | 0         |
| MishimaYukio      | Yukino Mishima          | bankQVR9GKYC                     | 0         |
| -Izabelle-        | Izabelle                | bankQVR9PJLQ                     | 2774063   |
| Nigel MacGyver    | Emitai the Archmage     | Accomplishments                  | 63        |
+-------------------+-------------------------+----------------------------------+-----------+
20 rows in set (0.00 sec)



Since all of the above were set on players, here's a listing on vars set on the modules, just by way of comparison:

Code:
mysql> select player, tag, name, val from pwdata where player = '~' and tag ='MODULE' LIMIT 20;
+--------+--------+----------------------------+------+
| player | tag    | name                       | val  |
+--------+--------+----------------------------+------+
| ~      | MODULE | FKY_CHAT_BANPLAYERQC47D3MT | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERFFU9J3KJ  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERFFUN7CYC  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERFFUVDCJP  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERFTMEKMUY  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQ77KFVME  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQC46GEEQ  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQC47D3MT  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQC6NY47F  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQG6F6F4N  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQGM93QYC  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQV4MCTFV  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQV6ECVTA  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQV6EWYFT  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQV6UMAED  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQVR9PJLQ  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQVRNPYCG  | 1    |
| ~      | MODULE | FKY_CHT_BANPLAYERQVRUXKD4  | 1    |
| ~      | MODULE | FKY_CHT_BANSHOUTFFUVDCJP   | 1    |
| ~      | MODULE | FKY_CHT_BANSHOUTFT6YJFF3   | 1    |
+--------+--------+----------------------------+------+
20 rows in set (0.00 sec)


Funky
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> General Discussion All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group