Vanilord Posted January 20, 2021 Share Posted January 20, 2021 (edited) Hello everyone ! I started learning to script in skyrim a few days ago. It's a lot of fun but I'm having some difficulties. I'm trying to make a certain object or NPC appear when I press a key.For now, the script is compile, is recognized, starts to run at launch and a debug message appears when I press the different keys. But no other action is happening. What do I need to change for the script to work ?Thanks for your help! :D ScriptName SpawnerScript1 extends Quest {This is my first script} Actor Property PlayerRef Auto ObjectReference property SpawnPlace auto Event OnInit() Debug.Notification("Debug 1") Debug.MessageBox ("Debug 2") RegisterForsingleUpdate(5) RegisterForKey(79) ; Numpad1 RegisterForkey(80) ; Numpad2 RegisterForkey(81) ; Numpad3 RegisterForKey(75) ; Numpad4 RegisterForkey(76) ; Numpad5 RegisterForkey(77) ; Numpad6 RegisterForkey(71) ; Numpad7 RegisterForkey(72) ; Numpad8 RegisterForKey(73) ; Numpad9 EndEvent Event OnUpdate() RegisterForSingleUpdate (1) EndEvent Event OnKeyDown(Int KeyCode) if (KeyCode == 79) spawnItemsAtPlayer(Game.GetForm(0x00064B33), 1) ; Spawn 1 cheese Debug.Notification("Numpad 1") elseif (KeyCode == 80) PlayerRef.PlaceAtMe(Game.GetForm(0x0001CA03), 10) ; Spawn 1 wolf Debug.Notification("Numpad 2") elseif (KeyCode == 81) PlayerRef.PlaceAtMe(Game.GetForm (0x00023A8A), 1) ; Spawn 1 bear Debug.Notification("Numpad 3") endif EndEvent Function spawnItemsAtPlayer (Form itemForm, int spawnCount = 1) while (spawnCount > 0) PlayerRef.AddItem (itemForm, 1, true) PlayerRef.Dropobject(itemForm, 1) spawnCount -= 1 endwhile EndFunction Edited January 21, 2021 by Vanilord Link to comment Share on other sites More sharing options...
IsharaMeradin Posted January 20, 2021 Share Posted January 20, 2021 (edited) I would approach it the following way. Formlist(s) to hold the items you want to drop and properties to hold the actors you want to spawn. You also need to use PlaceActorAtMe for your actors instead of PlaceAtMe. The wiki indicates that GetForm should not be used beyond debugging purposes. So if properties are not viable for some reason, you can use GetFormFromFile instead. The following is an adaptation of what you posted converted to how I would do it. The script compiles but has not been tested in-game. ScriptName SpawnerScript1 extends Quest {This is my first script} Actor Property PlayerRef Auto ObjectReference property SpawnPlace auto FormList Property Numpad1Items Auto ; create formlist and drag-n-drop the items you want in the formlist Actor Property Numpad2Actor Auto Actor Property Numpad3Actor Auto Event OnInit() Debug.Notification("Spawner quest started") RegisterForsingleUpdate(1.0) EndEvent Event OnUpdate() RegisterForKey(79) ; Numpad1 RegisterForkey(80) ; Numpad2 RegisterForkey(81) ; Numpad3 RegisterForKey(75) ; Numpad4 RegisterForkey(76) ; Numpad5 RegisterForkey(77) ; Numpad6 RegisterForkey(71) ; Numpad7 RegisterForkey(72) ; Numpad8 RegisterForKey(73) ; Numpad9 Debug.MessageBox ("Numpad Keys are registered") EndEvent Event OnKeyDown(Int KeyCode) if (KeyCode == 79) spawnItemsAtPlayer(Numpad1Items, 1) ; Spawn 1 cheese Debug.Notification("Numpad 1") elseif (KeyCode == 80) PlayerRef.PlaceActorAtMe(Numpad2Actor.GetBaseObject() as ActorBase) ; Spawn actor assigned to Numpad2Actor property Debug.Notification("Numpad 2") elseif (KeyCode == 81) PlayerRef.PlaceActorAtMe(Numpad3Actor.GetBaseObject() as ActorBase) ; Spawn actor assigned to Numpdad3Actor property Debug.Notification("Numpad 3") elseif (KeyCode == 75) Debug.Notification("Numpad 4") elseif (KeyCode == 76) Debug.Notification("Numpad 5") elseif (KeyCode == 77) Debug.Notification("Numpad 6") elseif (KeyCode == 71) Debug.Notification("Numpad 7") elseif (KeyCode == 72) Debug.Notification("Numpad 8") elseif (KeyCode == 73) Debug.Notification("Numpad 9") endif EndEvent Function spawnItemsAtPlayer(FormList ItemList = None, int spawnCount = 1) Int index = 0 If ItemList != None While index < ItemList.GetSize() Form Entry = ItemList.GetAt(index) If Entry ;make sure the item is valid While spawnCount > 0 PlayerRef.PlaceAtMe(Entry,1) spawnCount -= 1 EndWhile EndIf index += 1 EndWhile EndIf EndFunction Edited January 20, 2021 by IsharaMeradin Link to comment Share on other sites More sharing options...
Vanilord Posted January 20, 2021 Author Share Posted January 20, 2021 (edited) Thanks for the quick answer and the clean code ! I've tried to make your revised code work, but my limited understanding of formlist seems to block me. I read the wiki but I don't understand if I'm suppose to create a file outside of my script or create the formlist inside. The GetFormFromFile seems not necessary for this case, as I only want to make spawn vanilla items and npc. I tried some variations but none of my garbage worked. PlayerRef.PlaceAtMe(Game.GetFormFromFile(0x00013478, "Skyrim.esm") as ActorBase) PlayerRef.PlaceAtMe(Game.GetFormFromFile(0x00013478, "Skyrim.esm") as Actor) PlayerRef.PlaceAtMe(Game.GetFormFromFile(0x00013BBF, "Skyrim.esm") as Actor) I made a simpler version of the code for testing but the formlist is out of my range :pinch: ScriptName BasicSpawn extends Quest {This is still my first script} Actor Property PlayerRef Auto FormList Property Numpad1Items Auto ; create formlist ? How ? Actor Property Numpad2Actor Auto FormList Property ListOfCreatures auto ; formlist ? where ? how ? Actor Property Creature1 Auto ; useseful ? Event OnInit() Debug.Notification("Spawner quest started") RegisterForsingleUpdate(1.0) EndEvent Event OnUpdate() RegisterForKey(79) ; Numpad1 RegisterForkey(80) ; Numpad2 Debug.MessageBox ("Numpad Keys are registered") EndEvent Event OnKeyDown(Int KeyCode) ; When a key is pressed, an item or an NPC spawn. if (KeyCode == 79) PlayerRef.PlaceActorAtMe(Numpad2Actor.GetBaseObject() as ActorBase) ; Spawn actor assigned to Numpad2Actor property ? How ? Debug.Notification("Numpad 2") endif EndEvent Edited January 21, 2021 by Vanilord Link to comment Share on other sites More sharing options...
dylbill Posted January 20, 2021 Share Posted January 20, 2021 For formlists, you make them in the creation kit under Miscellaneous / Formlist. You drag and drop other forms into it. Also make sure your properties are filled. Alternatively, if you don't want to use a formlist, you can put the property directly in the script. Name it the same as it is in the CK and click Auto Fill All in the script property menu and they will be automatically set. With formlist: Actor Property PlayerRef Auto FormList Property Numpad1Items Auto ; create formlist ? How ? Actor Property Numpad2Actor Auto Formlist Property ListOfCreatures auto ; formlist ? where ? how ? Actor Property Creature1 Auto ; useseful ? Event OnInit() Debug.Notification("Spawner quest started") RegisterForsingleUpdate(1.0) EndEvent Event OnUpdate() RegisterForKey(79) ; Numpad1 RegisterForkey(80) ; Numpad2 Debug.MessageBox ("Numpad Keys are registered") EndEvent Event OnKeyDown(Int KeyCode) ; When a key is pressed, an item or an NPC spawn. if (KeyCode == 79) Creature1 = PlayerRef.PlaceActorAtMe(ListOfCreatures.GetAt(0) as actorbase) ; Spawn actor in slot 0 of formlist and save to creature1 Debug.Notification("Numpad 2") endif EndEvent With a direct property: Actor Property PlayerRef Auto ActorBase Property EncFrostbiteSpider auto ; Actor Property Creature1 Auto ; useseful ? Event OnInit() Debug.Notification("Spawner quest started") RegisterForsingleUpdate(1.0) EndEvent Event OnUpdate() RegisterForKey(79) ; Numpad1 RegisterForkey(80) ; Numpad2 Debug.MessageBox ("Numpad Keys are registered") EndEvent Event OnKeyDown(Int KeyCode) ; When a key is pressed, an item or an NPC spawn. if (KeyCode == 79) Creature1 = PlayerRef.PlaceActorAtMe(EncFrostbiteSpider) ; Spawn spider and save to creature1 Debug.Notification("Numpad 2") endif EndEvent Link to comment Share on other sites More sharing options...
Vanilord Posted January 21, 2021 Author Share Posted January 21, 2021 (edited) I've found the formlists in the creation kit under Miscellaneous, I'll have ti dive into it to understand it properly. Is it normal that the version "With a direct property" don't spawn anything ? In a simpler manner would it be possible to make an item/NPC spawn with only the Base ID ? If so how ? As far as I understand, nothing happen because the script doesn't know what "EncFrostbiteSpider" refers to. Or do the game understand what "EncFrostbiteSpider" refers to ? Scriptname dylbill1 extends Quest {Just something I use to test stuff.} Actor Property PlayerRef Auto ActorBase Property EncFrostbiteSpider auto ; ActorBase Property WolfBaseProperty auto ActorBase Property EncTrollFrost auto ActorBase Property EncWolf auto Actor Property Creature1 Auto ; useseful ? Event OnInit() Debug.Notification("Spawner quest started") RegisterForsingleUpdate(1.0) EndEvent Event OnUpdate() RegisterForKey(79) ; Numpad1 ;Debug.MessageBox ("Numpad Keys are registered") EndEvent Event OnKeyDown(Int KeyCode) ; When a key is pressed, an item or an NPC spawn. if (KeyCode == 79) Creature1 = PlayerRef.PlaceActorAtMe(EncFrostbiteSpider) ; Spawn spider and save to creature1 PlayerRef.PlaceActorAtMe(EncTrollFrost) PlayerRef.PlaceActorAtMe(WolfBaseProperty, 1) PlayerRef.PlaceAtMe(EncWolf, 3) PlayerRef.PlaceActorAtMe(WolfBaseProperty).StartCombat(Game.GetPlayer()) Debug.Notification("Numpad 1") endif EndEvent ; 0x00023ABE : wolf ; Base ID : 00023ABE ; Name : Wolf ; Editor Name : EncWolf Edited January 21, 2021 by Vanilord Link to comment Share on other sites More sharing options...
dylbill Posted January 21, 2021 Share Posted January 21, 2021 You have to fill the properties in the creation kit. After compiling, in the creation kit, click on Properties, then click on Auto Fill All, they should be set automatically if they are named the same as in the creation kit. For other objects you would use PlaceAtMe. MiscObject Property Gold001 Auto Event OnKeyDown(Int KeyCode) PlayerRef.PlaceAtMe(Gold001, 1) ;place one gold piece at the player. EndEvent Link to comment Share on other sites More sharing options...
Vanilord Posted January 21, 2021 Author Share Posted January 21, 2021 That's working ! What was missing is the autofill option ! THANKS ! For those who will find this thread later and wondering how to solve it : 1) Once your script is in CK, double click on your script to go to its menu2) Go to the script tab3) Right click on your script name and select "Edit Properties"4) Click the auto-fill All button5) Click Ok on everything and save your script :) Link to comment Share on other sites More sharing options...
dylbill Posted January 21, 2021 Share Posted January 21, 2021 No problem, happy modding :) Link to comment Share on other sites More sharing options...
Coolstriker64 Posted November 24, 2021 Share Posted November 24, 2021 I'm trying to make this EXACT THING!Have you posted this anywhere?I'm in way over my head here. Link to comment Share on other sites More sharing options...
Recommended Posts