Jump to content

Photo

I need help with my skyrim script

papyrus script need help

  • Please log in to reply
10 replies to this topic

#1
Shockyyy

Shockyyy

    Stranger

  • Members
  • Pip
  • 5 posts

So I am a beginner in coding things, but I spent a whole day writing this script and trying to get it to work, it works in some way, but not fully. The main idea for the script is kind of simple: When I press a specific key on my keyboard it must spawn the creature, which i binded for this key. Also I wrote in the beginning that game will show a message when I load a save or start a new game. I compiled the script, it said that everything compiled succesfully and without any troubles. Then I opened the Creation Kit and selected Skyrim.esm and Update.esm as a master files and added a new quest, and in the quest properties I added my script and just saved it. Everything seemed fine, but the thing is that it shows the message when i load save or start a new game, but it doesn't spawn any creatures that i binded. I just don't know what I should do, but I have a feeling that I did something wrong in creation kit. Please help me, I just want to get this thing to work. (I attached the script file and also wrote it in this spoiler)

Spoiler
 


Edited by Shockyyy, 15 April 2021 - 04:16 PM.


#2
dylbill

dylbill

    Resident poster

  • Premium Member
  • 2,948 posts

For the OnKeyDown instead of using Game.GetForm I would just use the properties directly, same for the spawnRandomUnit function. For this you can use a formlist filled with actor bases, that way you can keep it dynamic. For actors, use PlaceActorAtMe(ActorBase) instead of PlaceAtMe: 

Formlist Property MyActorBases Auto

FUNCTION spawnRandomUnit()
    int randomIndex = utility.randomInt(0, MyActorBases.GetSize() - 1)
    ObjectReference newUnit = PlayerRef.PlaceActorAtMe(MyActorBases.GetAt(randomIndex) as ActorBase)
    ; newUnit.SetScale(getRandomScale())
endFUNCTION 

 

Also, make sure your properties are filled. In the CK, click on your script, click on the Properties button and click Auto Fill All. If they are named the same in the script as in the CK they will automatically set. Otherwise you can set them manually by clicking on the property and then Edit Value.



#3
Shockyyy

Shockyyy

    Stranger

  • Members
  • Pip
  • 5 posts

I did the Auto Fill thing and it worked! (Thank you) But not at all, it turned on this line to spawn cheese every second:

; ; SPAWN CHEESE WHEEL
	 spawnItemsAtPlayer(Game.GetForm(0x00064B33), 10)

But the binds for spawning still didn't work. Also I didn't fully understand you with this replacing Game.GetForm thing. What should I do with it? And about that spawnRandomUnit, I don't really use it, I just need the spawn thing to work.


Edited by Shockyyy, 15 April 2021 - 05:58 PM.


#4
dylbill

dylbill

    Resident poster

  • Premium Member
  • 2,948 posts

So to do properties directly you would do something like this. Again for actors use PlaceActorAtMe. Since that function doesn't have an amount, it only places 1 actor, you could set up another function to place multiple actors:

 

Actorbase Property EncMammothWild Auto 

Event OnKeyDown (int keyCode)
    if (KeyCode == 21) ;Y
        ; SPAWN MAMMOTHS
        PlaceMultipleActorAtMe(PlayerRef, EncMammothWild, 10) ;place 10 mamoths at player.
    Endif
EndEvent

Function PlaceMultipleActorAtMe(ObjectReference Ref, Actorbase akActorBase, Int Amount) 
    While Amount > 0 
        Ref.PlaceActorAtMe(akActorBase) 
        Amount -= 1 
    EndWhile 
EndFunction

You could also use a formlist. Drag and drop the actors or items you want to spawn into a new formlist (found in the miscellaneous section of the CK). Then do something like this:

Formlist Property MyItems Auto 

Event OnKeyDown (int keyCode)
    if (KeyCode == 21) ;Y
        ; SPAWN MAMMOTHS
        PlaceMultipleAtMe(PlayerRef, MyItems.GetAt(0), 10) ;Place 10 items at the player that's index 0 of the formlist
    elseif (KeyCode == 79) ;Numpad1
        ; SPAWN CHEESE
        PlaceMultipleAtMe(PlayerRef, MyItems.GetAt(1), 10) ;Place 10 items at the player that's index 1 of the formlist
    Endif
EndEvent

Function PlaceMultipleAtMe(ObjectReference Ref, Form Item, Int Amount) 
    If Item As ActorBase ;is the item an actor?
        Actorbase akActorBase = Item as ActorBase
        While Amount > 0 
            Ref.PlaceActorAtMe(akActorBase) 
            Amount -= 1 ;subract 1 from amount. While loop will repeat until amount is 0.
        EndWhile 
    Else 
        Ref.PlaceAtMe(Item, Amount)
    Endif 
EndFunction

I changed the function so that it will detect actor bases automatically.



#5
Shadeybladey

Shadeybladey

    Ansfrida Eyowulfsdottir, Druid Witch Queen of All Skyrim!

  • Premium Member
  • 2,733 posts

...I spent a whole day writing this script and trying to get it to work, it works in some way, but not fully. 

 

It's a long time since I wrote scripts, but one thing I do know is that you MUST test the script on a saved game file that has never seen your mod. Trying to fix a script and re-testing on a save that has the old version baked in won't work. I learned this at a great cost of time and frustration and several clumps of hair!

 

:smile:



#6
Shockyyy

Shockyyy

    Stranger

  • Members
  • Pip
  • 5 posts

you MUST test the script on a saved game file that has never seen your mod. 

I am always starting a new game when I want to test it



#7
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 10,541 posts

I know why your script was spawning cheese every second.  In the OnInit event you register for an update after 5 seconds.  In the OnUpdate event you've commented out every line but spawning the cheese and re-registering for an update after 1 second.  So... every second it will spawn cheese.

 

If it is still on your script, remove the following line as it is overriding the SKSE variant.

Function RegisterForKey(int keyCode) native

With that line in your script, you'll never get your keys properly registered.



#8
Shockyyy

Shockyyy

    Stranger

  • Members
  • Pip
  • 5 posts

I know why your script was spawning cheese every second. 

And I know it too. It is just another function that I decided to do and it works perfectly.

About Function RegisterForKey: If I delete that line then the script will not compile. It says that RegisterForKey is not a function or does not exist.



#9
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 10,541 posts

Make sure you have properly installed SKSE's PSC files.  Otherwise, the compiler will tell you that that function does not exist because it cannot find it on the script where it is supposed to be.



#10
Shockyyy

Shockyyy

    Stranger

  • Members
  • Pip
  • 5 posts

Skse installed, all of the .pex files are in the Data/Scipts and all of the .psc files are in the Data/Scripts/Source







Also tagged with one or more of these keywords: papyrus, script, need help

IPB skins by Skinbox
Page loaded in: 1.199 seconds