How do you get an object reference to an item in the heroes inventory?
#1
Posté 09 janvier 2010 - 11:53
Is there a GetItemFromInventory or similar?
I tried the following two but they don't seem right.
- GetItemsInInventory
- GetObjectByTag
#2
Posté 10 janvier 2010 - 12:32
#3
Posté 10 janvier 2010 - 12:33
FalloutBoy wrote...
What's wrong with GetItemsInInventory? It returns an array of everything in your inventory. You'll then need to loop through the array and find the object you are looking for. Or if you want to get a currently equipped item then use GetItemInEquipSlot.
I figured I would have to loop through it. But there is no example of that anywhere.
Do you happen to have an example somewhere by any chance?
I would gladly update the builder wiki if you could provide that.
Here is what I have so far:
object [] oInventoryItems = GetItemsInInventory(oHero, GET_ITEMS_OPTION_ALL, 0, "testitem");
Modifié par JackFuzz, 10 janvier 2010 - 12:54 .
#4
Posté 10 janvier 2010 - 12:38
#5
Posté 10 janvier 2010 - 12:42
EJ42 wrote...
Your questions would be easier to answer if you told us what you're trying to do.
You want to know the whole scope? I think you know already from previous posts
Basically the last thing I need to know how to do is use:
GetItemsInInventory
..................
Explanation of what I'm doing.
I need to store global variables. So I made a "gb_sword" item (yes an actual sword) and attached a custom 2DA to it. Anytime I want global variables I just add this "gb_sword" to the users inventory and it will store a "String" containing data I need to access from two scripts.
I just don't know how to access the sword once it's in the users inventory. But once I have a object reference to the sword the code works great. I 'm able to set and retrieve a string from the swords 2DA.
Honestly I wish there was a better way to do this.
Modifié par JackFuzz, 10 janvier 2010 - 12:49 .
#6
Posté 10 janvier 2010 - 12:58
object GetJacksSpecialSwordFromInventory( object oCreature )
{
object[] oInv = GetItemsInInventory( oCreature, GET_ITEMS_OPTION_ALL, 0, "gb_sword" );
if ( GetArraySize( oInv ) > 0 )
return oInv[0];
else
return OBJECT_INVALID;
}
#7
Posté 10 janvier 2010 - 01:03
FalloutBoy wrote...
I don't know why you don't just add whatever global vars you need to var_module but I'm sure you have your reasons. Anyway this should do it:object GetJacksSpecialSwordFromInventory( object oCreature )
{
object[] oInv = GetItemsInInventory( oCreature, GET_ITEMS_OPTION_ALL, 0, "gb_sword" );
if ( GetArraySize( oInv ) > 0 )
return oInv[0];
else
return OBJECT_INVALID;
}
This is great man, I really really appreciate it !! Thanks!
On a side note, I would like to use var_module. It sounds like using modules is the correct approach. I'm modifying the single player campaign. Am I still able to use my own module somehow? I've never made a module.
Also I"m making a mod I intend to make public. Installation involves simply letting them drag drop a folder into their override (that's it), i'm not sure how modules play into this.
What is the easiest way to:
1. Make a module (for the intention of using it as a local variable holder)
2. Attach var_module to it in someway.
3. Use GetModule() with Set/GetLocalstring from any script no matter where my PC is in the world.
A quick and dirty answer would suffice if you have the time
Modifié par JackFuzz, 10 janvier 2010 - 01:05 .
#8
Posté 10 janvier 2010 - 01:35
object GetItemPossessedBy( object oObject, string sTag );
Here is an example:
object oHero = GetHero(); object oArmor = GetItemPossessedBy(oHero, "[color="#3366ff"][b]TagOfItem[/b][/color]"); int ej42Success = 0; ej42Success = EquipItem(oHero, oArmor);
TagOfItem is the item resource's name without the .UTI appended. (e.g. "gen_im_cth_mag_mor" for Morrigan's Robes)
Modifié par EJ42, 10 janvier 2010 - 01:37 .
#9
Posté 10 janvier 2010 - 01:37
EJ42 wrote...
Why not just use GetItemPossessedBy?object GetItemPossessedBy( object oObject, string sTag );
Here is an example:object oHero = GetHero(); object oArmor = GetItemPossessedBy(oHero, "[color="#3366ff"][b]TagOfItem[/b][/color]"); int ej42Success = 0; ej42Success = EquipItem(oHero, oArmor);
TagOfItem is the item resource's name without the .UTI appended. (e.g. "gen_im_cth_mag_mor" for Morrigan's Robes)
Very nice! Why didn't they just call this GetItemAsObject or something.. or just GETITEM lawlz.
#10
Posté 10 janvier 2010 - 01:56
GetItemPossessedBy
In my second script (the one that fires after a cutscene) the GetItemPossessedBy returns NOTHING. Yet in the first script which fires from a conversation
GetItemPossessedByworks.
I'm sooo ****ing angry.
I want to do such a simply ****ing thing and it's .. i'm close to giving up..!!
Man if cutscenes just loaded synchronously I wouldn't of had to do any of this bull****.
All i want to do is equip a new piece of armor on the PC. Play a cutscene with the new armor.. Then when the cutscene is over reequip the original armor.
I can't believe that is so hard to do.
Modifié par JackFuzz, 10 janvier 2010 - 02:05 .
#11
Posté 10 janvier 2010 - 02:53
1) Saving the tag of the item the player has equipped before the cutscene.
2) Forcing the player to remove the item before the cutscene.
3) Causing the player to equip a new item before the cutscene.
4) Playing the cutscene.
5) At the end of the cutscene, a script fires to recover the tag of the item the player originally had equipped.
6) Replacing the original item back on the player.
In which case, why are you running the "GetItemPosessedBy" at the beginning? You should be using GetItemInEquipSlot to start with...
object GetItemInEquipSlot(
int nSlot,
object oCreature = OBJECT_SELF,
int nWeaponSet = INVALID_WEAPON_SET
);
To get the initial item. Then, you just run GetTag to grab the tag of the item to store for later...
string GetTag(
object oObject
);
Then, later, you run the GetItemPosessedBy with the tag you stored from the previous step.
Is that not what you're doing?
#12
Posté 10 janvier 2010 - 03:22
I was thinking of just using GetModule() and GetLocalString. But now I have to anticipate all the problems I'm going to have by extending one module onto the single player campaign.
SCRIPT 1 - Fires from conversation
#include "log_h"
#include "utility_h"
#include "wrappers_h"
#include "events_h"
#include "ntb_constants_h"
int StartingConditional()
{
//This script triggers from a conversation
//Get PC into an object
object oHero = GetHero();
//Add the sword object to inventory that stores a custom 2DA to store local variables (This is lame i know)
object oLocalVarHolder = UT_AddItemToInventory(R"testitem.uti");
//Add new chest piece to the users inventory
object oNewChestPiece = UT_AddItemToInventory(R"hf_body_b.uti");
//Set chest piece the user is currently wearing to an object
object oOriginalChestArmor = GetItemInEquipSlot(INVENTORY_SLOT_CHEST, oHero);
//Store the tag of the users original chest piece
SetLocalString(oLocalVarHolder, "bp_string1", GetTag(oOriginalChestArmor));
//unequip original chest armor piece
UnequipItem(oHero, oOriginalChestArmor);
//Equip new armor piece
EquipItem(oHero, oNewChestPiece);
//Ready for cutscene
resource rCutscene = R"testcreature.cut";
CS_LoadCutscene(rCutscene);
PlayCutscene(oHero);
return 1;
}
SCRIPT 2 - Fires from the end of the cutscene
#include "log_h"
#include "utility_h"
#include "wrappers_h"
#include "events_h"
#include "ntb_constants_h"
void main()
{
// This script triggers when the cutscene if finished
// Get PC into an object
object oHero = GetHero();
//Grab global variable holder, the item that is holding the tag of the original chest piece armor
//This fails, why I have no idea. The name of the item is testitem
object oLocalVarHolder = GetItemPossessedBy(oHero, "testitem");
//Grab tag of original chest piece worn
string sOriginalChestPiece = GetLocalString(oLocalVarHolder, "bp_string1");
//Remember chest piece that is now to be removed
object oNewChestPiece = GetItemInEquipSlot(INVENTORY_SLOT_CHEST, oHero);
//Unequip the new piece of armor that was only intended for the cutscene
UnequipItem(oHero, oNewChestPiece);
//Remove the new piece of armor that we used in the cutscene
UT_RemoveItemFromInventory(R"hf_body_b.uti",1);
//Grab original chest piece worn
object oOriginalChestPiece = GetItemPossessedBy(oHero, sOriginalChestPiece);
//Equip original chest armor
EquipItem(oHero, oOriginalChestPiece);
//Remove the local variable object that stored the tag string
UT_RemoveItemFromInventory(R"testitem.uti",1);
}
Modifié par JackFuzz, 10 janvier 2010 - 03:26 .
#13
Posté 10 janvier 2010 - 04:14
This may sound silly, but did you remember to export the testitem?JackFuzz wrote...
Man I appreciate your help. I'm following your methodology.
SCRIPT 1 - Fires from conversation
#include "log_h"
#include "utility_h"
#include "wrappers_h"
#include "events_h"
#include "ntb_constants_h"
int StartingConditional()
{
//This script triggers from a conversation
//Get PC into an object
object oHero = GetHero();
//Add the sword object to inventory that stores a custom 2DA to store local variables (This is lame i know)
object oLocalVarHolder = UT_AddItemToInventory(R"testitem.uti");
EquipItem(oHero, oLocalVarHolder); //Add this line, and watch your cutscene just to see if he/she has the item.
You may want to test your script at least once with the character entering the cutscene with the testitem sword equipped just as a sanity check that he/she actually has the item. Look at the bold part above for reference.
#14
Posté 10 janvier 2010 - 04:29
EJ42 wrote...
This may sound silly, but did you remember to export the testitem?JackFuzz wrote...
Man I appreciate your help. I'm following your methodology.
SCRIPT 1 - Fires from conversation
#include "log_h"
#include "utility_h"
#include "wrappers_h"
#include "events_h"
#include "ntb_constants_h"
int StartingConditional()
{
//This script triggers from a conversation
//Get PC into an object
object oHero = GetHero();
//Add the sword object to inventory that stores a custom 2DA to store local variables (This is lame i know)
object oLocalVarHolder = UT_AddItemToInventory(R"testitem.uti");
EquipItem(oHero, oLocalVarHolder); //Add this line, and watch your cutscene just to see if he/she has the item.
You may want to test your script at least once with the character entering the cutscene with the testitem sword equipped just as a sanity check that he/she actually has the item. Look at the bold part above for reference.
Hmmmm. I'll try that, let's see if its there.
Maybe I have to set something else for testitem.uti .. Maybe it doesn't appear in the inventory even though it was created?... Maybe I'm supposed to do something else when I create a new item.
I never did add an icon image. I wonder if that is a requirement.
Modifié par JackFuzz, 10 janvier 2010 - 04:30 .
#15
Posté 10 janvier 2010 - 04:46
#16
Posté 10 janvier 2010 - 04:56
FalloutBoy wrote...
Usually when I have to put together a 10-step process like this, I do one step at a time and make sure each step works correctly before adding on. Much easier to debug this way. Find the exact point of failure and fix just that, then move on to the next one.
You're so right. I try to do this as much as I can. Keep clean code, comment, organized folders. But still all it takes is one minor slip up and it's headache time! lol .. I think it's time for a break to minimize small stupid errors.
I haven't looked at it yet but I'm pretty sure that is the problem. testitem.uti, i must of forgotten to do something ot make a valid weapon to appear in inventory.
#17
Posté 10 janvier 2010 - 05:08
function: ej42_getchest
#include "utility_h"
void main()
{
object oHero = GetHero();
object oArmor = GetItemPossessedBy(oHero, "ej42_dummyitem");
SetName(oArmor, GetTag(GetItemInEquipSlot(INVENTORY_SLOT_CHEST, oHero)));
}function: ej42_putchest
#include "utility_h"
void main()
{
object oHero = GetHero();
object oArmor = GetItemPossessedBy(oHero, "ej42_dummyitem");
string theItem = GetName(oArmor);
object oItem = GetItemPossessedBy(oHero, theItem);
int ejWorked = 0;
ejWorked = EquipItem(oHero, oItem);
}I loaded these with console commands, and just made sure I only put one of the dummy item in my inventory. Then, I equipped a chest piece, and ran "runscript ej42_getchest" in the console. Next, I took off that chest piece, and ran "runscript ej42_putchest" to have it put back on. Interestingly, the name of the dummy item (when you mouse over it in your inventory) did change to the "gen_im_arm_cht_lgt_rlr" to match the leather I was wearing.
#18
Posté 10 janvier 2010 - 05:45
JackFuzz wrote...
FalloutBoy wrote...
Usually when I have to put together a 10-step process like this, I do one step at a time and make sure each step works correctly before adding on. Much easier to debug this way. Find the exact point of failure and fix just that, then move on to the next one.
You're so right. I try to do this as much as I can. Keep clean code, comment, organized folders. But still all it takes is one minor slip up and it's headache time! lol .. I think it's time for a break to minimize small stupid errors.
I haven't looked at it yet but I'm pretty sure that is the problem. testitem.uti, i must of forgotten to do something ot make a valid weapon to appear in inventory.
Unfortunately it's not the item.
I'm actually using GetModule() now instead of testitem.uti
The problem may be GetItemPossessedBy being used from a script after finishing a cutscene. But I doubt that, but that's what it looks like.
I tried:
object oOriginalChestPiece = GetItemPossessedBy(oHero, "gen_im_wep_mel_lsw_fam");
That is the tag of the cousland family sword which I kept and is in my inventory.
PrintToLog("valid");
PrintToLog(GetTag(oOriginalChestPiece));
PrintToLog("/valid");
Returns nothing in the log.. And I know the log debugging is working because GetItemPossessedBy works just fine in my first script which fires from a conversation.
*sigh*
#19
Posté 10 janvier 2010 - 05:52
EJ42 wrote...
This is kind of dumb, but it works. It at least proves that you can access the dummy item. I just can't figure out why the SetLocalString isn't taking.
function: ej42_getchest#include "utility_h" void main() { object oHero = GetHero(); object oArmor = GetItemPossessedBy(oHero, "ej42_dummyitem"); SetName(oArmor, GetTag(GetItemInEquipSlot(INVENTORY_SLOT_CHEST, oHero))); }
function: ej42_putchest#include "utility_h" void main() { object oHero = GetHero(); object oArmor = GetItemPossessedBy(oHero, "ej42_dummyitem"); string theItem = GetName(oArmor); object oItem = GetItemPossessedBy(oHero, theItem); int ejWorked = 0; ejWorked = EquipItem(oHero, oItem); }
I loaded these with console commands, and just made sure I only put one of the dummy item in my inventory. Then, I equipped a chest piece, and ran "runscript ej42_getchest" in the console. Next, I took off that chest piece, and ran "runscript ej42_putchest" to have it put back on. Interestingly, the name of the dummy item (when you mouse over it in your inventory) did change to the "gen_im_arm_cht_lgt_rlr" to match the leather I was wearing.
GetItemPossessedBy works in my first script which is fired from a conversation. But it does not work when I launch it from the end of a cutscene script.
I also use "gen_im_arm_cht_lgt_rlr" as my original chest piece
I'm going to try using the loop and see if that works. If that doesn't work then my conclusion is the script fired from when a cutscene is finished is bugged when it comes to getting object references from your inventory.
#20
Posté 10 janvier 2010 - 05:58
object oHero = GetHero();
//Remember chest piece that is now to be removed
object oNewChestPiece = GetItemInEquipSlot(INVENTORY_SLOT_CHEST, oHero);
//Unequip the new piece of armor that was only intended for the cutscene
UnequipItem(oHero, oNewChestPiece);
//Remove the new piece of armor that we used in the cutscene
UT_RemoveItemFromInventory(R"hf_body_b.uti",1);
//Grab tag of original chest piece worn
string sOriginalChestPiece = GetLocalString(GetModule(), "bp_string1");
---- i can't get this loop part to compile ----
//Grab original chest piece worn
object oOriginalChestPiece(oHero)
{
object[] oInv = GetItemsInInventory(GetHero(), GET_ITEMS_OPTION_ALL, 0, sOriginalChestPiece);
if (GetArraySize(oInv) > 0)
return oInv[0];
else
return OBJECT_INVALID;
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PrintToLog("valid");
PrintToLog(GetTag(oOriginalChestPiece));
PrintToLog("/valid");
Modifié par JackFuzz, 10 janvier 2010 - 06:00 .
#21
Posté 10 janvier 2010 - 06:17
As for the error, I suppose it's because you did not type oHero
it should be:
object oOriginalChestPiece(object oHero)
But why not simply do
oOriginalChestPiece = GetItemPossessedBy(oHero, sOriginalChestPiece);
instead of using the function you created
Anyway, on the whole idea, why do you bother playing with storing object tag as string variable for what you need
You can declare object variables in GDA, not only string or int.
Then just store directly the object, instead of storing its tag, then you just have to read the variable from GDA to directly get the object again.
PS: going offline, so don't expect any further reply soon
Modifié par elys, 10 janvier 2010 - 06:19 .
#22
Posté 10 janvier 2010 - 06:21
elys wrote...
When you have a compilation, it's better to post the error here as well.
As for the error, I suppose it's because you did not type oHero
it should be:
object oOriginalChestPiece(object oHero)
But why not simply do
oOriginalChestPiece = GetItemPossessedBy(oHero, sOriginalChestPiece);
instead of using the function you created
Anyway, on the whole idea, why do you bother playing with storing object tag as string variable for what you need
You can declare object variables in GDA, not only string or int.
Then just store directly the object, instead of storing its tag, then you just have to read the variable from GDA to directly get the object again.
I'm going to try the object route.
On a side note, it seems GetItemPossessedBy is not working in my second script, even if I try using it to get common items in my inventory.
But GetItemsInInventory is working.
On a side note, GetItemPossessedBy works in my first script which is called from a conversation.
Anyways I got it all working now finally. But I still may go the object route it seems the most efficient like you said.
#23
Posté 10 janvier 2010 - 07:01
SetLocalObject(GetModule(), "bp_object1", oOriginalChestArmor);
Script 2
object oOriginalChestPiece = GetLocalObject(GetModule(), "bp_object1");
Excel Image
img710.imageshack.us/img710/6986/localvargda.jpg
I'm trying the object route but it doesn't seem to be working. Maybe I did something wrong in the excel file?
Modifié par JackFuzz, 10 janvier 2010 - 07:04 .
#24
Posté 10 janvier 2010 - 07:26
Thanks for all ur help





Retour en haut






