OpenXcom Forum
OpenXcom Forks => OXCE Support => OpenXcom Extended (OXCE) => OXCE Support Y-scripts => Topic started by: skyhawk on January 06, 2020, 10:18:23 am
-
I'd like to implement an integrated medical system in advanced armors.
The scripting system seems like a bit of a black art to me. I can provide psuedocode of exactly what I want to happen, but have no idea where to even start coding it. Is there some digestable reference that my quick google-fu has failed to find?
In this context, 'break' means to cease execution. The script should never do more than one thing per turn per soldier.
newTurnUnit
if IsXComTurn == true
if SoldierInFancyArmor == true
if FatalWounds > 0 [Any gaping holes?]
FatalWounds = FatalWounds - 1
HP = HP + 3 [Standard medkit heal behaviour]
break
if Unconscious
Administer stim shot
break
if MoraleDamagedDueInjury [How does morale and painkillers work wrt injury, vs buddies dying, vs psi fuckery?]
Administer a painkiller shot
break
if Energy < MaxEnergy * 0.6 [Exhausted from all that running around?]
Administer a stim shot
break
if StunLevel > HP * 0.5 [At risk of incapacitation?]
Administer a stim shot
break
Scripts done and tested good as far as I can tell, thanks all!
This is what the pseudocode for the final product looks like:
newTurnUnit
if IsXComTurn == true
if SoldierInFancyArmor == true
if FatalWoundsNum > 0 [Any gaping holes?]
HP = HP + DiceRoll * FatalWoundsNum
break
if Unconscious
Administer stim shot
break
if Energy < MaxEnergy * 0.6 [Exhausted from all that running around?]
Administer a stim shot
break
if StunLevel > HP * 0.5 [At risk of incapacitation?]
Administer a stim shot
break
-
look on https://openxcom.org/forum/index.php/topic,7731.0.html where I answered similar question,
for start, conditions are write in different way usual scripts, closer to lisp than C-like.
`if IsXComTurn == true` should be
if eq side 0;
# ...
end;
where 0 is xcom, 1 is aliens and 2 is civilians
`if SoldierInFancyArmor == true` you need define new tag in armor to check for something like that, example is in liked post
`if FatalWounds > 0` should be `var int fatal; ... unit.getFatalwoundsTotal fatal; ... if gt fatal 0; ... end;`
var int fatal;
# ...
unit.getFatalwoundsTotal fatal;
# ...
if gt fatal 0;
#...
end;
`if Energy < MaxEnergy * 0.6` should be
var int energy;
var int energyMax;
# ...
unit.getEnergy energy;
unit.getEnergyMax energyMax;
muldiv energyMax 6 10; // energyMax = (energyMax * 6) / 10
# ...
if lt energy energyMax;
unit.setEnergy 100; #it will try to set energy to value 100
end;
This probably should be enough to start experimenting. Remember to check logs for scripts errors, enable verbose logging for more info about scripts and use `debug_log "some text" some_value "some unit" unit;` to output data from scripts to log.
-
Thanks for the starting point Yankes.
Is there a reference anywhere? googling 'OpenXCom getFatalwoundTotal" yields literally zero results. Any documentation regarding getting game engine data into and out of the script would be much appreciated.
edit: I just found this (https://raw.githubusercontent.com/ohartenstein23/Yankes-Scripting/master/yankesScript.txt), and am skimming through it.
-
What you found is the output from the openxcom.log file when you turn debug and verbose logging on in the options.cfg file. I periodically make a copy of that output and post it on github as a reference later, which is what you found. It's likely out of date, so you should run OXCE once with debug + verbose logging and make a copy for your own reference.
The only other reference material are the scripts used in other mods - Piratez and XCF use the same set of scripts I wrote with some minor changes. You can find the base file here on github as well (https://github.com/ohartenstein23/Yankes-Scripting/blob/master/Yankes_Scripts.rul).
-
I don't suppose there's any flow control? I'd just about kill for a for or while loop right about now.
I haven't gotten to the point where I need it yet, but a break; statement would also save me a whole lot of if statements.
Edit again: I just noticed 'return;' in some examples - maybe that's the break; I'm looking for.
-
AFAIK, loops are not added yet. The return statement is for returning control back to the game. Basically exiting your current script.
-
Right now we have only `if`and `else`, loop wait in line when I add scoped variables then I could add proper `loop` operation.
-
AFAIK, loops are not added yet. The return statement is for returning control back to the game. Basically exiting your current script.
Which is exactly what I was doing with break in my psuedocode. Perfect.
-
How do I write
if ((a == b) or (a < b)) ?
I think it's
if or lt a b eq a b
-
That is correct.
You also have le (less than or equal) ge (greater than or equal) and neq (not equal).
Gesendet von meinem Pixel 2 mit Tapatalk
-
Thanks for your help all!
I've got a working script that I'm pretty happy with. Couldn't do the healing fatal wounds thing, but really that's ok because that's what medikits are for. Also decided painkillers weren't worth the effort. [I'm sure my soldiers love me]
I have uncovered possibly incorrect behavior in the stun mechanic though!
[07-01-2020_23-42-57] [DEBUG] Script debug log at 0x6f6: IMS - Incapacitation detected for ID 2 . health = 20 , stun = 29 , maxStun = 180
[07-01-2020_23-42-57] [DEBUG] Script debug log at 0x87c: IMS - Shooting some stims for ID 2 , Energy now 87 , Stun now 25
Soldier is a heap on the floor
[07-01-2020_23-43-15] [DEBUG] Script debug log at 0x6f6: IMS - Incapacitation detected for ID 2 . health = 20 , stun = 24 , maxStun = 180
[07-01-2020_23-43-15] [DEBUG] Script debug log at 0x87c: IMS - Shooting some stims for ID 2 , Energy now 87 , Stun now 20
Soldier is a heap on the floor
[07-01-2020_23-43-43] [DEBUG] Script debug log at 0x780: IMS - Incapacitation risk for ID 2 . health = 20 , stun = 19 , maxStun = 180
[07-01-2020_23-43-43] [DEBUG] Script debug log at 0x87c: IMS - Shooting some stims for ID 2 , Energy now 87 , Stun now 15
Even before my mod pumped a stimmie into this soldier, he should be on his feet, but he's not!
[07-01-2020_23-45-52] [DEBUG] Script debug log at 0x780: IMS - Incapacitation risk for ID 2 . health = 20 , stun = 14 , maxStun = 180
[07-01-2020_23-45-52] [DEBUG] Script debug log at 0x87c: IMS - Shooting some stims for ID 2 , Energy now 87 , Stun now 10
NOW the soldier is finally up and about.