Jump to content

[LE] Script to Spawn NPC at the Player


Recommended Posts

Could somebody take a look at my script and tell me what I've done wrong. I wanted to create a script that would spawn an NPC at the player when they activate my activator and do other things as well, everything else works except for the npc spawning. I've read just about all I could on the wiki and here's what I came up with....

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

ScriptName MMFTDemonicShrine1 extends ObjectReference

Armor property DiscipleRobes auto
Armor property GoatHead auto
Weapon property DaggerofCeremony auto
Perk property MarkoftheDamned auto
Actor Property Familiar auto
Spell property AzazelCurse auto
ActorBase MyActorBase

Event OnActivate(ObjectReference akActionRef)
If akActionRef == Game . GetPlayer() ; only the pla yer can activate this
ObjectReference SelfObj = Self as ObjectReference
AzazelCurse.cast(SelfObj, game.getplayer())
Game. GetPlayer(). AddItem(DiscipleRobes, 1, true)
Game.GetPlayer().AddItem(GoatHead, 1, true)
Game.GetPlayer().AddItem(DaggerofCeremony, 1, true)
Game.GetPlayer().EquipItem(DiscipleRobes)
Game.GetPlayer().EquipItem(GoatHead)
Game.GetPlayer().EquipItem(DaggerofCeremony)
Game.GetPlayer().AddPerk(MarkoftheDamned)
MyActorBase = Familiar.GetBaseObject() as ActorBase
PlaceActorAtMe(MyActorBase)
utility.wait(1)
SelfObj.delete()
EndIf
EndEvent

 

 

-----------------------------------------------------------------------------------------------------------------------------------------

 

....Like I said everything else works except the Npc I'm trying to spawn doesn't spawn. I looked up all I could on the CK wiki, so now I turn to you skyrim modding community :cool:

Link to comment
Share on other sites

What do you have in that Actor property? Because that only works with things that are already spawned in the world. I think if you replace it with an ActorBase property instead, and then use that directly in the PlaceAtMe, it should work correctly.

Link to comment
Share on other sites

Yeah it worked :laugh:! Thanks for the help guys I realized that foamyerque was right an that the actor would already have to be in skyrim, other wise I'd have to do as Ghaunadaur said.

here's the new script in case anybody wants to know

 

------------------------------------------------------------------------------------------------------------------------------------------------

 

ScriptName MMFTDemonicShrine1 extends ObjectReference

Armor property DiscipleRobes auto
Armor property GoatHead auto
Weapon property DaggerofCeremony auto
Perk property MarkoftheDamned auto
Spell property AzazelCurse auto
ActorBase property MyActorBase auto

Event OnActivate(ObjectReference akActionRef)
If akActionRef == Game . GetPlayer() ; only the pla yer can activate this
ObjectReference SelfObj = Self as ObjectReference
AzazelCurse.cast(SelfObj, game.getplayer())
Game. GetPlayer(). AddItem(DiscipleRobes, 1, true)
Game.GetPlayer().AddItem(GoatHead, 1, true)
Game.GetPlayer().AddItem(DaggerofCeremony, 1, true)
Game.GetPlayer().EquipItem(DiscipleRobes)
Game.GetPlayer().EquipItem(GoatHead)
Game.GetPlayer().EquipItem(DaggerofCeremony)
Game.GetPlayer().AddPerk(MarkoftheDamned)
Game.GetPlayer().PlaceActorAtMe(MyActorBase)
utility.wait(1)
SelfObj.delete()
EndIf
EndEvent

 

-------------------------------------------------------------------------------------------------------------------------------------------------------

 

now that he spawns I have to figure out how to place him instead of spawning literally right at the player, like say behind the player. I'll check the wiki but if anybody knows how please let me know. Thanks again guys :laugh:

Link to comment
Share on other sites

Thanks for the reply I'm stuck though trying to move the NPC. I don't think the marker will work either because if I cant move the Npc I don't think I'd be able to move the marker.

This is my script:

------------------------------------------------------------------------------------------------------------------------------------------------

 

ScriptName MMFTDemonicShrine1 extends ObjectReference

Armor property DiscipleRobes auto
Armor property GoatHead auto
Weapon property DaggerofCeremony auto
Perk property MarkoftheDamned auto
Spell property AzazelCurse auto
ActorBase property MyActorBase auto

 

Function MoveTo(ObjectReference akTarget, float afXOffset = 0.0,
float afYOffset = 0.0, float afZOffset = 0.0, bool abMatchRotation = false ) native
Event OnActivate(ObjectReference akActionRef)
If akActionRef == Game . GetPlayer() ; only the player can activate this
ObjectReference SelfObj = Self as ObjectReference
AzazelCurse.cast(SelfObj, game.getplayer())
Game. GetPlayer(). AddItem(DiscipleRobes, 1, true)
Game.GetPlayer().AddItem(GoatHead, 1, true)
Game.GetPlayer().AddItem(DaggerofCeremony, 1, true)
Game.GetPlayer().EquipItem(DiscipleRobes)
Game.GetPlayer().EquipItem(GoatHead)
Game.GetPlayer().EquipItem(DaggerofCeremony)
Game.GetPlayer().AddPerk(MarkoftheDamned)
Game.GetPlayer().PlaceActorAtMe(MyActorBase)

Actor PlayerRef = Game.GetPlayer()
MyActorBase.SetPosition(PlayerRef, 120.0 * Math. Sin (Player Ref.GetAngleZ()), 120.0 * Math. Cos (Player Ref.GetAngleZ()), PlayerRef.GetHeight())
utility.wait(1)
SelfObj.delete()
EndIf
EndEvent

EndFunction

 

-------------------------------------------------------------------------------------------------------------------------------------------------------

 

This is the script I came up with based on the reading the wiki. Whenever I try to compile I get failed. it says

 

no viable alternative at input '\\r\\n'

error while attempting to read script MMFTDemonicShrine1: Object reference not set to an instance of an object.

Not sure what that means. My first thought was that it doesn't know what actor to move since Myactorbase is an Actorbase not an Actor. So i tried setting the setposition command right after the spawn so it was like this:

Game.GetPlayer().PlaceActorAtMe(MyActorBase.SetPosition(PlayerRef, 120.0 * Math.Sin(PlayerRef.GetAngleZ()), 120.0 * Math.Cos(PlayerRef.GetAngleZ()), PlayerRef.GetHeight())

But I still got the same error, so than I tried changeing the Setposition command to MoveTo but ended up with the same results. Any thoughts or suggestions? I feel like it should be a simple script but its driving me crazy.

 

Oh yeah I even tried setting akTarget as a property like

Actor property akTarget auto

Than in the Ck i was going to put the akTarget property to be the player but it still didn't compile. I tried replacing the aktarget with Game.GetPlayer() but still no luck.

Edited by mmft93
Link to comment
Share on other sites

The actor reference can be stored like this:

 

Actor MyActorRef = Game.GetPlayer().PlaceActorAtMe(MyActorBase)

 

SetPosition is expecting an ObjectReference, so you may need to make a cast

 

(MyActorRef as ObjectReference).SetPosition(PlayerRef, 120.0 * Math. Sin (Player Ref.GetAngleZ()), 120.0 * Math. Cos (Player Ref.GetAngleZ()), PlayerRef.GetHeight())

 

Cleaned up script:

ScriptName MMFTDemonicShrine1 extends ObjectReference

Armor property DiscipleRobes auto
Armor property GoatHead auto
Weapon property DaggerofCeremony auto
Perk property MarkoftheDamned auto
Spell property AzazelCurse auto
ActorBase property MyActorBase auto


Event OnActivate(ObjectReference akActionRef)
    Actor PlayerRef = Game.GetPlayer()
    If akActionRef  ==   PlayerRef  ; only the player can activate this
        ObjectReference  SelfObj = Self as ObjectReference 
        AzazelCurse.cast(SelfObj, game.getplayer())
        PlayerRef.AddItem(DiscipleRobes, 1, true) 
        PlayerRef.AddItem(GoatHead, 1, true)
        PlayerRef.AddItem(DaggerofCeremony, 1, true)
        PlayerRef.EquipItem(DiscipleRobes)
        PlayerRef.EquipItem(GoatHead)
        PlayerRef.EquipItem(DaggerofCeremony)
        PlayerRef.AddPerk(MarkoftheDamned)
        Actor MyActorRef = PlayerRef.PlaceActorAtMe(MyActorBase)
        (MyActorRef as ObjectReference).SetPosition(120.0 * Math.Sin(PlayerRef.GetAngleZ()), 120.0 * Math.Cos(PlayerRef.GetAngleZ()), PlayerRef.GetHeight()) 
        utility.wait(1)
        SelfObj.delete()
    EndIf
EndEvent
Edited by Ghaunadaur
Link to comment
Share on other sites

Hey thanks guys for the reply. Sorry got busy with finales. I still wasn't able to move the new actor, but I found it easier to have markers already placed in the area and than just spawn the new NPC at those markers. :) thanks again for the replies.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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