Jump to content

Scripting Help for Armor Durability Mod


tnt90

Recommended Posts

There seems to be a bit of misunderstanding in this thread, so hopefully I can clear it up in this post.

 

The special variable "Self" refers to the object to which the script is attached, not the script itself. The confusion here arouses, I suspect, due to the fact that "Self" refers to the object cast to the type defined by the script. Every Papyrus script is essentially a type definition. For example, Actor.psc defines the type "Actor". If I write a script called "MyActorScript" that extends "Actor", then I'm essentially defining a type called "MyActorScript", and every Actor to which MyActorScript attached will be an object of type MyActorScript.

 

GetBaseObject returns the base object (of type Form) of the object on which it is called. If it's called without explicitly specifying the object on which it should be called, then it is called on "Self". In this case, that means the scripted object as the type you're defining in your script. As your script extends ObjectReference, it also inherits all of ObjectReference's functions, including GetBaseObject.

 

The difficulty you're facing is likely due to issues with inventory items. I can't remember when it will and won't work, but I think creating the item outside of an inventory then adding it to an inventory will cause it to act appropriately, whereas creating an item inside an inventory may cause issues.

 

This isn't something I've had to deal with very much, though, so I can't tell you off the top of my head how to solve your problem. Hopefully I've at least clarified what's going on here a bit for you though.

 

Cipscis

Link to comment
Share on other sites

I just read something that might shed some light...

 

From http://www.creationkit.com/OnItemAdded_-_ObjectReference

 

In the notes section, the first note, "Once an object has been added to a container it is no longer valid to call member functions on it. Member functions on akItemReference (which is often None) will most likely fail to run with an error."

 

This seems to be saying that the functions in scripts attached to objects in a container cannot be called from "external" scripts - those not attached to that object.

 

e.g. A script attached to a player cannot call a function of a script attached to the armor he's wearing.

 

Am I reading that right?

Link to comment
Share on other sites

Yeah I figured that's what's happening. ... which would be why GetBaseObject isn't working when its in an inventory.

Cipscis, am I understanding correctly then that self should return the armor the script is attached to without any other calling needed to be made? And if so, since no other callings need to be made then it should return the armor if it is in or out of an inventory.

Hmmm, let me try this real quick before I head to work..

 

Strange, it now works when dropping or picking it up from the ground but not when taking it from an actor or adding via console/forge. But we're closer!

 

I think I understand what is going on now, self gets set when its out of an inventory so then it'll work, but until then it doesn't know what itself even is.

So for it to work you'd need to drop every armor before using it.

I think the next step is to see the processing order of OnContainerChange and OnItemAdded. If OnItemAdded runs first I can just take the object that returns and use that for the OnContainerChange event, if not, then is there perhaps a command to have a script wait a bit then finish processing?

Link to comment
Share on other sites

I do believe I've solved it. My test cases have all worked as intended.

 

Here's what I did: I added on a OnItemAdded event to my player reference alias script and an array of forms onto my quest updater script along with some of Chesko's array functions. That new event adds the added form to the form array if it has one of the 5 armor type keywords. The OnContainerChange event now has a wait added in to make sure the new event runs and adds the form to the array then the OCC event takes the first form from the array and removes it as well as sorting everything down. This should hopefully make adding armors in quick succession still work.

 

If anyone wants to see the new modified code, let me know, I'll stick in another spoiler tag.

 

Thanks to everyone.

Link to comment
Share on other sites

I've been thinking of a better way to get your armor script onto armors without having to manually attach them in CK.

 

First of all, holy crap the truckload of armor objects to edit and attach a script to...

 

But mostly because I think it would conflict with any other mod that also directly alters vanilla armor objects. Plus any mod that adds new armors wouldn't benefit from your mod.

 

Lastly, you had mentioned before about it not working on pre-existing armors. Presumably because scripts directly attached to base objects (forms) are only added to instances at creation. Since they didn't have the script when the game was saved, they're not going to get the new script when savegame is loaded.

 

By dynamically attaching the script as needed, all those issues aren't issues. So far, the only way I've seen to do this is by attaching a ReferenceAlias script to a reference alias and then setting the target of the alias at runtime using ForceRefTo which effectively attaches that ReferenceAlias script to the ObjectReference.

 

Anyways, just some thoughts I had. Not sure if anything would pan out from it.

 

 

I'd like to see your modified code, if you wouldn't mind. Reading other people's code helps me learn.

Link to comment
Share on other sites

Oh I'd love to be able to dynamically attach these, but I haven't really looked into it too much. I'll have to take a look at how that function is used.

 

If I say call that when I add in an armor and change to alias to work on that added armor (lets say a hide cuirass), if I then add in another armor (hide boots), will the alias be removed from the cuirass? The whole reason I'm putting a script on each armor is so that they can store their independent durability HP. Otherwise you could just drop it and pick it back up to reset the HP or something along that line.

 

 

Code for Armor (still working on a good wait time, sometimes it works and sometimes it doesn't)

Scriptname TNTArmorGeneric extends ObjectReference  

TNTUpdaterScript Property HitQuest auto
float LocalHP
float LocalHPMax
bool DoOnce
Actor rplayer
bool CanWear
Form ArmorForm

Event Oninit()



EndEvent

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)

rplayer = Game.GetPlayer()
Utility.Wait(0.25)
if HitQuest.incomingarmorarray[0] != None
	ArmorForm = HitQuest.incomingarmorarray[0]
	;Debug.Notification("This ArmorFomr is: " + ArmorForm)
	HitQuest.ArrayRemoveForm(HitQuest.incomingarmorarray, HitQuest.incomingarmorarray[0], true)
else
	Debug.Notification("The array didn't have enough time or something")
endif
if DoOnce == false && akNewContainer As Actor == rplayer
	DoOnce = true
	LocalHPMax = HitQuest.GetMaxArmorHealth(ArmorForm as Armor)
	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 || ArmorForm.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 || ArmorForm.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 ArmorForm.HasKeyWordString("ArmorHelmet")
	;Debug.Notification("Helmet")	
	HitQuest.HHealth = LocalHP
elseif ArmorForm.HasKeyWordString("ArmorCuirass")
	;Debug.Notification("Cuirass")	
	HitQuest.CHealth = LocalHP
elseif ArmorForm.HasKeyWordString("ArmorBoots")
	;Debug.Notification("Boots")	
	HitQuest.BHealth = LocalHP
elseif ArmorForm.HasKeyWordString("ArmorGauntlets")
	;Debug.Notification("Gauntlets")	
	HitQuest.GHealth = LocalHP
elseif ArmorForm.HasKeyWordString("ArmorShield")
	;Debug.Notification("Shield")	
	HitQuest.SHealth = LocalHP
else
	Debug.Notification("ThisArmor did not match any of the armor keywords")
endif

EndFunction

Float Function GetHP()

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

EndFunction

Event OnUnequipped(Actor akActor)

if akActor == rplayer
	LocalHP = GetHP()
endif

EndEvent

Code for Reference Alias on player

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

and

Scriptname TNTItemDetectorScript extends ReferenceAlias  

TNTUpdaterScript Property HitQuest auto

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

if akBaseItem.haskeywordstring("ArmorCuirass") || akbaseitem.haskeywordstring("ArmorBoots") || akbaseitem.haskeywordstring("Armorgauntlets") || akbaseitem.haskeywordstring("ArmorHelmet") || akbaseitem.haskeywordstring("ArmorShield")
	;Debug.Notification("Armor added to array")
	HitQuest.ArrayAddForm(HitQuest.incomingarmorarray, akBaseItem)
endif

EndEvent

Code for Quest Updating

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
form[] Property incomingarmorarray 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)
incomingarmorarray = new form[20]

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

; from Chesko's available array functions
bool function ArrayAddForm(Form[] myArray, Form myForm)

       ;-----------\
       ;Description \  Author: Chesko
       ;----------------------------------------------------------------
       ;Adds a form to the first available element in the array.
       
       ;-------------\
       ;Return Values \
       ;----------------------------------------------------------------
       ;               false           =               Error (array full)
       ;               true            =               Success
                       
       int i = 0
       ;notification("myArray.Length = " + myArray.Length)
       while i < myArray.Length
               if myArray[i] == none
                       myArray[i] = myForm
                       ;notification("Adding " + myForm + " to the array.")
                       return true
               else
                       i += 1
               endif
       endWhile
       
       return false

endFunction

bool function ArrayRemoveForm(Form[] myArray, Form myForm, bool bSort = false)
       
       ;-----------\
       ;Description \  Author: Chesko
       ;----------------------------------------------------------------
       ;Removes a form from the array, if found. Sorts the array using ArraySort() if bSort is true.
       
       ;-------------\
       ;Return Values \
       ;----------------------------------------------------------------
       ;               false           =               Error (Form not found)
       ;               true            =               Success

       int i = 0
       while i < myArray.Length
               if myArray[i] == myForm
                       myArray[i] = none
                       ;notification("Removing element " + i)
                       if bSort == true
                               ArraySort(myArray)
                       endif
                       return true
               else
                       i += 1
               endif
       endWhile        

       return false
       
endFunction

bool function ArraySort(Form[] myArray, Int i = 0)

        ;-----------\
        ;Description \  Author: Chesko
        ;----------------------------------------------------------------
        ;Removes blank elements by shifting all elements down.
        ;Optionally starts sorting from element i.

        ;-------------\
        ;Return Values \
        ;----------------------------------------------------------------
        ;                 false                   =                       No sorting required
        ;                 true                 =                          Success

        bool bFirstNoneFound = false
        int iFirstNonePos = i
        while i < myArray.Length
                 if myArray[i] == none
                          if bFirstNoneFound == false
                                       bFirstNoneFound = true
                                       iFirstNonePos = i
                                       i += 1
                          else
                                       i += 1
                          endif
                 else
                          if bFirstNoneFound == true
                          ;check to see if it's a couple of blank entries in a row
                                       if !(myArray[i] == none)
                                                ;notification("Moving element " + i + " to index " + iFirstNonePos)
                                                myArray[iFirstNonePos] = myArray[i]
                                                myArray[i] = none
                       
                                                ;Call this function recursively until it returns
                                                ArraySort(myArray, iFirstNonePos + 1)
                                                return true
                                       else
                                                i += 1
                                       endif
                          else
                                       i += 1
                          endif
                 endif
        endWhile

        return false

endFunction

 

Edited by tnt90
Link to comment
Share on other sites

Well there are only three times that it needs to run, when you change container, when you equip it and when you unequip it. Object References have those events built in so as long as we can still call those events we should be fine.

And it seems we can, if I understand it right.

 

I'd actually really like to see if it will stick or not or if there is a way to do that with papyrus. If we can get it to dynamically add the script to the armors then we can also add a script to actors the player has targeted/is near/is fighting to make weapon durability possible as well. But that's a whole other ball game there.

Edited by tnt90
Link to comment
Share on other sites

So far as I've been reading, it seems the cloak spell method described in here: http://www.creationkit.com/Dynamically_Attaching_Scripts will work for any weapon durability actions just fine. But unless I was to create an alias for every possible armor, I don't think I could achieve what I'm after with armors. Sure it'd prevent incompatibilities, but require even more work than manually attaching each one I think.

 

Does anyone know a better way?

Link to comment
Share on other sites

  • Recently Browsing   0 members

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