Jump to content

Need Help with my Mod, scripting


Recommended Posts

Posted

Hey, in need Help, hope its the right place to ask. I wrote a few modauthors, but they seem no longe be active. My mod is a bookshop where you can craft your own books and should sell them there. I need a script which deletes items from vendor chest and adds the worth amount of gold into another every day. I looked at the scripts of drunken dragon and aduras merchant mod but i cant use them because they have special scripts for more than that, and if i look at the scripts i really dont understand whats going on because i am a real noob in programming.

Posted (edited)

Right place? No idea; but usually see such questions in technical support topic.

 

Usually you'd just mark items with the `vendor item' keyword and then you can just sell them using the standard in game mechanism. But if you must have a script that does that, it could look like something along these lines:

 

ScriptName SellDaily extends Quest ; or ObjectReference/.../etc. Depends where you put this script. Here I've assumed its on a quest.

 

ObjectReference property VendorChest auto    ; Chest to search, fill in CK (eg pick in render window)

ObjectReference property goldBox auto           ; Where to store the gold.  dito

FormList property BookTypes auto                    ; Form List of things that should be sold. Create and fill this formlist in the CK. Then fill this property with that list.
Form Property Gold001 auto                             ; one gold coin, autofill

 

int Function SellContent()
{ Clears the content of the given container. Returns the amount of gold its worth. }
  int t = 0                                                    ; Total gold.
  int i = VendorChest.GetNumItems()        ; How many items in chest ?
  while i > 0                                              ; Loop through all items
    i = i - 1
    Form b = VendorChest.GetNthForm( i )                  ; Get ith item in the chest  << added missing `venderchest.' to this line
    if BookTypes.find( b ) >= 0                    ; Is it a book?
        int g = b.getGoldValue()                              ; how much the book is worth.
        int c = VendorChest.GetItemCount( b )       ; how many are there?
        VendorChest.RemoveItem(b, c, true, none)  ; Remove c copies of b, silently, moving them to nowhere.
        if c > 0                                ; if worth anything
            t += c * g
            GoldBox.Additem(Gold001, c * g )    ; add gold for removed books.
        endif
    endif
  endWhile
  return t                                                       ; Not strictly needed as we've already added the gold to the box, added just in case it's useful somewhere...
EndFunction

 

Event OnUpdateGameTime()
{ Call above daily. Call RegisterForSingleUpdateGameTime(...) once to start it. }
    SellContent()
    RegisterForSingleUpdateGameTime( 24.0 )   ; Call me tomorrow.
EndEvent

 

Edited by MTB
think i-- is not proper papyrus, adjusted.
Posted
On 1/12/2025 at 11:57 PM, shadson said:

Thank you very much, i will try it tomorrow :)

Not sure if it worked or not but if you need help you can check out my blog.

It's also worth mentioning that chatgpt can actually write vanilla papyrus scripts so that might work too. Keep in mind though that chatgpt my sometimes use queryselector even though they don't exist in papyrus.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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