Author Topic: Destroying and recreating an item  (Read 757 times)

Legacy_Wall3T

  • Hero Member
  • *****
  • Posts: 748
  • Karma: +0/-0
Destroying and recreating an item
« on: February 08, 2016, 10:43:27 pm »


               

Hi everyone! this problem has been fixed, please read my last comment below.



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Destroying and recreating an item
« Reply #1 on: February 08, 2016, 11:17:58 pm »


               

Correct me if I'm wrong but it looks like you are using the tag instead of the resref when you try to create the item. From the downloadable lexicon ->



CreateItemOnObject(string, object, int, string)
Create a specific item in an objects inventory.
 
object CreateItemOnObject( 
    string sItemTemplate, 
    object oTarget = OBJECT_SELF, 
    int nStackSize = 1,
    string sNewTag = ""
);
Parameters
sItemTemplate
 
The blueprint ResRef string of the item to be created or tag.
 
oTarget
 
The inventory where you want the item created. (Default: OBJECT_SELF) 
 
nStackSize
 
The number of items to be created. (Default: 1) 
 
 sNewTag
 
Sets the tag. If this string is empty (""), it be set to the default tag from the template. (Default: "")

Before you ask - the resref is found under the advanced tab.


 


TR



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Destroying and recreating an item
« Reply #2 on: February 09, 2016, 12:58:07 am »


               

You probably want to use GetItemPossessebyBy instead of GetObjectByTag in this line



// Destroy an object.
DestroyObject(GetItemPossessedBy(oPC, "ag_item_axfell"));

Right now you're getting the first object with that tag anywhere in the module.  Also make sure "ag_item_axfell" is not stackable.


               
               

               
            

Legacy_Wall3T

  • Hero Member
  • *****
  • Posts: 748
  • Karma: +0/-0
Destroying and recreating an item
« Reply #3 on: February 09, 2016, 01:33:23 am »


               

hmmm... the line meaglyn gave me didnt seem to work... I've made sure the resref matched with the coding and just doesnt seem to want to work....


 


 Its as if the script is a little confused as to what i'm trying to do ':lol:'


 


I may try my second solution and create a second NPC and leave the other as a starting NPC (that may prevent the game from yelling at me again ':whistle:' )


 


I'll keep this open until i've found some kind of solution... so thank you everybody who has helped thus far



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Destroying and recreating an item
« Reply #4 on: February 09, 2016, 02:13:51 am »


               

When you say "didn't work" that's not really very useful... how did it not work?


 


If you are getting a duplicate then it was never a resref versus tag problem on the create. It's the destroy that's not working...


               
               

               
            

Legacy_Wall3T

  • Hero Member
  • *****
  • Posts: 748
  • Karma: +0/-0
Destroying and recreating an item
« Reply #5 on: February 09, 2016, 07:07:29 pm »


               

@ Meaglyn I'm not really sure what else to tell ya there, the script just seems to want to skip that first line and thats it


 


Also Ive come up with a solution: I decided to have the NPC just teleport the player to their Base and applied a trigger that would give the player their Token once per player.


 


Since I'm running this on a server the only issue I'll have, is if i restart the server the players will receive a second Base item. So... I'm close! and far away from the old problem before



               
               

               
            

Legacy_Asymmetric

  • Sr. Member
  • ****
  • Posts: 289
  • Karma: +0/-0
Destroying and recreating an item
« Reply #6 on: February 09, 2016, 07:44:31 pm »


               

Check the tag and resref of the item. You're using "ag_item_axfell" both with CreateItem (here you'll need the resref) and GetItemPossessedBy/GetObjectByTag (you'll need the resref). Make sure they are actually the same.



               
               

               
            

Legacy_Wall3T

  • Hero Member
  • *****
  • Posts: 748
  • Karma: +0/-0
Destroying and recreating an item
« Reply #7 on: February 09, 2016, 08:46:20 pm »


               

For such instances of items the resref is also the same annunciation as the tag (IE if the resref is "ag_item_axefell" then the tag is "ag_item_axfell") i've double checked, its spelled the exactly the same as its copied and pasted so as to not cause any human errors.


 


Either way ive found a solution written above, so that script should no longer really be needed. The one I came up with is below:


 


 


This is applied to a trigger as the PC teleports into their home base


void main()

{

    // Get the creature who triggered this event.

    object oPC = GetEnteringObject();


    // Only fire for (real) PCs.

    if ( !GetIsPC(oPC)  ||  GetIsDMPossessed(oPC) )

        return;


    // Only fire once per PC.

    if ( GetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF)) )

        return;

    SetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE);


    // Give "ag_item_axfell" to the PC.

    CreateItemOnObject("ag_item_axfell", oPC);

}


 


 


Right away the only problem I'll have with this is server resets which will reset the trigger and hence duplicate the item again.



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Destroying and recreating an item
« Reply #8 on: February 09, 2016, 10:54:43 pm »


               

Have you tried putting a variable on the PC to count how many of an item they would have if you were to give them another one? In pseudo code ->


 


Get value of variable from pc


add one to it


if value > 1


    return                 // Do not update variable on PC, Do not give PC item


store value on PC


give PC item


 


TR



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Destroying and recreating an item
« Reply #9 on: February 09, 2016, 11:59:12 pm »


               

Usually when you create an item with a resref, the tag becomes uppercase.  Most tag commands are case sensitive, (i.e. "ag_item_axfell" and "AG_ITEM_AXFELL" are not the same thing).



               
               

               
            

Legacy_Tchos

  • Sr. Member
  • ****
  • Posts: 454
  • Karma: +0/-0
Destroying and recreating an item
« Reply #10 on: February 10, 2016, 12:54:46 am »


               

The case of the tag is whatever it was given in the blueprint.  In the vanilla content they seemed to like tags in all-caps, but my convention is to always make the resref and tag identical in any of my custom blueprints.



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Destroying and recreating an item
« Reply #11 on: February 10, 2016, 02:33:36 am »


               

I'm stating what the Toolset does as default.  If you do not want all caps, then you are changing the tag instead of using the default.



               
               

               
            

Legacy_Tchos

  • Sr. Member
  • ****
  • Posts: 454
  • Karma: +0/-0
Destroying and recreating an item
« Reply #12 on: February 10, 2016, 05:04:48 am »


               

Are you saying that the toolset automatically fills in the tag when you create a blueprint, using the resref that you type but changing it to uppercase?



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Destroying and recreating an item
« Reply #13 on: February 10, 2016, 03:06:26 pm »


               

Yes, if the blueprint is typed with any capitals, the resref will still be all lowercase and thus different. This is default Toolset behavior.  Given the way it behaves it is very easy for someone to create a blueprint, see that the tag is carried over, and come to the false conclusion that they are in fact the same.  I think that is what the OP is experiencing.



               
               

               
            

Legacy_Zwerkules

  • Hero Member
  • *****
  • Posts: 1997
  • Karma: +0/-0
Destroying and recreating an item
« Reply #14 on: February 10, 2016, 03:52:23 pm »


               It seems a bit strange to destroy the item if the PC already got it. Why don't you check if the PC got the item and only create a new one for them if they don't have one already?

if (GetItemPossessedBy(oPC, "ag_item_axfell") == OBJECT_INVALID) CreateItemOnObject("ag_item_axfell", oPC);