FunkySwerve
Joined: 02 Jun 2005 Posts: 377
|
Posted: Mon Jan 07, 2008 11:04 Post subject: |
|
|
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 |
|