[Quest API] Add convert_money_to_string() to Perl/Lua (#3418)

* [Quest API] Add convert_money_to_string() to Perl/Lua

# Perl
- Add `quest::convert_money_to_string(money_hash)`.

# Lua
- Add `eq.convert_money_to_string(money_table)`.

# Notes
- Allows operators to convert money in to a readable string using `Strings::Money`.

# Examples

## Perl
```pl
sub EVENT_SAY {
	if ($text=~/#a/i) {
		my %money_data = (
			"platinum" => 3123,
			"gold" => 5692,
			"copper" => 9
		);
		quest::message(315, quest::convert_money_to_string(%money_data));
	}
}
```

## Lua
```lua
function event_say(e)
	if e.message:find("#a") then
		local money_data = {
			gold = 12,
			silver = 523904,
			copper = 3
		}
		eq.message(315, "Lua: " .. eq.convert_money_to_string(money_data))
	end
end```

* Update lua_general.cpp
This commit is contained in:
Alex King
2023-06-18 15:29:14 -04:00
committed by GitHub
parent a663c822e8
commit 6efb9ec228
4 changed files with 47 additions and 2 deletions
+20
View File
@@ -5325,6 +5325,25 @@ void Perl__send_channel_message(Client* from, const char* to, uint8 channel_numb
quest_manager.SendChannelMessage(from, to, channel_number, guild_id, language_id, language_skill, message);
}
std::string Perl__convert_money_to_string(perl::hash table)
{
uint64 platinum = table.exists("platinum") ? static_cast<uint64>(table["platinum"]) : 0;
uint64 gold = table.exists("gold") ? static_cast<uint64>(table["gold"]) : 0;
uint64 silver = table.exists("silver") ? static_cast<uint64>(table["silver"]) : 0;
uint64 copper = table.exists("copper") ? static_cast<uint64>(table["copper"]) : 0;
if (
!copper &&
!silver &&
!gold &&
!platinum
) {
return std::string();
}
return Strings::Money(platinum, gold, silver, copper);
}
void perl_register_quest()
{
perl::interpreter perl(PERL_GET_THX);
@@ -5649,6 +5668,7 @@ void perl_register_quest()
package.add("collectitems", &Perl__collectitems);
package.add("commify", &Perl__commify);
package.add("completedtasksinset", &Perl__completedtasksinset);
package.add("convert_money_to_string", &Perl__convert_money_to_string);
package.add("countitem", &Perl__countitem);
package.add("countspawnednpcs", &Perl__countspawnednpcs);
package.add("createdoor", (uint16(*)(const char*, float, float, float, float))&Perl__CreateDoor);