Jump to content

Array Manipulation? (obse + pluggy)


greatgiginthesky

Recommended Posts

Hello again helpful residents,

After getting some exposure to scripting, I'm coming back to the idea of modding a way to convert items into a portion of their gold value. The most elegant thing I could come up with is a spell, which opens a container when cast. The player (aka me!) can place items in the container to be turned into gold. I've set up an always-on gamemode script which I want to check the contents of that container every x seconds, and if there are items present, do calculations to assess value like [(value / 2) * (alterationskill / 100)] then remove the items and give that much gold to the player.

 

As I understand it, currently the best way to handle inventory functions is using GetItems(?) I got frustrated trying to figure out how to implement GetItems and thought I would ask if anyone has experience using this OBSE function and could help me understand how to use it. Would I, in each periodic check of the container, do:

myArray CreateArray

set myArray to myContainer.GetItems

if ArraySize myArray > 0

loop <array size> times to tally value of each item

myArray DestroyArray

myContainer.RemoveAllItems

player.additem gold001 <tallied value>

 

I miss C#

Thanks for reading and for any help you can give or alternative suggestions. :)

Link to comment
Share on other sites

Looks like you are familiar with C, so I will not give you exact script(I am lazy...), but can give you some advices(Hope you know basics of CS scripting):

Quest Script:

I prefer using while - loop, however iterators may be used as well, however I personally hate Java language and prefer using C, C++.

You do not have to use Pluggy, OBSE provides everything.

 

array_var ChestItems

 

short DoOnce

short ArraySize

float fQuestDelayTime

 

ref Item

ref Chest

 

Begin GameMode

 

if DoOnce == 0

set DoOnce to 1

set Chest to MyChest ;container ref

set fQuestDelayTime to 1.0

endif

 

let ChestItems := ar_Construct Array

let ChestItems := Chest.GetItems

let ArraySize := ar_Size ChestItems

while(ArraySize > 0)

let Item := ChestItems[0]

;now you have item, perform any action you want

Chest.RemoveItem Item 1 ;maybe be more than 1 item, can produce bugs, quantity can be measured with GetItemCount function

ar_Erase ChestItems 0

set ArraySize to ArraySize - 1

loop

let ChestItems := ar_Null

 

End

Link to comment
Share on other sites

Wow! This is terrific. Within minutes of trying, I was completely successful at adapting this for my use. Heck, you did everything but compile it for me and do my taxes. I really can't thank you enough. And now I understand how to work with arrays in CS script to boot. +kudos! let me just... ARLADRIS.mod karma 5, additem gold 1000000..
Link to comment
Share on other sites

  • Recently Browsing   0 members

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