Jump to content

Help with Small Quest Script


BlackCompany

Recommended Posts

The last thing I wanted to do was bother the community with stuff like this. Figured I could get it from the Wiki. But no such luck. And those scripting tutorials...yeah.

 

 

What I need is a script I can attach to a quest, that will:

 

-check the player's health/health percentage. I know I can use getactorvaluepercent health for this. Don't know how to put it into a quest script.

 

-When the player is below 5% of max health, player.CIOS/Game.getplayer.().addspell one of 4 or 5 "wound effects" I created

 

-If the player is at Zero health, do the wound thing a second time, more severe version, then player.resethealth

 

 

The goal of the mod is to let players play the game in Essential mode. Then to add severe penalties for getting knocked out of fights. Sure, you can get back in, but it will be with a minus 25 Stamina and Health/-50 stamina/-50 health/-100% health regen "wound" nagging you until you heal it. And you can only heal it by gathering/crafting bandages, which will only work when you are outside of combat, with your weapon put away, and will only work once, then are lost.

 

Any help with this code is appreciated. Were this Oblivion/Fallout, it would be done by now, but Alas for Papyrus. Thanks to the community. And by all means, if someone else has made this, please do not hesitate to let me know.

Link to comment
Share on other sites

I don't know about Fallout, but I've modded for Oblivion, and even there when the player gets to 0 health you die. It's the same in Skyrim, there's no way to restore the player to full health one he/she is dead.

 

In Skyrim, scripts aren't running every frame, or at least they aren't supposed to. You could make a quest script to monitor the player's health this way, but it would be easier to put a scripted magic effect or a reference alias on the player instead. If I was doing this, I would give the player an ability with this script attached to its active magic effect:

 

 

Scriptname ExampleMEScript extends ActiveMagicEffect


Formlist property Debuffs01 auto
Formlist property Debuffs02 auto

Actor Player
Int WoundedState


Event OnEffectStart(Actor akTarget, Actor akCaster)

Player = akTarget

EndEvent

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)

if (Player.GetActorValuePercentage("Health") < 0.05) && (WoundedState == 0)
	int index = Utility.RandomInt(0, Debuffs01.GetSize()
	Player.AddSpell(Debuffs01.GetAt(index) as Spell)
	WoundedState = 1
endif

EndEvent

Event OnEnterBleedout()

int index = 0
while (index < Debuffs01.GetSize())
	Player.RemoveSpell(Debuffs01.GetAt(index) as Spell)
	index += 1
endwhile
index = Utility.RandomInt(0, Debuffs02.GetSize())
Player.AddSpell(Debuffs02.GetAt(index) as Spell)
WoundedState = 2
Player.RestoreAV("Health", 9999)

EndEvent

 

 

I don't really know when the player starts bleeding out though, so you might have to put the code there into the OnHit event as well. The formlists would be filled with the spells you were talking about. It's easier than having a bunch of if and elseif statements to try and randomize it.

Edited by fg109
Link to comment
Share on other sites

Thanks for this code.

 

The whole idea here is to set the player to Essential (setessential 7 1) to avoid the annoying 'death and reload' problem...but then really make things hard if you get careless in combat. Hence, the monitoring health from a quest script. Sadly, while I caught right on to the former scripting language, this is not happening with Papyrus, for some reason. What I have so far is:

 

Scriptname aaaBCScriptWounding extends Actor  

Event OnInit()
player = Game.GetPlayer()
RegisterForUpdate(1.0)
endEvent

Even OnUpdate

If game.player.getav Health == 0
If game.getplayer.HasMagicEffect BCWoundability == 0
Game.getplayer().addspell BCWoundAbility
endif
endif
endevent

Quest Property aaaBCQuestWoundingControl  Auto 

 

 

I know some of this is right (likely very little) and most wrong. But right now the Wiki is lacking too much information for me to be able to piece together syntax. Your code helps with that, however, and I will keep trying.

 

Odd that Bethesda creates these Wiki's, then doesn't bother placing any info on them...

 

Thanks again.

Edited by BlackCompany
Link to comment
Share on other sites

Hmm... I remember that there were problems with setting the player as essential in Oblivion, so I've never tried that for Skyrim. It would be nice if it worked though.

 

About your code, you need to change it to this to compile:

 

Scriptname aaaBCScriptWounding extends Actor  

Quest Property aaaBCQuestWoundingControl Auto
Spell property BCWoundability auto
Actor Player

Event OnInit()
player = Game.GetPlayer()
RegisterForUpdate(1.0)
endEvent

Event OnUpdate()

If Player.getav("Health") == 0
	If Player.HasSpell(BCWoundability) == 0
		Player.addspell(BCWoundAbility)
	endif
endif

endevent

 

The properties and variables don't need to be at the top of the script, I just like putting them there. Unlike in Oblivion, you can't use form IDs in scripts. Instead of being able to reference anything directly, you have to use properties. You declare a property in the script, and then use it where you would have used a form ID before. Just remember that you have to set a value to the property once you've compiled your script. Even if your ability is actually named BCWoundAbility, and your property is called BCWoundAbility, you still have to set it outside of the script.

 

I see you used "Player = Game.GetPlayer()" but it's a waste of processing power if you don't actually use "Player" in your script! I changed "HasMagicEffect" to "HasSpell". Spells and magic effects aren't the same.

 

One thing I'm not sure about is the "If Player.getav("Health") == 0". Does an essential actor ever drop to 0 health? I thought that's what the essential status is supposed to prevent.

Link to comment
Share on other sites

Just for reference, I remembered this from perusing scripts a while back. This is the script for the restoration perk "Avoid Death". Which "Once a day, heals 250 points automatically if you fall below 10% health." It looks like quite a bit of stuff is the same as fg109s stuff:

 

 

 

 

Scriptname PerkAvoidDeathScript extends ActiveMagicEffect  

; ready to heal you
Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked )
; ;	debug.trace(self + " Enter Bleedout");	
If PerkAvoidDeathTimer.GetValue() < GameDaysPassed.GetValue()
	; cast heal spell
	PercentHealth = GetTargetActor().GetAVPercentage("Health")
	If PercentHealth < 0.1
		HealSpell.Cast(GetTargetActor())
		PerkAvoidDeathTimer.SetValue(GameDaysPassed.GetValue() + 1.0)
; ;			debug.trace(self + " Heal "+ PerkAvoidDeathTimer.GetValue() + " " + GameDaysPassed.GetValue())
	EndIf
Else
; ;		debug.trace(self + " Timer not reset " + PerkAvoidDeathTimer.GetValue() + " " + GameDaysPassed.GetValue())
EndIf
endEvent


Spell Property HealSpell  Auto  

GlobalVariable Property PerkAvoidDeathTimer  Auto  

GlobalVariable Property GameDaysPassed  Auto  

float Property PercentHealth = 100.0 Auto  

 

 

 

Obviously if you ignore the cooldown stuff, and replace the HealSpell.cast() with the acivation of your own... stuff. An elseif for even lower health, maybe 2% could simulate checking for 0 health(and having previously activated your first bleedout state) to activate your second stage effect ... This isn't like ... an interupt or anything though so far as I know I'd be worried about getting killed anyways lol. Maybe the actor values aren't changed by the hit till after this event is called I don't know.

 

The main point being, the game relies on code almost identical to fg109s version to save the player from death. So sounds reasonable me. Idea sounds intriguing. Something like fight to survive? but you ... won't actually die anyways...

Link to comment
Share on other sites

Thanks everyone for this info. This is great.

 

As for setting the player to essential, it does work in Skyrim. I first learned this by studying how hand to hand "bar brawls" work. You are Essential during that time. So II did some testing. If you do the following:

 

setessential 7 1

 

This will set the player (whose base id is 7) to Essential. A "mod" (really, this instruction) on the Nexus pointed that out. When the player's health reaches 0, they drop out of combat. Better still, NPC's consider them defeated and give you some room. Also, the insult you nicely, too.

 

Now, what will not happen...is the player getting back up on their own. Even if you use a health potion...no go. You have to actually do player.resethealth to get the player back up and going. This heals you and gets you back to fighting.

 

What I thought to do was sure, refill the health bar. But Wound the player first. A drain health/stamina/regen rate wound, that gets progressively worse for each stage, based on the number of knocks outs you suffer. This to me is better than the old 'save and reload' system, for immersion, and more punishing, as well, since now you're still stuck dealing with the boss/dungeon/dragon, except now, you're wounded on top of that.

 

Thanks again for this. Good stuff and I should be able to get where I am going now.

Edited by BlackCompany
Link to comment
Share on other sites

  • Recently Browsing   0 members

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