This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
Files
YimMenu/src/lua/bindings/stats.cpp
gir489 afd3a5e943 Add Garage drop-down to Spawn PV menu (#2171)
* Fixed edge case where a garage that contained only banned vehicles would show if the user was using Spawn Clone.
Refactored a large portion of the garage code to be production ready.
Formatting changes.

* Added singular garage items to the m_garage setter like the Terrorbyte.

* Fixed is_blacklisted_vehicle returning an inverted condition.
Fixed Garage drop-down not updating properly.

* Separated out m_garage's setter into a ctor function.
Replaced the 4 singular garages that use an overloaded index with a define to be able to shift them easier when new properties are added.

* Removed obsolete and incorrect player.character_slot config entry.
Removed deprecated local_player.hpp.
Added self::char_slot that is guaranteed to be correct.

* Removed extraneous semi-colon.

* Added more stuff to fillsnacks.
Removed more extraneous usages of MPPLY_LAST_MP_CHAR.

* Added the vehicle's name to player info.

* Fixed get_property_garage_size returning the incorrect size for the facility.
Fixed get_static_property_name returning the Nightclub's name instead of Nightclub Service Entrance to maintain consistency with the Mechanic.
Fixed garage_slot_iterator not starting and ending at the correct indexes.

* Shifted the singular properties down one to compensate for the new math.

* Fixed backwards math on Terrorbyte and Nightclub B1.

* Fixed garage not being updated when the player moved the vehicle.

* Fixed backwards comments.
2023-09-22 23:16:33 +02:00

291 lines
8.5 KiB
C++

#pragma once
#include "stats.hpp"
#include "natives.hpp"
namespace lua::stats
{
// Lua API: Table
// Name: stats
// Table for manipulating GTA stats.
// Lua API: Function
// Table: stats
// Name: get_character_index
// Returns: integer: The current multiplayer character index (0 or 1).
static int get_character_index()
{
return self::char_index;
}
static Hash stat_text_to_hash(std::string& text)
{
if (text[0] == '$')
{
text = text.substr(1);
}
std::transform(text.begin(), text.end(), text.begin(), ::toupper);
if (text.substr(0, 3) == "MPX")
text[2] = get_character_index() + '0';
return rage::joaat(text);
}
// Lua API: Function
// Table: stats
// Name: get_bool
// Param: stat_hash: integer: the stat hash.
// Returns: boolean: The value of the given stat.
static bool get_bool_hash(Hash stat_hash)
{
int out_value;
STATS::STAT_GET_BOOL(stat_hash, &out_value, -1);
return out_value;
}
// Lua API: Function
// Table: stats
// Name: get_bool
// Param: stat_name: string: the stat name.
// Returns: boolean: The value of the given stat.
static bool get_bool_name(std::string stat_name)
{
return get_bool_hash(stat_text_to_hash(stat_name));
}
// Lua API: Function
// Table: stats
// Name: get_bool_masked
// Param: stat_hash: integer: the stat hash.
// Param: bit_index: integer: bit index.
// Returns: boolean: The value of the given stat.
static bool get_bool_masked_hash(Hash stat_hash, int bit_index)
{
int out_value;
constexpr int bit_count = 8;
STATS::STAT_GET_MASKED_INT(stat_hash, &out_value, bit_index, bit_count, -1);
return out_value;
}
// Lua API: Function
// Table: stats
// Name: get_bool_masked
// Param: stat_name: string: the stat name.
// Param: bit_index: integer: bit index.
// Returns: boolean: The value of the given stat.
static bool get_bool_masked_name(std::string stat_name, int bit_index)
{
return get_bool_masked_hash(stat_text_to_hash(stat_name), bit_index);
}
// Lua API: Function
// Table: stats
// Name: get_float
// Param: stat_hash: integer: the stat hash.
// Returns: float: The value of the given stat.
static float get_float_hash(Hash stat_hash)
{
float out_value;
STATS::STAT_GET_FLOAT(stat_hash, &out_value, -1);
return out_value;
}
// Lua API: Function
// Table: stats
// Name: get_float
// Param: stat_name: string: the stat name.
// Returns: float: The value of the given stat.
static float get_float_name(std::string stat_name)
{
return get_float_hash(stat_text_to_hash(stat_name));
}
// Lua API: Function
// Table: stats
// Name: get_int
// Param: stat_hash: integer: the stat hash.
// Returns: integer: The value of the given stat.
static int get_int_hash(Hash stat_hash)
{
int out_value;
STATS::STAT_GET_INT(stat_hash, &out_value, -1);
return out_value;
}
// Lua API: Function
// Table: stats
// Name: get_int
// Param: stat_name: string: the stat name.
// Returns: integer: The value of the given stat.
static int get_int_name(std::string stat_name)
{
return get_int_hash(stat_text_to_hash(stat_name));
}
// Lua API: Function
// Table: stats
// Name: get_masked_int
// Param: stat_hash: integer: the stat hash.
// Param: bit_start: integer: bit start.
// Param: bit_size: integer: bit size.
// Returns: integer: The value of the given stat.
static int get_masked_int_hash(Hash stat_hash, int bit_index, int bit_size)
{
int out_value;
STATS::STAT_GET_MASKED_INT(stat_hash, &out_value, bit_index, bit_size, -1);
return out_value;
}
// Lua API: Function
// Table: stats
// Name: get_masked_int
// Param: stat_name: string: the stat name.
// Param: bit_index: integer: bit index.
// Param: bit_size: integer: bit size.
// Returns: integer: The value of the given stat.
static int get_masked_int_name(std::string stat_name, int bit_index, int bit_size)
{
return get_masked_int_hash(stat_text_to_hash(stat_name), bit_index, bit_size);
}
// Lua API: Function
// Table: stats
// Name: set_bool
// Param: stat_hash: integer: the stat hash.
// Param: new_value: boolean: the new value for the stat.
// Returns: boolean: True if succeeded.
static bool set_bool_hash(Hash stat_hash, bool new_value)
{
return STATS::STAT_SET_BOOL(stat_hash, new_value, true);
}
// Lua API: Function
// Table: stats
// Name: set_bool
// Param: stat_name: string: the stat name.
// Param: new_value: boolean: the new value for the stat.
// Returns: boolean: True if succeeded.
static bool set_bool_name(std::string stat_name, bool new_value)
{
return set_bool_hash(stat_text_to_hash(stat_name), new_value);
}
// Lua API: Function
// Table: stats
// Name: set_bool_masked
// Param: stat_hash: integer: the stat hash.
// Param: new_value: boolean: the new value for the stat.
// Param: bit_index: integer: bit_index.
// Returns: boolean: True if succeeded.
static bool set_bool_masked_hash(Hash stat_hash, bool new_value, int bit_index)
{
constexpr int bit_count = 8;
return STATS::STAT_SET_MASKED_INT(stat_hash, new_value, bit_index, bit_count, true);
}
// Lua API: Function
// Table: stats
// Name: set_bool_masked
// Param: stat_name: string: the stat name.
// Param: new_value: boolean: the new value for the stat.
// Param: bit_index: integer: bit_index.
// Returns: boolean: True if succeeded.
static bool set_bool_masked_name(std::string stat_name, bool new_value, int bit_index)
{
return set_bool_masked_hash(stat_text_to_hash(stat_name), new_value, bit_index);
}
// Lua API: Function
// Table: stats
// Name: set_float
// Param: stat_hash: integer: the stat hash.
// Param: new_value: float: the new value for the stat.
// Returns: boolean: True if succeeded.
static bool set_float_hash(Hash stat_hash, float new_value)
{
return STATS::STAT_SET_FLOAT(stat_hash, new_value, true);
}
// Lua API: Function
// Table: stats
// Name: set_float
// Param: stat_name: string: the stat name.
// Param: new_value: float: the new value for the stat.
// Returns: boolean: True if succeeded.
static bool set_float_name(std::string stat_name, float new_value)
{
return set_float_hash(stat_text_to_hash(stat_name), new_value);
}
// Lua API: Function
// Table: stats
// Name: set_int
// Param: stat_hash: integer: the stat hash.
// Param: new_value: integer: the new value for the stat.
// Returns: boolean: True if succeeded.
static bool set_int_hash(Hash stat_hash, int new_value)
{
return STATS::STAT_SET_INT(stat_hash, new_value, true);
}
// Lua API: Function
// Table: stats
// Name: set_int
// Param: stat_name: string: the stat name.
// Param: new_value: integer: the new value for the stat.
// Returns: boolean: True if succeeded.
static bool set_int_name(std::string stat_name, int new_value)
{
return set_int_hash(stat_text_to_hash(stat_name), new_value);
}
// Lua API: Function
// Table: stats
// Name: set_masked_int
// Param: stat_hash: integer: the stat hash.
// Param: new_value: integer: the new value for the stat.
// Param: bit_start: integer: bit_start.
// Param: bit_size: integer: bit_size.
// Returns: boolean: True if succeeded.
static bool set_masked_int_hash(Hash stat_hash, int new_value, int bit_start, int bit_size)
{
return STATS::STAT_SET_MASKED_INT(stat_hash, new_value, bit_start, bit_size, true);
}
// Lua API: Function
// Table: stats
// Name: set_masked_int
// Param: stat_name: string: the stat name.
// Param: new_value: integer: the new value for the stat.
// Param: bit_start: integer: bit_start.
// Param: bit_size: integer: bit_size.
// Returns: boolean: True if succeeded.
static bool set_masked_int_name(std::string stat_name, int new_value, int bit_start, int bit_size)
{
return set_masked_int_hash(stat_text_to_hash(stat_name), new_value, bit_start, bit_size);
}
void bind(sol::state& state)
{
auto ns = state["stats"].get_or_create<sol::table>();
ns["get_bool"] = sol::overload(get_bool_hash, get_bool_name);
ns["get_bool_masked"] = sol::overload(get_bool_masked_hash, get_bool_masked_name);
ns["get_float"] = sol::overload(get_float_hash, get_float_name);
ns["get_int"] = sol::overload(get_int_hash, get_int_name);
ns["get_masked_int"] = sol::overload(get_masked_int_hash, get_masked_int_name);
ns["set_bool"] = sol::overload(set_bool_hash, set_bool_name);
ns["set_bool_masked"] = sol::overload(set_bool_masked_hash, set_bool_masked_name);
ns["set_float"] = sol::overload(set_float_hash, set_float_name);
ns["set_int"] = sol::overload(set_int_hash, set_int_name);
ns["set_masked_int"] = sol::overload(set_masked_int_hash, set_masked_int_name);
}
}