Hi everyone! this problem has been fixed, please read my last comment below.
Destroying and recreating an item
#1
Posté 08 février 2016 - 10:43
#2
Posté 08 février 2016 - 11:17
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
#3
Posté 09 février 2016 - 12:58
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.
- Zwerkules aime ceci
#4
Posté 09 février 2016 - 01:33
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 ![]()
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
)
I'll keep this open until i've found some kind of solution... so thank you everybody who has helped thus far
#5
Posté 09 février 2016 - 02:13
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...
#6
Posté 09 février 2016 - 07:07
@ 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
#7
Posté 09 février 2016 - 07:44
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.
#8
Posté 09 février 2016 - 08:46
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.
#9
Posté 09 février 2016 - 10:54
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
#10
Posté 09 février 2016 - 11:59
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).
#11
Posté 10 février 2016 - 12:54
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.
#12
Posté 10 février 2016 - 02:33
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.
#13
Posté 10 février 2016 - 05:04
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?
#14
Posté 10 février 2016 - 03:06
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.
#15
Posté 10 février 2016 - 03:52
if (GetItemPossessedBy(oPC, "ag_item_axfell") == OBJECT_INVALID) CreateItemOnObject("ag_item_axfell", oPC);
#16
Posté 10 février 2016 - 05:18
hey everyone i've since fixed the problem, so i havent replied to everyone's comments.
Ive removed all resemblance of the script on the npc and made him teleport the player to their designated base. A second npc is there that will now speak to the PC, and give them the token they require.
It eliminates any hassle of my original plan, which seemed to require more than what the game was capable of. thanks for everyone's replies!
#17
Posté 10 février 2016 - 06:02
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.
I must say I was not aware that the NWN1 toolset exhibits that undesirable behaviour. It is not that way at all in NWN2.
#18
Posté 10 février 2016 - 08:41
I'm not aware of this myself... and as to correct any misinformation should be spread about this, i have enclosed an image pertaining to the item. you can clearly see both the tag and the resref are spelled the same, all lower cased and addressed correctly.
regardless the item is being distributed properly now, and will continue to do so for now on
![]()

If the image is rather small i apologize, it was done on short notice!
- Tchos aime ceci
#19
Posté 10 février 2016 - 11:13
To fully correct this. The tag can contain both upper and lower case letters. The resref can only have lower case letters. Both can (and very often do) contain numerals and sometimes underscores. Should you copy and paste a string that has upper-case characters into a resref, the toolset will automatically convert the offending characters to lower case. One major difference between the two is that the resref is restricted to 16 (I think - this is from memory) characters and the tag is not.
TR
- Tchos aime ceci
#20
Posté 12 février 2016 - 12:39
I'm not aware of this myself... and as to correct any misinformation should be spread about this, i have enclosed an image pertaining to the item. you can clearly see both the tag and the resref are spelled the same, all lower cased and addressed correctly.
Odd, from your original post the resref ended in a double "l" in the DestroyObject() command, while your screenshot only has it ending in a single "l" for both tag and resref.





Retour en haut






