Jump to content

I need help defining properties / objects etc. in papyrus.


Recommended Posts

Greetings!
I'll try making this short and straight to the point:
I want the game to trigger a custom sound (T51Battery_CapacityLow) when the player is in a Power Armor suit and only when the fusion core battery (AmmoFusionCore health according to the game) reaches below 45%.
I was given some general instructions by kinggath down below but I could use some further help. See my own script results at the end. Any assistance is highly appreciated and will be credited in my work.
==============
General Guideline:
==============
- Setup a Quest, add an Alias to the player, add a script to that player alias
- In that script you're going to be watching an event that happens periodically, use the (OnLocationChange) event
- In it, you'll check if they are using PowerArmor (IsInPowerArmor)
- Once you've confirmed you're in power armor, you're going to check that power armor's inventory for a fusion core, and use (GetItemHealthPercent) on it
- If it's under 25, you play your sound, and store the reference to the fusion core, so next time this triggers you can check if it's the same fusion core so that it doesn't keep playing the sound over and over.

Summary:
Set up: ObjectReference Property oLastFusionCore Auto Hidden at the top of your script, and then during the same check of GetItemHealthPercent < 25, you check if that ref != oLastFusionCore
In fact you don't even need an alias to the fusion core with this method, just one to the player
So, setup a Quest, add an Alias to the player, add a script to that player alias, use the OnLocationChange event, and then write code to do what I described above.
=======
My script
=======
Scriptname T51DACSBatteryCapacty extends ReferenceAlias

ObjectReference Property oLastFusionCore Auto Hidden
Event OnLocationChange(Location akOldLoc, Location akNewLoc)
  if (Game.GetPlayer().GetCurrentLocation() == akOldLoc)
    if (Game.GetPlayer().IsInPowerArmor())
      if (Game.GetPlayer().GetItemCount(AmmoFusionCore) == 1)
        if (AmmoFusionCore.GetItemHealthPercent() < 45 )
          int instanceID =T51Battery_CapacityLow.play(self) 
        endIf
      endIf
    endIf
  endIf
endEvent
Link to comment
Share on other sites

Ok, I think your script has following problems (I may be wrong with some of them as never experimented neirher with onLocationChange or with how fusion cores are working)

1)To detect when player location is changed, currentlocation shouldn't be equal (!=) to oldLoc (but it may function differently as wiki has same line as you)

2)getitemhealthpercent returns float value from 1.0 to zero, so you should check if it is less than 0.45

The main problem is that you cannot call getitemhealthpercent on inventory items, as it is objectreference function and items in inventory don't have references and as far as I know fusion cores will be in player inventory.

 

I think there may be a better way to check all that, can do some testing with that tomorrow.

Link to comment
Share on other sites

Hey WestTek,

 

Just saw your PM - I was working on my mod on another PC.

 

If you still need help, let's talk about it tomorrow 'cause I'm wiped out now (past 4 a.m. in Paris... o_O)

 

Like Shavkacagarikia, I haven't played around much with LocationChange nor power armors but at a quick glance the quest idea seems a good idea - or a scripted spell which you add to the player when he enters powerArmor.

 

The main issue I see though is how can we find a function which detects which fusion core is being used by the PA you're in. GetItemCount(...) will probably return more than 1, because we all carry several in our inventory. I for one may carry several cores which are full and some others which are as low as 4 or 5 that I intend to sell - so your sound would be playing all the time in my game. You'd probably need some sort of polling function to detect which one among the10 or 12 fusion cores in my inventory is currently depleting because it's being used by my PA - see what I mean?

 

In the meantime, someone else may come up with some new ideas for you.

 

G'night all.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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