Jump to content

Script Issue for my First PlayerHome Mod


Recommended Posts

I´m having a little problem with my first script (really the first one I´ve written myself). The function should be that I, in my case, activate a shrine on a trial basis and a certain Soul Gem should be removed and a Black Soul Gem should appear in my inventory. However, the problem is that even if i don´t have another one to remove, the Black Soul Gem still spawn when i activate it. But this is to much. Maybe someone has an idea what the script is missingScreenshot(38).thumb.png.13133b0d5f523da4cff131fc950c87ef.png

Edited by Dark09188
Link to comment
Share on other sites

Instead of a screenshot, can you copy and paste the code inside of a code box here in the forums.  The forum software does not allow for zooming of images and I cannot effectively read what is in the image.

Based on what you've said you want to happen, the script should be something like this (not tested for compilation or function)

FormList Property SoulGemList Auto
SoulGem Property SoulGemBlack Auto

Event OnActivate(ObjectReference akActivator)
  If akActivator == Game.GetPlayer()                        ; player did the activation
    If akActivator.GetItemCount(SoulGemList) >= 1           ; at least one soul gem exists
      Int index = SoulGemList.GetSize()                     ; find how big the soul gem list is
      While index > 0                                       ; look at each entry in the form list
        index -= 1                                          ; index counts are 0 to X rather than 1 to Y, reduce count by one before using
        Form Entry = SoulGemList.GetAt(index)               ; get the current entry and store it as a form
        If Entry && akActivator.GetItemCount(Entry) > = 1   ; the entry exists and player has at least one
          akActivator.RemoveItem(Entry,1)                   ; remove the one gem
          akActivator.AddItem(SoulGemBlack,1)               ; replace with black gem
          index = 0                                         ; did what we wanted, stop going through the list
        EndIf
      EndWhile
    EndIf
  EndIf
EndEvent

Property variable names may need to be adjusted for your needs.

  • Thanks 1
Link to comment
Share on other sites

Scriptname AB0000Test02 extends ObjectReference  

SoulGem Property SoulGemBlack  Auto
formlist property DLC01SoulcairnLRodGemList auto

int i

Event OnActivate(ObjectReference akActionRef) 
     
      if i ==1

      ; remove the least valuable soul gem
      if akActionRef == Game.GetPlayer().RemoveItem(DLC01SoulcairnLRodGemList)
      if Game.GetPlayer().RemoveItem(DLC01SoulcairnLRodGemList) == Game.GetPlayer().AddItem(SoulGemBlack)
         
   endif 
   endif
endEvent

Link to comment
Share on other sites

I have just use a own created formlist with greater and grand SoulGem in there. As i must confess to being a total beginner when it comes to scripting. Unfortunately, I only had the templates in the new Creation Kit Wiki, but also English tutorials and they are not quit as precise for my script in the explanation , or were difficult to understand. That´s why I used the script forthe time being. And I found the explanations behind it really helpful to understand how it works. 

Link to comment
Share on other sites

@Dark09188 coding doesn't work like that, very code has a API that explains how it works, the trick is turning your idea into practical code look at this

  1. The function should be that I, in my case,
  2. activate a shrine on a trial basis and
  3. a certain Soul Gem should be removed and
  4. a Black Soul Gem should appear in my inventory. 
  5. However, the problem is that even if i don´t have another one to remove

refine to this

  1. On activate The Shrine
  2. If The Shrine contain THE BACK  SOUL GEM (or whatever)
  3. If the player has weaker soul gem item to trade
    1. If trade the item? (infinite spawning whatever you desire etc)
    2. remove the player lessar item to oblivion
  4. Else Do Nothing

then you check the API

Boom Shaka La you got your code, Notice it is purely the logic at this stage? you do not start writing the code until you have the logic as guide for your code, trust me when I said this, you cannot make it up as you go.. 

Let me show you this

https://ck.uesp.net/wiki/RemoveItem_-_ObjectReference

Function RemoveItem(Form akItemToRemove, int aiCount = 1, bool abSilent = false, ObjectReference akOtherContainer = None) native

let remove the soul gem from the shrine and give to the player 

Shrine.RemoveItem(BlackSoulGem, 1, false, Game.GetPlayer())

that how you trade a unique item in the game, using the reference window in the Kit you place a black soul gem in the shrine and then transfer it to the player, while sending the lesser soul gem in the player inventory to oblivion

 are you sure you got your code worked out?, I do not think you have even place black soul gem in the shrine using the  reference window in the creation kit))) I know this to true cos unlike IsharaMeradin I can read your code, and I do not see an ObjectReference

Just because a soul gem is removed from player inventory and Black one added doesn't mean it work out at all, you got a lot of work to do here here mate, validating the shrine and transferring the item for starters

 

Link to comment
Share on other sites

PS if you intent is infinite spawning as long as you have a trade item, please say so, it really matters OK, regarding the code, if the item is once off and unique, that matters too, be clear about what your after.

If it reset after so many games days, that matters tooo.....

Link to comment
Share on other sites

The thing is, I've only been scripting for a week and I have no experience in this area. I'm just starting out with the first steps. In my head I know how it should work, but I have realized that an identical implementation is not possible, but has to be done via detours and steps that are not obvious at first glance. What makes it even more difficult is that I have not yet found a tutorial in my language, which is also related to the game and the scripting

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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