You are viewing a potentially older version of this package. View all versions.
Klehrik-HelperFunctions-1.0.5 icon

HelperFunctions

A collection of helper functions for modding.

Date uploaded 6 months ago
Version 1.0.5
Download link Klehrik-HelperFunctions-1.0.5.zip
Downloads 505
Dependency string Klehrik-HelperFunctions-1.0.5

This mod requires the following mods to function

ReturnOfModding-ReturnOfModding-1.0.45 icon
ReturnOfModding-ReturnOfModding

Lua Mod Loader for Risk of Rain Returns

Preferred version: 1.0.45

README

A collection of helper functions for modding.

To use, paste this line in your code (you can rename the Helper table):

mods.on_all_mods_loaded(function() for k, v in pairs(mods) do if type(v) == "table" and v.hfuncs then Helper = v end end end)

Installation Instructions

Install this mod through the Mod Manager:

  • Download the Immediate Mod Manager and open it.
  • Launch the game once through Steam with the Mod Manager open to complete the setup.
  • Close the game, and install this mod along with its dependencies (ReturnOfModding and HelperFunctions) from the list on the left-hand side.
  • Launch the game by clicking the "Launch Game" button, and the mods should be loaded. Enjoy!

Credits


Functions

Instances

find_active_instance(index) -> instance or nil

index           The object_index of the instance

Returns the first active instance of the specified
object_index, or nil if none can be found.
find_active_instance_all(index) -> table, bool

index           The object_index of the instance

Returns:
1. a table of all active instances of the specified object_index
2. true if the table is not empty
instance_exists(inst) -> bool

inst            The instance to check

Returns true if the instance exists.

Specific Instances

get_client_player() -> instance or nil

Returns the player instance belonging to
this client, or nil if none can be found.

Edited by Miguelito to work in Trials.
get_host_player() -> instance or nil

Returns the player instance belonging to
the host, or nil if none can be found.
get_teleporter() -> instance or nil

Returns the stage teleporter,
or nil if there isn't one.

If there is more than one, the first one
found is returned, and the Divine Teleporter
takes precedence over standard teleporters.
get_chests() -> table, bool

Returns:
1. a table of all chests on the stage
2. true if the table is not empty
get_multishops() -> table, bool

Returns:
1. a table of all multishops on the stage
2. true if the table is not empty

Misc.

ease_in(x, n) -> float

x               The input value
n               The easing power (default 2 (quadratic))

Returns an ease in value for
a given value x between 0 and 1.
ease_out(x, n) -> float

x               The input value
n               The easing power (default 2 (quadratic))

Returns an ease out value for
a given value x between 0 and 1.
chance(n) -> bool

n               The chance to succeed (between 0 and 1)

Returns true on success.
add_chat_message(text) -> void

text            The message to send

Taken from ShareItem mod.
is_lobby_host() -> bool

Returns true if this game client
is the host of the lobby.

Adapted from code by Miguelito.
table_merge(...) -> table

...             A variable amount of tables.

Returns a new table containing
the values from input tables.

Combining two number indexed tables will
order them in the order that they were inputted.

    e.g.    a = {1, 2, 3}
            b = {4, 5, 6}
            c = Helper.table_merge(a, b)

            log.info(table.concat(c))   ->  "123456"
            log.info(c[5])              ->  5

When mixing number indexed and string keys, the
indexed values will come first in order,
while string keys will come after unordered.

Items

rarities = {
    white = 1,
    green = 2,
    red = 3,
    equipment = 4,
    boss = 5,
    purple = 6,
    food = 7,
    notier = 8
}
initialize_item_table() -> void

Initializes a table of item data tables.

Called internally by the item
functions below, but can be
reinitialized anytime.

Each item data table contains:
.id             The object_index of the item
.localization   The localization string of the item (i.e., "item.crowbar.name")
.name           The name of the item in the current language
.rarity         The rarity (tier) of the item  (number)
                * This also corresponds to the .rarities enum at the top
                * White (Common) is indexed from 1 here, while in-game it is tier 0
                * "notier" (tier 8) items may be missing object_indexes
.class_id       The index within the class_item/class_equipment arrays
.namespace      The namespace that the item resides in (vanilla uses "ror")
.identifier     The internal identifier that the item uses (i.e., "crowbar")
get_all_items(rarity) -> table

rarity          Item rarity filter (optional)

Returns a table of item data tables (see initialize_item_table).
If given, only returns items of a specified rarity.
find_item(identifier) -> table or nil

identifier      object_index, localization string
                or "namespace-identifier" string of the item

Returns the item data table (see initialize_item_table)
if it exists, or nil otherwise.

CHANGELOG

v1.0.10

  • Marked as deprecated on Thunderstore.
  • Fixed chat_add_user_message hook firing for every message after receiving first Net message.

v1.0.9

  • Added: is_lobby_client
  • Added: spawn_crate
  • string_to_table now reads nil correctly.
  • find_item and get_all_items now return new copies of the item data tables.
    • This is to prevent direct manipulation of the main one, which is shared by all mods.
  • Net functionality now intercepts messages instead of scanning chat and deleting.

v1.0.8

  • Added: net_clear

v1.0.7

  • Added: is_singleplayer_or_host
  • net_send can now exclude a player.

v1.0.6

  • Added: table_to_string
  • Added: string_to_table
  • Added: net_send
  • Added: net_listen
  • Added: net_has
  • Added: is_singleplayer
  • Added: get_player_from_name

v1.0.5

  • get_client_player works in Trials mode now.

v1.0.4

  • find_item works with "namespace-identifier" strings now.
  • Added: get_host_player
  • Added: is_lobby_host
  • Added: table_merge

v1.0.3

  • Updated manifest dependency.
  • Added add_chat_message (from ShareItem).

v1.0.2

  • Added more fields to item data tables.

v1.0.1

  • Edited documentation a bit.

v1.0.0

  • Initial release.