Jump to content

A problem with game.getplayer()


wangcx

Recommended Posts

Hello guys,

 

I'm new here and a beginner to Papyrus scripting, and It's my first time to ask a question on this site, so thank u very much .

 

I intended to add a follower , who is sneaking when not in combat, and stop sneaking when combat starts.

 

Creationkit.com says my script should be "Game.GetPlayer().StartSneaking()" , but that's the action for the player, not for the specific NPC I am adding. How could I replace "Game.GetPlayer()"with another one to make it work, or is there a better way to solve this problem?

 

Thanks again for your help :smile:

Link to comment
Share on other sites

First question is this: Where is the script located?

 

The location of the script determines how the script is written.

 

Myself, I'd put the script on either the follower's actor record or on a quest alias that points to the follower's actor record.

 

On the actor record I would have:

 

 

Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
	If	(aeCombatState == 0)  ;not in combat
		If	!(Self.IsSneaking())
			Self.StartSneaking()	;starts sneak
		EndIf
	Else
		If	(Self.IsSneaking())
			Self.StartSneaking()	;cancel sneak
		EndIf
	EndIf
EndEvent 

 

On the alias record I would have:

Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
	If	(aeCombatState == 0)  ;not in combat
		If	!(Self.GetActorRef().IsSneaking())
			Self.GetActorRef().StartSneaking()	;starts sneak
		EndIf
	Else
		If	(Self.GetActorRef().IsSneaking())
			Self.GetActorRef().StartSneaking()	;cancel sneak
		EndIf
	EndIf
EndEvent 

Link to comment
Share on other sites

First question is this: Where is the script located?

 

The location of the script determines how the script is written.

 

Myself, I'd put the script on either the follower's actor record or on a quest alias that points to the follower's actor record.

 

On the actor record I would have:

 

 

Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
	If	(aeCombatState == 0)  ;not in combat
		If	!(Self.IsSneaking())
			Self.StartSneaking()	;starts sneak
		EndIf
	Else
		If	(Self.IsSneaking())
			Self.StartSneaking()	;cancel sneak
		EndIf
	EndIf
EndEvent 

 

 

Thanks very much for your help. :smile:

No, my script is located in a reference object (a specific NPC), is that suppose to be okay? :ohmy:

And I still have a question.

As you said in your actor record, after the word "else":

If (Self.IsSneaking())

Self.StartSneaking() ;cancel sneak

EndIf

how does this work? Do you mean when the NPC is not in combat , already not hiding but start sneaking? How? I mean he's not sneaking the moment he's out of combat, how can it enter this "if"?

And also, sneaking plus sneaking equals not sneaking? Which....you know what i mean?

 

And a stupid question : how can i define the function "StartSneaking " And "IsSneaking" :sad:

Edited by wangcx
Link to comment
Share on other sites

The function StartSneaking() is a toggle. If the actor is sneaking it will make them stop sneaking. If the actor is not sneaking it will make them start sneaking. IsSneaking is a default papyrus function to check if the actor in question is sneaking or not.

 

What the script event I posted would do is the following:

When combat status changes and no combat is going on make sure I am not already sneaking and go into sneak mode. Otherwise if any other combat status is going on check to see if I am sneaking, if I am stop sneaking.

 

Putting the script on the reference object of the NPC should be ok. If you had put the script on the actor record itself, the reference object would inherit the script anyway.

Link to comment
Share on other sites

The function StartSneaking() is a toggle. If the actor is sneaking it will make them stop sneaking. If the actor is not sneaking it will make them start sneaking. IsSneaking is a default papyrus function to check if the actor in question is sneaking or not.

 

What the script event I posted would do is the following:

When combat status changes and no combat is going on make sure I am not already sneaking and go into sneak mode. Otherwise if any other combat status is going on check to see if I am sneaking, if I am stop sneaking.

 

Putting the script on the reference object of the NPC should be ok. If you had put the script on the actor record itself, the reference object would inherit the script anyway.

Thanks. I put the script in the reference object.

The compilation passed, but I don't think it actually works. There's no other mods or scripts currently being used, but The NPC is still standing there, doing nothing, whenever he's in or out of combat. :(

Perhaps there's something wrong I did? I still don't understand...

Link to comment
Share on other sites

AI packages might conflict and/or override scripted behavior. If you have no AI packages running, then I'm at a loss. You can always try setting up a quest alias that points to the actor and applying the alias variation of the script event. Beyond that, at this point, I have no idea.

Link to comment
Share on other sites

AI packages might conflict and/or override scripted behavior. If you have no AI packages running, then I'm at a loss. You can always try setting up a quest alias that points to the actor and applying the alias variation of the script event. Beyond that, at this point, I have no idea.

Yeah.. I guess so.

In fact, I set all the selections in AI packages to "none", but the NPC is still moving around ,go to sit on a chair, get close to fireplace, etc. He still has that sort of actions, instead of standing at where he was. I guess this is the reason why he doesn't listen to me :pinch: But I've already set all AI package to "none"!

And also, both methods you gave to me proved to be not working. :sad:

Link to comment
Share on other sites

  • Recently Browsing   0 members

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