Giter Club home page Giter Club logo

pd2-hoplib's Introduction

HopLib

Collection of functions and useful tools, currently mostly about retrieving information about units.

Classes

NameProvider

Provides names based on a unit name or tweak_data id. The active NameProvider instance can be retrieved by calling HopLib:name_provider(). There are two functions that can be called on the NameProvider instance:

  • NameProvider:name_by_id(tweak) Returns the name based on the tweak_data id.
  • NameProvider:name_by_unit(unit, [u_key]) Returns the name based on the unit or u_key if you provided it, which is useful if the unit doesn't actually exist currently. This is done through a lookup table, so it is not guaranteed to return a name (Only works for units defined in CharacterTweakData:character_map() which should contain all human enemies).

The names are taken from the localization file if available, otherwise the modified string id (Capitalized words, removed underscores, etc) will be used as the name.

UnitInfoManager

Can be used to return information about a unit. Unit infos are created upon request (i.e. a call to get_info) or by HopLib in certain cases. The following functions can be called on the active UnitInfoManager instance, which can be retrieved by calling HopLib:unit_info_manager():

  • UnitInfoManager:all_infos() Returns a table (indexed by unit key) containing all unit infos.
  • UnitInfoManager:clear_info(unit, [u_key]) Clears the information about unit.
  • UnitInfoManager:get_info(unit, [u_key], [temp]) Returns the information about unit (creates it if it doesn't have it yet). Setting the temp argument to true will retrieve the unit information but not save it.

Providing the optional u_key skips the function's internal unit:key() which might be useful if the unit has already been deleted but you have its key.

UnitInfo

The UnitInfoManager creates and returns UnitInfo instances, which contain information about the unit. The following functions can be called on a UnitInfo retrieved from the UnitInfoManager:

  • UnitInfo:unit() Returns the unit.
  • UnitInfo:key() Returns the unit key.
  • UnitInfo:id() Returns the unit id.
  • UnitInfo:type() Returns the type of the unit. Possible values are "local_player", "remote_player", "npc", "team_ai", "joker", "sentry" and "vehicle".
  • UnitInfo:name() Returns the name of the unit.
  • UnitInfo:nickname() Returns the nickname of the unit (used for jokers and sentries). If it doesn't have one, returns the same as UnitInfo:name().
  • UnitInfo:owner() Returns the UnitInfo of the unit owner if it has one (used for jokers and sentries).
  • UnitInfo:damage() Returns the amount of damage the unit has dealt.
  • UnitInfo:kills() Returns the number of kills the unit made.
  • UnitInfo:peer() Returns the peer object if the unit is of type "player".
  • UnitInfo:level() Returns the level if the unit is of type "player".
  • UnitInfo:rank() Returns the infamy rank if the unit is of type "player".
  • UnitInfo:color_id() Returns the color id of the unit.
  • UnitInfo:is_civilian() Returns true if the unit is a civilian.
  • UnitInfo:is_special() Returns true if the unit is a special enemy.
  • UnitInfo:is_boss() Returns true if the unit is a boss type enemy.
  • UnitInfo:is_female() Returns true if the unit is female.

Hooks

HopLib provides the following hooks:

  • HopLibOnMinionAdded with parameters (unit, player_unit) Called when an enemy is converted by a player.
  • HopLibOnMinionRemoved with parameters (unit) Called when a converted enemy is removed (died, released, etc).
  • HopLibOnUnitDamaged with parameters (unit, damage_info) Called whenever a unit takes damage.
  • HopLibOnUnitDied with parameters (unit, damage_info) Called when a unit dies.
  • HopLibOnCharacterMapCreated with parameters (char_map) Called before CharacterTweakData:character_map returns.

Utility

HopLib also provides some utility functions:

  • HopLib:get_game_language() Returns the language the game is set to as a string.
  • HopLib:get_modded_language() Returns the language the game is set to through mods.
  • HopLib:load_localization(path, [localization_manager]) Automatically chooses the correct language file in the path directory and loads it in localization_manager. Tries to use the registered LocalizationManager if localization_manager is not specified. Returns the language loaded.
  • HopLib:load_assets(assets) Loads all files in the assets table. Entries must be tables containing ext, path and file keys and may contain an optional override key.
  • HopLib:run_required(path) Runs the file matching the current RequiredScript if it exists in path.

Color Utility

Additional utility functions that operate on color values:

  • Color:grayscale() Returns a grayscale version of the color by taking the average of all color channels.
  • Color:invert([invert_alpha]) Returns the inverse of the color, inverting the alpha channel if invert_alpha is set.

All color utility functions operate on the game's color objects (e.g. Color.black:invert()) and return a new Color rather than changing the existing one.

Table Utility

Additional utility functions that operate on tables:

  • table.union(tbl1, tbl2, [match_type]) Merges all values from tbl2 into tbl1, replacing existing values in tbl1. If match_type is set, the value types in both tables must match to be replaced.
  • table.replace(tbl1, tbl2, [match_type]) Replaces only existing values in tbl1 with values from tbl2. If match_type is set, the value types in both tables must match to be replaced.
  • table.recurse(tbl, func) Calls func(value, key) for each non-table value in tbl. If the value is a table itself, calls itself on that table.

Menu Builder

Automatically creates a options menu from an identifier and a settings table. The following functions exist:

  • MenuBuilder:new(id, settings_table, [settings_params]) Creates a new menu builder with the mod identifier id using the table settings_table. The optional parameter settings_params allows to specify custom ranges, items and priorities for specific settings.
  • MenuBuilder:save_settings() Saves the current settings. Called automatically when settings are changed via the options menu.
  • MenuBuilder:load_settings() Loads previously saved settings. Called automatically when the menu builder is created.
  • MenuBuilder:create_menu(menu_nodes, [parent_menu]) Creates the menu. menu_nodes are the existing menu nodes obtained in the MenuManagerBuildCustomMenus hook. The optional parameter parent_menu determines where the menu is added, defaults to the BLT mod options menu.

pd2-hoplib's People

Contributors

breakinbenny avatar chromka avatar gullwing-door avatar iamgoofball avatar makinday avatar segabl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pd2-hoplib's Issues

Fatal error on MenuBuilder:load_settings()

I've been having issues using 'MenuBuilder.lua'. The script works fine if there is no settings file in 'PAYDAY 2\mods\saves'. But if that file exists when I open the game my TestMod won't load in correctly and there is no settings menu under the in-game mod options.

Reading the logs at 'PAYDAY 2\mods\logs' I get this error:

12:07:20 AM FATAL ERROR:  (C:\projects\payday2-superblt\src\InitiateState.cpp:320) mods/TestMod/MenuBuilder.lua:31: attempt to call field 'replace' (a nil value)
stack traceback:
	mods/TestMod/MenuBuilder.lua:31: in function 'load_settings'
	mods/TestMod/MenuBuilder.lua:13: in function 'init'
	[string "core/lib/utils/coreclass.lua"]:35: in function 'new'
	mods/TestMod/main.lua:9: in main chunk
	[C]: in function 'dofile'
	mods/base/base.lua:169: in function 'run_hook_file_orig'
	mods/The Fixes Preventer/coresystem.lua:145: in function 'RunHookFile'
	mods/base/base.lua:157: in function 'RunHookTable'
	mods/base/base.lua:189: in function 'OrigRequire'
	mods/BeardLib/Core.lua:406: in function 'require'
	[string "lib/setups/setup.lua"]:72: in main chunk
	...
	mods/BeardLib/Core.lua:406: in function 'require'
	[string "lib/setups/menusetup.lua"]:1: in main chunk
	[C]: in function 'require'
	mods/base/base.lua:188: in function 'OrigRequire'
	mods/BeardLib/Core.lua:406: in function 'require'
	[string "lib/entry.lua"]:13: in main chunk
	[C]: in function 'require'
	mods/base/base.lua:188: in function 'OrigRequire'
	mods/BeardLib/Core.lua:406: in function 'require'
	[string "core/lib/coreentry.lua"]:19: in main chunk

If I understand the logs correctly the problem is on this line:

table.replace(self._table, data, true)

because the function table.replace() does not exist.


I've searched on the Lua Reference Manual and under Table Manipulation I see there is no mention about a table.replace() function. Could this be an old and deprecated function that no longer works?

Furthermore, the manual does not have a table.union() function, so maybe there is also a problem on line 90:

local params = self._params[k] and table.union(clone(inherited_params), self._params[k]) or inherited_params

I'm completely new to both modding and the Lua language and I don't really know what I'm doing. I don't even know if looking up the functions in the online manual was the correct move or if that has nothing to do with the error I'm having.

This problem could very well be caused by an error on my part and in that case I'm sorry to bother, but I'd like to understand what I'm doing wrong.

FBI Heavy SWAT renaming causes crashing

It's not an issue with your mod, per say, but when I try to make NameProvider.lua allow modifying the string representing the FBI Heavy SWAT (Maximum Force Responder in PC terms), it crashes. I believe part of the problem has to be that there's already an enemy tweak table called "fbi".

What do you think, @segabl?

Add three dots (...) in the parameter list (variable number of arguments) of function GroupAIStateBase:convert_hostage_to_criminal

The function GroupAIStateBase:convert_hostage_to_criminal(unit, peer_unit) in groupaistatebase.lua is also hooked by PocoHud, Full Speed Swarm, Intimidated Outlines (Unsynced version), and also probably the other Intimidated Outlines versions/modifications too, including the original Intimidated Outlines, Less Confusing Intimidated Outlines and Anti Intimidated Outlines.

Since it is hooked by many mods, to increase compatibility, it should also be defined with three dots (...) in the parameter list so that it can take a variable number of arguments. The other hooked functions by HopLib already have ... in the parameter list, but this function doesn't.

e.g., function GroupAIStateBase:convert_hostage_to_criminal(unit, peer_unit, ...)
convert_hostage_to_criminal_original(self, unit, peer_unit, ...)

Possible Crash From unitnetworkhandler.lua

Since the update issued on the 12th, I've crashed multiple times, with it originating from the file unitnetworkhandler.lua.

[string "lib/network/handlers/unitnetworkhandler.lua"]:1714: attempt to perform arithmetic on local 'rot_speed_mul' (a nil value)

Dived through the mods folder and this was the only mod active to have this file. The mod was also updated the same day the crashes stared, and I've not suffered any crashes since removing it, so I'm fairly confident that it's coming from this mod. Crash.txt file attached.
crash.txt

HopLib causing crash after recent update

Never happened before recent update.
Not Void UI or GameInfoManager's fault.. I think.

Application has crashed: C++ exception
[string "lib/network/handlers/unitnetworkhandler.lua"]:2830: attempt to perform arithmetic on a nil value

SCRIPT STACK

mark_minion() @mods/HopLib/lua/unitnetworkhandler.lua:14
mark_minion_original() @mods/Void UI/lua/jokers.lua:51
@mods/GameInfoManager/GIM_Unit_Plugin.lua:270


Callstack:

     payday2_win32_release  (???)     ???                                                 
     payday2_win32_release  (???)     zip_get_name                                        
     payday2_win32_release  (???)     zip_get_name                                        

Current thread: Main


System information:
Application version : 1.89.554.
CPU : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (2 cores); SSE; SSE2; SSE3; SSSE3; SSE4.1; SSE4.2
DirectX : 12.0
GPU : NVIDIA GeForce GTX 1070 / nvldumd.dll[23.21.13.9135]
Language : english
Memory : 16211MB 800KB
OS : 6.2.9200 () 0x100-0x1 (64 bits)
Physics : threaded
Renderer : DX9 threaded
Sound : Realtek Semiconductor Corp. (Speakers (Realtek High Definition Audio))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.