Jump to content

Scripting Help for Armor Durability Mod


tnt90

Recommended Posts

Just have one thing that would make my life so much simpler if it could be done, but I don't know how to do it.

 

Does anyone know how to reference the object reference a script is attached to without having to manually define it with a property every time you attach the script?

 

Having to manually define the armor each time I add the script to an armor is a pain, but that's what I've been doing so far. Finally got fed up enough to ask the forums.

 

Thank you.

Link to comment
Share on other sites

You could use GetFormID() from the form script section of creadtion kit papyrus page http://www.creationkit.com/Form_Script

But this would come with multiple issues. If you are attaching the script to say the iron cuirass form as I suspect then it would reference all iron cuirasses in the game, not just the 1 instance of it. Also if you are attaching the script to all items in the gsme it would make all other mods that alter them, incompatable. I've made a mod, helmet toggle which alters all the helmets in the game and for that I had to add a script to the player that references all helmets in the game through propertys, though its made easier by naming them exactly then clicking auto add propertys to link them all to the form of the same name. though that may not be much help either if u need to reference the instance. I'll have another look for instance referencing scripts. I'd also be interested in how your script works at the moment if you wouldnt mind sharing.

 

Edit - also you could reference it using event on equip if that works with form scripts.

Type

 
Form property currentobject
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
Currentobject = akbaseobject

CurrentObject will then be the form you refur too in the script.

 

It might be

form current object

instead, cant remember

Edited by maniczombie
Link to comment
Share on other sites

Yeah, in order to have each armor have a unique stored HP value, it's almost necessary to add a script to each one. I've had some ideas where I could make a version without altering the armors but it wouldn't keep track of them once the player has dropped them.

Haven't tried GetFormID() yet, so I'll have a go at that and see if it returns what I want. I'm pretty much using this to get access to the armor's keywords so I can tell what it is to generate its HP.

 

My code bits are as follows, there are three main scripts, one for the armor, one for hit detection, and one to keep track of everything.

 

 

The Armor Script

Scriptname TNTArmorGeneric extends ObjectReference  

TNTUpdaterScript Property HitQuest auto
float LocalHP
float LocalHPMax
bool DoOnce
Armor Property ThisArmor auto
Actor rplayer
bool CanWear

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)

rplayer = Game.GetPlayer()
if DoOnce == false && akNewContainer As Actor == rplayer
	DoOnce = true
	LocalHPMax = HitQuest.GetMaxArmorHealth(ThisArmor)
	if akOldContainer.GetType() == 43
		;Debug.Notification("This should be a NPC")
		DeadCheck( akOldContainer)
	elseif akOldContainer.GetType() == 44
		;Debug.Notification("This should be a leveled actor")
		DeadCheck( akOldContainer)
	elseif akOldContainer.GetType() == 62
		;Debug.Notification("This should be a character")
		DeadCheck( akOldContainer)
	else
		RollHealth()
	endif
	if CanWear == false && akNewContainer As Actor == rplayer
		Debug.Notification("This armor is the wrong gender or size")	
		LocalHP = -1
	endif
endif

EndEvent

Function SexCheck(objectreference akOldContainer)

if (akOldContainer As Actor).GetActorBase().GetSex() == 1 || (akOldContainer As Actor).GetLeveledActorBase().GetSex() == 1 || ThisArmor.HasKeyWordString("ArmorShield") == 1
	;Debug.Notification("This actor is female or this is a shield")
	CanWear = true
	LocalHP = (LocalHPMax * Utility.RandomFloat(0, 0.6))		
else
	;Debug.Notification("This actor is not female")
	CanWear = false
endif

EndFunction

Function DeadCheck(objectreference akOldContainer)

if (akOldContainer As Actor).IsDead()
	SexCheck( akOldContainer)	
else
	RollHealth()
endif

EndFunction

Function RollHealth()

if Utility.RandomInt(1,2) == 1 || ThisArmor.HasKeyWordString("ArmorShield") == 1
	CanWear = true
	LocalHP = (LocalHPMax * Utility.RandomFloat(0, 1.0))		
else
	CanWear = false
endif	

EndFunction

Event OnEquipped(Actor akActor)

if akActor == rplayer
	SetHP()
endif

EndEvent

Function SetHP()

if ThisArmor.HasKeyWordString("ArmorHelmet")
	;Debug.Notification("Helmet")	
	HitQuest.HHealth = LocalHP
elseif ThisArmor.HasKeyWordString("ArmorCuirass")
	;Debug.Notification("Cuirass")	
	HitQuest.CHealth = LocalHP
elseif ThisArmor.HasKeyWordString("ArmorBoots")
	;Debug.Notification("Boots")	
	HitQuest.BHealth = LocalHP
elseif ThisArmor.HasKeyWordString("ArmorGauntlets")
	;Debug.Notification("Gauntlets")	
	HitQuest.GHealth = LocalHP
elseif ThisArmor.HasKeyWordString("ArmorShield")
	;Debug.Notification("Shield")	
	HitQuest.SHealth = LocalHP
endif

EndFunction

Float Function GetHP()

if ThisArmor.HasKeyWordString("ArmorHelmet")
	Return HitQuest.HHealth
elseif ThisArmor.HasKeyWordString("ArmorCuirass")
	Return HitQuest.CHealth
elseif ThisArmor.HasKeyWordString("ArmorBoots")
	Return HitQuest.BHealth
elseif ThisArmor.HasKeyWordString("ArmorGauntlets")
	Return HitQuest.GHealth
elseif ThisArmor.HasKeyWordString("ArmorShield")
	Return HitQuest.SHealth
endif

EndFunction

Event OnUnequipped(Actor akActor)

if akActor == rplayer
	LocalHP = GetHP()
endif

EndEvent

The Quest Updating Script

Scriptname TNTUpdaterScript extends Quest  Conditional

Import Game

Float Property PlayerHealth auto
Float property CHealth auto
Float Property HHealth auto
Float Property BHealth auto
Float Property GHealth auto
Float Property SHealth auto
Message Property HitMessageC auto
Message Property HitMessageB auto
Message Property HitMessageG auto
Message Property HitMessageH auto
Message Property HitMessageS auto
ObjectReference Property TempCont auto
Armor Property AddedArmor auto
Spell Property CheckSpell auto
Actor rplayer
MiscObject Property brokenarmor auto

Int FurBase = 40
int HideBase = 30
int IronBase  = 50
int LeatherBase = 50
int StuddedBase = 45
int BandedIronBase = 55
int ElvenBase = 60
int SteelBase = 60
int ForSwornBase = 40
int DwarvenBase = 70
int ScaledBase = 55
int GlassBase = 70
int BladesBase = 70
int OrcBase = 80
int EbonyBase = 90

float CuirassMult = 1.00
float HelmMult = 0.50
float BootsMult = 0.50
float GlovesMult = 0.40
float ShieldMult = 0.85

Event OnInit()

RegisterforSingleUpdate(0.5)

EndEvent

Event OnUpdate()

rplayer = Game.GetPlayer()
PlayerHealth = rplayer.getav("health")
if rplayer.HasSpell(CheckSpell) == 0
	rplayer.addspell(CheckSpell)
endif
if WearCuirass() == 1 && CHealth <= 0
	CHealth = 1
	Armor Cuirass = Game.GetPlayer().GetWornForm(0x00000004) As Armor
	DropTHeShit(Cuirass)
	HitMessageC.Show()	
endif
if WearBoots() == 1 && BHealth <= 0
	BHealth = 1
	Armor Boots = Game.GetPlayer().GetWornForm(0x00000080) As Armor
	DropTHeShit(Boots)
	HitMessageB.Show()	
endif
	if WearGloves() == 1 && GHealth <= 0
	GHealth = 1
	Armor Gloves= Game.GetPlayer().GetWornForm(0x00000008) As Armor
	DropTHeShit(Gloves)
	HitMessageG.Show()	
endif
if WearHelmet() == 1 && HHealth <= 0
	HHealth = 1
	Armor Helmet = Game.GetPlayer().GetWornForm(0x00000002) As Armor
	DropTHeShit(Helmet)
	HitMessageH.Show()	
endif
if WearShield() == 1 && SHealth <= 0
	SHealth = 1
	Armor Shield = Game.GetPlayer().GetWornForm(0x00000200) As Armor
	DropTHeShit(Shield)
	HitMessageS.Show()	
endif
RegisterforSingleUPdate(0.5)

EndEvent

Function DropTheShit(armor item0)

rplayer.removeitem(item0, 1, 1)
rplayer.additem(brokenarmor, 1, 1)

EndFunction

Bool Function IsWearingArmor()

if WearHelmet() == 1 || WearCuirass() == 1 || WearBoots() == 1 || WearGloves() == 1 || WearShield() == 1
	return 1
else
	return 0
endif

EndFunction

Bool Function WearCuirass()

Armor Cuirass = Game.GetPlayer().GetWornForm(0x00000004) As Armor
return Cuirass != None	

EndFunction

Bool Function WearHelmet()

Armor Helm = Game.GetPlayer().GetWornForm(0x00000002) As Armor
return Helm != None	

EndFunction

Bool Function WearBoots()

Armor Boots = Game.GetPlayer().GetWornForm(0x00000080) As Armor
return Boots != None	

EndFunction

Bool Function WearGloves()

Armor Gloves = Game.GetPlayer().GetWornForm(0x00000008) As Armor
return Gloves != None	

EndFunction

Bool Function WearShield()

Armor Shield = Game.GetPlayer().GetWornForm(0x00000200) As Armor
return Shield != None	

EndFunction

float Function GetMaxArmorHealth(Armor mArm)

if mArm.HasKeyWordString("VendorItemAnimalHide") || mArm.HasKeyWordString("ArmorMaterialImperialLight") || mArm.HasKeyWordString("ArmorMaterialStormcloak")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * FurBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * FurBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * FurBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * FurBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * FurBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialDwarven")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * DwarvenBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * DwarvenBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * DwarvenBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * DwarvenBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * DwarvenBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialDaugr") ||  mArm.HasKeyWordString("ArmorMaterialIronBanded")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * BandedIronBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * BandedIronBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * BandedIronBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * BandedIronBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * BandedIronBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialElven")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * ElvenBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * ElvenBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * ElvenBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * ElvenBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * ElvenBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialElvenGilded")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * (ElvenBase + 5))
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * (ElvenBase + 5))
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * (ElvenBase + 5))
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * (ElvenBase + 5))
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * (ElvenBase + 5))
	endif
elseif mArm.HasKeyWordString("ArmorMaterialElvenLight")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * (ElvenBase - 5))
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * (ElvenBase - 5))
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * (ElvenBase - 5))
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * (ElvenBase - 5))
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * (ElvenBase - 5))
	endif
elseif mArm.HasKeyWordString("ArmorMaterialSteel") || mArm.HasKeyWordString("ArmorMaterialImperialHeavy")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * SteelBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * SteelBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * SteelBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * SteelBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * SteelBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialIron")
	;Debug.Notification("This is an Iron ...")
	if mArm.HasKeyWordString("ArmorCuirass")
		;Debug.Notification("... Cuirass")
		return (CuirassMult * IronBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		;Debug.Notification("... Boots")
		return (BootsMult * IronBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		;Debug.Notification("... Shield")
		return (ShieldMult * IronBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		;Debug.Notification("... Gauntlets")
		return (GlovesMult * IronBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		;Debug.Notification("... Helmet")
		return (HelmMult * IronBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialHide")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * HideBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * HideBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * HideBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * HideBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * HideBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialImperialStudded") || mArm.HasKeyWordString("ArmorMaterialStudded")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * StuddedBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * StuddedBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * StuddedBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * StuddedBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * StuddedBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialLeather")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * LeatherBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * LeatherBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * LeatherBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * LeatherBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * LeatherBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialSteelPlate")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * (SteelBase+10))
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * (SteelBase+10))
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * (SteelBase+10))
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * (SteelBase+10))
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * (SteelBase+10))
	endif
elseif mArm.HasKeyWordString("ArmorMaterialBlades")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * BladesBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * BladesBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * BladesBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * BladesBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * BladesBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialScaled")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * ScaledBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * ScaledBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * ScaledBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * ScaledBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * ScaledBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialOrcish")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * OrcBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * OrcBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * OrcBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * OrcBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * OrcBase)
	endif
elseif mArm.HasKeyWordString("ArmorMaterialEbony")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * EbonyBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * EbonyBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * EbonyBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * EbonyBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * EbonyBase)
	endif
else
	Debug.Notification("This Armor Does not have a armorhealth entry!")
	if mArm.HasKeyWordString("ArmorCuirass")
		return (CuirassMult * LeatherBase)
	elseif mArm.HasKeyWordString("ArmorBoots")
		return (BootsMult * LeatherBase)
	elseif mArm.HasKeyWordString("ArmorShield")
		return (ShieldMult * LeatherBase)
	elseif mArm.HasKeyWordString("ArmorGauntlets")
		return (GlovesMult * LeatherBase)
	elseif mArm.HasKeyWordString("ArmorHelmet")
		return (HelmMult * LeatherBase)
	endif
endif

EndFunction

The Hit Detector Script

Scriptname TNTHitDetectorScript extends ReferenceAlias  

Import Game
Import Debug

TNTUpdaterScript Property HitQuest auto
Faction property CreatureFaction Auto
Message property DebugMessage Auto
MagicEffect property Fire       Auto
MagicEffect property Frost      Auto
MagicEffect property Shock      Auto
float HealthLost
float damratio
actor rplayer
int HelmE
int GloveE
int BootE
int ShieldE
int CuirassE

float diceroll

Event OnHit(ObjectReference Aggressor, Form Source, Projectile FlyingDeadlyThing, bool PowerAttack, bool SneakAttack, bool BashAttack, bool Blocked)

rplayer = GetPlayer()
if (Aggressor As Actor).GetequippedItemType(0) == 0 && ((Aggressor as Actor).GetEquippedItemType(1) == 0)
if ((Aggressor as Actor).IsInFaction(CreatureFaction)) || ((Aggressor as Actor).GetActorBase()) == False
	if HitQuest.IsWearingArmor() == 1
		ShowArmorPtsLost(Blocked)
	endif
else
	;brawling
endif
else
if HitQuest.IsWearingArmor() == 1
	ShowArmorPtsLost(Blocked)
endif
endif

EndEvent

Function NAssigner()

if HitQuest.WearHelmet() && HitQuest.HHealth > 0
	HelmE = 1
else
	HelmE = 0
endif
if HitQuest.WearBoots() && HitQuest.BHealth > 0
	BootE = 1 + HelmE
else
	BootE = HelmE
endif
if HitQuest.WearGloves() && HitQuest.GHealth > 0
	GloveE = 1 + BootE
else
	GloveE = BootE
endif
if HitQuest.WearShield() && HitQuest.SHealth > 0
	ShieldE = 1 + GloveE
else
	ShieldE = GloveE
endif
if HitQuest.WearCuirass() && HitQuest.CHealth > 0
	CuirassE = 2 + ShieldE
else
 	CuirassE = ShieldE
endif

EndFunction

Int Function TotalWear()

int total
if HitQuest.WearBoots() && HitQuest.BHealth > 0
	total += 1
endif
if HitQuest.WearGloves() && HitQuest.GHealth > 0
	total += 1
endif
if HitQuest.WearShield() && HitQuest.SHealth > 0
	total += 1
endif
if HitQuest.WearHelmet() && HitQuest.HHealth > 0
	total += 1
endif
if HitQuest.WearCuirass() && HitQuest.CHealth > 0
	total += 2
endif
return total

EndFunction

Function WearToHit(float damage)

NAssigner()
int total = TotalWear()
int Random = Utility.RandomInt(1,total)
;DebugMessage.Show(total, Random, HelmE, BootE, GloveE, ShieldE, CuirassE)
if Random == HelmE
	if HitQuest.WearHelmet()
		HitQuest.HHealth = HitQuest.HHealth - Damage
		;debug.Notification("Helmet Damaged: " + Damage)
	else
		WearToHit(damage)
	endif
elseif Random == BootE
	if HitQuest.WearBoots()
		HitQuest.BHealth = HitQuest.BHealth - Damage
		;debug.Notification("Boots Damaged: " + Damage)
	else
		WearToHit(damage)
	endif
elseif Random == GloveE
	if HitQuest.WearGloves()
		HitQuest.GHealth = HitQuest.GHealth - Damage
		;debug.Notification("Gauntlets Damaged: " + Damage)
	else
		WearToHit(damage)
	endif
elseif Random == ShieldE
	if HitQuest.WearShield()
		HitQuest.SHealth = HitQuest.SHealth - Damage
		;debug.Notification("Shield Damaged: " + Damage)
	else
		WearToHit(damage)
	endif
elseif Random == CuirassE || Random == CuirassE - 1
	if HitQuest.WearCuirass()
		HitQuest.CHealth = HitQuest.CHealth - Damage
		;debug.Notification("Cuirass Damaged: " + Damage)
	else
		WearToHit(damage)
	endif
endif

EndFunction

Bool Function HitByMagics()

if rplayer.hasmagiceffect(Fire) || rplayer.hasmagiceffect(Frost) || rplayer.hasmagiceffect(Shock)
	return true
else 
	return false
endif

EndFunction

Function ShowArmorPtsLost(bool Blk)

	HealthLost =  HitQuest.playerhealth - rplayer.getAV("Health")
	HitQuest.playerhealth = rplayer.getAV("Health")
	if HealthLost < 0
		HealthLost = HealthLost * -1
	endif
	if HitByMagics() == false
		damratio = HealthLost * 0.3
	else
		damratio = HealthLost * 0.05
	endif
	DiceRoll = Utility.Randomfloat(0, damratio)
	if DiceRoll > 0.3
		if Blk && HitQuest.WearShield()
			HitQuest.SHealth = HitQuest.SHealth - DiceRoll
		else
			WearToHit(DiceRoll)
		endif
	endif

EndFunction

 

 

 

Thats pretty much it, other than a simple effect script that tell you what the armor HP values are.

Also, this code isn't commented so.. yeah sorry about that.

 

Edit: Nope, GetFormID() didn't work.

 

Edit2: Can't use OnObjectEquipped either because I'm not certain which occurs first, OnObjectEquipped or OnContainerChange.

Tried putting in form current object but the compiler just gives me errors.

Edited by tnt90
Link to comment
Share on other sites

I'll have another look tommorrow, trying to read through this much code on my phone isn't easy >.< lol

 

Edit - all I can think of at the moment is doing it through the script on the player as the only known (to me) ways to get for base object is through container change and equip events.

Edited by maniczombie
Link to comment
Share on other sites

Yeah take your time, there's a lot of code and I haven't really commented it at all. My programming professors would skin me alive for not doing so. :P

 

I'll probably go back through that post and try to add in a few comments on what everything should do.

Link to comment
Share on other sites

I only started learning this stuff yesterday so I'm probably wrong or maybe I don't understand what you're asking, but isn't that what Self is for?

 

ScriptName someObjRefScript Extends ObjectReference

ObjectReference objRef

Event OnInit()
   objRef = Self as ObjectReference
EndIf

Link to comment
Share on other sites

Yes, but aren't they sort of one in the same, indirectly? I mean, I assume you want an ObjectReference pointer so you can call methods on it, which will execute against the base object - presumably the object the script is attached to. At least that's how it seems to work in the 1 script I've written so far.

 

Sorry if I'm way off, I'm still a little confused by the blur between scripts and objects in Papyrus.

Link to comment
Share on other sites

I just re-read your first post. I mis-understood. I thought you wanted an ObjectReference variable, not a variable of some specific object type, like Armor. Maybe this will work

 

ScriptName someArmor Extends ObjectReference

Armor theArmor

Event OnInit()
   theArmor = GetBaseObject() as Armor
EndEvent

Link to comment
Share on other sites

Tried that, didn't work though. GetBaseObject() just returns a None.

 

So far I've tried:

GetBaseObject() - returned None

self - returned the script

self.GetBaseObject() - can't remember what it returned but it wasn't the armor

GetFormID() - returned 0

probably some others I can't remember as well

 

The only thing I can think of is checking which block OnContainerChange of the incoming object or OnItemAdded() on the player triggers first and if it is consistent.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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