Jump to content

Need help with limb condition script


Mattressi

Recommended Posts

I'm working on making a script (for hardcore mode) where sleeping will heal you and restore your limb condition - however it will do so slowly and will not work on crippled (limb condition = 0) limbs; meaning that you'll need to use a doctors bag on crippled limbs in order for them to heal.

 

I've made a script that does all of this, but the maths of it doesn't work in game. Here's the test script:

 

scn aaSleepHealCond

Float FullHP
Float HPPerHour
Float ResultHP
Float SleepTime
Float ResultCond

Int OncePer

Begin MenuMode

If GetPCSleepHours != 0 && OncePer == 0
	Set SleepTime to GetPCSleepHours 	
	Set FullHP to player.GetBaseActorValue Health
	Set HPPerHour to (fullHP / 10)
	Set ResultHP to HPPerHour * SleepTime 
	Player.RestoreActorValue Health ResultHP 

	Set ResultCond to 10 * SleepTime
	if player.GetActorValue PerceptionCondition > 0		
		Player.RestoreActorValue PerceptionCondition ResultCond
	endif
	if player.GetActorValue EnduranceCondition > 0
		Player.RestoreActorValue EnduranceCondition ResultCond
	endif 
	if player.GetActorValue  LeftAttackCondition > 0
		Player.RestoreActorValue LeftAttackCondition ResultCond
	endif
	if player.GetActorValue  RightAttackCondition > 0	
		Player.RestoreActorValue RightAttackCondition ResultCond
	endif
	if player.GetActorValue LeftMobilityCondition > 0
		Player.RestoreActorValue LeftMobilityCondition ResultCond
	endif
	if player.GetActorValue RightMobilityCondition > 0
		Player.RestoreActorValue RightMobilityCondition ResultCond
	endif
	Set OncePer to 1
Endif

End

Begin GameMode

If OncePer == 1
	Set OncePer to 0
Endif
End

 

I'm using this as a test script - I'm trying to make it so that every 1 hour you sleep, you will gain back 10% of your limb condition and 10% of your health (the actual mod will have lower values, but I'm using increments of 10 for ease of calculation and for testing purposes). The problem that I'm having is that this isn't how it's working at all: when I sleep for 1 hour, no health or limb condition is restored. Same when I sleep for two. When I sleep for 3 hours, I get some health back and sometimes limb condition (when it's low).

 

Here's some quick figures that I got when testing just then. Note that I tested by sleeping for the amount of time listed, then I reloaded the save to sleep again for a different time.

Base Health: 230

Current health: 148

1 hours sleep: 148

2 hours sleep: 148

3 hours sleep: 171

4 hours sleep: 148

4 hours sleep again: 230

4 hours sleep again: 148

4 hours sleep again: 171

 

Left limb: 70.06

1 hours sleep: 70.06

2 hours sleep: 70.06

3 hours sleep: 70.06

4 hours sleep: 70.06

5 hours sleep: 80.06

So, you can see that the limb condition and health do increase in 10% increments - but they sure as hell doesn't seem to increase linearly based on the number of hours slept. They don't increase at all for a few hours sleep, then they finally increase by a small amount, as if only an hour of sleep had been had. Also, the 4 hour tests for health show that it seems to be almost random in the way that the game is restoring health: the first time I tested, the health hadn't increased, so I tested again and again and noticed that it just seemed random.

 

Does anyone know why this is happening? I can't see an issue with my code (maybe there is?), especially because the problems seem to be random. Is there any way to fix this? I can keep testing to get more values if that would help, but I thought I'd post this now in case anyone knows what it is just from this information. If not, I'll do more testing. Thanks :)

 

Edit: I'm new to scripting with the GECK, so I've used the basic structure from the 'A Good Nights Sleep' mod, which was recommended to me as a good basis for creating the mod that I want (it enables healing when sleeping in hardcore mode). So, I'm not sure what things like "If GetPCSleepHours != 0 && OncePer == 0" do, though I (obviously) understand the general logic of the rest of it.

 

Edit #2: I've just tried using the GetPCSleepHours function in game and it hasn't done anything. It hasn't thrown out an error or anything, but it isn't returning a value, whether I type it while standing still, in the sleep menu with the slider adjusted, or even when I quickly type it in when sleeping. I added a 'player.' to the front of it and tried again (just in case), but still nothing. Am I using it wrong or does it just not do anything?

Edited by Mattressi
Link to comment
Share on other sites

Create a message called TestMessage and in the text box put:

 

SleepTime is %5.0f

 

In your script, add the following line:

 

Set ResultCond to 10 * SleepTime
ShowMessage TestMessage SleepTime
if player.GetActorValue PerceptionCondition > 0 

 

Find out what SleepTime is getting set to.

 

Thanks for that; it really helped. I set my sleeping for 7 hours and when the countdown just ticked over to 3 hours, the message popped up and said "sleep time: 4 hours". So, there's clearly a significant delay there. Any ideas why and/or how to fix it?

 

For now I'm just going to use a quick and dirty fix of setting ResultCond to 10 * (SleepTime + 1). That isn't really tackling the problem, just working around it, but hopefully it works out.

Link to comment
Share on other sites

Hi.

 

My guess is that the quest you have your script attached to is using the default “Script Processing Delay” of fife seconds, meaning the script is executed only once every fife seconds.

This would explain why you don't see anything happening if you sleep only one or two hours, because in the short time the hours tick by, the script is usually not executed. Every once in a while, if you sleep for one hour, the script might actually run if the fife second delay is about to run out just as you click “Sleep”. But its not reliable.

 

The easiest way is probably to just set the “Script Processing Delay” of the quest to some lower number, to force the script to run more often. 0.5 for example would make the script run twice a second and pretty much guarantee that it always catches the first hour of sleep.

 

Usually I am not a big friend of quest scripts being executed that often because it can be a resource hog on slower systems. In this case however, I don't really see any other possibility short of scripting each and every bed base object in the game individually, which isn't really feasible :biggrin:

 

I see another little problem with your script: You do the healing all at once, as soon as the player clicks “Sleep”. This could be exploited by choosing to sleep 24 hours and then clicking cancel after only one hour of actual sleep. The player would still get the healing benefit of 24 hours sleep. There is also the possibility of a quest event waking up the player prematurely.

 

Therefore I suggest doing it like this (have the quest run the script twice a second or faster):

ScriptName aaSleepHealCond

Short lasthours		;to remember last GetPCSleepHours result

Begin MenuMode 1012					;sleep/wait menu is open
If IsPCSleeping == 0				;if the player is not yet sleeping (or he is only waiting)
	Set lasthours To 0			;reset hour counter
	Return					;and exit
EndIf
If lasthours != GetPCSleepHours			;if hours left to sleep changed
	Set lasthours To GetPCSleepHours	;remember current hours left

	;do healing here for one hour worth of sleep

EndIf
End

Using “Begin MenuMode 1012” instead of just “Begin MenuMode” causes that part of the script to only run while the player actually has the “Wait/Sleep” menu open. It won't run during dialog, bartering, playing blackjack, picking locks, etc. This script would heal the player once for each hour of actual sleep.

Since there is no GameMode block, running the quest script very often should have very little impact on performance during normal play.

 

Have fun and good luck.

Link to comment
Share on other sites

Ah, those are very good points. You're right about the script delay: but now I'm not sure whether I want to make it run all that often anyway (it seems a waste to be running a script every few seconds or milliseconds). I'll see if there's a way around it. I just wish that I could tie the script to sleeping (as in, when sleeping, the script is activated) rather than making a script to keep checking.

 

And that's a good point about being able to exploit it by setting it to 24 hours and then unsleeping - I should have picked that up. Thanks for the fix for it and thanks for all your help :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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