Jump to content
ℹ️ Intermittent Download History issues ×

[LE] Help with a simple issue compiling a script


SamHe11

Recommended Posts

I'm new to papyrus scripting and am having some trouble transitioning from Oblivion script, which I was pretty good at years ago. I've spent a couple nights going over the beginner scripting tutorials on the CS website. I've tried applying what I've learned from them to create a script that forces a third person camera when the player's weapon is drawn, and then forces a first person camera when sheathed. Pretty simple. The script is attached to a quest that auto starts when the game loads. But what I have so far isn't compiling. I'm getting a couple of errors that have me stumped. Here's what it looks like:

 

Scriptname shCameraScript extends Actor 
{Script for forcing the camera in or out depending on if the player has a weapon drawn.}

bool WeaponOut = player.isweapondrawn()

Function ForceFirstPerson() global

  if WeaponOut == true
    game.forcethirdperson()
  elseif WeaponOut == false
    game.forcefirstperson()
endif

endFunction

And the compiler output says this:

 

Starting 1 compile threads for 1 files...
Compiling "shCameraScript"...
C:\program files (x86)\steam\steamapps\common\Skyrim\Data\Scripts\Source\temp\shCameraScript.psc(4,17): no viable alternative at input 'player'
C:\program files (x86)\steam\steamapps\common\Skyrim\Data\Scripts\Source\temp\shCameraScript.psc(4,23): required (...)+ loop did not match anything at input '.'
C:\program files (x86)\steam\steamapps\common\Skyrim\Data\Scripts\Source\temp\shCameraScript.psc(4,5): Unknown user flag player
No output generated for shCameraScript, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on shCameraScript

 

Not really sure what to do at this point.

Link to comment
Share on other sites

There's at least two errors here:

 

1. When declaring a variable value outside of a function or event, it must be a literal: A specific string, integer, float, etc.

2. If you fix that, your script will do nothing, since nothing will call your function; you'll need to hook into an event of some sort to call it. Offhand I don't know of any that trigger on weapon draws and sheathing, but you might be able to register for animation events and use those. It's not an area I'm especially familiar with, though.

Edited by foamyesque
Link to comment
Share on other sites

Here is an untested but compiles without error example of how one can get something to take place when the player draws and sheathes their weapon.

 

 

Scriptname CameraSwitchOnWeaponUse extends Quest

Actor PlayerRef 	;local variable to reference the player
Bool CIF = false 	;local variable to reference camera state - CIF stands for Camera In First

Event OnInit()
	RegisterForActorAction(0)	;weapon swing
	RegisterForActorAction(1)	;spell cast
	RegisterForActorAction(8)	;draw end - catches both spells and weapons
	RegisterForActorAction(10)	;sheath end - catches both spells and weapons
	PlayerRef = Game.GetPlayer()	;assign player data to the local variable
EndEvent

Event OnActorAction(int actionType, Actor akActor, Form source, int slot)
	If akActor == PlayerRef					;is the actor the player
		If !PlayerRef.IsInCombat()			;player is not fighting - switch camera with sheath and draw
			If actionType == 8				;draw end
				Game.ForceThirdPerson()		;switch to third
				CIF = false					;designate camera state
			ElseIf actionType == 10			;sheath end
				Game.ForceFirstPerson()		;switch to first
				CIF = true					;designate camera state
			EndIf
		Else 										;player is fighting - check camera state and swap if necessary
			If (actionType == 0 || actionType == 1)	;if swinging weapon or casting spell/stave
				If CIF == true						;check current camera state, process if in first person
					Game.ForceThirdPerson()			;switch to third
					CIF = false						;designate camera state
				EndIf
			EndIf
		EndIf
	EndIf
EndEvent 

 

There is concern that with drawing and sheathing only, the event will trigger twice when swapping between weapons while weapons are drawn. Therefore, there is additional code which checks whether the player is in combat and if they are checks the camera state and swaps on weapon swing or spell cast as needed and then blocks the camera from switching until combat is over and weapons are sheathed..

 

Link to comment
Share on other sites

Thanks for the help. I took your comment about the player switching weapons/spells while drawn into consideration and decided to revamp the script to check/force camera perspective when the "Ready Weapon" control is triggered instead. The script I now have compiles, but nothing's happening when I push the Ready Weapon button. Here's how it looks:

 

 

Scriptname shCameraScript extends Quest
{Script for forcing the camera in or out depending on if the player has a weapon drawn.}


Function RegisterForControl(string control) native


Event OnInit()

    RegisterForControl("Ready Weapon")
    debug.messagebox("Quest running. Control registered.")

EndEvent



Event OnControlDown(string control)

    If control == "Ready Weapon"
        Debug.MessageBox("Ready Weapon button has been pressed.") ;This is where the camera logic takes place, but keeping it simple right now for testing purposes
    EndIf

EndEvent

 

 

 

The first message fires telling me the quest and script are starting correctly, but the debug message isn't popping up when the Ready Weapon control is pressed. I have the quest set to Start Game Enabled and Run Once. Is the script only processing once and then stopping b/c of a quest setting? Or do I just not have the code right? It's compiling...no errors for once...but nothing's happening when the Ready Weapon control is pressed.

Link to comment
Share on other sites

First, RegisterForControl and OnControlDown are both SKSE functions/events. Therefore, make sure that you run the game via SKSE.

 

This is what the problem was. I'd already installed SKSE, but I didn't have it extracted to the proper directories, hence the compiler not recognizing any of the SKSE functions. When I reinstalled it, everything worked perfectly. Thanks for the help. Sorry I'm such a bonehead.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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