Author Topic: Item Variables  (Read 243 times)

Legacy_Devling99

  • Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Item Variables
« on: May 11, 2011, 11:46:38 pm »


               How do i store Variables on an Item possesed by a player?
How do i set them and how to i call them into a script?
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Item Variables
« Reply #1 on: May 12, 2011, 01:17:25 am »


               Just use an undropable item, I call mine database. Then just use the get item posssessed by, and write the variable to the database. For instance:

object oDatabase = GetItemPossessedBy(oPC, "database");
//checks to see if the player has the object.
SetLocalInt(oDatabase,"NaggingWound", GetLocalInt(oDatabase,"NaggingWound")+1);
//example of how to increment a local variable on the database object

 if (!GetIsObjectValid(oDatabase))
     {
       // Now create the database on the PC
       CreateItemOnObject("database", oPC, 1);
//example of part of onclient enter which creates the database object on the player if they don't have one.

 if (GetLocalInt(oDatabase, "Expired") == 1)
          {
      DelayCommand (12.0,(ApplyEffectToObject (DURATION_TYPE_INSTANT, eDeath, oPC, 1.0f)));
      DelayCommand (14.0,SendMessageToPC(oPC, " STILL DEAD! "));
      DelayCommand (100.0, SetLocalInt (oDatabase, "Expired", 0));
          }
//example of how to check the database for a specific int set to specific number.
    if (GetLocalInt(oDatabase,"NaggingWound") > 10)
//example of checking for an incrmented int if higher than a certain number.

DeleteLocalInt(oDatabase,"MountI");
//example of deleting a local int
 SetLocalInt(oDatabase,"MountI", 1);
//example of setting a local int
               
               

               


                     Modifié par ffbj, 12 mai 2011 - 12:33 .
                     
                  


            

Legacy_Devling99

  • Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Item Variables
« Reply #2 on: May 12, 2011, 01:34:21 pm »


               Thank you:)
               
               

               
            

Legacy_Devling99

  • Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Item Variables
« Reply #3 on: May 12, 2011, 09:45:41 pm »


               I have some problems with setting/creating the variables on the item.

First of all,
is the Varaible Created in the toolset on the item Description->Variables or in a script?

Second, i had some problems by setting the Variable, am i  doing this wrong?
atm i have this small script, that should set the variable called Triggered to 1 when my PC enters an invisible generic trigger.

Code:
void main()
{
object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;
      
object oCloth = GetItemPossessedBy(oPC, "cloth");
  
SetLocalInt(oCloth,"Triggered", 1);
///////////////////////
Am i doing this wrong?
}
               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Item Variables
« Reply #4 on: May 12, 2011, 09:58:59 pm »


               Q1. is the Varaible Created in the toolset on the item Description->Variables or in a script?
A1. You can do this either way. I personally prefer setting variables via script whenever possible - but that's just a psersonal preference of mine.

Q2. Second, i had some problems by setting the Variable, am i  doing this wrong?
A2. Make sure that the TAG of the item you are setting this variable on is truly "cloth" (without the quotes). Note that this is also case sensitive as well, so the tag needs to be all lowercase to match your script. Otherwise, your script looks good and *should* work...
               
               

               
            

Legacy_Devling99

  • Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Item Variables
« Reply #5 on: May 12, 2011, 10:08:11 pm »


               Thanks,
Q2, i had Both Tag, Name and Resref set to cloth, but the "Name" was Cloth in uppercase, when i lowered that it worked, thank you.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Item Variables
« Reply #6 on: May 12, 2011, 11:22:48 pm »


               The name is irrelevant unless you use setname and getname, which you are not doing.
The name of the object/item is on the left.
The tag is to the right and the resref is just below the tag.