sm-plugins/forceclass.sp

209 lines
5.3 KiB
SourcePawn

/* Plugin Template generated by Pawn Studio */
#include <sourcemod>
#include <tf2>
#include <tf2_stocks>
#include <sdktools_stocks>
#include <sdktools_functions>
#include <entity_prop_stocks>
#undef REQUIRE_PLUGIN
#include <adminmenu>
/* Keep track of the top menu */
new Handle:hAdminMenu = INVALID_HANDLE
new Handle:hPlayerSelectMenu = INVALID_HANDLE;
new Handle:hClassSelectMenu = INVALID_HANDLE;
new String:targetSelected[32] = "";
public Plugin:myinfo =
{
name = "ClassForcer",
author = "Chefe",
description = "wayne",
version = "1.2",
url = ""
}
public OnPluginStart()
{
/* See if the menu pluginis already ready */
new Handle:topmenu;
if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
{
/* If so, manually fire the callback */
OnAdminMenuReady(topmenu);
}
}
public OnLibraryRemoved(const String:name[])
{
if (StrEqual(name, "adminmenu"))
{
hAdminMenu = INVALID_HANDLE;
}
}
public OnAdminMenuReady(Handle:topmenu)
{
/* Block us from being called twice */
if (topmenu == hAdminMenu)
{
return;
}
hAdminMenu = topmenu;
/* If the category is third party, it will have its own unique name. */
new TopMenuObject:player_commands = FindTopMenuCategory(hAdminMenu, ADMINMENU_PLAYERCOMMANDS);
if (player_commands == INVALID_TOPMENUOBJECT)
{
/* Error! */
return;
}
AddToTopMenu(hAdminMenu, "sm_forceclass", TopMenuObject_Item, AdminMenu_ForceClass, player_commands, "sm_forceclass", ADMFLAG_SLAY);
}
public AdminMenu_ForceClass(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength)
{
if (action == TopMenuAction_DisplayOption)
{
Format(buffer, maxlength, "Force Class");
}
else if (action == TopMenuAction_SelectOption)
{
hPlayerSelectMenu = CreateMenu(Menu_PlayerSelect);
SetMenuTitle(hPlayerSelectMenu, "Select Target");
new maxClients = GetMaxClients();
for (new i=1; i<=maxClients; i++)
{
if (!IsClientInGame(i))
{
continue;
}
new TFClassType:class = TF2_GetPlayerClass(i);
new String:infostr[200];
Format(infostr, sizeof(infostr), "%N (%s)", i, class);
new String:indexstr[32];
IntToString(i, indexstr, sizeof(indexstr));
AddMenuItem(hPlayerSelectMenu,indexstr, infostr)
}
AddMenuItem(hPlayerSelectMenu, "red", "Red Team");
AddMenuItem(hPlayerSelectMenu, "blue", "Team Blu");
AddMenuItem(hPlayerSelectMenu, "all", "All Player");
SetMenuExitButton(hPlayerSelectMenu, true);
DisplayMenu(hPlayerSelectMenu, param, MENU_TIME_FOREVER);
}
}
public Menu_PlayerSelect(Handle:menu, MenuAction:action, param1, param2)
{
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select)
{
new String:info[32];
GetMenuItem(menu, param2, info, sizeof(info));
targetSelected = info;
hClassSelectMenu = CreateMenu(Menu_ClassSelect);
SetMenuTitle(hClassSelectMenu, "Select Class");
AddMenuItem(hClassSelectMenu, "scout", "Scout");
AddMenuItem(hClassSelectMenu, "soldier", "Soldier");
AddMenuItem(hClassSelectMenu, "pyro", "Pyro");
AddMenuItem(hClassSelectMenu, "demoman", "Demoman");
AddMenuItem(hClassSelectMenu, "heavy", "Heavy");
AddMenuItem(hClassSelectMenu, "engineer", "Engineer");
AddMenuItem(hClassSelectMenu, "medic", "Medic");
AddMenuItem(hClassSelectMenu, "sniper", "Sniper");
AddMenuItem(hClassSelectMenu, "spy", "Spy");
SetMenuExitButton(hClassSelectMenu, true);
DisplayMenu(hClassSelectMenu, param1, MENU_TIME_FOREVER);
}
/* If the menu was cancelled, print a message to the server about it. */
else if (action == MenuAction_Cancel)
{
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
public Menu_ClassSelect(Handle:menu, MenuAction:action, param1, param2)
{
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select)
{
new String:class[32];
GetMenuItem(menu, param2, class, sizeof(class));
if (strcmp(targetSelected, "red", false) != 0 && strcmp(targetSelected, "blue", false) != 0 && strcmp(targetSelected, "all", false) != 0)
{
new client = StringToInt(targetSelected);
if (IsClientInGame(client))
{
changePlayerClass(client, class);
}
}
else
{
if (strcmp(targetSelected, "red") == 0 || strcmp(targetSelected, "blue") == 0)
{
new targetteam = FindTeamByName(targetSelected);
new maxClients = GetMaxClients();
for (new i=1; i<=maxClients; i++)
{
if (!IsClientInGame(i))
{
continue;
}
if (GetClientTeam(i) == targetteam)
{
changePlayerClass(i, class);
}
}
}
else if (strcmp(targetSelected, "all") == 0)
{
new maxClients = GetMaxClients();
for (new i=1; i<=maxClients; i++)
{
if (!IsClientInGame(i))
{
continue;
}
changePlayerClass(i, class);
}
}
}
}
/* If the menu was cancelled, print a message to the server about it. */
else if (action == MenuAction_Cancel)
{
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
changePlayerClass(client, String:class[32])
{
new TFClassType:classtf = TF2_GetClass(class);
TF2_SetPlayerClass(client, classtf, false, true);
FakeClientCommand(client, "kill");
PrintToChat(client, "[OF] You have been forced to class %s", class);
}