Aller au contenu

Photo

Item Variables


  • Veuillez vous connecter pour répondre
6 réponses à ce sujet

#1
Devling99

Devling99
  • Members
  • 13 messages
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?

#2
ffbj

ffbj
  • Members
  • 593 messages
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 .


#3
Devling99

Devling99
  • Members
  • 13 messages
Thank you:)

#4
Devling99

Devling99
  • Members
  • 13 messages
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?
}

#5
Thayan

Thayan
  • Members
  • 244 messages
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...

#6
Devling99

Devling99
  • Members
  • 13 messages
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.

#7
ffbj

ffbj
  • Members
  • 593 messages
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.