AslanKebab Posted April 23, 2018 Share Posted April 23, 2018 (edited) Hello Everyone, I´m in the process of creating a script that I want to work across several different Armor sets, without the need for duplication to adjust minor values.In this case, the enchantment has its own health variable that has to be hacked away at before the player health is affected, and I would like to be able to adjust it across various armour sets without having to duplicate the script for each item. I have considered using Global Variables but I am not sure how I would employ them, considering that they seem to be mainly used for setting custom conditions for when the Enchantment works and when it does not. One idea was to pick an unused but already defined value that is accessible through the armor editor window, but I am not sure how to make the variable available there. Below is an example of the kind of stuff the script is going to do, it is not complete and needs some more thorough testing but it should give an idea of its functionality.And in this case, I would like to insert the value into the baseArmorHealth value. Scriptname GuardEnchScript extends ActiveMagicEffect Actor Property PlayerREF Auto Keyword Property MagicDamageShock Auto Float baseArmorHealth; Float currentArmorHealth; bool isOnCoolDown = false; Function BarrierProtection() baseArmorHealth = 100; currentArmorHealth = baseArmorHealth; Float ArmorhealthDiff = baseArmorHealth - currentArmorHealth; PlayerREF.RestoreActorValue("Health", ArmorhealthDiff); endFunction Event OnEffectStart(Actor akTarget, Actor akCaster) Debug.Notification("On Effect Start!") endEvent Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked) Debug.Notification("On Hit is running ") if (isOnCoolDown && (1 * currentArmorHealth) > 0.1) isOnCoolDown = false; Debug.Notification("Cool down Reset"); endIf if (currentArmorHealth == 0) Debug.Notification("Cool Down Started"); isOnCoolDown = true; endIf if (!isOnCoolDown) if (currentArmorHealth >= 0 && (akSource as Weapon)) Debug.Notification("Is a Weapon attack") BarrierProtection(); elseIf (currentArmorHealth >= 0 && ((akSource as spell) || (akSource as Enchantment)) ) Debug.Notification("Is a Spell attack") if (akSource.HasKeyword(MagicDamageShock)) Debug.Notification("Shock Keyword") BarrierProtection(); endIf endIf else Debug.Notification("is on Cooldown"); endIf endEvent Any ideas and suggestions on this matter are welcome Thank you all in advance. Edited April 23, 2018 by AslanKebab Link to comment Share on other sites More sharing options...
AslanKebab Posted April 25, 2018 Author Share Posted April 25, 2018 Maybe I was unclear. I am looking for a way to change a custom variable value, present in a script from the creation kit editor.This would prevent me from duplicating the script just for some value changes when I am creating variations of the item. In this case, it is a script which I place Armor pieces. is This Possible or is there another way to achieve this kind of customization? Link to comment Share on other sites More sharing options...
FrankFamily Posted April 25, 2018 Share Posted April 25, 2018 (edited) You'd use a Int or Float property instead of a "hard coded" number in the script and set that propertie's value in CK. That's the point of properties in papyrus that you can reuse scripts because everything that conects to an item or form in the game, or a number can be changed in ck for a particular instance of the same script. Basically, change "Float baseArmorHealth" to "Float Property baseArmorHealth Auto" and you can set it's value in ck, or additionally set the default value like this: "Float property baseArmorHealth = 100.0 Auto" still being editable in CK. Edited April 25, 2018 by FrankFamily Link to comment Share on other sites More sharing options...
AslanKebab Posted April 25, 2018 Author Share Posted April 25, 2018 You'd use a Int or Float property instead of a "hard coded" number in the script and set that propertie's value in CK. That's the point of properties in papyrus that you can reuse scripts because everything that conects to an item or form in the game, or a number can be changed in ck for a particular instance of the same script. Basically, change "Float baseArmorHealth" to "Float Property baseArmorHealth Auto" and you can set it's value in ck, or additionally set the default value like this: "Float property baseArmorHealth = 100.0 Auto" still being editable in CK. This somehow flew over my head despite all the wiki reading..... Now I need to decide if I should move the script to the armour piece instead of the magic effect and tweak it so that I can have more variations in the enchantments as well. Thanks for pointing this out FrankFamily! Link to comment Share on other sites More sharing options...
FrankFamily Posted April 25, 2018 Share Posted April 25, 2018 On the armor form you won't get OnHit to trigger, that event is sent to the actor, it's aliases and magic effects but you can't get it from a script on the armor piece itself which would extend ObjectReference usually. If you want to not use the enchantment you'd need a quest alias. Link to comment Share on other sites More sharing options...
AslanKebab Posted April 26, 2018 Author Share Posted April 26, 2018 (edited) On the armor form you won't get OnHit to trigger, that event is sent to the actor, it's aliases and magic effects but you can't get it from a script on the armor piece itself which would extend ObjectReference usually. If you want to not use the enchantment you'd need a quest alias.If that is the case, would it not be easier to have a small script on the armor pecies that manipulates the value of "armorbasehealth" on the magic effect? Can global variables in the magic effect script be reached from a script on the armor peice holding the enchantment that the active magic effect is attached to, For example? (without SKSE) As the intention is to create a series of enchantments with various buffs/debuffs for magic schools and stats etc,in addition to the protection barrier from script above. I would like it to work this way, in order to take into account the increase in protection for higher level armors and insure the possibility of variation in the enchantments. Edited April 26, 2018 by AslanKebab Link to comment Share on other sites More sharing options...
foamyesque Posted April 26, 2018 Share Posted April 26, 2018 Is this all meant to work exclusively on the player? Link to comment Share on other sites More sharing options...
AslanKebab Posted April 26, 2018 Author Share Posted April 26, 2018 Yes Link to comment Share on other sites More sharing options...
FrankFamily Posted April 26, 2018 Share Posted April 26, 2018 You could easily make it work it work in any actor if you wanted I think, just store OnEffectStart's aktarget and use that instead of playerref. Imo, if you can keep the whole thing isolated in an activemagiceffect it's much better, just make properties for everything you want modified, then in ck you make all variations of the magic effect, same scripts, differently filled properties for the armor health, keyword, whatever. And then the same amount of enchantments. Now, if you wanted the armor piece to affect the functionality of the enchantment so you get extra variety without having to make a ton of magic effects and enchantments then instead of another script I'd say add custom keywords to these armor pieces and then check if those keywords are present from the magic effect's script (https://www.creationkit.com/index.php?title=WornHasKeyword_-_Actor) Link to comment Share on other sites More sharing options...
AslanKebab Posted May 2, 2018 Author Share Posted May 2, 2018 (edited) Thank you FrankFamliy for your ideas but I think I going to test this idea out. So, I´ve had a few days of testing with this and in theory, what I have should work but for some reason, it does not. Here´s a small recapMy item setup is the following in the creation kit.Magic effect(has a script) -> Enchantment -> Armor (Has a script) The idea is to create a relatively modular script that I can re-use without affecting other enchantments I want to add to other variation of this item. So I would like to make it easier down the line to create higher and lower level variants of armours carrying the functionality of this script with them but with different armour ratings and different accompanying enchantments. Scriptname GuardEnchScript extends ActiveMagicEffect Actor Property PlayerREF Auto Keyword Property MagicDamage Auto BarierHealthControl Property BarierHealth Auto ;Cast Float baseArmorHealth; Value is set from a script propety placed on the armor pecie. Float currentArmorHealth bool isOnCoolDown = false Function BarrierProtection() Float ArmorhealthDiff = baseArmorHealth - currentArmorHealth Debug.Notification("Armor damage is " + ArmorhealthDiff) PlayerREF.RestoreActorValue("Health", ArmorhealthDiff) endFunction Event OnEffectStart(Actor akActor, Actor akCaster) Debug.Notification("On Effect Start!") BarierHealth.SetBaseArmorHealth = baseArmorHealth Debug.Notification("Barrier Health " + baseArmorHealth) currentArmorHealth = baseArmorHealth endEvent Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked) Debug.Notification("On Hit is running ") if (isOnCoolDown && (currentArmorHealth/baseArmorHealth) > 0.1) isOnCoolDown = false Debug.Notification("Cool down Reset") endIf if (currentArmorHealth == 0) Debug.Notification("Cool Down Started") isOnCoolDown = true endIf if (!isOnCoolDown) if (currentArmorHealth >= 0 && (akSource as Weapon)) Debug.Notification("Is a Weapon attack") BarrierProtection() Debug.Notification("armor Barrier Healh is " + currentArmorHealth) elseIf (currentArmorHealth >= 0 && ((akSource as spell) || (akSource as Enchantment)) ) Debug.Notification("Is a Spell attack") if (akSource.HasKeyword(MagicDamage)) Debug.Notification("Shock Keyword") BarrierProtection() Debug.Notification("armor Barrier Healh is " + currentArmorHealth) endIf endIf else Debug.Notification("is on Cooldown") endIf endEvent The solution I am attempting is to have property variables being cast from a tiny script in the armour item to the script in the magic effect, updating its main variable to change how much damage this protective barrier can take before it is gone and the player health is affected. Here´s also the mini script on the Armour that takes the values. Scriptname BarierHealthControl extends ObjectReference Float Property SetBaseArmorHealth Auto Event OnEquipped(Actor akActor) Debug.Notification("Equipped") Debug.Notification("Set Barrier " + SetBaseArmorHealth) EndEvent What am I doing wrong here? When I run this, the baseArmorHealth variable in the magic effect script does not update to match the SetBaseArmorHealth variable in the armour script.Is my entire approach to this wrong? Any suggestions are welcome. Thank you. Edited May 2, 2018 by AslanKebab Link to comment Share on other sites More sharing options...
Recommended Posts