Jump to content

[LE] I need help with my skyrim script


Shockyyy

Recommended 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)

 

  Reveal hidden contents

 

Edited by Shockyyy
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  On 4/15/2021 at 4:06 PM, Shockyyy said:

...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:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  On 4/17/2021 at 3:50 AM, IsharaMeradin said:

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.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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