Skip to content

Commit

Permalink
change the add_money_hud
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Auto committed Oct 8, 2023
1 parent 7d33935 commit 4f5649f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
25 changes: 0 additions & 25 deletions docs/examples/add_money_hud.lua

This file was deleted.

18 changes: 17 additions & 1 deletion src/game_api/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1839,9 +1839,25 @@ int32_t get_current_money()
return money;
}

int32_t add_money_hud(int32_t amount, std::optional<uint8_t> display_time)
int32_t add_money(int32_t amount, std::optional<uint8_t> display_time)
{
auto state = State::get().ptr();
auto hud = get_hud();
state->money_shop_total += amount;
hud->money.counter += amount;
hud->money.timer = display_time.value_or(0x3C);
return get_current_money();
}

int32_t add_money_slot(int32_t amount, uint8_t player_slot, std::optional<uint8_t> display_time)
{
auto state = State::get().ptr();
auto hud = get_hud();
uint8_t slot = player_slot - 1;
if (slot > 3)
return get_current_money();

state->items->player_inventories[slot].money += amount;
hud->money.counter += amount;
hud->money.timer = display_time.value_or(0x3C);
return get_current_money();
Expand Down
3 changes: 2 additions & 1 deletion src/game_api/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ void set_frametime_inactive(std::optional<double> frametime);
std::optional<double> get_frametime_inactive();
ENT_TYPE add_custom_type(std::vector<ENT_TYPE> types);
int32_t get_current_money();
int32_t add_money_hud(int32_t amount, std::optional<uint8_t> display_time);
int32_t add_money(int32_t amount, std::optional<uint8_t> display_time);
int32_t add_money_slot(int32_t amount, uint8_t player_slot, std::optional<uint8_t> display_time);
10 changes: 7 additions & 3 deletions src/game_api/script/lua_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2104,9 +2104,13 @@ end
/// short for state->money_shop_total + loop[inventory.money + inventory.collected_money_total]
lua["get_current_money"] = get_current_money;

/// Display the effect of adding or subtracting money in the hud, does not actually change the amount of money
/// It actually subtracts the amount of money first for the effect, look at the example, default display_time = 60 (about 2s)
lua["add_money_hud"] = add_money_hud;
/// Adds money to the state.money_shop_total and displays the effect on the HUD for money change
/// Can be negative, default display_time = 60 (about 2s)
lua["add_money"] = add_money;

/// Adds money to the state.items.player_inventory[player_slot].money and displays the effect on the HUD for money change
/// Can be negative, default display_time = 60 (about 2s)
lua["add_money_slot"] = add_money_slot;

lua.create_named_table("INPUTS", "NONE", 0, "JUMP", 1, "WHIP", 2, "BOMB", 4, "ROPE", 8, "RUN", 16, "DOOR", 32, "MENU", 64, "JOURNAL", 128, "LEFT", 256, "RIGHT", 512, "UP", 1024, "DOWN", 2048);

Expand Down

0 comments on commit 4f5649f

Please sign in to comment.