Jump to content

[LE] How to properly script a custom conditional system which will be used by a quest script?


Recommended Posts

Hello there, thanks for taking a look at my help request here :smile:

 

I'm currently trying to make a script which contains a custom conditional system which will be used by a particular quest script. The quest script is about a transformation feature which transform the player into something, and that transformation effect is triggered when some conditions are met. Those conditions are contained inside something i called "custom conditional system" above. To make things clearer and easy to read, i'll try to arrange it better here.

 

Transformation

  • Transform the player into "lost control" state
  • Lost control state replaces the player with a set of prepared NPCs which will be choosen depend on what weapons the player currently wield before being transformed
  • The replacer NPC is driven by an AI to attack and kill everything near it
  • The transformation effect has a calculated duration which is calculated from something called "killcount". Killcount checks how many kills the replacer NPC made after being transformed. The more it kills, the longer the duration.
  • Trigger for this whole transformation effect depends on calculations contained in the Transform Condition System

Transform Condition System

  • Has something i call "Condition meter" which has ranged values from 0 to 1000
  • Condition meter 1000 means 100% chance for the transformation effect to happen. Condition meter 0 means 0% chance to transform.
  • Condition meter will be filled or be emptied based on some game statistics' values. Some game statistics increase the condition meter, but some others reduce the meter.
  • Each game statistic is given a base value to add or subtract the condition meter.
  • Whenever the player do something which contribute to a particular game statistic, the base value of that game statistic will be contributed into the condition meter (either add it or subtract it).
  • The amount of condition meter will then determine the chance for the player to transform into lost control state.

I already have the base script for Transformation, but still currently trying to make Transform Condition System. I'm not sure whether it has to be written into its own script or can be included within Transformation script. If it has to be made separately, then do i need to add "extends Quest Conditional" or simply "extends Quest" (i'm still confused on the usage of Conditional keyword in scriptname line). Also, do i need to extends the script into Quest script or instead into some other script?

 

It will also be cool if someone would help me to write the base for Transform Condition System script :teehee:

 

I'm still new to papyrus scripting, so any guides will be appreciated. Thanks in advance :smile:

Link to comment
Share on other sites

It turns out that i have managed to solve most of them. There are still some works need to be done though, such as 1) making sure that Transformation only works when the player wears specific armor AND only in combat with health below xx% (configurable), 2) making codes to copy player's weapons into the replacer NPC's inventory, 3) adding "area fear effect" around the replacer NPC so that any innocent/weak NPCs will run away instead of trying to fight the replacer NPC. So, i'll still accept any helps for these areas.

 

Oh, i also want to notify that the scripts i'm using are based on Moonlight Tales Essentials Overhauled (MTEO) by ubuntufreakdragon. He gave me permission to use his scrips as long as i credited him. So all credits go to him since he has done most of the work :smile:

What i did was simply replacing his "Lunar Transformation" system with Transform Condition System (in which i renamed it into Morality System), replacing "feed" mechanism into "kill" mechanism (since the replacer NPCs are humanoids, not werewolves), replacing all instances about werewolf NPC replacer into my NPC replacer (named "Berserker"), removing any codes related to skin changer/updater, renaming properties and variables to suit my needs, and some minor things i couldn't remember. I also decided to give a name to Transformation mechanism with Lost Control (just like what MTEO uses).

 

I'll post my WIP script here so that people will get a better idea on what i'm working on (a bit long, but can't be helped lol)

Transformation (a.k.a. Lost Control) script (contains Morality System which is now built in into it):

 

  Reveal hidden contents

 

 

Link to comment
Share on other sites

  • 2 weeks later...

You wrote: "I'll post my WIP script here so that people will get a better idea on what i'm working on"

 

My advice use smaller papyrus projects to understand the basics of this language. Find your own coding style.

Use this website as lexicon: http://www.creationkit.com/index.php?title=Category:Scripting

 

Berserk_Loose_Control_Script

  Reveal hidden contents

 

Link to comment
Share on other sites

  On 1/22/2019 at 2:32 AM, ReDragon2013 said:

You wrote: "I'll post my WIP script here so that people will get a better idea on what i'm working on"

 

My advice use smaller papyrus projects to understand the basics of this language. Find your own coding style.

Use this website as lexicon: http://www.creationkit.com/index.php?title=Category:Scripting

 

Berserk_Loose_Control_Script

  Reveal hidden contents

 

Thanks for coming here too, ReDragon2013! :laugh:

 

Yes, one really shoud to start from smaller projects first before delving further into the depths of papyrus scripting. But unfortunately, the features i realy want to have in my mod requires such kind of advanced codes, so i have no other choices other than get my hands dirty with such complex papyrus scripting. Fortunately, ubuntufreakdragon made a mod which works just exactly what i need, and he gave me permission to use his scripts as long as i credit him. So that helped me a lot with a robust base script for a feature i want in my mod, and i need to edit and tweak it further (also removing unnecessary codes) in order to get the result i really want.

 

The script i posted here was an "old" version since it has been edited and updated further, although it's not finished yet (i'm still in progress on finishing it). That said, thanks for your edited script and i'll try to elaborate it. If i have some problems or questions regarding it, then sorry if i'll bother you again for asking about it (i'll most likely try to post the new version of the script so that you and other people can take a look at it and see if there's anything need to be corrected or improved). Big thanks to you anyway! I'll surely put your name in the credits for the mod once it's released. :smile:

 

Edit: Just did a quick glance on your edited script, and i find that you've added some significant improvements i could never think of. I could learn a thing or two from this. But now i need to take a rest since my body is atching all over, wanting to go to bed earlier. :laugh:

Edited by qwertypol012
Link to comment
Share on other sites

Alright, so i have somehow -more or less- finished the scripts, except MCM script which i'm still working on to finish. Here i'll post the scripts, hopefully you can take a look and check if there's something wrong or need improvement.

 

There are several scripts. Some of them are linked each other, ie. some functions from a script are called by other scripts. I'll post the scripts with the name on it.

 

1. Berserk_Loose_Control_Script.

This is the main script which governs lose control mechanism.

 

  Reveal hidden contents

 

 

2. SCRBerserkArmorCheckIfSet.

This script is to add the spell which trigger the transformation to the player. I need to give a bit more explanations about this. So, the mod i'm trying to make is a transformation feature which is casted by a spell. The transformation has chance to make the player "losing control". The spell to transform is added to the player when he/she is wearing a certain armor. This script (ie. SCRBerserkArmorCheckIfSet) checks if the player has worn the armor properly, then add the spell. In addition, this script also contains additional features such as initialising the loose control script (ie. Berserk_Loose_Control_Script) and giving chance to transform when getting hit.

 

  Reveal hidden contents

 

 

3. Berserk_RefAlias_Playerreplacement_Script

This script is a ref alias for the player replacement when he/she's losing control and being replaced by the NPC replacer.

 

  Reveal hidden contents

 

 

4. Berserk_Effect_Warningspell_Script

This script is for warning spell which will be casted when the player is about to lose control.

 

  Reveal hidden contents

 

 

I still have additional script to add kill skill gain feature, but it's still on the plan so i can't upload it yet. Currently, i'm still wondering whether i have put function Initialise() and TransformBack() from Berserk_Loose_Control_Script properly. Initialise() acts as an "Start" button for lose control system,and TransformBack() acts as "Stop" button.

I really hope that you can check on these and give me feedbacks or corrections if necessary. Thanks in advance. :smile:

Edited by qwertypol012
Link to comment
Share on other sites

At first let us make clear the dependencies and scripting order.

 

(1) SCRBerserkArmorCheckIfSet, renamed as

qlBerserk_ArmorScript

  Reveal hidden contents

 

As you can see I removed some code to make it more clean. I wonder if the OnHit() event would be triggered for this armor script.

 

(2) Berserk_Effect_Warningspell_Script, renamed as

qlBerserk_EffectScript

  Reveal hidden contents

 

 

I remove the OnInit() event and added instead the OnEffectStart() event, which is much more useful to take for ActiveMagicEffect scripts.

 

(3) Berserk_RefAlias_Playerreplacement_Script, renamed as How much is this script used and for what RefAliases?

qlBerserk_PlayerAliasScript

  Reveal hidden contents

 

 

This is the right place for the OnHit() event code from armor script above. I cannot see any sense to use OnObjectEquipped() here.

 

(4) Berserk_Loose_Control_Script, renamed as

qlBerserk_QuestScript

  Reveal hidden contents

 

 

This quest script only with two functions, I believe there is still some work to make code inside more understandable. Some code of this is truly strange for me.

Edited by ReDragon2013
Link to comment
Share on other sites

Well, i need to elaborate it (ie. your edited scripts) at first (that's a lot of new logics and conditions :sweat:, but that's good if it improve the scripts :laugh: ) ... I couldn't imagine such simple-looking scripts from me could become something more complex-looking :pinch:


Anyway, you renamed the scripts with "qlxxxx". What does "ql" refer to btw?



I also have some feedbacks to what you wrote above:

1. You asked: "How much is this script used and for what RefAliases?" and "I cannot see any sense to use OnObjectEquipped()".

Berserk_RefAlias_Playerreplacement_Script or qlBerserk_PlayerAliasScript is only used for 1) calling function "player_replacement_was_killed" ie. if the player was killed during losing control, 2) updating the player health when the npc replacer is getting hit, 3) updating the player pos when the npc replacer goes too far (or enter a new cell i guess), 4) and to check if the player is equipping any ammo.

Ammo equpping check is used by Berserk_Loose_Control_Script or qlBerserk_QuestScript for the function "copy_player_gears_to_replacement()", which is if the player is equipping any ammo then it will be added to the npc replacer when lose control is triggered. So yeah, that function is needed, and it's put in the ref alias script to check if the player is equipping any ammo.


2. You wrote: "This is the right place for the OnHit() event code from armor script above."

I'm not sure if you've understood it correctly, but i just want to clarify that OnHit() in SCRBerserkArmorCheckIfSet is actually different with OnHit() in Berserk_RefAlias_Playerreplacement_Script. As the name of each script suggests, the first one is for the player, and the second one is for the NPC replacer. In other words, OnHit() in SCRBerserkArmorCheckIfSet runs when the player is getting hit (means that he/she is not losing control), while OnHit() in Berserk_RefAlias_Playerreplacement_Script runs when the NPC replacer (not the player) is getting hit (means that the player is losing control and hence is replaced by the NPC replacer) and then update the player's health based on the damage done to the NPC replacer. So i think we need 2 OnHit() events in separate scripts, right?


3. You wrote: "EVENT OnDetachedFromCell() ; no idea whether this will be triggered within a playerAlias script"

This is the original event from the player replacement ref alias script of MTEO by ubuntufreakdragon, and it does seem to work for some reason. Though i also do have no clue about this anyway. But do note that the function "update_player_pos()" called by this event is also called within Berserk_Loose_Control_Script or qlBerserk_QuestScript by OnUpdate() and OnUpdateGameTime() events. So i guess those two also contribute to make it work.


4. You wrote: "Some code of this is truly strange for me."

Which one do you mean?



I do have an additional question:

In the last edit, in Berserk_Loose_Control_Script, i tweaked MoralScore variable under Initialise() and Force_control_to_player() to set it into 0. So it's: MoralScore = 0

Is this necessary? I just want to restore it to zero so that it will be filled again when the lose control roll is running again.

Edited by qwertypol012
Link to comment
Share on other sites

ql is refering to your nickname "qwertypol012", keep in mind every script is stored in the same script folder.

In case two moders use the same script name in their mods, only the script from last loaded mod (esp-file) will be used ingame. That would be a problem.

 

You added "int MoralScore" as global script variable, not a good idea. Why? It is used as local function variable "float MoralScore", which makes really confusing.

 

About hit event your are right, this can be triggered also in ObjectReference scripts.

I need some time to update the scripts according to your explanation.

 

You wrote: "Berserk_RefAlias_Playerreplacement_Script or qlBerserk_PlayerAliasScript is only used for .."

My question was, how many RefAliases may have attached this script?

Link to comment
Share on other sites

"In case two moders use the same script name in their mods, only the script from last loaded mod (esp-file) will be used ingame. That would be a problem."

I see. You got a point. That nickname will really help.

 

"You added "int MoralScore" as global script variable, not a good idea. Why? It is used as local function variable "float MoralScore", which makes really confusing."

Uh, right. But it's actually remnants from your edited script of Berserk_Loose_Control_Script. You put "Int KillScore" as script variable, then put "float KillScore" as local function variable, then i renamed it to "MoralScore" and removed some math calculations from it, making it more simple since now it's purely calculated based on game stats, hence no need for additional values except from the used game stats and related variables.

So, should it be a script variable or local function variable? But it's used by at least 2 functions, so will it work without it's set as script variable?

 

"My question was, how many RefAliases may have attached this script?"

I'm not sure if i understand your question properly, but i can only say that the player replacement ref alias script is only meant for the npc replacer. If it doesn't bother you, mind to explain to me a bit about RefAliases? I think i'll make some mistakes if i don't understand about RefAliases properly (i tried to read the article in creation kit website but it's a bit complicated, a bit unfathomable for me).

 

 

Btw, i actually has a player ref alias script which currently only serves as a mean to give severe damage to the player when he's "overtransform". Here's the script:

  Reveal hidden contents

 

This also needs more explanations. In addition to everything i have written above (regarding the mod i'm trying to make), there are actually 2 kinds of transformation magic effect. The first one is normal transformation, and the second one is a dangerous transformation. Both are casted from a single spell (let's call it Transformation Spell), but with different conditions so that only one of them will be triggered whenever the spell is casted.

 

As i have said earlier (or so i think), the transformations leave after effects which will be triggered whenever the transformation ends. They are negative effects from some magic effects which are casted from a spell. If you noticed in the loose control script (Berserk_Loose_Control_Script), there's "BerserkerLostControlAfterEffects" spell. This is the spell to cast these negative effects (let's call it "After-effects Spell"). These negative effects have durations and will wear off once the durations end. If the player cast the Transformation Spell after these negative effects end, then the player will be transformed normally (normal transformation). If the player cast the Transformation Spell while the negative effects still active, then the player will go into the dangerous transformation. Basically, the dangerous transformation is only a more severe version of normal transformation. A notable feature from dangerous transformation is that the player will get additional damage when he's hit. To make it work, i had to make a script which does just this, and that's the script i posted above.

 

Actually, i'm still not sure where should i attach this script. The only thing i know is that it's different from the player replacement alias, so maybe i need to put it in a different quest script? But no clue if it can actually be simplified or included in any existing scripts.

 

 

Additonal notes:
To make things clearer (if it's still unclear), the lose control feature only runs when the player is in combat (i already set the condition in the lose control script). On top of that, there are also 3 additional conditions, and either 1 of them must be filled in order for lose control to run: 1) player has Transformation Spell (in other words, the player is wearing the armor, ie. the spell is added via the armor), 2) player is under normal transformation, or 3) player is under dangerous transformation.

What i really want to achieve from this is that, the lose control feature should work in ANY conditions (but only in combat), as long as the player is wearing the armor or he/she is being transformed. Note that when the player is being transformed, he/she will not wear the armor (it will be force-unequipped because the player will be force-equipped with other gears which replace the armor), so i need to put both transformation conditions on top of wearing the armor (a.k.a has the spell) condition.

 

TLDR, here's a basic simulation/scheme which summarizes all of above explanations:

 

Player wears the Armor => Transformation Spell added to Player

Player cast Transformation Spell => Player enter a Transformation state => Armor unequipped from Player, Armor2 equipped to Player

 

Transformation state:

1. Normal => casted after duration3 end

2. Dangerous => casted when duration3 still run

 

When Player is in Transformation state & if Player is in combat => has chance to Lose Control

 

If Lose Control is not triggered => Transformation state continues until its duration1 end

If Lose Control is triggered => Armor2 unequipped from Player, Armor equpped to Player, control taken from Player, Player replaced by NPC Replacer until its duration2 end

 

After duration1 end => Armor2 uneqipped from Player, Armor equipped to Player, Negative Effects casted to Player until its duration3 end

After duration2 end => NPC Replacer disabled, give control back to Player, Negative Effects casted to Player until its duration3 end

 

If duration3 still run & Player cast Transformation Spell => Player enter Dangerous Transformation

After duration3 end & Player cast Transformation Spell => Player enter Normal Transformation

 

When Player is in Dangerous Transformation & Player getting hit => Severe Damage spell casted to Player

 

 

I'll also post any additional scripts related to these functionalities (just in case if they're necessary):

1. qlBerserk_TransformScript

This is the script for Transformation Spell. Attached to both Normal Transformation and Dangerous Transformation magic effects.

 

  Reveal hidden contents

 

 

2. qlBerserk_RevertFormScript

This is the script to revert form. It's attached to a magic effect which will be triggered from Revert Form Spell. This spell is added after Player entered a Transformation state (see qlBerserk_TransformScript). This script calls RevertForm function from qlBerserk_TransformScript. It also force control Player when he/she is Losing Control.

 

  Reveal hidden contents

 

 

3. Other scripts which manage transformation conditions and related stuff:

 

  Reveal hidden contents

 

Edited by qwertypol012
Link to comment
Share on other sites

  • Recently Browsing   0 members

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