Jump to content

[LE] Script for buying a home


Recommended Posts

So I'm working on a player home mod where the player purchases the home by depositing gold into a strongbox(activator).

 

The player will walk up to the strongbox and activate it. A menu will pop up asking if the player wants to deposit the money or not. If they deposit the money they receive the house key, if they choose not to deposit the money the player exits from the menu. They can exit the menu as many times as they like, but they can only deposit the money once.

 

To be clear, if the player chooses to deposit the money, that money is removed directly from the players inventory.

 

I have no idea how to write this script so if there is anybody out there that can help me out I'd really appreciate it.

Link to comment
Share on other sites

You may wanna take a look at this, is quite easy to do it.

 

Here you will find a script.

https://www.nexusmods.com/skyrim/mods/36756

 

This is to add script commands to be processed when a message button is pressed (from your pop up menu).

http://wiki.tesnexus.com/index.php/Skyrim_Messagebox_Menu_Tutorial

Edited by maxarturo
Link to comment
Share on other sites

No tested by me but you can try:

Scriptname QLG_Script_Nexus001 extends ObjectReference 

	Key Property QKey Auto
	{ Key to give Player }
	
	Int Property QGold Auto
	{ Gold to Collect from Player }
	
	Actor Property QPlayer Auto
	{ Player Ref }
	
	Message Property QMsg Auto
	{ Message to show }
	
	
auto State WaitForPlayer
	Event OnActivate()
	
	Int QReturn = QMsg.show()
	
	If ( QReturn == 1 )						; if Player wanted to buy Key
		If ( QPlayer.GetGoldAmount() > QGold )
			QPlayer.AddItem( QKey , 1 )
			QPlayer.RemoveItem( GoldBase , QGold )
		Else								; Player don't have gold
			Debug.Trace( "You don't have enough Gold !..." )
		EndIf
	EndIf
		
		GoToState( "Done" )
		
	EndEvent
EndState

State Done
	; Do nothing
EndState


Y i know GoToState is in wrong place :)...

but i dont even know that this Script will work or no xD

Edited by TobiaszPL
Link to comment
Share on other sites

No tested by me but you can try:

Scriptname QLG_Script_Nexus001 extends ObjectReference 

	Key Property QKey Auto
	{ Key to give Player }
	
	Int Property QGold Auto
	{ Gold to Collect from Player }
	
	Actor Property QPlayer Auto
	{ Player Ref }
	
	Message Property QMsg Auto
	{ Message to show }
	
	
auto State WaitForPlayer
	Event OnActivate()
	
	Int QReturn = QMsg.show()
	
	If ( QReturn == 1 )						; if Player wanted to buy Key
		If ( QPlayer.GetGoldAmount() > QGold )
			QPlayer.AddItem( QKey , 1 )
			QPlayer.RemoveItem( GoldBase , QGold )
		Else								; Player don't have gold
			Debug.Trace( "You don't have enough Gold !..." )
		EndIf
	EndIf
		
		GoToState( "Done" )
		
	EndEvent
EndState

State Done
	; Do nothing
EndState


Y i know GoToState is in wrong place :smile:...

but i dont even know that this Script will work or no xD

So anywhere where there are brackets like these { } I would fill in that property with the ID of the key, the amount of gold to remove from the player, etc...?

Link to comment
Share on other sites

Nope brackets {} are used for description, so you know what is the above set to do, brackets are not seen by the game's engine reading the script, only you can read it.

You need to go into the scripts property to fill the amount of gold - what message should be shown etc...

Click on the property button, where is the Add Script - Remove Script - Property.

Edited by maxarturo
Link to comment
Share on other sites

If you are simply buying a key, you could use this video from Darkfox127 that allows merchants to sell keys:

 

 

It uses an "OnContainerChange" script which may be helpful to you.

Well I am buying a key, but the vendor is an inanimate object. You're essentially buying the key from a strongbox.

Link to comment
Share on other sites

Ugh bro...

 

1) Open CK ( lel )

2) Create any Message ( find in YT or CK Wiki how to - too much to write here xD )

3) Put on ground any Activator ( Static from Object Window in Activator tab )

4) Double click this activator ( the one on grund in Render Window ) to open Edit Window

5) Scroll to "Script" tab

6) click "Add" on right from Script List

7) Add your script

:cool: clikc ONCE on your script then click "Properties"

9) Fill properties, new window should open and you should see 4 options

10)

- in QKey select your Key

- in QGold set amount of gold that player need to Pay for Key

- in QPlayer click "Auto-Fill" ( button on Right ) and be sure its set to Player and Cell on Any

- in QMessage select your Message Box you create

 

How to Compile Script: ( if this gonna be your first script )

1) Go to your Data

2) Find for "Scripts.zip"

3) Unpack them in ../Skyrim/Data/ < HERE >

4) Restart / Start your CK

5) Select "Gameplay" and "Papyrus Script"

6) Click on List with Right Mouse Button and select "New"

7) Name your Script and in Reference write "ObjectReference"

:cool: Find your created script in Filter

9) Click on your Script with Right Mouse Button and select "Open in External Editor" - Use N++ or something xD

10) Copy my script - but ignore first line ( dont copy first line )

11) Clicl on your Script with Right Mouse Button and select "Compile"

 

if no Errors Compile window should just close

if you got any error paste them here or try to Google :tongue:

 

 

i hope you know how to make MessageBoxes or Keys :tongue:

 

Script ( just Copy and Paste ) - keep your First line that CK create for your Script

 

 

	Key Property QKey Auto
	{ Key to give Player }
	
	Int Property QGold Auto
	{ Gold to Collect from Player }
	
	Actor Property QPlayer Auto
	{ Player Ref }
	
	Message Property QMsg Auto
	{ Message to show }
	
	
auto State WaitForPlayer
	Event OnActivate()
	
	Int QReturn = QMsg.show()
	
	If ( QReturn == 1 )						; if Player wanted to buy Key
		If ( QPlayer.GetGoldAmount() > QGold )
			QPlayer.AddItem( QKey , 1 )
			QPlayer.RemoveItem( GoldBase , QGold )
                        GoToState( "Done" )
		Else								; Player don't have gold
			Debug.Trace( "You don't have enough Gold !..." )
		EndIf
	EndIf
		
	EndEvent
EndState

State Done
	; Do nothing
EndState

 

 

 

Give me few H and i maybe give you my Script to Buy and upgrade houses :x...

cause i want to make few houses in my mod too xD so i start doing it now and give you free script xD lol

Edited by TobiaszPL
Link to comment
Share on other sites

Keep in mind that ToiaszPL script or any script won't work if you don't "add script commands to be processed when a message button is pressed".



So if you are a newvie i'll choose a different route if you don't know how to do it, you'll encounter problems with your pop up menu (mod not working - buy key not working) that will be releated to the above.

Link to comment
Share on other sites

Thank you for that explanation! As you can probably tell I haven't done much scripting. I added your script to the activator (changed the first line of course) and tried to save. When it tried to compile the script I got the below message. (I should also point out at this point that I am making this for Skyrim SE, I just started this thread in Skyrim knowing that there would be a wider knowledge base).

 

Starting 1 compile threads for 1 files...
Compiling "MarasRespiteBuyScript"...
C:\Program Files (x86)\Steam\steamapps\common\Skyrim Special Edition\Data\Source\Scripts\temp\MarasRespiteBuyScript.psc(16,23): variable GoldBase is undefined
C:\Program Files (x86)\Steam\steamapps\common\Skyrim Special Edition\Data\Source\Scripts\temp\MarasRespiteBuyScript.psc(9,1): the parameter types of function onactivate in state waitforplayer on script marasrespitebuyscript do not match the parent script objectreference
No output generated for MarasRespiteBuyScript, compilation failed.

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

Link to comment
Share on other sites

  • Recently Browsing   0 members

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