OpenXcom Forum
Modding => Help => Topic started by: WaldoTheRanger on March 16, 2020, 07:21:30 pm
-
Hello. I am trying to do something similar to what I described in this post:
https://openxcom.org/forum/index.php/topic,7987.msg124573.html#msg124573
I have gotten stuck trying to call the variable unit.getMorale and using it.
I have no idea why. it is being called and used only about 12 lines up in another script using a very similar hook.
unit.getMoraleMax seems to be working just fine.
these are the edits I'm trying to make:
from scripts_XCOMFILES.rul
newTurnUnit:
- offset: 1
code: |
#add morale and energy totals for calculating readiness
var int moraleLostTurn;
var int energySpentTurn;
var int currentMorale;
var int currentEnergy;
unit.getMoraleMax moraleLostTurn;
unit.getEnergyMax energySpentTurn;
unit.getMorale currentMorale;
unit.getEnergy currentEnergy;
sub moraleLostTurn unit.getMorale;
sub energySpentTurn unit.getEnergy;
unit.setTag Tag.UNIT_TOTAL_MORALE_LOST moraleLostTurn;
unit.setTag Tag.UNIT_TOTAL_ENERGY_SPENT energySpentTurn;
debug_log "Total Morale Lost is now" UNIT_TOTAL_MORALE_LOST;
debug_log "Total Energy Spent is now" UNIT_TOTAL_ENERGY_SPENT;
and this is the error message I get in the log file:
[16-03-2020_07-06-48] [ERROR] Unknown argument 'unit.getMorale'
[16-03-2020_07-06-48] [ERROR] Error in matching arguments for operator 'sub'
[16-03-2020_07-06-48] [ERROR] Error in parsing script 'newTurnUnit' for 'Global Event Script': invalid operation in line: 'sub moraleLostTurn unit.getMorale;'
-
problem is that you can't do two operations in one:
sub moraleLostTurn unit.getMorale;
Errors is that `sub` expect value as second argument not "function".
you need do something like:
unit.getMorale x; sub moraleLostTurn x;
where `x` is new variable.
-
ah. that worked.
thanks.
-
now I'm trying to use those stats to set mana at the battle end, like so:
returnFromMissionUnit:
- offset: 1
code: |
#Mana
var int manaCurrent;
var int x;
var int y;
unit.getTag x Tag.UNIT_TOTAL_MORALE_LOST;
unit.getTag y Tag.UNIT_TOTAL_ENERGY_SPENT;
unit.getMana manaCurrent;
muldiv x 1 1;
muldiv y 1 1;
sub manaCurrent x;
sub manaCurrent y;
unit.setMana manaCurrent;
It is doing nothing, but there are no compile errors.
it worked when I edited the manapool, using BattleUnit.Stats.getManaPool
and BattleUnit.Stats.setManaPool
but that's not quite what I want.
the muldiv 1 1 thing is for testing purposes.
-
Fist one, what you want change? battle unit or soldiers? this is two separate things, battle unit exists only for duration of battle and soldier exists for hole game (until he is killed).
If you use any function that start with `BattleUnit` this mean you edit game object that will soon deleted without trace.
You need look for `GeoscapeSoldier` and operations available on it.
-
I am trying to change the geoscape soldier's available mana, similar to how readiness works in xcf currently, but not based on amount of turns.
So, something like this?:
unit.getMana manaCurrent;
muldiv x 1 1;
muldiv y 1 1;
sub manaCurrent x;
sub manaCurrent y;
GeoscapeSoldier.setMana manaCurrent;
that gives this error:
[16-03-2020_10-40-44] [ERROR] Error in parsing script 'returnFromMissionUnit' for 'Global Event Script': invalid operation in line: 'GeoscapeSoldier.setMana manaCurrent;'
would I need to change things to reference a geoscape soldier in other places also?
-
First of all you need check what operations are available for given object.
Second "Mana" is only concept in battlespace, same as health. Correct stats for Solders are `*ManaPool` or even more accuracy `setManaMissing` or `getManaMissing`.
-
Oh, yeah. That should have made sense much earlier.
my bad.
-
Well, I'm not getting any errors, but it's not doing anything. manaMissing seems to be unaffected by the script.
returnFromMissionUnit:
- offset: 1
code: |
#Mana
var int manaCurrent;
var int x;
var int y;
var int z;
unit.getTag x Tag.UNIT_TOTAL_MORALE_LOST;
unit.getTag y Tag.UNIT_TOTAL_ENERGY_SPENT;
muldiv x 1 2;
muldiv y 1 10;
add x y;
soldier.getManaMissing z;
add x z;
soldier.setManaMissing x;
-
I find this really weird.
when I use soldier.setManaMissing x; it does nothing.
when I use soldier.Stats.setManaPool x;, that works. but that's not what I want. I don't want soldiers to be permanently crippled after a single gang fight.
-
Ok, unfortunate code order, script is first run and after that game update `setManaMissing`this mean overwrite value you set.
I will see how best handle this case, I will fix it to allow custom scripts to alter it in one way or another.
-
Oh sweet.
Thanks a ton.
-
Also, if there isn't a particular reason for there not being a BattleUnit.Exp.get[stat increase] for time units, stamina, and health, then it would be nice if those could be added.
-
Also, if there isn't a particular reason for there not being a BattleUnit.Exp.get[stat increase] for time units, stamina, and health, then it would be nice if those could be added.
Those can't be added because they don't exist even in the unscripted part of the code. If you get battle experience in any way, you automatically get a chance to roll increases in those stats.
-
ok. makes sense.
so does that also mean that there's no circumstance in which you'd only get an increase in those stats and nothing else?
-
If you only get one firing experience point, you have a chance of rolling +0 gain in firing accuracy but still get the secondary stat rolls. You need at least 3 experience in primary stats to guarantee at least +1 in that stat, except for bravery which needs something like 10 experience for guaranteed gain.
-
Oh I'm dum. I was confused by the difference between xp and the actual stat increases.
that's cool. actually a bit more useful anyways.
-
Guys, I appreciate the enthusiasm, but I've already made some decisions (based on our previous conversation). So feel free to experiment of course, but we don't really need anything else at this point for XCF.
-
What a relief. I was very quickly getting in over my head :)
can't wait to see what you've got coming.