Jump to content

Item Display and Storage - Script Help


thejadeshadow

Recommended Posts

Terra Nova, why do you say that line isn't setting it to false? Also (not directed at Terra Nova), bools are false by default. "Bool Property IsPlaced Auto Hidden" shoould start with IsPlaced as false.

 

Anyway, yes, it can be expanded. I haven't tested this, but see if it compiles. If so, you should be able to fill up ONE array. It will find the first array that isn't empty and ignore EVERYTHING else. So you can't mix and match with this.

 

 

  Reveal hidden contents

 

Also, the CanDisplayItem function should be able to be shortened and simplified. I haven't done so, because I won't be testing it, but all it does it checks if an item is in an array. You can try this. If it doesn't work, revert to the previous. If it works, it'll be a lot faster than actually iterating through the array and checking each item (since that's what "find" does, but it's native).

 

  Reveal hidden contents

 

 

EDIT: I completely forgot that you can't cast one type to another when they're arrays. Had to replace that casting with iterative casting. Also had to include a function to initialize an array to a variable. I've tested if it compiles, and now it does. However, I still haven't tested if it works.

Edited by Xander9009
Link to comment
Share on other sites

  On 12/15/2014 at 1:18 PM, Xander9009 said:

Terra Nova, why do you say that line isn't setting it to false? Also (not directed at Terra Nova), bools are false by default. "Bool Property IsPlaced Auto Hidden" shoould start with IsPlaced as false.

 

I've never trusted doing this: (and I think that only applies to variables.)

Bool property bMyBool =False auto

I mean it doesn't set it to false/true in the property manager.

 

If I'm wrong, then I'm wrong, but I prefer to play safe with this language.

Edited by Terra Nova
Link to comment
Share on other sites

  On 12/15/2014 at 2:24 PM, Terra Nova said:

 

  On 12/15/2014 at 1:18 PM, Xander9009 said:

Terra Nova, why do you say that line isn't setting it to false? Also (not directed at Terra Nova), bools are false by default. "Bool Property IsPlaced Auto Hidden" shoould start with IsPlaced as false.

 

I've never trusted doing this: (and I think that only applies to variables.)

Bool property bMyBool =False auto

I mean it doesn't set it to false/true in the property manager.

 

If I'm wrong, then I'm wrong, but I prefer to play safe with this language.

 

If it was just to play it safe, then that makes sense. I just tested it in game and it does work the way it would be expected to, which makes sense since properties are variables (they're just variables which happen to be editable with the property manager). If it's not set, it's false, if it is set when declared, it's whatever it was initialized to. But no, it doesn't actually show what it's defaulted to in the property manager. That why whenever I set a variable with a default in my own scripts, I always include that information in the property help text.

Link to comment
Share on other sites

All of this is because the CK can't fill a generic Form type even though Papyrus has no problem with them.

 

I had created and tested my own version that looks very much like Xander9009's code. And after read that post have revised my code to use the Find function directly from the master container script.

 

I named the properties so that all of the ItemToPlace arrays would be together. My version actually lets you put items in more than one of the lists since it merges them. I don't know if that would ever be useful, but it was just as easy as using only one list at a time.

 

My NewFormArray function only initializes approximately the right number of slots and I use a variable to record the real length. I'm too lazy to generate all 128 elseif blocks since it's highly unlikely someone would use more than a half-dozen anyway. (And yes I did test that feature.)

 

 

Here are my two revised and tested scripts. I attached them to some items in my game and they worked just like I expected (after a few edits of course).

 

 

 

 

  Reveal hidden contents

 

Link to comment
Share on other sites

The trick to getting all 128 is to use Notepad++ and use its macro feature. List 1-128, and then record yourself correcting one using only the keyboard, and then pres ctrl-shift-p until you're done.

 

However, since I've already got the 1-128, just copy that to a text editor and do a find replace.

 

 

  Reveal hidden contents

 

The find/replace method only took about 10 seconds :) 'Cause trust me, I'm lazy too hahaha.

Link to comment
Share on other sites

I'd edit my last post, but I don't want this to be missed: your find function will fail if it finds the item as the first element of the array and if it doesn't find the item at all. When it doesn't find the item, it returns -1. If it does, it returns the element index, which is 0 for the first element, and so on. Meaning, "if DisplayActivator.ItemToPlace.Find(akBaseItem)" will be true if the item isn't found, since it'll be -1, and a negative int is true (only 0 is false). It needs to be "if DisplayActivator.ItemToPlace.Find(akBaseItem) >= 0"

Edited by Xander9009
Link to comment
Share on other sites

OK, for anyone else who might be interested. I've fixed up the scripts and added a few more utility functions. In theory other scripts could use some of the new functions to trigger some extra events that aren't handled by default. Some examples of the new features are:

 

The activators now have a TransferAllMatchingItems property so that they can be set to grab all of the items configured instead of just one. That means clicking the activator might take all of your ebony ingots instead of just one. You could configure an activator with all of the ingot items and then use a matching display item of a pile of ingots.

 

Separate TakeItemsFromPlayer(), ReturnAllItemsToPlayer(), and UpdateDisplay() can be called on each activator from other scripts.

 

Those same three scripts are also in the MasterContainer script, along with a DisableActivationByPlayer property. Setting that property to true would allow you to attach another script to the container to capture the OnActivate event. It could display a menu of choices like "Open", "Retrieve All Items", "Store Matching Items", etc.

 

I didn't try to write some sort of alternate activation function because it would have to be linked to a message and I'm still trying to keep these general purpose scripts.

 

 

So here are the new versions. Hopefully without bugs this time.

 

 

  Reveal hidden contents

 

Link to comment
Share on other sites

I haven't looked over every line, but a quick glance looks good :) Nicely done. The only thing I noticed was that there's no inclusion of ingredients (something I also overlooked with my version). I'm not sure if I'd bother adding it, since it's both easy for others to add and not too likely to be displayed, but just a thought. Since it's generic, those new functions should prove quite useful :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...