Jump to content

Help with a script please


Job4aCowboy

Recommended Posts

Hey, I'm new to the modding scene. Learnt the CK from scratch and gotten quite good at it. Now i'm trying to learn scripting, I've never done anything like this before. I'm not doing to bad, understand the basics.

 

Before I start with my question I'd just like to say that this is not a "do it for me" request. Most of the work I've done so far I've learnt by myself and by my own research. While this may seem easy to the scripting gurus out there, a few weeks ago I didn't even know what papyrus was, let alone seen a script. :laugh:

 

 

So anyway, what I'm trying to do is activate the RaceMenu when the player activates an object. This part I've got I think...

 

Scriptname Showracemenuonactivate extends ObjectReference

{Shows race menu when object is activated}

 

auto state waiting

event OnActivate (ObjectReference akActivator)

Game.ShowRaceMenu()

EndEvent

endstate

 

 

 

It compiles OK but I'm yet to test it out in game.

 

My problem is the bug that causes skills etc. to reset when you use the show race menu. Would I be right in thinking that I should use the "GetActorValue" and "SetActorValue" functions to get around this?

I'm guessing you use the "GetActorValue" function for each stat, including Health, Magicka and Stamina, (and possibly perks?) and then use the "SetActorValue" to return the values gained from "GetActorValue" to the player. Is this right?

 

How would I set this all up to run in order? If anyone can point me in the right direction, that would be great. :thumbsup:

 

 

Thanks

Link to comment
Share on other sites

Maybe something like this. You would have to account for a stat getting set lower then the original value with damageactorvalue()

 

String[] StatList
Float[] SavedStats

Event OnInit()
StatList = new string[21]
StatList[0]	="Health"
StatList[1]	="Magicka"
StatList[2]	="Stamina"
StatList[3]	="OneHanded"
StatList[4]	="TwoHanded"
StatList[5]	="Marksman"
StatList[6]	="Block"
StatList[7]	="Smithing"
StatList[8]	="HeavyArmor"
StatList[9]	="LightArmor"
StatList[10] ="Pickpocket"
StatList[11] ="Lockpicking"
StatList[12] ="Sneak"
StatList[13] ="Alchemy"
StatList[14] ="Speechcraft"
StatList[15] ="Alteration"
StatList[16] ="Conjuration"
StatList[17] ="Destruction"
StatList[18] ="Illusion"
StatList[19] ="Restoration"
StatList[20] ="Enchanting"

SavedStats = new float[21]
EndEvent

Event OnActivate(ObjectReference akActivator)
RegisterForMenu("RaceSex Menu")
PlayerStats()
Game.ShowRaceMenu()
EndEvent

Event OnMenuClose(string menuName) ;catches event because we registerd for it.
if (menuName == "RaceSex Menu")
	PlayerStats(true)
endif
EndEvent

Function PlayerStats(bool abSwitch = false)
int arrayLength = StatList.Length
int i = 0

if (abSwitch == false)
	while(i < arrayLength);store values
		SavedStats[i] = Game.GetPlayer().GetActorValue(StatList[i])
		debug.notification("Storing " + StatList[i])
		i += 1
	endwhile
else
	while(i < arrayLength);set values
		Game.GetPlayer().SetActorValue(StatList[i], SavedStats[i])
		debug.notification("Setting " + StatList[i])
		i += 1
	endwhile
endif

EndFunction

Link to comment
Share on other sites

Thanks for the reply! :thumbsup:

 

I don't understand what you mean by damageactorvalue. Do you mean if the player is injured before they enter the menu than their stats will be lower?

Also is there any chance you can explain how this script works. I understand the objectreference section slightly, but you've totally lost me with the rest lol. Really want to learn how it functions rather than just knowing it does.

 

Thanks for your time.

Link to comment
Share on other sites

Added some comments but I dont even know if it works. Didnt test it. DamageAV just means minus the value.

String[] StatList	;This is a new string array.
Float[] SavedStats	;Arrays are a variable that store multiple values. Each value in the array has an index. 

Event OnInit()
       StatList = new string[21] ;Arrays need to be initialized with a length. That is how many values the array can store.
       ;Arrays start at 0, thats why the highest index is 20 and not 21.

       StatList[0]  ="Health"	;Now set index 0 to "Health"
       StatList[1]  ="Magicka" ;and so on for each stat you want to save
       StatList[2]  ="Stamina"
       StatList[3]  ="OneHanded"
       StatList[4]  ="TwoHanded"
       StatList[5]  ="Marksman"
       StatList[6]  ="Block"
       StatList[7]  ="Smithing"
       StatList[8]  ="HeavyArmor"
       StatList[9]  ="LightArmor"
       StatList[10] ="Pickpocket"
       StatList[11] ="Lockpicking"
       StatList[12] ="Sneak"
       StatList[13] ="Alchemy"
       StatList[14] ="Speechcraft"
       StatList[15] ="Alteration"
       StatList[16] ="Conjuration"
       StatList[17] ="Destruction"
       StatList[18] ="Illusion"
       StatList[19] ="Restoration"
       StatList[20] ="Enchanting"

       SavedStats = new float[21] ;Im initializing this array with 21 empty values
EndEvent

Event OnActivate(ObjectReference akActivator)
       RegisterForMenu("RaceSex Menu") ;Register for the Race menu so you can listen for OnMenuClose()
       PlayerStats() ;Store player values
       Game.ShowRaceMenu() ;pop the race menu
EndEvent

Event OnMenuClose(string menuName) ;catches event because we registered for it.
       if (menuName == "RaceSex Menu")
               PlayerStats(true) ;switch to the set values mode when you close the race menu.
       endif
EndEvent

Function PlayerStats(bool abSwitch = false)
       int arrayLength = StatList.Length ;Finds the length of how many values are in the stats list
       int i = 0	;This is the index you want to start at. i just stands for integer or index 

       if (abSwitch == false)
               while(i < arrayLength) ;Starting at 0, loop until i is greater than the amount of values in the array
                       SavedStats[i] = Game.GetPlayer().GetActorValue(StatList[i]) ;get the value of index starting at 0
                       debug.notification("Storing " + StatList[i]) ;should print the stat name your saving
                       i += 1  ;add 1 to i
               endwhile
       else
               while(i < arrayLength) ;same thing backwards
                       Game.GetPlayer().SetActorValue(StatList[i], SavedStats[i])
                       debug.notification("Setting " + StatList[i])
                       i += 1
               endwhile
       endif

EndFunction

Link to comment
Share on other sites

This is awesome, but i'm having a problem compiling it. When i try i get an error...

 

Starting 1 compile threads for 1 files...

Compiling "Racemenuonactivate"...

C:\Program Files (x86)\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\Racemenuonactivate.psc(36,8): RegisterForMenu is not a function or does not exist

No output generated for Racemenuonactivate, compilation failed.

 

Batch compile of 1 files finished. 0 succeeded, 1 failed.

Failed on Racemenuonactivate

 

 

I've looked at the creation kit script references and Registerformenu is there, it says it requires SKSE, which I have the most recent version for. Do you know what I'm doing wrong, do I have to run it through SKSE somehow?

 

Sorry, i'm a total noob to this :laugh:

Link to comment
Share on other sites

Ok, disregard my last reply. Apparently I hadn't updated the scripts. Silly me. Now it compiled fine.

 

Anyways I've been testing the script out. When I activate a button the race menu opens. Seemed to work OK until I discovered that if the player enters the menu without full health/magicka/stamina and bars than their stats will be reduced. For example if the player had stamina 50/100 than their stamina would be reduced by 50 when they exit the menu.

 

Also it seemed to level up a coc character, although there were no skill increases, not sure why this happens but I can duplicate it. I then tested it out with my main character and everything worked fine. (apart from the above issue)

 

Is there a way to get the players maximum values instead of getting the bases values. This to me seems to be the problem.

 

Thanks again

Link to comment
Share on other sites

Actually you want to get the player's base value rather than their current value.

 

GetActorValue() gets the current value thus if the player has 50 of 100 stamina they'll be given 50 stamina on exiting your menu.

 

GetBaseActorValue() gets the base value before any modifications caused by equipped items thus if the player has 50 of 100 stamina they'll be given 100 stamina on exiting your menu.

 

However, the base value may not be what you want for the skills themselves as those you would want the specific current value.

 

In all honesty you shouldn't be checking the health, magicka or stamina stats those should remain unchanged when using any form of the race menu. It is only the skills themselves to be worried about.

Link to comment
Share on other sites

Actually you want to get the player's base value rather than their current value.

 

GetActorValue() gets the current value thus if the player has 50 of 100 stamina they'll be given 50 stamina on exiting your menu.

 

GetBaseActorValue() gets the base value before any modifications caused by equipped items thus if the player has 50 of 100 stamina they'll be given 100 stamina on exiting your menu.

 

However, the base value may not be what you want for the skills themselves as those you would want the specific current value.

 

In all honesty you shouldn't be checking the health, magicka or stamina stats those should remain unchanged when using any form of the race menu. It is only the skills themselves to be worried about.

 

I thought the health/magicka/stamina stats get reset or evened out when you use the race menu?

 

Quoted from http://www.uesp.net/wiki/Skyrim:Console

 

"showracemenu

Opens the character creation menu

Note: Using this command to alter one's race will reset skills and health/magicka/stamina to default levels. This command can be safely used to alter a character's appearance without causing any unwanted side-effects as long as race is not changed. However, it should be noted that upon completing your changes and choosing a name for your character, all temporary active effects (such as Gift of Charity or shrine blessings) will be removed. Racial resistances will no longer be listed in Active Effects until the game is loaded from the main menu, at which time racial resistances will be automatically reapplied. Permanent active effects such as those from guardian stones or perks will not be lost. Active effects granted from enchanted items will not be listed until the items are re-equipped."

Edited by Job4aCowboy
Link to comment
Share on other sites

Why not test it out for sure to see if the H/M/S does get knocked back to 100 on a high level character?

 

If it does, then apply the GetBaseActorValue() for H/M/S and GetActorValue() for the skills.

If it does not, then you do not need to worry about H/M/S.

 

I've learned to take the wiki with a grain of salt. i.e. It is not always 100% correct.

Link to comment
Share on other sites

Didnt mean to confuse. Like IsharaMeradin said getbaseactorvalue() is probably better but I dont even know what kinds of numbers these functions normally return. The script above was meant to just get the basic idea going.

 

This might help see what values your storing.

Replace the other storing message with this one. It will print the stat your saving and the value.

debug.notification("Storing " + StatList + " with value " + SavedStats)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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