Jump to content
ℹ️ Intermittent Download History issues ×

[LE] Some scripting Tips? Making a auto sell stuff mod...


Recommended Posts

Well that looks very neat really. You get every item he has and sell it all at the same time :D I will need to test this for sure. So it is a spell then that you cast on your self?

 

Thanks a lot for sharing your script :smile:

 

I have so much to learn, but this also means it will get much more optimized really. You could use GetFormID instead of GetName though, but if the name is unique, it does not matter really. I sometimes find odd stuff when I loop inside containers, like tokens and sh*t like that... I will remake my script and we see what we will be able to end up with.

Edited by Pellape
Link to comment
Share on other sites

  • Replies 82
  • Created
  • Last Reply

Top Posters In This Topic

In order to compile scripts that contain SKSE functions / events all you need to do is make sure that you have first extracted the scripts.zip or scripts.rar file (depending upon version of Skyrim) found in the Data folder after having installed the Creation Kit. Once you have done that, you need to ensure that you copy the SKSE PSC files into the same directory as the base game's PSC files.

 

For 32 Bit Skyrim you should probably copy / move the DLC PSC files prior to the SKSE PSC files. For 64 bit Skyrim, they are already in a combined folder.

 

Alternatively you can setup a third party tool like Notepad++ or Sublime Text to utilize multiple source file locations when compiling.

 

There is no "loading SKSE" with the Creation Kit. The compiler just needs access to the PSC files.

Link to comment
Share on other sites

AHHHH. Now i undestand. I also saw a video about that yesterday as well. This one:



I feel much less frustrated now for sure. Mega thanks IsharaMeradin. So you think my script looks okay? Will it work? Did i miss anything? I saw we can declare variables anywhere, but I like my old C++ / Oblivion way of structure the code... It looks more clean and viable this way.
ScriptName PekSellAllThisStuff

Int PekNumberOfItemsinStack
Int PekFormIndex
Int PekGoldValue
Form PekForm

Event OnActivate (ObjectReference PekHandle)
	
	PekFormIndex = PekContainerREF.GetNumItems()

	While PekFormIndex > 0 
		
		PekFormIndex -= 1

		PekForm = Player.GetNthForm(PekFormIndex)
		PekNumberOfItemsinStack = Player.GetItemCount(PekForm)
		PekGoldValue = PekForm.GetGoldValue()
		
		PekGoldValue = PekGoldValue * PekNumberOfItemsinStack 

		Player.RemoveItem(PekForm, PekNumberOfItemsinStack ) 
		Player.Additem(GoldBase, PekGoldValue)
	EndWhile

endEvent

After reading more examples, I see the Event OnActivate in many different places and they all starts with:

Event OnActivate(ObjectReference akActionRef)

So maybe i think wrong when i add the name of the activator ref here?

Event OnActivate (ObjectReference PekHandle)

It is good if we can get this tiny script as bug free as possible before tonight, as it takes so long time for me to start the game. I cannot be alone, feeling the frustration while waiting for the game to start up? Well comparing to Oblivion? Morrowind do takes a bit longer to load than Oblivion really when i think about it as well but not close to the time it takes to start Skyrim.

Edited by Pellape
Link to comment
Share on other sites

Sphered. What I do not understand is where does the gold in your example end up?

 (Game.GetForm(0x14) as ObjectReference).AddItem(Game.GetForm(0xF),Counter,True)

as it should be enough really to just use:

Player.Additem(GoldBase, Counter)

right? Or do the gold end up at the Companion? is it not better to really use the ObjectNames instead of the Form ID's as it really feel like we did 1989... ;) Poke this and Peek this, to make the code run faster at our first 8-bit computers, instead of using the inbuilt basic commands, which could do the same thing, but did it MUCH slower. :D That only worked on Atari 8-bits by the way, not the Commondore 64, which did not have any viable commands in the same way the Atari did, well, a bad compare but still... ;)

 

What I did learn when I took C classes around 1990 (Ansi C and GEM coding) was to write the code, so it gets as easy to read for everyone as it is possible to structure the stuff in so many different ways and it seems that we are able to do the same thing in Skyrim in many many different ways. Well I will figure it out, one day... ;) What I want to add by this, is, it must be best to keep things as simple as possible right?

Link to comment
Share on other sites

Oh thats just preference there. You can declare player and 0xF gold if you want to, I just like to keep things clean and avoid properties etc if they arent really necessary

 

Game.GetPlayer().AddItem(GoldBaseObjectRecord) works perfectly fine too

 

Was glancing at the ObjectReference script and saw another SKSE one called ResetInventory() I didnt recall seeing before. If I were guess, it does the same thing as Formlist's Revert() for a container. Could be convenient too perhaps

Link to comment
Share on other sites

OnActivate(ObjectReference akActionRef)

vs

OnActivate(ObjectReference SomethingElse)

 

Both will function the same. akActionRef is the parameter variable name that Bethesda used when defining the event. That is the primary reason that most authors continue to use it. They copy / pasted the code from a working script. Or they're just in the habit of utilizing Bethesda's variable names when it comes to native functions or events.

 

Regarding the PlayerRef thing...

If the event / function contains a parameter that would reference the player, use that instead of declaring a property or local variable.

Example:

Event OnActivate(ObjectReference akActionRef)
  If akActionRef == Game.GetPlayer()  ;player activated
    akActionRef.AddItem(Gold01,10) ;give player 10 gold
  EndIf
EndEvent

If the player data needs to be used across multiple functions or events, it may be better (easier) to use a property or local variable. But for a small limited use, avoid the property and local variable if possible while more importantly avoiding multiple calls to GetPlayer(). Because GetPlayer() is on the Game script, the current thread needs to pause while Papyrus jumps to the Game script to run the GetPlayer() code. Storing in a variable will always be faster than repeated calls to the same function that will always return the same answer.

 

There are threads on this subject going back a decade or more. Feel free to search those up if you want more information (you won't find a consensus that is certain).

Link to comment
Share on other sites

So let me see if I got this right then... I am a bit confused right now. :wink: In Oblivion we only use Int or Ref and now there are so many new things that does not mean much to me, not yet at least. :D Strings as one example, when used in OBSE, it can cause big issues as String Bloating in the save files, if not destructed, which is a subject I debate with the OBSE author (xOBSE)... Well, Lets focus at my next question.

So the Player is a property right? It is an ObjectID in Oblivion. But I have used similar really when I think about it, like:

Ref PlayerRef
Set PlayerRef to Player

;In Skyrim it would be:
ObjectReference PlayerRef
PlayerRef = Player 


I have seen this in a couple of scripts, and maybe it is so that Oblivion works the same way? Otherwise, what is the point of putting the player inside a variable and use it instead? I mostly call Persistant Referenses in or from my scripts on every line, when I call them, instead of putting them inside separate variables but maybe I should stop doing that, even in Oblivion?

I also did a miss in my script when I think about it. It should be best to really check if something really exist, before trying to remove it or add gold to the player.... :wink: Also check so the form is not empty... Well I will test soon and we see. I will do as you suggest, put the player inside a variable and use it instead.

 

Ahhh, Yes Sphered, I get it now when I think about it :D The player is ObjectID 00000014 in all the games :D 0xF is also gold in all games... Well Daggerfall excluded, as we only talk Net Immerse here anyway... Its just we never use the ObjectID numbers that way in Oblivion nor Morrowind. We use it in the console but never in scripts.

 

I do still play Daggerfall by the way, time to time as well, fully modded with the new Unity engine... :wink: Works very good in 1080p and some stuff looks almost better than Oblivion does when it comes to the normals and light reflections... :wink:

 

In Oblivion we have a command of Funtion called PrintToConsole or short, PrintC. I tried to find it but I guess Debug.Trace("Some text") will do the same? It is not so clear at the reference page really what each command or function really is doing. I saw we can open logs and close them and I guess the log is written to the consolle, but it is a lot of guesses now really and 4 hours left until I will be able to make tests... :wink:

Edited by Pellape
Link to comment
Share on other sites

Lotta stuff is preference or simply going with whats familiar

If you are dealing with multiple scripts and expect frequent communication and variable modification, etc etc, especially when busy like combat situations, indeed you will want to declare many elements and make the game have to work as little as possible to resolve things. In my deal I send a pet off while im messing around in town or whatever, and one time, upon return I fetch a couple GetForm calls which wont matter here

 

Those debug calls as you might figure, are for test usage and generally you should have those papyrus settings set to off in your inis unless actively wanting their data

 

Declaration names dont matter. I often call mine PCA and PCO for player. One when its actor and one when just needing as ObjectReference. Doesnt matter what they are called, but you have to call them something

Link to comment
Share on other sites

Oki. Thanks again for all help :) I started up CK now, so we see where I end up at. I am in the right cell now at least.

 

This script will only run when I activate the button and later also from a spell, so it will not have any impact on any performance at all, no matter if I use the references direct or from variables but... ;)

 

When I script for Oblivion, I do think about performance first as so many miss use scripting, allowing scripts to run every damn frame in Game Mode when they often only need to run ones in a while, like from a quest, every 3rd second. Look at my framerate in this video, where I have 8 FPS and now when I use quests instead, I have 3 times as much at least :D It sure took me log time to figure out when I need scripts to run every frame or not. I am so happy now that this room works so fast as it does, and I managed to make the weapons to rain. Oblivon is not meant for Wepon Displays in the way I use them here. Skyrim is, not Oblivion. It took me 1.5 year to solve this :D This cell is now extremely steady and works perfect, just as an example how I think when I script :D This whole mod is unique, released yesterday. I call it the Legacy of the Champion, as it is based on the Legacy of the Dragonborn. Maybe it is so that I can increase the performance more using this method? ;)

 

Well enjoy the video as I bet you have never seen something like this? If you have, well show me... ;)

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...