Cre library
Action functions
clone_creature (list creature, [str edits, arrowlist editstring, bool allow_missing])
edit_all_creatures ([str edits, arrowlist editstring])
edit_creature (list creature, [str edits, arrowlist editstring, bool tv, allow_missing])
install_creature (list creature, [str edits, location, locbase, arrowlist editstring, bool tv, allow_missing]
Standard editors; no special features
make_creature (str creature, [str edits, arrowlist editstring])
The creature created has its animation, saving throws, and THAC0 set to the appropriate value for a creature of its type (unless they are manually set in the creation process). If an animation cannot be found, a warning will be displayed. (For non-PC classes we try RACE_GENDER, and then just RACE, in ANIMATE.ids.) 
Standard-form patch functions
Basic patch functions (absolute)

name1_string  (0x8,LONG)
name2_string  (0xc,LONG)
xp_value  (0x14,LONG) 
hp_current   (0x24,SHORT) 
hp_max    (0x26,SHORT)
animation_code  (0x28,SHORT)
effect_type  (0x33,BYTE)
color_metal   (0x2c,BYTE)
color_minor   (0x2d,BYTE)
color_major   (0x2e,BYTE)
color_skin   (0x2f,BYTE)
color_leather   (0x30,BYTE)
color_armor   (0x31,BYTE)
color_hair   (0x32,BYTE)
hide_in_shadows   (0x45,BYTE) 
ac_natural   (0x46,SHORT)
ac_effective    (0x48,SHORT)
thac0  (0x52,BYTE)
attacks   (0x53,BYTE) 
save_vs_death   (0x54,BYTE)
save_vs_wand   (0x55,BYTE) 
    synonym: save_vs_wands
save_vs_poly    (0x56,BYTE)
    synonym: save_vs_polymorph
save_vs_breath  (0x57,BYTE)
save_vs_spell   (0x58,BYTE) 
   synonym: save_vs_spells 
detect_illusions   (0x64,BYTE)
set_traps   (0x65,BYTE)
lore   (0x66,BYTE)
open_locks  (0x67,BYTE)
move_silently  (0x68,BYTE)
find_traps  (0x69,BYTE)
pick_pockets  (0x6a,BYTE)
resist_fire   (0x59,BYTE)
resist_cold   (0x5a,BYTE)
resist_electricity   (0x5b,BYTE)
resist_acid   (0x5c,BYTE)
resist_magic   (0x5d,BYTE)
resist_magic_fire   (0x5e,BYTE)
resist_magic_cold   (0x5f,BYTE)
resist_slashing   (0x60,BYTE)
resist_crushing   (0x61,BYTE)
resist_piercing   (0x62,BYTE)
resist_missile   (0x63,BYTE)
level   (0x234,BYTE)  - synonym: level1
level2  (0x235,BYTE)
level3   (0x236,BYTE)
str   (0x238,BYTE)  -  synonym: strength
str_ex   (0x239,BYTE)  -  synonym: strength_ex
int   (0x23a,BYTE)  -  synonym: intelligence
wis   (0x23b,BYTE)  - synonym: wisdom
dex   (0x23c,BYTE)  -  synonym: dexterity
con   (0x23d,BYTE)  -  synonym: constitution
cha   (0x23e,BYTE)  -  synonym: charisma
script_override    (0x248,ASCII)
script_class    (0x250,ASCII)
script_race  (0x258,ASCII)
script_general  (0x260,ASCII)
script_default  (0x268,ASCII)
specifics    (0x274,BYTE)
dv  (0x280,ASCII20)
dialog  (0x2cc,ASCII)
morale    (0x23f,BYTE)
morale_break    (0x240,BYTE)


Basic patch functions (relative to offset)

For items:
item_resource  (0x0,ASCII)
item_charges_1  (0xa, SHORT)
item_charges_2  (0xc,SHORT)
item_charges_3  (0xe, SHORT)

For spells:
spell_resource  (0x0,ASCII)

For effects:
opcode  (0x8,LONG)
effect_resource  (0x28,ASCII) 
 - synonym: resource

target  (0x1c,LONG)
probability1  (0x24,SHORT)
probability2  (0x26,SHORT)
duration  (0x20,LONG)
parameter1  (0x14,LONG)
parameter2  (0x18,LONG)

For others:
memorized_spell  (0x0,ASCII)
item_slot  (0x0,SHORT)


IDS-based patch functions (all absolute)
animation  (0x28,SHORT)  -  from ANIMATE.ids
allegiance  (0x270,BYTE)  -  from EA.ids
general  (0x271,BYTE)  -  from GENERAL.ids
race  (0x272,BYTE)  -  from RACE.ids
class  (0x273,BYTE)  -  from CLASS.ids
alignment  (0x27b,BYTE)  -  from ALIGN.ids
kit_vanilla  (0x244,LONG_REVERSED)  -  from KIT.ids
(use kit instead)

Flag-based patch functions (all absolute) 

state_sleeping  (0x20,0)
state_berserk  (0x20,1)
state_panic   (0x20,2)
state_stunned  (0x20,3)
state_invisible  (0x20,4)
state_helpless  (0x20,5)
state_frozen_death  (0x20,6)
state_stone_death ( 0x20,7)
state_exploding_death (0x21,0)
state_flame_death (0x21,1)
state_acid_death (0x21,2)
state_dead (0x21,3)
state_silenced (0x21,4)
state_charmed (0x21,5)
state_poisoned (0x21,6)
state_hasted (0x21,7)
state_slowed (0x22,0)
state_infravision (0x22,1)
state_blind (0x22,2) 
state_hidden  (0x22,3)
state_feebleminded (0x22,4)
state_nondetection (0x22,5)
state_improved_invisibility (0x22,6)
state_bless (0x22,7)
state_chant (0x23,0)
state_drawuponholymight (0x23,1)
state_luck (0x23,2)
state_aid (0x23,3)
state_chantbad (0x23,4)
state_blur (0x23,5)
state_mirrorimage (0x23,6)
state_confused (0x23,7)


Composite functions

hitpoints (sets both current and total hp)

level (sets all three levels)

ac (sets both ac settings)

saves (takes as input five numbers separated by commas; sets the five saving throws in order death, wands, poly, breath, spells)

gender (takes as input an entry from GENDER.ids. Uses it to set the gender byte (0x275) and, if the entry is "FEMALE", also sets the "sex" byte (0x237) to female (2)).
read_gender also available, based only on 0x275.

kit (takes as input a kit from kit.ids; uses it to correctly set the kit.)
read_kit also available.

Script-setting functions

enforce script_order (str arguments)
"Arguments" should be either "script1 above script2" or "script1 below script2". The positions in which those scripts occur are swapped, if necessary, to ensure that they occur in the specified order.

insert_script (str arguments)
"arguments" should be either "script1 above script2", or "script1 below script2" ("before" and "after" are acceptable synonyms for "above" and "below"). script1 is slotted in directly before or after script2, or not at all if script2 is not present. If necessary, other scripts are moved to make space. If there are insufficient free slots (i.e., none, and script1 does not occur) no insertion occurs and a warning is printed.

insert_script_high (str arguments)
Inserts "arguments" in the top (override) script slot, moving other scripts down if necessary; does nothing except print a warning if space is not available.

insert_script_low (str arguments)
Inserts "arguments" in the bottom (default) script slot, moving other scripts up if necessary; does nothing except print a warning if space is not available.

locate script (list arguments -> int value)
If the listed script is present, returns its location (0=override, etc). If not, returns -1.

match_script (str arguments -> bool value)
Returns 1 if the argument is present in a script slot.

strip script (list arguments)
Removes all scripts in the list. If "arguments" is set to "all", removes all scripts.

swap_script (arrowlist arguments)
For each pair of scripts in "arguments", replace all occurrences of the first with the second and vice versa.
Enforcement of features
enforce_animation (str arguments)
SFO attempts to set an animation type for the creature, based on the following rules:
   (i) If [class]_[gender]_[race] is an ANIMATE.ids entry, use that. (Classes are mapped to their standard representations  -  so for Paladins, [class]=FIGHTER.)
   (ii) Failing that, if [race]_[gender] is an ANIMATE.ids entry, use that. (e.g., VAMPIRE_FEMALE.)
   (iii) Failing that, if [race] is an ANIMATE.ids entry, use that. 
   (iv) Failing that, leave the existing setting unchanged and print a warning.
If "arguments" is set to "only_if_new", the animation type is only set if its existing value is -1.

enforce_hp (str arguments)
The creature's hit points (current and total) are adjusted to come in line with its class and level. The value calculated is chosen to lie between the minimum and maximum possible hit points: the position in that range is determined (as a % of distance towards the maximum) by the ini file setting "hitpoint_percentage", or 75% if that setting is not present. The syntax use for "arguments" is as follows: 
   * if "arguments" is "at_worst", hit points will only be adjusted if they are less good than the calculated value
   * if "arguments" is "at_best", hit points will only be adjusted if they are better than the calculated value
   * if "arguments" is "only_if_new", hit points will only be adjusted if they are set to 65535. (You probably won't use this; it's called by make_creature.)
   * if "arguments" has any other value or is blank, hit points will be adjusted whenever they differ from the calculated value.
Note that the algorithm used in this function does not deal correctly with dual-classed creatures (they are treated as if multi-classed).

enforce_saves (str arguments)
The creature's saving throws are adjusted to come in line with the legal values for its class and level, using this syntax:
   * if "arguments" is "at_worst", saving throws will only be adjusted if they are less good than the legal value
   * if "arguments" is "at_best", saving throws will only be adjusted if they are better than the legal value
   * if "arguments" is "within_tolerance", saving throws will only be adjusted if they are within a distance "tolerance" of their correct value, where "tolerance" is set by the "save_tolerance" entry in the ini file. (The idea here is to correct small errors while leaving intentionally wildly-different values alone.)
   * if "arguments" is "only_if_new", saving throws will only be adjusted if they are set to -1. (You probably won't use this; it's called by make_creature.)
   * if "arguments" has any other value or is blank, saving throws will be adjusted whenever they are incorrect.

enforce_thac0 (str arguments)
The creature's THAC0 is adjusted to come in line with the legal value for its class and level, using the same syntax as enforce_saves. ("tolerance" is set by the "thac0_tolerance" entry in the ini file.)

Spell functions
add_known_spells (list arguments) 
Each item on the list is added as a known spell, using the following syntax:
   (i) if the item is the IDS reference of a spell file, add that spell
   (ii) if adding one but not both of "CLERIC" or "WIZARD" to the item produces the IDS reference of a spell file, add that spell (e.g., there is WIZARD_FIREBALL but not CLERIC_FIREBALL)
   (iii) if both "CLERIC" and "WIZARD" can be added to produce an IDS reference, add the WIZARD one and print a warning
   (iv) if the item is the resource name of an existing spell, add that spell.
   (v) Otherwise, fail.
Level and type are inferred from the spell file.
If the argument is "all", instead give the creature all cleric/druid spells appropriate to their class, level and alignment, deleting any illegal cleric/druid spells in the process.

add_spells (list arguments)
Each item on the list is added as a memorized spell, using the same syntax as add_known_spells.
If a nonnegative integer is added in parentheses (as in: FIREBALL(3)), add that many copies of the spell.

remove_spells (list arguments)
Process each element in "arguments" as follows:
   (i) If set to "all", remove all known and memorized spells.
   (ii) If set to "priest", "wizard" or "innate", remove all known and memorized spells of that type. ("cleric" and "mage" are acceptable synonyms for "priest" and "wizard, respectively).
   (iii) Otherwise, treat the element as an individual spell, using the same syntax as add_known_spells, and remove it from the known and memorized list.

Immunity functions
immunity_to_icon (list arguments)

The creature is made immune (opcode 169) to the display icons in the list.



immunity_to_opcode (list arguments)
The creature is made immune (opcode 101) to each opcode on the list.

immunity_to_spell (list arguments)
The creature is made immune (opcode 206) to each spell on the list, using the same syntax as add_known - _spells. (i.e., "FIREBALL", "WIZARD_FIREBALL", and "SPWI304" are all legal ways to give immunity to fireball.

immunity_to_string (list arguments)
The creature is made immune (opcode 267) to each strref in the list.

Others
movement (int arguments)
Sets the movement rate to "arguments" via opcode 176.

say_sounds (str arguments)

steal_colors_from (str arguments)
If "arguments".cre exists, sets the colorscheme of the creature being patched to match that creature. If not, prints a warning.

steal_sounds_from (str arguments)
If "arguments".cre exists, sets the soundste of the creature being patch to match that creature. If not, prints a warning.








