Author Topic: Storing string information on PC (PERMANENT)  (Read 416 times)

Legacy_Thamiar

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
Storing string information on PC (PERMANENT)
« on: January 24, 2014, 12:32:43 pm »


               Hello,
I have got a small question. I would like to store some string information on PC character. I know i can use:
SetLocalString(oPC,
sTag, sInformation);  Does those variables disapear after restart of
the serwer? Is there any other option to store information on PC? I
heard that it can by saved on Hide (INVENTORY_SLOT_CARMOUR) Is it true?
How it can be done?
               
               

               
            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Storing string information on PC (PERMANENT)
« Reply #1 on: January 24, 2014, 05:41:00 pm »


               Yes, variables set on the PC disappear (i.e. are not persistent) after the module is shut down and restarted.

You can, however, place variables onto inventory items and those will persist after a restart (including your creature armor suggestion, but it also applies to all items in inventory - weapons, tokens, torches, etc...).  

So, an easy option for you would to be to create an inventory item, such as a "Player Token" (name it something relevant to your module) and give it to all new players (make the item plot, stolen, and undroppable to prevent your players from losing it).  I prefer this option over the idea of the creature armor slot, as there may be times when that creature hide gets displaced, whereas an inventory item that is small and weightless is almost inconsequential, can be named something relevant to the story of your module, and wouldn't need to be touched.

However you proceed, you can store strings, ints, floats, etc.. onto inventory items.  So, when you need to apply or retrieve persistent information to/from  a player, you just reference that item rather than the PC.

Saving data is as simple as using the SetLocalString function onto the item.  Retrieving data uses GetLocalString function.  Instead of setting it on the PC, you set and retreive it from the inventory item.

For example:

Set the string
object oPC = GetPCSpeaker();
object oDatabase = GetItemPossessedBy(oPC, "database");
string sName = GetName(oPC);
SetLocalString(oDatabase, "Name", sName);

Retrieve the string:
object oPC = GetPCSpeaker();
object oDatabase = GetItemPossessedBy(oPC, "database");
string sName = GetLocalString(oDabatase, "Name");

Hope that helps.
               
               

               


                     Modifié par BelowTheBelt, 24 janvier 2014 - 05:41 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Storing string information on PC (PERMANENT)
« Reply #2 on: January 24, 2014, 09:29:22 pm »


               To be clear, you don't want the undroppable flag set on the item, which controls whether npcs drop it when they die; you want the cursed flag set so the pc cannot drop it.

If you're a novice scripter, BtB's suggested approach is probably the best (though I didn't check his code, just his suggestion). There are a few problems with undroppable items (they can, for example, often be forced out of inventory by clever players), but by and large this solution works.

Funky
               
               

               
            

Legacy_Thamiar

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
Storing string information on PC (PERMANENT)
« Reply #3 on: January 25, 2014, 04:14:33 pm »


               Thank you very much!
I wrote as you said, using hide:

To save data,
object oPC = GetItemActivator();
object oHide = GetItemInSlot(INVENTORY_SLOT_CARMOUR,oPC);
string sTag = "TAG";
string sString = "abc";
SetLocalString(oHide, sTag, sString);



To get data
object oPC = GetItemActivator();
object oHide = GetItemInSlot(INVENTORY_SLOT_CARMOUR,oPC);
string sTag = GetLocalString(oHide, "TAG");

And it works. But when I save and export the character, exit the game and create a new game (using saved character) it does not work. (I tried also using INVENTORY_SLOT_NECK, and the result was the same.)
What am I doing wrong?
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Storing string information on PC (PERMANENT)
« Reply #4 on: January 25, 2014, 06:48:18 pm »


               

Thamiar wrote...

Thank you very much!
I wrote as you said, using hide:

To save data,
object oPC = GetItemActivator();
object oHide = GetItemInSlot(INVENTORY_SLOT_CARMOUR,oPC);
string sTag = "TAG";
string sString = "abc";
SetLocalString(oHide, sTag, sString);



To get data
object oPC = GetItemActivator();
object oHide = GetItemInSlot(INVENTORY_SLOT_CARMOUR,oPC);
string sTag = GetLocalString(oHide, "TAG");

And it works. But when I save and export the character, exit the game and create a new game (using saved character) it does not work. (I tried also using INVENTORY_SLOT_NECK, and the result was the same.)
What am I doing wrong?


I think 1.69 introduced the player's hide to change to PC Properties for the sake of the horses. So if this other module you're loading and importing your character into still has this feature in the scripts, the hide on your imported character is being replaced by PC Properties, which would not have the variable stored on it from your other module.

FP!
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Storing string information on PC (PERMANENT)
« Reply #5 on: January 25, 2014, 07:10:02 pm »


               

Fester Pot wrote...

Thamiar wrote...

Thank you very much!
I wrote as you said, using hide:

To save data,
object oPC = GetItemActivator();
object oHide = GetItemInSlot(INVENTORY_SLOT_CARMOUR,oPC);
string sTag = "TAG";
string sString = "abc";
SetLocalString(oHide, sTag, sString);



To get data
object oPC = GetItemActivator();
object oHide = GetItemInSlot(INVENTORY_SLOT_CARMOUR,oPC);
string sTag = GetLocalString(oHide, "TAG");

And it works. But when I save and export the character, exit the game and create a new game (using saved character) it does not work. (I tried also using INVENTORY_SLOT_NECK, and the result was the same.)
What am I doing wrong?


I think 1.69 introduced the player's hide to change to PC Properties for the sake of the horses. So if this other module you're loading and importing your character into still has this feature in the scripts, the hide on your imported character is being replaced by PC Properties, which would not have the variable stored on it from your other module.

FP!


You need to use characters stored in an actual server vault and launch your games as if launching a server as well. Information stored on items does not transfer with local vault saves.
               
               

               
            

Legacy_Thamiar

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
Storing string information on PC (PERMANENT)
« Reply #6 on: January 28, 2014, 07:09:57 pm »


               Thank you all very much for answers and advices!
It works now '<img'>
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Storing string information on PC (PERMANENT)
« Reply #7 on: February 08, 2014, 07:28:09 am »


               This may help you...
==============================================

//  gen_skin_inc
//////////////////////////////////////////////////
// Created By: Genisys / Guile
// Created On: 2/06/2014
////////////////////////////////////////////////////////////////////////////////
/*   
   This will handle ALL PC Skin Functions & Persistent Variable Storage...
   This is a very simplified script include!  (Tested Thoroughly!)
*/
////////////////////////////////////////////////////////////////////////////////
//  Required Includes
//  (NONE & Don't Add Any!)
////////////////////////////////////////////////////////////////////////////////
// Declare All Prototypes...


// Returns the Bioware PC Skin (if one doesn't exist, it creates it)
object GetSkin(object oPC);

// Returns an Int Set on the PC Skin by the variable name sVar
int GetSkinInt(object oPC, string sVar);

// Returns an Int Set on the PC Skin by the variable name sVar
float GetSkinFloat(object oPC, string sVar);

// Returns a String Set on the PC Skin by the variable name sVar
string GetSkinString(object oPC, string sVar);

// Returns an Object Set on the PC Skin by the variable name sVar
object GetSkinObject(object oPC, string sVar);

// Returns a Location Set on the PC Skin by the variable name sVar
location GetSkinLocation(object oPC, string sVar);


void DeleteSkinInt(object oPC, string sVar);
void DeleteSkinFloat(object oPC, string sVar);
void DeleteSkinString(object oPC, string sVar);
void DeleteSkinObject(object oPC, string sVar);
void DeleteSkinLocation(object oPC, string sVar);

void SetSkinInt(object oPC, string sVar, int nInt);
void SetSkinFloat(object oPC, string sVar, float fFloat);
void SetSkinString(object oPC, string sVar, string sString);
void SetSkinObject(object oPC, string sVar, object oObject);
void SetSkinLocation(object oPC, string sVar, location lLoc);
////////////////////////////////////////////////////////////////////////////////
//Define all prototypes...
//-------------------------------------------------------------------------
object GetSkin(object oPC){ 
object oSkin = GetItemInSlot(INVENTORY_SLOT_CARMOUR, oPC); 
if(oSkin == OBJECT_INVALID) {  oSkin = CreateItemOnObject("x3_it_pchide", oPC); 
AssignCommand(oPC, ActionEquipItem(oSkin, INVENTORY_SLOT_CARMOUR)); }
 return oSkin;}
//-------------------------------------------------------------------------
int GetSkinInt(object oPC, string sVar){ 
object oSkin = GetSkin(oPC);  return GetLocalInt(oSkin, sVar);}
//-------------------------------------------------------------------------
float GetSkinFloat(object oPC, string sVar){ 
object oSkin = GetSkin(oPC);  return GetLocalFloat(oSkin, sVar);}
//-------------------------------------------------------------------------
string GetSkinString(object oPC, string sVar){ 
object oSkin = GetSkin(oPC);  return GetLocalString(oSkin, sVar);}
//-------------------------------------------------------------------------
object GetSkinObject(object oPC, string sVar){ 
object oSkin = GetSkin(oPC);  return GetLocalObject(oSkin, sVar);}
//-------------------------------------------------------------------------
location GetSkinLocation(object oPC, string sVar){ 
object oSkin = GetSkin(oPC);  return GetLocalLocation(oSkin, sVar);}
//-------------------------------------------------------------------------
void DeleteSkinInt(object oPC, string sVar){ 
object oSkin = GetSkin(oPC);  DeleteLocalInt(oSkin, sVar);}
//-------------------------------------------------------------------------
void DeleteSkinFloat(object oPC, string sVar){ 
object oSkin = GetSkin(oPC);  DeleteLocalFloat(oSkin, sVar);}
//-------------------------------------------------------------------------
void DeleteSkinString(object oPC, string sVar){ 
object oSkin = GetSkin(oPC);  DeleteLocalString(oSkin, sVar);}
//-------------------------------------------------------------------------
void DeleteSkinObject(object oPC, string sVar){ 
object oSkin = GetSkin(oPC);  DeleteLocalObject(oSkin, sVar);}
//-------------------------------------------------------------------------
void DeleteSkinLocation(object oPC, string sVar){ 
object oSkin = GetSkin(oPC);  DeleteLocalLocation(oSkin, sVar);}
//-------------------------------------------------------------------------
void SetSkinInt(object oPC, string sVar, int nInt){ 
object oSkin = GetSkin(oPC);
DeleteSkinInt(oPC, sVar);   // Prevent Bloat! 
SetLocalInt(oSkin, sVar, nInt);}
//-------------------------------------------------------------------------
void SetSkinFloat(object oPC, string sVar, float fFloat){ 
object oSkin = GetSkin(oPC); 
DeleteSkinFloat(oPC, sVar);  // Prevent Bloat! 
SetLocalFloat(oSkin, sVar, fFloat);}
//-------------------------------------------------------------------------
void SetSkinString(object oPC, string sVar, string sString){ 
object oSkin = GetSkin(oPC); 
DeleteSkinString(oPC, sVar);  // Prevent Bloat! 
SetLocalString(oSkin, sVar, sString);}
//-------------------------------------------------------------------------
void SetSkinObject(object oPC, string sVar, object oObject){ 
object oSkin = GetSkin(oPC); 
DeleteSkinObject(oPC, sVar);  // Prevent Bloat! 
SetLocalObject(oSkin, sVar, oObject);}
//-------------------------------------------------------------------------
void SetSkinLocation(object oPC, string sVar, location lLoc){ 
object oSkin = GetSkin(oPC); 
DeleteSkinLocation(oPC, sVar);  // Prevent Bloat! 
SetLocalLocation(oSkin, sVar, lLoc);}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
// End Include...
//-------------------------------------------------------------------------
               
               

               


                     Modifié par _Guile, 08 février 2014 - 10:56 .
                     
                  


            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Storing string information on PC (PERMANENT)
« Reply #8 on: February 08, 2014, 10:48:21 am »


               I am curious if it is safe to store variables on PC hides? I haven't done any testing, but I would be wary, because of possible bad interactions with the horse system, polymorphs, and possibly even extended PC race systems. I'd hate to be counting on something stored on a hide and then find out it isn't there because the toon was shifted into minotaur shape when he talked to the NPC or something. Meanwhile, hides may be get its locals wiped if the PC is saved to a local vault, like most other items (not in containers) do...
               
               

               


                     Modifié par MrZork, 08 février 2014 - 10:50 .