Skip to content

Commit cc7f21a

Browse files
committed
Skill can be number or string
1 parent fe11a7d commit cc7f21a

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Client/mods/deathmatch/logic/luadefs/CLuaWeaponDefs.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,17 @@ int CLuaWeaponDefs::SetWeaponClipAmmo(lua_State* luaVM)
694694
return 1;
695695
}
696696

697-
std::variant<float, int, bool, CLuaMultiReturn<float,float,float>> CLuaWeaponDefs::GetWeaponProperty(lua_State* luaVM, std::variant<CClientWeapon*, int, std::string> weapon, eWeaponSkill skill, eWeaponProperty property)
697+
std::variant<float, int, bool, CLuaMultiReturn<float,float,float>> CLuaWeaponDefs::GetWeaponProperty(lua_State* luaVM, std::variant<CClientWeapon*, int, std::string> weapon, std::variant<int, std::string> weaponSkill, eWeaponProperty property)
698698
{
699+
eWeaponSkill skill = WEAPONSKILL_POOR;
700+
if (std::holds_alternative<int>(weaponSkill))
701+
skill = static_cast<eWeaponSkill>(std::get<int>(weaponSkill));
702+
else if (std::holds_alternative<std::string>(weaponSkill))
703+
StringToEnum(std::get<std::string>(weaponSkill), skill);
704+
705+
if (skill < eWeaponSkill::WEAPONSKILL_POOR || skill >= eWeaponSkill::WEAPONSKILL_MAX_NUMBER)
706+
throw LuaFunctionError("Invalid weapon skill value.", true);
707+
699708
// custom weapon
700709
if (std::holds_alternative<CClientWeapon*>(weapon))
701710
{
@@ -831,7 +840,7 @@ std::variant<float, int, bool, CLuaMultiReturn<float,float,float>> CLuaWeaponDef
831840
return false;
832841
}
833842

834-
std::variant<float, int, bool, CLuaMultiReturn<float, float, float>> CLuaWeaponDefs::GetOriginalWeaponProperty(lua_State* luaVM, std::variant<int, std::string> weapon, eWeaponSkill skill, eWeaponProperty property)
843+
std::variant<float, int, bool, CLuaMultiReturn<float, float, float>> CLuaWeaponDefs::GetOriginalWeaponProperty(lua_State* luaVM, std::variant<int, std::string> weapon, std::variant<int, std::string> weaponSkill, eWeaponProperty property)
835844
{
836845
eWeaponType weaponType = eWeaponType::WEAPONTYPE_INVALID;
837846
if (std::holds_alternative<int>(weapon))
@@ -842,6 +851,15 @@ std::variant<float, int, bool, CLuaMultiReturn<float, float, float>> CLuaWeaponD
842851
if (weaponType < eWeaponType::WEAPONTYPE_UNARMED || weaponType > eWeaponType::WEAPONTYPE_FLARE)
843852
throw LuaFunctionError("Weapon ID or name is invalid.", true);
844853

854+
eWeaponSkill skill = WEAPONSKILL_POOR;
855+
if (std::holds_alternative<int>(weaponSkill))
856+
skill = static_cast<eWeaponSkill>(std::get<int>(weaponSkill));
857+
else if (std::holds_alternative<std::string>(weaponSkill))
858+
StringToEnum(std::get<std::string>(weaponSkill), skill);
859+
860+
if (skill < eWeaponSkill::WEAPONSKILL_POOR || skill >= eWeaponSkill::WEAPONSKILL_MAX_NUMBER)
861+
throw LuaFunctionError("Invalid weapon skill value.", true);
862+
845863
CWeaponStat* weaponStats = g_pGame->GetWeaponStatManager()->GetOriginalWeaponStats(weaponType, skill);
846864
if (!weaponStats)
847865
return false;

Client/mods/deathmatch/logic/luadefs/CLuaWeaponDefs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class CLuaWeaponDefs : public CLuaDefs
2525
LUA_DECLARE(CreateWeapon);
2626
LUA_DECLARE(FireWeapon);
2727
LUA_DECLARE(SetWeaponProperty);
28-
static std::variant<float, int, bool, CLuaMultiReturn<float, float, float>> GetWeaponProperty(lua_State* luaVM, std::variant<CClientWeapon*, int, std::string> weapon, eWeaponSkill skill, eWeaponProperty property);
29-
static std::variant<float, int, bool, CLuaMultiReturn<float, float, float>> GetOriginalWeaponProperty(lua_State* luaVM, std::variant<int, std::string> weapon, eWeaponSkill skill, eWeaponProperty property);
28+
static std::variant<float, int, bool, CLuaMultiReturn<float, float, float>> GetWeaponProperty(lua_State* luaVM, std::variant<CClientWeapon*, int, std::string> weapon, std::variant<int, std::string> weaponSkill, eWeaponProperty property);
29+
static std::variant<float, int, bool, CLuaMultiReturn<float, float, float>> GetOriginalWeaponProperty(lua_State* luaVM, std::variant<int, std::string> weapon, std::variant<int, std::string> weaponSkill, eWeaponProperty property);
3030
LUA_DECLARE(SetWeaponState);
3131
LUA_DECLARE(GetWeaponState);
3232
LUA_DECLARE(SetWeaponTarget);

0 commit comments

Comments
 (0)