Jump to content

Issues with a MGEF to modify some Actor Value


payl0ad

Recommended Posts

I've been working on my first actual mod for some time now and I've run into a really weird issue. I *could* work around that issue by using more custom scripts, but I'd rather do the thing I'd like to do with in-engine mechanisms than with *another* script. So here goes.

My mod focuses on plausible behavior of radiation effects on the player. For this, I need to measure the amount of radioactive particles the player character ingests. I created a custom Actor Value Information record that has the "Minimum 1" flag (which I assume to mean "this value can not go below 1") to store that information. It is attached to the player.

I have created a Perk that permanently attaches an ActiveMagicEffect script to the player which handles all (or most) of my custom stuff. It has the following Event to react to the player eating irradiated food (which I put in 3 FormID lists referenced as properties here):

Event OnItemEquipped(Form akBaseObject, ObjectReference akReference)
if akBaseObject.HasKeyword(pFoodKeyword)
if pRawFoodList.HasForm(akBaseObject)
pPlayer.ModValue(pIngRadValue, 16.0)
elseif pPWFoodList.HasForm(akBaseObject)
pPlayer.ModValue(pIngRadValue, 32.0)
elseif pProFoodList.HasForm(akBaseObject)
pPlayer.ModValue(pIngRadValue, 8.0)
endIf
endIf
endEvent


This actually works. When I do player.getav tr_IngestedRads in the console after eating I can see the value actually changing.

Now to save code and performance, I created Magic Effects that modify Actor Values. Essentially, I copied those from regular radiation effects, which seem to also simply modify the "Rads" Actor Value. I changed them to change my custom Actor Value and tried to fire them from a spell my script casts:

Event OnItemEquipped(Form akBaseObject, ObjectReference akReference)
if akBaseObject.HasKeyword(pFoodKeyword)
if pRawFoodList.HasForm(akBaseObject)
pRawFoodSpell.Cast(pPlayer)
Debug.MessageBox("Rawfood spell cast")
elseif pPWFoodList.HasForm(akBaseObject)
pPWFoodSpell.Cast(pPlayer)
Debug.MessageBox("PW Food spell cast")
elseif pProFoodList.HasForm(akBaseObject)
pProFoodSpell.Cast(pPlayer)
Debug.MessageBox("Processed Food spell cast")
endIf
endIf
endEvent

In fact, I created 2 Effects: One that should add ingested rads, one that removes them again. The removing effect is fired by a modified RadAway ALCH item directly.

Now the weird part starts.

When I start all that stuff and the mod starts up, I can eat food and have that trigger the Debug.MessageBox instructions, so the part with the FormID List lookup works correctly. They don't apply the Magic Effect as the Actor Value does *not* change when I look it up with Player.getav tr_IngestedRads in console. I could already verify that the Effect does get applied, it just does not change anything, at least in the positive direction.

However, the tr_PurgeIngestedRadsEffect actually does work, sort of: When I player.modav tr_IngestedRads 500 and then consume a RadAway item, it counts down my Actor Value. If you look at the screenshot, you can see I specified a duration of 32 seconds. However, the effect does not stop to count down the Actor Value after it finishes (and disappears from the PipBoy status menu, which it currently doesn't because of the "Hide in UI" flag. I've tried with the flag active and inactive.). It does not even stop at 1 (even though my AV has that "Min 1" flag) and counts into negative numbers.

So I need help with 2 questions:

* Why doesn't tr_IncreaseIngestedRadsEffect fire correctly and mod my AV?

* What is the correct way to define a Value that can't be modified below 1, and why does my MGEF not stop after it finishes its duration?

Link to comment
Share on other sites

Spells work not the same as magic effects.

 

The easy way to attach a magic effect is a chem or food.

event some event

Player.EquipItem(MyChem)

 

You attach rads effect to the chem and you set a duration and magnitude in this chem so you don`t need to create remove effects. Also don`t fill it`s name if you want it to be a hidden item and remove all sounds to make it silent.

 

There was an article in the CK wiki that explained the difference and limitations for each category (magic effects, spells and enchantments). .

Maybe you also could use a disease instead of chem, but I have not created diseases and can`t remember if they work the same way or not.

 

And about your custom value I can`t tell anything as I I`m not sure what you are trying to achive with it.

Edited by kitcat81
Link to comment
Share on other sites

Thanks for the idea, that will be more consistent with other things I'm doing or trying to do with the mod.

 

Well I do know that my Value Modifier effect gets applied as I have a debug event for that. Calling the magic effect from an item (like from the RadAway item) seems to work better for me, whyever that may be. Hope this works, because from what I can tell it shouldn't. The effect gets applied after all.

 

The custom value is needed to store information about how much radioactive particles the player has ingested. I want to track that to calculate a chance to fire custom radiation poisoning diseases on a permanent background timer. That part actually works alright already. I'm still totally unsure how to keep that value above 0. AVs seem to have a flag for exactly this but for some reason it doesn't work like regular RadAway at all (where the "Rads" AV stops at 1). The concept is that RadAway can help you get rid of radiation (or rather, particles made up of radioactive nuclides) in your body and their nasty side effects but it can not cure tissue damage from radiation exposure (which the red bar in vanilla FO4 should represent), for that you need a new medicine that is also included in my mod.

Link to comment
Share on other sites

Be sure your rads effect has On EffectFinish and mods values back, in other way it won`t ever expire even if the duration is over.

 

Vanilla Actor Values are hardcoded. May be this is the reason they don`t go below one. But the game actually counts all point (i.e. if you modav perception -30 it will show 1, but if you mod it back +30 it will return everything as it was before modifying).

 

You can set a chance to get a disease by adding an int to your perk script.

Int MyValue = 0 

   Event OnItemEquipped(Form akBaseObject, ObjectReference akReference)
        if akBaseObject.HasKeyword(pFoodKeyword)
            if pRawFoodList.HasForm(akBaseObject)
                MyValue = MyValue + 16
            elseif pPWFoodList.HasForm(akBaseObject)
                MyValue = MyValue + 32
            elseif pProFoodList.HasForm(akBaseObject)
                MyValue = MyValue + 8
            endIf
        endIf
      If MyValue >= YourNumber
     Do something
     My Value = 0 (resets value)
  End If
EndEvent

Or you do it another way by adding a condition to your script (at the beginning before other conditions or at the end)

ActorValue RadValue = Player.GetValue(pIngRadValue)
If RadValue < 1 
Player.SetValue(pIngRadValue,1)
(optional elseif RadValue >= Your Number fire your disease or use a randomint as "flip coin" for firing your disease))
EndIf

Or you can add a chance to get your disease to your magic effect chem.

 

I just don`t completelly understand what exactly makes your value to go below zero. I mean what affects this value and makes it go down.

 

And adding a chance to the script can look like this :

int MyDiseaseChance = YourNumber
int roll = Utility.RandomInt(1, 100)
 If roll <= MyDiseaseChance
 Fire your disease

If you explain how do you want to calculate a chance for your disease and what else apart from your script affects this custom AV it will make a better picture.

Edited by kitcat81
Link to comment
Share on other sites

> I just don`t completelly understand what exactly makes your value to go below zero. I mean what affects this value and makes it go down.

 

This effect does that:

 

http://imgur.com/TtGGe77

http://imgur.com/LkicrOI

 

My current way of applying diseases is working. That's not the problem. It just needs this value to change by eating irradiated food. But I guess I'll just roll my own for that... ModValue() does work correctly after all.

Link to comment
Share on other sites

Good to know :smile: I asked for more details because it does not make a whole picture of the structure. it`s not really clear how all this is linked together I can only suggest that you can add something to this purging effect like

Player.GetValue(YourValue)

And heal/clean radiation YourValue -1

Then it should not go below zero.

 

Or OnEffectFinish

to set this value to 1

 

Or anotherr condition that this value and works only when this value is higher than 1

 

I`d make it without actor values using INT like i posted above and just add there one more elseif for equiping your radition cure (you don`t need the effect that reduces this value in this case), you just add a line elseif ;player equips your cure

int MyValue = MyValue - YourNumber (how much it cures)

Edited by kitcat81
Link to comment
Share on other sites

  • Recently Browsing   0 members

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