Table Misc

Functions that don't fit in the other modules.

Functions

HasLineOfSight(room1, pos1, pos2) Determine if there's a line of sight between two points.
FadeOut(speed) Do a full-screen fade-to-black.
FadeIn(speed) Do a full-screen fade-in from black.
SetCineBars(height, speed) Move black cinematic bars in from the top and bottom of the game window.
SetFOV(angle) Set field of view.
PlayAudioTrack(name, loop) Play an audio track
SetAmbientTrack(name) Set and play an ambient track
CalculateDistance(posA, posB) Calculate the distance between two positions.
CalculateHorizontalDistance(posA, posB) Calculate the horizontal distance between two positions.
PercentToScreen(x, y) Translate a pair of percentages to screen-space pixel coordinates.
ScreenToPercent(x, y) Translate a pair of coordinates to percentages of window dimensions.
Vibrate(strength, time) Vibrate gamepad, if possible.
PlaySound(sound, position) Play sound effect
KeyIsHeld(action) Check if particular action key is held
KeyIsHit(action) Check if particular action key was hit (once)
KeyPush(action) Emulate pushing of a certain action key
KeyClear(action) Clears particular input from action key


Functions

HasLineOfSight(room1, pos1, pos2)
Determine if there's a line of sight between two points.

i.e. if we run a direct line from one position to another will any geometry get in the way?

Note: if you use this with Moveable:GetPosition to test if (for example) two creatures can see one another, you might have to do some extra adjustments.

This is because the "position" for most objects refers to its base, i.e., the floor. As a solution, you can increase the y-coordinate of this position to correspond to roughly where the eyes of the creatures would be.

Parameters:

  • room1 float ID of the room where the first position is
  • pos1 Vec3 first position
  • pos2 Vec3 second position

Returns:

    bool is there a direct line of sight between the two positions?

Usage:

    local flamePlinthPos = flamePlinth:GetPosition() + Vec3(0, flamePlinthHeight, 0);
    print(Misc.HasLineOfSight(enemyHead:GetRoom(), enemyHead:GetPosition(), flamePlinthPos))
FadeOut(speed)
Do a full-screen fade-to-black. The screen will remain black until a call to FadeIn.

Parameters:

  • speed float (default 1.0). Speed in "amount" per second. A value of 1 will make the fade take one second.
FadeIn(speed)
Do a full-screen fade-in from black.

Parameters:

  • speed float (default 1.0). Speed in "amount" per second. A value of 1 will make the fade take one second.
SetCineBars(height, speed)
Move black cinematic bars in from the top and bottom of the game window.

Parameters:

  • height float (default 30) Percentage of the screen to be covered
  • speed float (default 30) Coverage percent per second
SetFOV(angle)
Set field of view.

Parameters:

  • angle float in degrees (clamped to [10, 170])
PlayAudioTrack(name, loop)
Play an audio track

Parameters:

  • name string of track (without file extension) to play
  • loop bool if true, the track will loop; if false, it won't (default: false)
SetAmbientTrack(name)
Set and play an ambient track

Parameters:

  • name string of track (without file extension) to play
CalculateDistance(posA, posB)
Calculate the distance between two positions.

Parameters:

  • posA Vec3 first position
  • posB Vec3 second position

Returns:

    int the direct distance from one position to the other
CalculateHorizontalDistance(posA, posB)
Calculate the horizontal distance between two positions.

Parameters:

  • posA Vec3 first position
  • posB Vec3 second position

Returns:

    int the direct distance on the XZ plane from one position to the other
PercentToScreen(x, y)
Translate a pair of percentages to screen-space pixel coordinates. To be used with Strings.DisplayString:SetPosition and Strings.DisplayString.

Parameters:

  • x float percent value to translate to x-coordinate
  • y float percent value to translate to y-coordinate

Returns:

  1. int x coordinate in pixels
  2. int y coordinate in pixels
ScreenToPercent(x, y)
Translate a pair of coordinates to percentages of window dimensions. To be used with Strings.DisplayString:GetPosition.

Parameters:

  • x int pixel value to translate to a percentage of the window width
  • y int pixel value to translate to a percentage of the window height

Returns:

  1. float x coordinate as percentage
  2. float y coordinate as percentage
Vibrate(strength, time)
Vibrate gamepad, if possible.

Parameters:

  • strength float
  • time float (in seconds, default: 0.3)
PlaySound(sound, position)
Play sound effect

Parameters:

  • sound int ID to play
  • position Vec3
KeyIsHeld(action)
Check if particular action key is held

Parameters:

  • action int mapping index to check
KeyIsHit(action)
Check if particular action key was hit (once)

Parameters:

  • action int mapping index to check
KeyPush(action)
Emulate pushing of a certain action key

Parameters:

  • action int mapping index to push
KeyClear(action)
Clears particular input from action key

Parameters:

  • action int mapping index to clear
generated by LDoc 1.4.6 Last updated 2022-08-11 22:43:52