Skip to content

base-decl

Fallout 2 engine builtins (external - not bundled into output)

function obj_item_subtype(obj: ItemPtr): number

Returns the subtype of an item object (weapon, armor, etc.)

function obj_type(obj: ObjectPtr): ObjType

Returns the type of an object (Item, Wall, Scenery, Critter, etc.)

function obj_pid(obj: ObjectPtr): number

Returns the prototype id # (pid) of an object

function obj_name(obj: ObjectPtr): string

Returns the name of an object

function elevation(obj: ObjectPtr): 0 | 1 | 2

Returns the object’s elevation (0-2)

function tile_num(obj: ObjectPtr): number

Returns the tile number of an object

function obj_art_fid(obj: ObjectPtr): number

Returns the fid # (art index) of an object

function obj_on_screen(obj: ObjectPtr): boolean

Returns true if the object is currently visible on-screen

function obj_is_locked(obj: DoorPtr | ContainerPtr): boolean

Returns true if the object is locked

function obj_is_open(obj: DoorPtr | ContainerPtr): boolean

Returns true if the object is open

function obj_lock(obj: DoorPtr | ContainerPtr): void

Lock an object

function obj_unlock(obj: DoorPtr | ContainerPtr): void

Unlock an object

function obj_open(obj: DoorPtr | ContainerPtr): void

Open an object

function obj_close(obj: DoorPtr | ContainerPtr): void

Close an object

function set_obj_visibility(obj: ObjectPtr, invisible: boolean): void

Sets the OBJ_OFF flag for an object (makes it not drawn). Note: visibility arg is inverted - set_obj_visibility(who, true) makes object invisible. Does not work when loading game.

function obj_set_light_level(obj: ObjectPtr, intensity: number, distance: number): void

Set the light level for an object to a given intensity (0-100, percentage of maximum) and distance of light in hexes (0-8).

function create_object_sid(pid: number, tile: number, elev: Elevation, sid: number): ObjectPtr

Creates a new object of prototype (pid) at a given tile and elevation (0-2). If sid is not -1, it overrides the default script with the specified script #.

function destroy_object(obj: ObjectPtr): number

Destroys an object, which will call its script in the destroy_proc section if the object is NOT the calling object.

function destroy_mult_objs(item: ItemPtr, count: number): number

Destroys count instances of an item object

function move_to(obj: ObjectPtr, tile: number, elev: Elevation): number

Immediately moves object to the given tile number and elevation (0-2) on the current map. Using this to change elevations during loading an in-combat save will lead to a crash. If called in map_enter_p_proc, wrap in not_is_loading_game to avoid the crash.

function critter_attempt_placement(who: CritterPtr, hex: number, elev: Elevation): number

Attempts to place a critter at a given destination hex & elevation (0-2). If it fails, it tries to find a nearby hex as near as possible to the start hex.

function obj_can_see_obj(src: ObjectPtr, dst: ObjectPtr): boolean

Returns True if the source object has line-of-sight (LOS) with the destination object. This also takes into account perception & stealth rolls if the objects are critters.

function obj_can_hear_obj(src: ObjectPtr, dst: ObjectPtr): boolean

Returns true if src_obj can hear dst_obj

function critter_state(who: CritterPtr): CritterState

Returns the state of a critter (dead, unconscious, etc.)

function critter_inven_obj(who: CritterPtr, slot: InvenSlot): ItemPtr
function get_critter_stat(who: CritterPtr, stat: STAT): number

Returns a critter stat value

function set_critter_stat(who: CritterPtr, stat: STAT, mod: number): number

DOES NOT SET THE STAT. Modifies attribute stat in critter who by value mod.

function critter_is_fleeing(who: CritterPtr): boolean

Returns true if the critter has its FLEE flag set

function critter_set_flee_state(who: CritterPtr, flee: boolean): void

Sets the FLEE flag on or off

function critter_stop_attacking(who: CritterPtr): number

Flags the critter as no longer wishing to be active in combat

function critter_add_trait(who: CritterPtr, traitType: TraitType, trait: number, amount: number): number

Adds a particular trait of a given type to a critter. Possible traits under the SPECIAL system are limited to Perks, Traits, Object-instance information (such as team #‘s, ai-packet #‘s, etc.)

function critter_rm_trait(who: CritterPtr, traitType: TraitType, trait: number, amount: number): number

Removes a trait from a critter

function has_trait(traitType: TraitType, who: ObjectPtr, trait: number): number

Returns the value of a critter’s trait of a given trait_type (see define.h). Can be used to determine if the player has a particular Perk, AI Packet, team num, current rotation, or Trait (finesse, bruiser, etc.) Also works with TRAIT_OBJECT for any object.

function critter_mod_skill(who: CritterPtr, skill: SKILL, amount: number): number

Modifies a given skill in a critter by a given amount. Note: Only works on dude_obj! Will not work on other critters. For tagged skills, the amount will be rounded down to the closest even number.

function get_poison(who: CritterPtr): number

Returns the critter’s poison level

function poison(who: CritterPtr, amount: number): void

Modifies the critter’s poison level by amount (can be negative)

function radiation_inc(who: CritterPtr, amount: number): void

Increments a critter’s radiation counter

function radiation_dec(who: CritterPtr, amount: number): void

Decrements a critter’s radiation counter

function critter_dmg(who: CritterPtr, amount: number, flags: number): void

Inflicts damage on a critter (who) of a given amount, killing it if necessary. Use DMG_* flags to customize behaviour.

function critter_heal(who: CritterPtr, amount: number): void

Heals a critter for a given amount (if given a value above their MaxHP will go up to their maximum HP). Note: can also input negative amounts, causing the critter to be hurt for that amount. This is useful because it bypasses all resistances and thresholds.

function critter_injure(who: CritterPtr, how: number): number

Injures a critter by crippling given limbs/body parts (defined by DAM_CRIP_ARM_LEFT, DAM_BLIND, etc. in define.h).

function kill_critter(who: CritterPtr, deathFrame: number): void

Kills a critter outright, placing it in the chosen death frame. Does NOT animate the critter and does NOT refresh the screen! Meant to be used in scripts run when entering/exiting a map (map_init/map_exit).

function kill_critter_type(pid: number): void

Kills all critters of a given type (pid) outright. NOTE: This can result in the ‘frozen bodies’ issue! kill_critter should always be used instead if possible.

function add_obj_to_inven(who: ObjectPtr, item: ItemPtr): void

Adds an object (item) to another object’s (who’s) inventory. Note that this only works with objects of type Item.

function add_mult_objs_to_inven(who: ObjectPtr, item: ItemPtr, count: number): void

Adds count instances of an item to an object’s inventory

function rm_obj_from_inven(who: ObjectPtr, item: ItemPtr): void

Removes an object from another object’s inventory. NOTE: this leaves the removed object at location (0,1) on the map! You must call move_to(…) to place it back on the map.

function rm_mult_objs_from_inven(who: ObjectPtr, item: ItemPtr, count: number): number

Removes count items from inventory, returns actual count removed

function move_obj_inven_to_obj(src: ObjectPtr, dst: ObjectPtr): void

Moves all items from srcObj to destObj

function obj_carrying_pid_obj(who: ObjectPtr, pid: number): ItemPtr

Returns an Object pointer to an instance of an object of type pid if the object is carrying an object of that type.

function obj_is_carrying_obj_pid(who: ObjectPtr, pid: number): number

Returns the quantity of objects with matching pid in inventory

function item_caps_total(obj: ObjectPtr): number

Returns the current caps total in an object’s inventory

function item_caps_adjust(obj: ObjectPtr, amount: number): number

Modifies the current caps count in an object by a given amount. Can be positive or negative.

function wield_obj_critter(who: CritterPtr, obj: ItemPtr): void

Sets up an animation causing a critter to wield an object in that critter’s inventory. This puts that object in the critter’s hand.

function drop_obj(obj: ItemPtr): void

Causes self_obj to drop an object from inventory

function pickup_obj(obj: ItemPtr): void

Causes self_obj to animate and pick up an object

function proto_data(pid: number, field: number): number

Returns the value (can be int or string) of a data-member of a given prototype (pid).

function tile_distance(tile1: number, tile2: number): number

Returns the tile distance between two tiles

function tile_distance_objs(obj1: ObjectPtr, obj2: ObjectPtr): number

Returns the tile distance between two objects

function tile_num_in_direction(tile: number, direction: Direction, distance: number): number

Returns the tile number of a tile offset from a starting tile in a given direction (0-5, the next tile in that direction).

function tile_is_visible(tile: number): boolean

Returns true if a tile is currently visible on-screen

function tile_contains_obj_pid(tile: number, elev: Elevation, pid: number): boolean

Returns true if a tile contains an object with matching pid

function tile_contains_pid_obj(tile: number, elev: Elevation, pid: number): ObjectPtr

Returns the first object matching pid on a tile

function rotation_to_tile(srcTile: number, destTile: number): Direction

Returns the rotation (0-5) to face a particular tile (destTile) from srcTile.

function attack_complex(who: CritterPtr, calledShot: number, numAttacks: number, bonus: number, minDamage: number, maxDamage: number, attackerResults: number, targetResults: number): void

Causes self_obj (must be a critter) to attack a critter with various parameters:

  • calledShot: 0/1/specific means none/random/specific (head, torso, etc.)
  • numAttacks: # of extra attacks self gets before the target
  • bonus: bonus to hit the target on the first turn only
  • minDamage/maxDamage: damage range for the first attack
  • attackerResults: what state the attacker ends in after the first attack
  • targetResults: what state the target ends in after the first attack
function attack_setup(who: CritterPtr, victim: CritterPtr): void

Sets up an attack from who on victim, without expecting this script to be involved. Can be used to setup attacks on critters from the map script.

function terminate_combat(): void

Tells the combat system to terminate prematurely. USE WITH CAUTION. This doesn’t prevent another (or even the SAME) script from re-starting combat, so make sure you turn off any hostile flags, etc.

function has_skill(who: CritterPtr, skill: SKILL): number

Returns the level of the skill (0-17) of the target critter. Returns 0-200 for Fallout 1, 0-300 for Fallout 2.

function get_pc_stat(stat: PcStatID): number

Returns a pc-only stat value (PCSTAT_*)

function do_check(who: CritterPtr, check: number, modifier: number): RollResult

Performs a check/test-roll versus one of the basic traits (strength, perception, etc.). Note: these cannot generate Critical Success or Critical Failure as they are a basic X==Y check.

function roll_vs_skill(who: CritterPtr, skill: SKILL, modifier: number): RollResult

Returns the value of a completed skill roll made upon an object’s skill level, modified by a given amount (may be zero). This value may then be passed to is_success and is_critical to determine states, and how_much can be used to determine the difference succeeded or failed by.

function skill_contest(skill: SKILL): RollResult

Returns the value of a completed skill vs skill contest

function is_success(rollResult: RollResult): boolean

Returns true if the roll result is a success (including critical)

function is_critical(rollResult: RollResult): boolean

Returns true if the roll result is a critical

function how_much(val: number): number

Returns how much the rolls differed by

function anim(who: ObjectPtr, anim: number, direction: Direction): void

Sets up a single-frame animation for the object that runs in the given direction.

function anim_action_frame(who: ObjectPtr, frame: number): number

Returns the action frame of an art frame

function anim_busy(who: ObjectPtr): boolean

Returns True if object is currently animating, otherwise False. Can be used to determine if an object has completed an animation.

function animate_move_obj_to_tile(who: CritterPtr, tile: number, speed: number): void

Sets up an animation for a critter to walk to a given tile at a given speed (walk/run). Speed can have a flag attached (see define.h) to force stopping current animation first.

function animate_run_to_tile(tile: number): void

Animate self_obj running to a tile

function animate_rotation(direction: Direction): void

Change self_obj’s facing direction (0-5)

function animate_set_frame(frame: number): void

Change self_obj’s animation frame

function animate_stand(): void

Run self_obj’s stand animation

function animate_stand_obj(obj: ObjectPtr): void

Run an object’s stand animation

function animate_stand_reverse(): void

Run self_obj’s stand animation in reverse

function animate_stand_reverse_obj(obj: ObjectPtr): void

Run an object’s stand animation in reverse

function reg_anim_func(cmd: number, arg: number | ObjectPtr): void

Low-level animation registration function

function reg_anim_end(): void

Activate the animation sequence

function reg_anim_animate(obj: ObjectPtr, anim: number, delay: number): void

Adds a single, in-place animation on an object to an animation sequence-list, at a given delay from the previous animation (delay should always be -1).

function reg_anim_animate_forever(obj: ObjectPtr, anim: number, delay: number): void

Adds a single, in-place animation to the sequence that will animate continuously until something interrupts it. Delay should always be -1. Use very sparingly.

function reg_anim_animate_reverse(obj: ObjectPtr, anim: number, delay: number): void

Add a reversed animation to the sequence

function reg_anim_obj_move_to_obj(who: CritterPtr, dest: ObjectPtr, delay: number): void

Adds an animation to cause a critter to attempt to walk to another object. Delay should always be -1.

function reg_anim_obj_move_to_tile(who: CritterPtr, tile: number, delay: number): void

Add a walk-to-tile animation

function reg_anim_obj_run_to_obj(who: CritterPtr, dest: ObjectPtr, delay: number): void

Add a run-to-object animation

function reg_anim_obj_run_to_tile(who: CritterPtr, tile: number, delay: number): void

Add a run-to-tile animation

function reg_anim_play_sfx(who: ObjectPtr, sfx: string, delay: number): void

Adds an animation to cause an object to play a sound effect at a given delay.

function add_timer_event(obj: ObjectPtr, ticks: number, info: number): void

Adds a timed event call to the queue at a given time offset to call an object’s script. Info is used to differentiate between timed event calls and is read back using fixed_param. Note that time is in ticks (use game_ticks(seconds) to convert from seconds).

function rm_timer_event(obj: ObjectPtr): void

Removes (clears) all timer events hooked to a given object’s script.

function game_ticks(seconds: number): number

Returns game ticks for a number of seconds

function game_time_advance(ticks: number): void

Advances game time by ticks

function metarule(func: number, param: ObjectPtr | number): number

Generic metarule function

function metarule3(func: number, param1: ObjectPtr | number, param2: ObjectPtr | number, param3: ObjectPtr | number): number

Generic metarule3 function

function inven_cmds(obj: ObjectPtr, cmd: number, param: number): ObjectPtr

Inventory commands function

function global_var(index: number): number

Returns the value of a global variable by index.

function set_global_var(index: number, value: number): void

Sets the value of a global variable by index to a given value.

function local_var(index: number): number

Returns the value of a local variable by index. Errors may occur if the script doesn’t have local vars up to this number.

function set_local_var(index: number, value: number): void

Sets the value of a local variable by index to a given value.

function map_var(index: number): number

Returns the value of a map-global variable by index.

function set_map_var(index: number, value: number): void

Sets a map variable value

function party_add(who: CritterPtr): void

Adds a critter into the list of party members. This will also setup those objects so they will not be saved in maps, and certain other things.

function party_remove(who: CritterPtr): void

Removes a critter from the list of party members. This will also change those objects so that certain object- and map-level things will respond differently.

function party_member_obj(pid: number): CritterPtr

Returns a CritterPtr to a party member that matches a given pid. If that critter isn’t currently a member of the party, returns NULL.

function dialogue_system_enter(): void

Request the talk system for this object

function start_gdialog(msgFileNum: number, who: CritterPtr, mood: number, headNum: number, bgIdx: number): void

Start the dialogue system focusing on a critter and in a given mood. Sets up appropriate dialog windows, head art, etc. Without this call, dialog windows will not come up, only grey boxes with text.

Mood argument is unused in vanilla. Instead, LVAR 0 of the script is checked:

  • LVAR > 10: good reaction (happy head)
  • -10 > LVAR >= 10: neutral
  • Else: angry head

With sfall StartGDialogFix enabled, mood argument works:

  • If mood == -1: use vanilla behaviour (check LVAR 0)
  • Else: use argument value with same thresholds
function end_dialogue(): void

End the dialogue system

function gSay_Start(): void

Start a dialog sequence

function gSay_End(varIndex: number): void

End a dialog sequence

function gSay_Reply(msgList: number, msgNum: number): void

Set up a reply (what the critter says)

function gSay_Message(msgList: number, msgNum: number, reaction: number): void

Sets up a sayMessage, which is a reply with just a [Done] option. The msg_list determines which message file to look in, and msg_num determines which line to use.

function gSay_Option(msgList: number, msgNum: number, target: Function, reaction: number): void

Sets up an option-choice for a reply block, getting the string from the message file and message number, which will cause a given reaction, and if chosen will jump to the given target procedure.

function giQ_Option(iqTest: number, msgList: number, msgNum: number, target: Function, reaction: number): void

Sets up an option-choice for a reply block if the player’s IQ is >= iq_test, getting the string from the message file and message number, which will cause a given reaction, and if chosen will jump to the target procedure. This is the only function that automatically accounts for Smooth Talker perk.

function dialogue_reaction(mood: number): void

Set up a reaction animation

function gdialog_mod_barter(modifier: number): number

Switch to barter screen with modifier

function gdialog_set_barter_mod(modifier: number): void

Set the barter modifier

function message_str(list: number, msgNum: number): string

Returns a string from the message module for a given list and a given message number.

function display_msg(message: string): void

Displays a string on the in-game PDA display (lower-left hand corner).

function float_msg(who: ObjectPtr, message: string, color: FloatMsgColor): void

Creates a floating-text message attached to an object using colors dictated by type. There are two special types: WARNING is used to print a message centered on the screen (such as for end-of-quest notifications), and SEQUENTIAL will cycle through the colors to give critters different-colored messages to differentiate them.

function debug_msg(msg: string): void

Prints a string to the debug monitor. Should be used exclusively for debug information, instead of display_msg()! The user will never see these messages unless they have debugging enabled and activated. If they have debugging enabled and DEBUGLOG set, the messages will only show up in debug.log file.

function give_exp_points(points: number): void

Adds experience points to the player’s total. These points may then be used by the player to enhance skills, etc.

function tokenize(str: string, offset: number | string, delim: number | string): string | 0

Tokenize a string at delimiters.

function load_map(mapName: string, startLocation: number): void

Loads a new map, removing all scripts currently running and passing on the entrance location to the new map’s map_init script. Can also use the number representing the map in the map list (for example, between 0 to 64 in Fallout 1).

function world_map(): void

Brings up the World Map screen

function town_map(): void

Brings up the Town Map screen (Fallout 1 only)

function wm_area_set_pos(areaIdx: number, x: number, y: number): void

Sets the World Map coordinates for a town

function set_map_start(x: number, y: number, elev: Elevation, rot: Direction): void

Sets the start location & rotation (0-5) for the next time this map is entered (loaded & run).

function override_map_start(x: number, y: number, elev: Elevation, rot: Direction): void

Used when loading a new map, forces the player to start at a particular location (x/y), elevation (0-2) and rotation (0-5) when first coming up.

function set_exit_grids(markElev: Elevation, mapID: number, elev: Elevation, tile: number, rot: Direction): void

Sets all exit grids on a given elevation (markElev) to point to a destination mapID (may be -1 to stay on this map), elevation, tileNum, and rotation.

function game_ui_disable(): void

Disables game UI input (must re-enable!)

function game_ui_enable(): void

Re-enables game UI input

function gfade_out(time: number): void

Does a palette fade to black. The time parameter is currently not actually used.

function gfade_in(time: number): void

Does a palette fade from black to the game palette. The time parameter is currently not actually used.

function set_light_level(level: number): void

Sets the ambient light level (1-100). Range is Full Darkness to Full Daylight. NOTE: level is NOT percentage, full darkness is not black screen. set_light_level(0) corresponds to 25% brightness, and certain brightness levels cannot be set.

function set_map_music(mapID: number, soundPath: string): void

Sets the map background music

function play_sfx(sfxFileName: string): void

Starts a new sound effect to be played on the queue.

function play_gmovie(movieNum: number): void

Plays one of the Fallout movies (full-screen, compressed, etc.).

function endgame_movie(): void

Plays the endgame movie

function endgame_slideshow(): void

Plays the endgame slideshow

function jam_lock(obj: DoorPtr | ContainerPtr): number

Jams a lock, preventing the player from picking it for approximately 24 hours. Meant to be used when a player critically fails to pick a lock.

function scr_return(): void

Sets the return value for C-engine node

function script_overrides(): void

Tells the C-engine that the script will override default behavior for the object. The C-engine will not attempt to do things it would normally do, expecting the script to handle them. Commonly used for player actions on objects: looking at them, using them (opening doors), or using items ON them (using a picklock or key on a door lock).

function random(min: number, max: number): number

Returns a random value between min and max, inclusive.

function floor(value: number): number
function use_obj(obj: ObjectPtr): void

Use a usable object

function use_obj_on_obj(item: ObjectPtr, target: ObjectPtr): ObjectPtr

Attempt to use an item object on a target object. This could be used to have a critter use a Stimpack on the player, or to use a key on a door.

function using_skill(who: CritterPtr, skill: SKILL): boolean

Returns true if an active skill is being used

function AddNamedEvent(name: string, proc: Function): void

Adds a named event handler (fires once)

function AddNamedHandler(name: string, proc: Function): void

Adds a named event handler (fires many times)

function ClearNamed(event: string): void

Removes all handlers for a named event

function SignalNamed(event: string): void

Signals a named event

function art_anim(fid: number): number

Returns the animation type of a fid

NameTypeDescription
dude_objCritterPtrReturns a pointer to the dude object (the player)
self_objObjectPtrReturns a pointer to the object connected to this script
source_objObjectPtrReturns a pointer to the source object (activator) for this action
target_objObjectPtrReturns a pointer to the target object for this action
obj_being_used_withObjectPtrReturns a pointer to the object being used on another object
action_being_usednumberReturns the current skill being used on a script object
fixed_paramnumberReturns the value of the script’s fixed parameter (used with add_timer_event)
script_actionnumberReturns the action that has activated this script
cur_map_indexnumberReturns the index # of the current map
days_since_visitednumberReturns the number of days since this map was last visited, or -1 if never
game_timenumberReturns the current game time in ticks
game_time_hournumberReturns the current hour (e.g., 721 = 7:21 am)
combat_is_initializedbooleanReturns true if the system is currently in combat mode
game_ui_is_disabledbooleanReturns true if the game UI is currently disabled
difficulty_levelDifficultyReturns the current Game difficulty level (0-2)
combat_difficultyDifficultyReturns the current Combat difficulty level (0-2)
running_burning_guynumberReturns the running-burning-guy setting
get_daynumberReturns the current day of the month
get_monthnumberReturns the current month of the year
explosionnumberSets up an explosion at a tile