LeahTheUnknown Posted August 21, 2019 Share Posted August 21, 2019 Say I have several items of food in a mod, and I want to add/remove a magic effect to/from all of them. Say, for example, I want to remove the radiation damage on all vanilla food. I've started an xEdit script that attempts to do this, but it, well, doesn't... unit RemoveRadsScript; const RadString = 'DamageRadiationChem "Chem: Radiation Damage" [MGEF:00024056]'; Function Process(eWorking: IInterface): integer; var iEcount, i: integer; eEffects: IInterface; begin eEffects := ElementBySignature(eWorking, 'Effects'); iECount := ElementCount(eEffects); for i := 1 to iECount do begin eEFID := GetEditValue(ElementBySignature(ElementByIndex(eEffects, iECount)), 'EFID'); if eEFID = RadString then RemoveByIndex(eEffects, iECount, FALSE); end; end; end. Where I assume it is failing is in the "eEffects := ElementByPath(eWorking, 'Effects');" part. Since there is no overarching signature for the magic effects, I don't know what to use instead of 'Effects', as that's what they are labeled as in xEdit, as seen here: Anyone have any information on how to correct this, I would be super happy! Cheers, ~GKX Link to comment Share on other sites More sharing options...
DieFeM Posted August 21, 2019 Share Posted August 21, 2019 unit RemoveRadsScript; const RadString = 'DamageRadiationChem "Chem: Radiation Damage" [MGEF:00024056]'; Function Process(e: IInterface): integer; var i: integer; eEffects: IInterface; eEFID: string; begin eEffects := ElementByPath(e, 'Effects'); for i := 0 to ElementCount(eEffects) do begin eEFID := GetElementEditValues(ElementByIndex(eEffects, i), 'EFID'); if eEFID = RadString then RemoveByIndex(eEffects, i, FALSE); end; end; end. Link to comment Share on other sites More sharing options...
LeahTheUnknown Posted August 21, 2019 Author Share Posted August 21, 2019 Whoo! Thanks so much! Still kind of new to xEdit scripting, so I'm not completely familiar with the nuance of the various function. It works now. Again, thank you. Cheers, ~GKX Link to comment Share on other sites More sharing options...
DieFeM Posted August 21, 2019 Share Posted August 21, 2019 I'm pretty new to it too, but I've been practicing a lot for the last month, and I think that I've done a little mistake in this script, in the for loop, it goes from 0 to the count when it should go from 0 to count -1, for this end there's a function, Pred(), which returns the value of the passed integer minus 1: for i := 0 to Pred(ElementCount(eEffects)) do begin Like in any other programming language, if the count is 5, it contains 5 index: 0, 1, 2, 3, 4. So the loop goes from 0 to 4 (5-1). Link to comment Share on other sites More sharing options...
LeahTheUnknown Posted August 21, 2019 Author Share Posted August 21, 2019 I just used for i := 1 to ElementCount(eEffects) do Seems to work. ~GKX Link to comment Share on other sites More sharing options...
Recommended Posts