Aller au contenu

Photo

Destroy/Create Item in Inventory?


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

#1
Happycrow

Happycrow
  • Members
  • 612 messages

Hi guys.

 

Am due to start piddling around with Lilac Soul's script generator to start learning my way here, and realized "this has GOT to have been done before."

 

Is there a script which can be put on an item which will read a variable (string, tagname) and create/equip the item with that tag, and then destroy itself?  Or some close variant?

 

Thanks in advance.  Working on something neat and it'll get released to the community WAY faster if I don't have to stumble around trying to re-invent the wheel on this.



#2
Tchos

Tchos
  • Members
  • 5 042 messages

Like a cursed unidentified item script?  Dann Pigdon made one:

http://www.nexusmods...inter2/mods/196



#3
Darin

Darin
  • Members
  • 282 messages

Yes, should be easy enough...is this an onaquire, onactivate, what?

 

the how to script depends on what exactly you need it to do...also where you want the variable.

 

If a cursed item, write an OnAquire...

 

I forget the commands off the top of my head, but you'll have 

 

void main()

{

object oItem = GetItem....something (GetItemAcquired() maybe?)

object oPC = GetLast....

 

//then have it read the variable, assuming it is on the item...

 

string sTag = GetLocalString(oItem,"sTag");

CreateItemOnObject(sTag, oPC, 1);

DestroyObject(oItem,0.01); //i like a slight delay

}



#4
Happycrow

Happycrow
  • Members
  • 612 messages

Thanks gents.

 

EF:  This would be onActivate/when the PC decides to use it, it "becomes" something else and gets equipped.  How does that change the declarations in your example?



#5
Darin

Darin
  • Members
  • 282 messages

Thanks gents.

 

EF:  This would be onActivate/when the PC decides to use it, it "becomes" something else and gets equipped.  How does that change the declarations in your example?

 

If it's on use, the first item needs a power to allow the OnActivate to work...

 

Then it would be an OnActivate item script...

 

void main()

{

   object oPC = GetItemActivator();

   object oItem = GetItemActivated();

 

   string sTag = GetLocalString(oItem,"sResref");

   object oNewItem =  CreateItemOnObject(sTag,oPC,1);

   DestroyObject(oItem,0.001);

}

 

the declaration of oNewItem allows you to play with the new item in the script, for instance:

 

...

object oNewItem =  CreateItemOnObject(sTag,oPC,1);

SetLocalString( oNewItem, "sResref", GetTag(oItem));

DestroyObject(oItem,0.001);

...

 

Allows you to save the tag of the old item on the new, in case you run this twice and make it reversible.



#6
Happycrow

Happycrow
  • Members
  • 612 messages

The latter part I was going to handle by variable as well for simplicity, but this looks great. Now all I gotta do is find the code for equipping oNewItem on oPC, and I'm cooking with butter.  Thanks, man.



#7
Happycrow

Happycrow
  • Members
  • 612 messages

Finding some discrepancies in ActionEquipItem -- is it calling an integer or a string?  nwn2 wiki says integer, suggesting I have to pass it a numeric value for the slot to be equipped, but script examples on the wiki use things like "INVENTORYSLOT_LEFTHAND" or somesuch, suggesting string....

 

almost got this, thanks!



#8
Tchos

Tchos
  • Members
  • 5 042 messages

Things like INVENTORYSLOT_LEFTHAND (usually things in all-caps) are constants that represent integers.  You can see their values in the script helper window under the "globals" tab.

 

You can, if you prefer, use the actual value of the integer, but I only do that when I'm entering the values in a conversation script, or as a local variable, where it has to be a numeric entry.

 

It's the same as the integer constants TRUE = 1 and FALSE = 0.



#9
4760

4760
  • Members
  • 1 204 messages

ActionEquipItem -- is it calling an integer or a string?

An integer.

 

 

"INVENTORYSLOT_LEFTHAND" or somesuch, suggesting string

Don't focus on the " ": INVENTORYSLOT_LEFTHAND is actually an integer (constant).



#10
Happycrow

Happycrow
  • Members
  • 612 messages

Okay, cool.

Do we have a way to define nInventoryslot as the inventory slot fo the old item and thus run with ActionEquipItem (oNewItem, nInventorySlot);?  That would make for a single, elegant script, rather than requiring an additional script for each different type of item altered.

 

Thanks in advance, as usual -- you guys are a godsend.



#11
Psionic-Entity

Psionic-Entity
  • Members
  • 195 messages

Not on the toolset but as far as I know they didn't include a function to check which inventory slot it's equipped in. If you want a fast script for this just loop over n = 0:15 and check whether the item in that slot is == to the item in question. Something like:

int GetInventorySlotFromEquippedItem(object oItem, object oPC == OBJECT_INVALID) {
 if (!GetIsObjectValid(oPC)) oPC = GetItemPossessor(oItem);
 int i = 0;
 while (i < 16) {
  if (GetItemInSlot(i,oPC) == oItem) return i;
  i = i + 1;
 }
 return -1;
}


#12
Happycrow

Happycrow
  • Members
  • 612 messages

So in this case, we're making the initial declaration but the value that gets fed into ActionEquipItem is i, correct?



#13
Psionic-Entity

Psionic-Entity
  • Members
  • 195 messages

Yep, or whatever you set as the return value. You run this code before destroying the item and it should give you the right slot ID to equip the new one to.



#14
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
I have a few items that transform including the Rod of Lordly Might. I decided not to auto-equip the items after transformation because when you remove an equipped weapon from the right hand sometimes the engine will automatically switch whatever is in the left hand to the right, which may not be what is desired. I suggest you look at the scripts used for the MotB Deeam Weapon also.

Regards

#15
Happycrow

Happycrow
  • Members
  • 612 messages

Ooh, yes, that could be an issue, couldn't it?

 

Okay, thanks, folks.



#16
Morbane

Morbane
  • Members
  • 1 883 messages

... when you remove an equipped weapon from the right hand sometimes the engine will automatically switch whatever is in the left hand to the right...

Regards

 

unequip both hands - then reequip accordingly - maybe?



#17
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages

unequip both hands - then reequip accordingly - maybe?


That's fine except when the off-hand weapon being unequipped has bonuses that you lose when it is unequipped, such as extra spell slots.

#18
AGhost_7

AGhost_7
  • Members
  • 62 messages

That's fine except when the off-hand weapon being unequipped has bonuses that you lose when it is unequipped, such as extra spell slots.

You could create an inventory item which holds all item properties so that you can then move them around.



#19
Dann-J

Dann-J
  • Members
  • 3 161 messages

You could create an inventory item which holds all item properties so that you can then move them around.

 

Unfortunately that doesn't work for items that grant bonuses to spell-casting ability scores. Any time you remove a nymph cloak, for instance, a sorceror's number of spells per day are deprecated. If you don the cloak and remove it again, your spells per day get deprecated again (even though you didn't rest in between to regain the bonus spells). You can keep doing that until you have no spells per day left at all, until you rest again. It doesn't matter if there's another item that boosts the same ability score. The game engine assumes that because you're unequipping something with an ability score bonus that boost spells-per-day, your spells-per-day should therefore decrease, even if that ability score doesn't actually change. Stupid game engine...



#20
AGhost_7

AGhost_7
  • Members
  • 62 messages

I think you're wrong since I've already fixed this problem with Kaedrin's Wildshape code (and is being used on RoT with multiple players reporting that it works). The real problem is that the inventory item doesn't get updated when you add the item properties. After which, if you remove the item from inventory it will still lower your number of slots.

 

The way to mitigate this is to create the item outside of your inventory then copy it with the item property already added to it. I call GetLocation() on the PC and then use the location with CreateObject() to create the item outside of the inventory then. After that its just a simple CopyItem() call to put it on the PC. The process is too fast for anyone to see the item on the ground.



#21
Dann-J

Dann-J
  • Members
  • 3 161 messages

Ah - creating the item outside of the inventory is something I hadn't thought of. Then it will trigger a proper item acquire event.

 

Although whether that works on an overland map is anyone's guess. I've had all sorts of weird things happen while trying to manipulate inventory items on the OLM. Often I'll get phantom copies of things showing up in the inventory that aren't really there - but which prove to be surprisingly persistent for non-existant objects.



#22
AGhost_7

AGhost_7
  • Members
  • 62 messages

Quite odd. I frankly haven't even tried using the SoZ trading system or overland map. Sounds like the only fix would be to ensure that the script won't execute if on the OLM.



#23
Dann-J

Dann-J
  • Members
  • 3 161 messages

Quite odd. I frankly haven't even tried using the SoZ trading system or overland map. Sounds like the only fix would be to ensure that the script won't execute if on the OLM.

 

My automatic cloak equip has to be on the OLM, since that's the only place I allow mounting of horses in my module.

 

However I did end up moving the automatic re-equip of the original cloak to the OnClientEnter scripts of other areas, rather than on the OLM OnExit script where I originally had it. That seems to have prevented most of the weird phantom inventory item problems. That's when the nymph cloak spell deprecating problem occurs with sorcerors and bards, which requires a complex work-around involving storing the spells known per level before removing the cloak, ForceRest() when you leave the OLM, followed by deprecating spells until they match the original configuration.

 

And it certainly seems that creating an item directly into the inventory doesn't trigger on OnAcquire event. I have items that I want to be 'cursed' after you've picked them up so that you can't drop them. If I choose to give them to another party member during a conversation, I thought it would be easier to destroy the original after copying it to the companion's inventory. However the OnAcquire script doesn't automatically curse the new item as I thought it would, so I created a GA_ conversation script that curses it separately. Dropping the new item (or putting it in a container) and picking it up again successfully cursed it though, since that certainly triggered the OnAcquire event.



#24
Happycrow

Happycrow
  • Members
  • 612 messages

A lot of this is, frankly, over my head.

But... is there a toolset guide reference to adding a power to an item so I can attach the script? I'm failing in my add-property and search-tutorials-fu....



#25
Dann-J

Dann-J
  • Members
  • 3 161 messages

The item property you add depends on what sort of tag-based script it runs. These are the most common ones I use.

 

On Hit script (weapons, ammo, armour, shields)

Fires when melee weapons or ammunition hit an enemy, or when an enemy hits you (armour & shields)

On Hit Item Property: "Unique Power (On Hit)"

Script Name: i_itemtag_hc

 

On Activate script (self only)

Fires immediately when the player activates an item's special ability

Cast Spell Item Property: "Unique Power Self Only"

Script Name: i_itemtag_ac

 

On Activate script (long range)

Fires when the player activates an item's special ability. Brings up a spell-like targeting cursor.

Cast Spell Item Property: "Activate Item (Long Range)"

Script Name: i_itemtag_ac