Add some console commands
This commit is contained in:
parent
5e0fb92c9d
commit
c9d01afa7f
@ -4,6 +4,8 @@
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include "game/scripting/execution.hpp"
|
||||
|
||||
#include "command.hpp"
|
||||
#include "game_console.hpp"
|
||||
#include "chat.hpp"
|
||||
@ -308,15 +310,120 @@ namespace command
|
||||
return;
|
||||
}
|
||||
|
||||
auto ps = game::g_entities[0].client;
|
||||
const auto wp = game::G_GetWeaponForName(params.get(1));
|
||||
if (wp)
|
||||
try
|
||||
{
|
||||
if (game::G_GivePlayerWeapon(ps, wp, 0, 0, 0, 0))
|
||||
const auto arg = params.get(1);
|
||||
const scripting::entity player = scripting::call("getentbynum", {0}).as<scripting::entity>();
|
||||
auto ps = game::g_entities[0].client;
|
||||
|
||||
if (arg == "ammo"s)
|
||||
{
|
||||
game::G_InitializeAmmo(ps, wp, 0);
|
||||
game::G_SelectWeapon(0, wp);
|
||||
const auto weapon = player.call("getcurrentweapon").as<std::string>();
|
||||
player.call("givemaxammo", {weapon});
|
||||
}
|
||||
else if (arg == "allammo"s)
|
||||
{
|
||||
const auto weapons = player.call("getweaponslist").as<scripting::array>();
|
||||
for (auto i = 0; i < weapons.size(); i++)
|
||||
{
|
||||
player.call("givemaxammo", {weapons[i]});
|
||||
}
|
||||
}
|
||||
else if (arg == "health"s)
|
||||
{
|
||||
|
||||
if (params.size() > 3)
|
||||
{
|
||||
const auto amount = atoi(params.get(2));
|
||||
const auto health = player.get("health").as<int>();
|
||||
player.set("health", {health + amount});
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto amount = game::Dvar_FindVar("g_player_maxhealth")->current.integer;
|
||||
player.set("health", {amount});
|
||||
}
|
||||
}
|
||||
else if (arg == "all"s)
|
||||
{
|
||||
const auto type = game::XAssetType::ASSET_TYPE_WEAPON;
|
||||
fastfiles::enum_assets(type, [&player, type](const game::XAssetHeader header)
|
||||
{
|
||||
const auto asset = game::XAsset{type, header};
|
||||
const auto* const asset_name = game::DB_GetXAssetName(&asset);
|
||||
|
||||
player.call("giveweapon", {asset_name});
|
||||
}, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto wp = game::G_GetWeaponForName(arg);
|
||||
if (wp)
|
||||
{
|
||||
if (game::G_GivePlayerWeapon(ps, wp, 0, 0, 0, 0))
|
||||
{
|
||||
game::G_InitializeAmmo(ps, wp, 0);
|
||||
game::G_SelectWeapon(0, wp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
game::CG_GameMessage(0, "Weapon does not exist");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
add("dropweapon", [](const params& params)
|
||||
{
|
||||
if (!game::SV_Loaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const scripting::entity player = scripting::call("getentbynum", {0}).as<scripting::entity>();
|
||||
const auto weapon = player.call("getcurrentweapon");
|
||||
player.call("dropitem", {weapon});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
add("take", [](const params& params)
|
||||
{
|
||||
if (!game::SV_Loaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (params.size() < 2)
|
||||
{
|
||||
game::CG_GameMessage(0, "You did not specify a weapon name");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto weapon = params.get(1);
|
||||
|
||||
try
|
||||
{
|
||||
const scripting::entity player = scripting::call("getentbynum", {0}).as<scripting::entity>();
|
||||
if (weapon == "all"s)
|
||||
{
|
||||
player.call("takeallweapons");
|
||||
}
|
||||
else
|
||||
{
|
||||
player.call("takeweapon", {weapon});
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ namespace entity_list
|
||||
{
|
||||
scripting::array result{};
|
||||
|
||||
for (unsigned int i = 0; i < all.size(); i++)
|
||||
for (auto i = 0; i < all.size(); i++)
|
||||
{
|
||||
const auto raw = all[i].get_raw();
|
||||
if (raw.type != game::SCRIPT_OBJECT)
|
||||
@ -405,7 +405,7 @@ namespace entity_list
|
||||
|
||||
const auto array = value.value();
|
||||
|
||||
for (unsigned int i = 0; i < array.size(); i++)
|
||||
for (auto i = 0; i < array.size(); i++)
|
||||
{
|
||||
const auto raw = array[i].get_raw();
|
||||
if (raw.type != game::SCRIPT_OBJECT)
|
||||
|
@ -165,9 +165,9 @@ namespace scripting
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned int array::size() const
|
||||
int array::size() const
|
||||
{
|
||||
return game::scr_VarGlob->objectVariableValue[this->id_].u.f.next;
|
||||
return static_cast<int>(game::scr_VarGlob->objectVariableValue[this->id_].u.f.next);
|
||||
}
|
||||
|
||||
unsigned int array::push(script_value value) const
|
||||
@ -212,8 +212,6 @@ namespace scripting
|
||||
{
|
||||
return this->get(key.as<std::string>());
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
script_value array::get(const std::string& key) const
|
||||
|
@ -32,7 +32,7 @@ namespace scripting
|
||||
array& operator=(array&& other) noexcept;
|
||||
|
||||
std::vector<script_value> get_keys() const;
|
||||
unsigned int size() const;
|
||||
int size() const;
|
||||
|
||||
unsigned int push(script_value) const;
|
||||
void erase(const unsigned int) const;
|
||||
|
Loading…
Reference in New Issue
Block a user