Skip to content

Commit

Permalink
feat(scripting/player): PerformMenuAction
Browse files Browse the repository at this point in the history
  • Loading branch information
skuzzis committed Jan 16, 2025
1 parent b3423c4 commit aaa5854
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/plugins/core/scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ class PluginPlayer

void QueryConvar(std::string cvar_name);

void PerformMenuAction(std::string action, int value);

bool IsValid();
};

Expand Down
16 changes: 16 additions & 0 deletions src/plugins/core/scripting/player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,20 @@ bool PluginPlayer::IsValid()
if (!pawn) return false;

return true;
}

void PluginPlayer::PerformMenuAction(std::string action, int value)
{
Player* self = g_playerManager->GetPlayer(this->playerId);
if (!self) return;

if(action == "useOption") {
while(self->GetSelection() != value-1)
self->MoveSelection();

self->PerformMenuAction(g_Config->FetchValue<std::string>("core.menu.buttons.use"));
} else if(action == "scrollToOption") {
while(self->GetSelection() != value-1)
self->MoveSelection();
}
}
1 change: 1 addition & 0 deletions src/plugins/lua/scripting/player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ LoadLuaScriptingComponent(
.addFunction("GetConnectedTime", &PluginPlayer::GetConnectedTime)
.addFunction("GetWeaponManager", &PluginPlayer::GetWeaponManager)
.addFunction("QueryConvar", &PluginPlayer::QueryConvar)
.addFunction("PerformMenuAction", &PluginPlayer::PerformMenuAction)
.addFunction("IsValid", &PluginPlayer::IsValid)
.endClass()
.addFunction("GetPlayer", scripting_GetPlayer);
Expand Down

0 comments on commit aaa5854

Please sign in to comment.