Added commands zr_zspawn_force, and zr_ztele_force.

Added options to ZAdmin that allow admins to force spawn players, or force teleport players.
This commit is contained in:
Greyscale 2009-06-25 17:03:34 -07:00
parent 1dff60542e
commit 3f08d6f72c
9 changed files with 499 additions and 93 deletions

View File

@ -790,6 +790,40 @@
"en" "Zombies may now only be damaged by headshots." "en" "Zombies may now only be damaged by headshots."
} }
// ===========================
// ZAdmin (core)
// ===========================
"ZAdmin main title"
{
"en" "ZAdmin\n Select Category:"
}
"ZAdmin main class multipliers"
{
"en" "Class Multipliers"
}
"ZAdmin main weapons"
{
"en" "Weapon Management"
}
"ZAdmin main zombie"
{
"en" "Zombie Management"
}
"ZAdmin main force zspawn "
{
"en" "Force ZSpawn"
}
"ZAdmin main force ztele"
{
"en" "Force ZTele"
}
// =========================== // ===========================
// Spawn Protect (module) // Spawn Protect (module)
// =========================== // ===========================
@ -848,6 +882,8 @@
// ZSpawn (module) // ZSpawn (module)
// =========================== // ===========================
// General
"ZSpawn double spawn" "ZSpawn double spawn"
{ {
"en" "ZSpawn can only be used if you joined late during a round in progress." "en" "ZSpawn can only be used if you joined late during a round in progress."
@ -859,6 +895,33 @@
"en" "The timelimit ({1} seconds), to use ZSpawn, has already expired." "en" "The timelimit ({1} seconds), to use ZSpawn, has already expired."
} }
// Menu
"ZSpawn clients title"
{
"en" "Force ZSpawn (zr_zspawn_force)\nSelect a Player:"
}
// Commands
"ZSpawn command force syntax"
{
"en" "Force ZSpawn on a client. Usage: zr_zspawn_force <client> ['0' = Spawn as human | '1' = Spawn as zombie]"
}
"ZSpawn command force successful"
{
"#format" "{1:s}"
"en" "Player {1} was successfully ZSpawned."
}
"ZSpawn command force unsuccessful"
{
"#format" "{1:s}"
"en" "Player {1} couldn't be ZSpawned."
}
// =========================== // ===========================
// ZTele (module) // ZTele (module)
// =========================== // ===========================
@ -906,6 +969,33 @@
"en" "Teleported back to spawn. (Count: {1}/{2})" "en" "Teleported back to spawn. (Count: {1}/{2})"
} }
// Menu
"ZTele clients title"
{
"en" "Force ZTele (zr_ztele_force)\nSelect a Player:"
}
// Commands
"ZTele command force syntax"
{
"en" "Force ZTele on a client. Usage: zr_ztele_force <client>"
}
"ZTele command force successful"
{
"#format" "{1:s}"
"en" "Player {1} was successfully ZTele'd."
}
"ZTele command force unsuccessful"
{
"#format" "{1:s}"
"en" "Player {1} couldn't be ZTele'd."
}
// =========================== // ===========================
// ZHP (module) // ZHP (module)
// =========================== // ===========================
@ -944,28 +1034,4 @@
"#format" "{1:s},{2:d}" "#format" "{1:s},{2:d}"
"en" "Player {1} has been slayed for camping in a restricted area. (ID: {2})" "en" "Player {1} has been slayed for camping in a restricted area. (ID: {2})"
} }
// ===========================
// ZAdmin Menu
// ===========================
"ZAdmin main title"
{
"en" "ZAdmin\n Select Category:"
}
"ZAdmin main class multipliers"
{
"en" "Class Multipliers"
}
"ZAdmin main weapons"
{
"en" "Weapon Management"
}
"ZAdmin main zombie"
{
"en" "Zombie Management"
}
} }

View File

@ -173,7 +173,7 @@ public Action:Command_Respawn(client, argc)
{ {
if (ZRIsClientValid(client)) if (ZRIsClientValid(client))
{ {
ZRAdminMenu(client); ZAdminMenu(client);
} }
else else
{ {

View File

@ -861,11 +861,8 @@ public InfectMenuClientsHandle(Handle:menu_infect_clients, MenuAction:action, cl
// Client selected an option. // Client selected an option.
if (action == MenuAction_Select) if (action == MenuAction_Select)
{ {
decl String:clientuserid[8]; // Get selected client index.
GetMenuItem(menu_infect_clients, slot, clientuserid, sizeof(clientuserid)); new target = MenuGetClientIndex(menu_infect_clients, slot);
// Get the targetted client through their userid which was set into the menu slot's info param.
new target = GetClientOfUserId(StringToInt(clientuserid));
// If target has left the server, then stop. // If target has left the server, then stop.
if (!target) if (!target)
@ -899,7 +896,7 @@ public InfectMenuClientsHandle(Handle:menu_infect_clients, MenuAction:action, cl
if (slot == MenuCancel_ExitBack) if (slot == MenuCancel_ExitBack)
{ {
// Re-open admin menu. // Re-open admin menu.
ZRAdminMenu(client); ZAdminMenu(client);
} }
} }
// Client hit "Exit" button. // Client hit "Exit" button.

View File

@ -138,7 +138,7 @@ public ZMenuMainHandle(Handle:menu, MenuAction:action, client, slot)
case 0: case 0:
{ {
// Copy return to resend variable. // Copy return to resend variable.
resend = !ZRAdminMenu(client); resend = !ZAdminMenu(client);
} }
// Select ZClass. // Select ZClass.
case 1: case 1:
@ -197,12 +197,78 @@ public ZMenuMainHandle(Handle:menu, MenuAction:action, client, slot)
} }
} }
/**
* Shows a list of all clients to a client, different handlers can be used for this, as well as title.
*
* @param client The client index.
* @param handler The menu handler.
* @param any Title is a translations phrase.
*/
stock MenuClientList(client, MenuHandler:handler, any:...)
{
// Create menu handle.
new Handle:menu_clients = CreateMenu(handler);
// Set client as translation target.
SetGlobalTransTarget(client);
// Translate phrase.
decl String:translation[TRANSLATION_MAX_LENGTH_CHAT];
VFormat(translation, sizeof(translation), "%t", 3);
// Set menu title to the translated phrase.
SetMenuTitle(menu_clients, translation);
decl String:clientoption[MAX_NAME_LENGTH];
decl String:clientuserid[8];
// x = Client index.
for (new x = 1; x <= MaxClients; x++)
{
// If client isn't in-game, then stop.
if (!IsClientInGame(x))
{
continue;
}
// Get client info.
GetClientName(x, clientoption, sizeof(clientoption));
IntToString(GetClientUserId(x), clientuserid, sizeof(clientuserid));
// Add option to menu.
AddMenuItem(menu_clients, clientuserid, clientoption);
}
// Create a "Back" button to the main admin menu.
SetMenuExitBackButton(menu_clients, true);
// Send menu.
DisplayMenu(menu_clients, client, MENU_TIME_FOREVER);
}
/**
* Gets the client index of the selected client in the menu.
*
* @param menu The menu handle.
* @param slot The menu slot that was selected.
* @return The client index, 0 if the selected client is no longer in the server.
*/
stock MenuGetClientIndex(Handle:menu, slot)
{
// Get menu slot's information.
decl String:clientuserid[8];
GetMenuItem(menu, slot, clientuserid, sizeof(clientuserid));
// Return the targetted client through their userid which was set into the menu slot's info param.
return GetClientOfUserId(StringToInt(clientuserid));
}
/** /**
* Return itemdraw flag for SM menus. * Return itemdraw flag for SM menus.
* *
* @param condition If this is true, item will be drawn normally. * @param condition If this is true, item will be drawn normally.
*/ */
MenuGetItemDraw(bool:condition) stock MenuGetItemDraw(bool:condition)
{ {
return condition ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED; return condition ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED;
} }

View File

@ -384,7 +384,7 @@ public ClassTeamSelectHandle(Handle:menu, MenuAction:action, client, slot)
{ {
if (slot == MenuCancel_ExitBack) if (slot == MenuCancel_ExitBack)
{ {
ZRAdminMenu(client); ZAdminMenu(client);
} }
} }
} }

View File

@ -104,7 +104,7 @@ public WeaponsMenuMainHandle(Handle:menu_weapons_main, MenuAction:action, client
if (slot == MenuCancel_ExitBack) if (slot == MenuCancel_ExitBack)
{ {
// Re-open admin menu. // Re-open admin menu.
ZRAdminMenu(client); ZAdminMenu(client);
} }
} }
// Client hit "Exit" button. // Client hit "Exit" button.

View File

@ -51,7 +51,7 @@ public Action:ZAdminCommand(client, argc)
} }
// Send admin menu. // Send admin menu.
ZRAdminMenu(client); ZAdminMenu(client);
// This stops the "Unknown command" message in client's console. // This stops the "Unknown command" message in client's console.
return Plugin_Handled; return Plugin_Handled;
@ -62,7 +62,7 @@ public Action:ZAdminCommand(client, argc)
* *
* @param client The client index. * @param client The client index.
*/ */
bool:ZRAdminMenu(client) bool:ZAdminMenu(client)
{ {
// If client isn't an admin, then stop. // If client isn't an admin, then stop.
if (!ZRIsClientAdmin(client)) if (!ZRIsClientAdmin(client))
@ -72,7 +72,7 @@ bool:ZRAdminMenu(client)
} }
// Create menu handle. // Create menu handle.
new Handle:menu_zadmin = CreateMenu(ZRAdminMenuHandle); new Handle:menu_zadmin = CreateMenu(ZAdminMenuHandle);
// Set translation target as the client. // Set translation target as the client.
SetGlobalTransTarget(client); SetGlobalTransTarget(client);
@ -80,8 +80,8 @@ bool:ZRAdminMenu(client)
SetMenuTitle(menu_zadmin, "%t\n ", "ZAdmin main title"); SetMenuTitle(menu_zadmin, "%t\n ", "ZAdmin main title");
decl String:classmultipliers[64]; decl String:classmultipliers[64];
//decl String:zspawn[64]; decl String:zspawn[64];
//decl String:ztele[64]; decl String:ztele[64];
decl String:weapons[64]; decl String:weapons[64];
decl String:infect[64]; decl String:infect[64];
//decl String:logflags[64]; //decl String:logflags[64];
@ -89,15 +89,15 @@ bool:ZRAdminMenu(client)
Format(classmultipliers, sizeof(classmultipliers), "%t", "ZAdmin main class multipliers"); Format(classmultipliers, sizeof(classmultipliers), "%t", "ZAdmin main class multipliers");
Format(weapons, sizeof(weapons), "%t", "ZAdmin main weapons"); Format(weapons, sizeof(weapons), "%t", "ZAdmin main weapons");
Format(infect, sizeof(infect), "%t", "ZAdmin main zombie"); Format(infect, sizeof(infect), "%t", "ZAdmin main zombie");
//Format(zspawn, sizeof(zspawn), "%t", "!zadmin main spawn"); Format(zspawn, sizeof(zspawn), "%t", "ZAdmin main force zspawn");
//Format(ztele, sizeof(ztele), "%t", "!zadmin main tele"); Format(ztele, sizeof(ztele), "%t", "ZAdmin main force ztele");
//Format(logflags, sizeof(logflags), "%t", "!zadmin main logflags"); //Format(logflags, sizeof(logflags), "%t", "!zadmin main logflags");
AddMenuItem(menu_zadmin, "classmultipliers", classmultipliers); AddMenuItem(menu_zadmin, "classmultipliers", classmultipliers);
AddMenuItem(menu_zadmin, "weapons", weapons); AddMenuItem(menu_zadmin, "weapons", weapons);
AddMenuItem(menu_zadmin, "infect", infect); AddMenuItem(menu_zadmin, "infect", infect);
//AddMenuItem(menu_zadmin, "zspawn", zspawn); AddMenuItem(menu_zadmin, "zspawn", zspawn);
//AddMenuItem(menu_zadmin, "ztele", ztele, ITEMDRAW_DISABLED); AddMenuItem(menu_zadmin, "ztele", ztele);
//AddMenuItem(menu_zadmin, "logflags", logflags); //AddMenuItem(menu_zadmin, "logflags", logflags);
// Set "Back" button. // Set "Back" button.
@ -118,7 +118,7 @@ bool:ZRAdminMenu(client)
* @param client The client index. * @param client The client index.
* @param slot The menu slot selected. (starting from 0) * @param slot The menu slot selected. (starting from 0)
*/ */
public ZRAdminMenuHandle(Handle:menu_zadmin, MenuAction:action, client, slot) public ZAdminMenuHandle(Handle:menu_zadmin, MenuAction:action, client, slot)
{ {
if (action == MenuAction_Select) if (action == MenuAction_Select)
{ {
@ -146,12 +146,30 @@ public ZRAdminMenuHandle(Handle:menu_zadmin, MenuAction:action, client, slot)
// Send list of clients to infect. // Send list of clients to infect.
InfectMenuClients(client); InfectMenuClients(client);
} }
// Force ZSpawn.
case 3:
{
// We're not resending this menu.
resend = false;
// Send list of clients to infect.
MenuClientList(client, ZSpawnForceHandle, "ZSpawn clients title");
}
// Force ZTele.
case 4:
{
// We're not resending this menu.
resend = false;
// Send list of clients to infect.
MenuClientList(client, ZTeleForceHandle, "ZTele clients title");
}
} }
// Re-send menu if selection failed. // Re-send menu if selection failed.
if (resend) if (resend)
{ {
ZRAdminMenu(client); ZAdminMenu(client);
} }
} }

View File

@ -42,6 +42,9 @@ ZSpawnOnCommandsCreate()
{ {
// Register ZSpawn command. // Register ZSpawn command.
RegConsoleCmd(SAYHOOKS_KEYWORD_ZSPAWN, ZSpawnCommand, "Spawn into the game after joining late."); RegConsoleCmd(SAYHOOKS_KEYWORD_ZSPAWN, ZSpawnCommand, "Spawn into the game after joining late.");
// Register admin command to force ZSpawn.
RegAdminCmd("zr_zspawn_force", ZSpawnForceCommand, ADMFLAG_GENERIC, "Force ZSpawn on a client. Usage: zr_zspawn_force <client> ['0' = Spawn as human | '1' = Spawn as zombie]");
} }
/** /**
@ -162,13 +165,15 @@ ZSpawnOnRoundEnd()
* Spawns a late-joining client into the game. * Spawns a late-joining client into the game.
* *
* @param client The client index. * @param client The client index.
* @param force (Optional) True to force spawning of the client, false to follow rules.
* @param zombie (Optional) If you are forcing spawn, you must override the team here.
* @return True if successful, false otherwise. * @return True if successful, false otherwise.
*/ */
bool:ZSpawnClient(client) bool:ZSpawnClient(client, bool:force = false, bool:zombie = false)
{ {
// If zspawn is disabled, then stop. // If zspawn is disabled, then stop.
new bool:zspawn = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN]); new bool:zspawn = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN]);
if (!zspawn) if (!force && !zspawn)
{ {
TranslationPrintToChat(client, "Feature is disabled"); TranslationPrintToChat(client, "Feature is disabled");
return false; return false;
@ -177,60 +182,78 @@ bool:ZSpawnClient(client)
// If client isn't on a team, then stop. // If client isn't on a team, then stop.
if (!ZRIsClientOnTeam(client)) if (!ZRIsClientOnTeam(client))
{ {
// Tell client the command may only be used when on a team. if (!force)
TranslationPrintToChat(client, "Must be on team"); {
// Tell client the command may only be used when on a team.
TranslationPrintToChat(client, "Must be on team");
}
return false; return false;
} }
// If client is alive, then stop. // If client is alive, then stop.
if (IsPlayerAlive(client)) if (IsPlayerAlive(client))
{ {
// Tell client the command may only be used when dead. if (!force)
TranslationPrintToChat(client, "Must be dead"); {
// Tell client the command may only be used when dead.
TranslationPrintToChat(client, "Must be dead");
}
return false; return false;
} }
// Block if client has already played during this round. // Block if client has already played during this round.
if (SteamidCacheClientExists(g_hZSpawnSteamIDCache, client)) if (!force && SteamidCacheClientExists(g_hZSpawnSteamIDCache, client))
{ {
// Tell client the command may only be used when joining late. // Tell client the command may only be used when joining late.
TranslationPrintToChat(client, "ZSpawn double spawn"); TranslationPrintToChat(client, "ZSpawn double spawn");
return false; return false;
} }
// Check if zspawn override is enabled, and if so get overidden value. new bool:teamzombie;
new bool:teamoverride = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_OVERRIDE]);
new bool:teamzombie = teamoverride ? GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_ZOMBIE]) : GetConVarBool(g_hCvarsList[CVAR_RESPAWN_TEAM_ZOMBIE]);
// Block is the time limit is up. if (!force)
new bool:zspawntimelimit = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT]);
if (zspawntimelimit)
{ {
if (tZSpawn == INVALID_HANDLE) // Check if zspawn override is enabled, and if so get overidden value.
new bool:teamoverride = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_OVERRIDE]);
teamzombie = teamoverride ? GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TEAM_ZOMBIE]) : GetConVarBool(g_hCvarsList[CVAR_RESPAWN_TEAM_ZOMBIE]);
// Block is the time limit is up.
new bool:zspawntimelimit = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT]);
if (zspawntimelimit)
{ {
new zspawntimelimitzombie = GetConVarInt(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_ZOMBIE]); if (tZSpawn == INVALID_HANDLE)
switch(zspawntimelimitzombie)
{ {
case -1: new zspawntimelimitzombie = GetConVarInt(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_ZOMBIE]);
switch(zspawntimelimitzombie)
{ {
// Get timelimit case -1:
new Float:zspawntime = GetConVarFloat(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME]); {
// Get timelimit
// Tell client the timelimit for this command has expired. new Float:zspawntime = GetConVarFloat(g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME]);
TranslationPrintToChat(client, "ZSpawn timelimit", RoundToNearest(zspawntime));
return false; // Tell client the timelimit for this command has expired.
} TranslationPrintToChat(client, "ZSpawn timelimit", RoundToNearest(zspawntime));
case 0: return false;
{ }
teamzombie = false; case 0:
} {
case 1: teamzombie = false;
{ }
teamzombie = true; case 1:
{
teamzombie = true;
}
} }
} }
} }
} }
else
{
// Use the override team in the function if were forcing the spawn.
teamzombie = zombie;
}
// Tell respawn module to respawn client. // Tell respawn module to respawn client.
RespawnSpawnClient(client, teamzombie); RespawnSpawnClient(client, teamzombie);
@ -238,6 +261,60 @@ bool:ZSpawnClient(client)
return true; return true;
} }
/**
* Menu callback (zspawn_force)
* Forces ZSpawn on a client.
*
* @param menu The menu handle.
* @param action Action client is doing in menu.
* @param client The client index.
* @param slot The menu slot selected. (starting from 0)
*/
public ZSpawnForceHandle(Handle:menu_zspawn_force, MenuAction:action, client, slot)
{
// Client selected an option.
if (action == MenuAction_Select)
{
// Get the client index of the selected client.
new target = MenuGetClientIndex(menu_zspawn_force, slot);
// Get the target's name for future use.
decl String:targetname[MAX_NAME_LENGTH];
GetClientName(target, targetname, sizeof(targetname));
// Force ZSpawn on the target.
new bool:success = ZSpawnClient(target, true);
// Tell admin the outcome of the action.
if (success)
{
TranslationReplyToCommand(client, "ZSpawn command force successful", targetname);
}
else
{
TranslationReplyToCommand(client, "ZSpawn command force unsuccessful", targetname);
}
// Re-send the menu.
MenuClientList(client, ZSpawnForceHandle, "ZSpawn clients title");
}
// Client closed the menu.
if (action == MenuAction_Cancel)
{
// Client hit "Back" button.
if (slot == MenuCancel_ExitBack)
{
// Re-open admin menu.
ZAdminMenu(client);
}
}
// Client exited menu.
if (action == MenuAction_End)
{
CloseHandle(menu_zspawn_force);
}
}
/** /**
* Command callback (zspawn) * Command callback (zspawn)
* Spawn into the game after joining late. * Spawn into the game after joining late.
@ -261,6 +338,69 @@ public Action:ZSpawnCommand(client, argc)
return Plugin_Handled; return Plugin_Handled;
} }
/**
* Command callback (zr_zspawn_force)
* Force ZSpawn on a client.
*
* @param client The client index.
* @param argc Argument count.
*/
public Action:ZSpawnForceCommand(client, argc)
{
// If not enough arguments given, then stop.
if (argc < 1)
{
TranslationReplyToCommand(client, "ZSpawn command force syntax");
return Plugin_Handled;
}
decl String:target[MAX_NAME_LENGTH], String:targetname[MAX_NAME_LENGTH];
new targets[MAXPLAYERS], bool:tn_is_ml, result;
// Get targetname.
GetCmdArg(1, target, sizeof(target));
// Find a target.
result = ProcessTargetString(target, client, targets, sizeof(targets), COMMAND_FILTER_DEAD, targetname, sizeof(targetname), tn_is_ml);
// Check if there was a problem finding a client.
if (result <= 0)
{
ZRReplyToTargetError(client, result);
return Plugin_Handled;
}
// Get item to give to client.
decl String:strZombie[4];
GetCmdArg(2, strZombie, sizeof(strZombie));
// Copy value of second (optional) parameter to 'zombie'.
// It will be false if the parameter wasn't specified.
new bool:zombie = bool:StringToInt(strZombie);
// x = Client index.
for (new x = 0; x < result; x++)
{
// Give client the item.
new bool:success = ZSpawnClient(targets[x], true, zombie);
// Tell admin the outcome of the command if only 1 client was targetted.
if (result == 1)
{
if (success)
{
TranslationReplyToCommand(client, "ZSpawn command force successful", targetname);
}
else
{
TranslationReplyToCommand(client, "ZSpawn command force unsuccessful", targetname);
}
}
}
return Plugin_Handled;
}
/** /**
* Timer callback, resets handle. * Timer callback, resets handle.
* *

View File

@ -55,8 +55,11 @@ new g_iZTeleTimeLeft[MAXPLAYERS + 1];
*/ */
ZTeleOnCommandsCreate() ZTeleOnCommandsCreate()
{ {
// Register ZMenu command. // Register ZTele command.
RegConsoleCmd(SAYHOOKS_KEYWORD_ZTELE, ZTeleCommand, "Teleport back to spawn if you are stuck."); RegConsoleCmd(SAYHOOKS_KEYWORD_ZTELE, ZTeleCommand, "Teleport back to spawn if you are stuck.");
// Register admin command to force ZTele.
RegAdminCmd("zr_ztele_force", ZTeleForceCommand, ADMFLAG_GENERIC, "Force ZTele on a client. Usage: zr_ztele_force <client>");
} }
/** /**
@ -131,9 +134,11 @@ ZTeleOnClientInfected(client)
* Teleports a client back to spawn if conditions are met. * Teleports a client back to spawn if conditions are met.
* *
* @param client The client index. * @param client The client index.
* @param force (Optional) True to force teleporting of the client, false to follow rules.
* @param zombie (Optional) True to teleport instantly, false to use delay.
* @return True if teleport was successful, false otherwise. * @return True if teleport was successful, false otherwise.
*/ */
bool:ZTeleClient(client) bool:ZTeleClient(client, bool:force = false)
{ {
// If the client is dead, then stop. // If the client is dead, then stop.
if (!IsPlayerAlive(client)) if (!IsPlayerAlive(client))
@ -145,7 +150,7 @@ bool:ZTeleClient(client)
// If zombie cvar is disabled and the client is a zombie, then stop. // If zombie cvar is disabled and the client is a zombie, then stop.
new bool:ztelezombie = GetConVarBool(g_hCvarsList[CVAR_ZTELE_ZOMBIE]); new bool:ztelezombie = GetConVarBool(g_hCvarsList[CVAR_ZTELE_ZOMBIE]);
if (infected && !ztelezombie) if (!force && infected && !ztelezombie)
{ {
// Tell client they must be human to use this feature. // Tell client they must be human to use this feature.
TranslationPrintToChat(client, "Must be human"); TranslationPrintToChat(client, "Must be human");
@ -155,7 +160,7 @@ bool:ZTeleClient(client)
// If zombie has spawned, get before value, get the after value otherwise. // If zombie has spawned, get before value, get the after value otherwise.
// If the cvar is disabled and the client is a human, then stop. // If the cvar is disabled and the client is a human, then stop.
new bool:ztelehuman = g_bZombieSpawned ? GetConVarBool(g_hCvarsList[CVAR_ZTELE_HUMAN_AFTER]) : GetConVarBool(g_hCvarsList[CVAR_ZTELE_HUMAN_BEFORE]); new bool:ztelehuman = g_bZombieSpawned ? GetConVarBool(g_hCvarsList[CVAR_ZTELE_HUMAN_AFTER]) : GetConVarBool(g_hCvarsList[CVAR_ZTELE_HUMAN_BEFORE]);
if (!infected && !ztelehuman) if (!force && !infected && !ztelehuman)
{ {
// Tell client that feature is restricted at this time. // Tell client that feature is restricted at this time.
TranslationPrintToChat(client, "ZTele restricted human"); TranslationPrintToChat(client, "ZTele restricted human");
@ -164,7 +169,7 @@ bool:ZTeleClient(client)
// If the tele limit has been reached, then stop. // If the tele limit has been reached, then stop.
new ztelemax = infected ? GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_ZOMBIE]) : GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_HUMAN]); new ztelemax = infected ? GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_ZOMBIE]) : GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_HUMAN]);
if (g_iZTeleCount[client] >= ztelemax) if (!force && g_iZTeleCount[client] >= ztelemax)
{ {
// Tell client that they have already reached their limit. // Tell client that they have already reached their limit.
TranslationPrintToChat(client, "ZTele max", ztelemax); TranslationPrintToChat(client, "ZTele max", ztelemax);
@ -174,19 +179,26 @@ bool:ZTeleClient(client)
// If teleport is already in progress, then stop. // If teleport is already in progress, then stop.
if (tZTele[client] != INVALID_HANDLE) if (tZTele[client] != INVALID_HANDLE)
{ {
TranslationPrintToChat(client, "ZTele in progress"); if (!force)
{
TranslationPrintToChat(client, "ZTele in progress");
}
return false; return false;
} }
// If we are forcing, then teleport now and stop.
if (force)
{
// Teleport client to spawn.
ZTeleTeleportClient(client);
return true;
}
// Get current location. // Get current location.
GetClientAbsOrigin(client, g_vecZTeleOrigin[client]); GetClientAbsOrigin(client, g_vecZTeleOrigin[client]);
// If timer is running, kill it.
if (tZTele[client] != INVALID_HANDLE)
{
KillTimer(tZTele[client]);
}
// Set timeleft array to value of respective cvar. // Set timeleft array to value of respective cvar.
g_iZTeleTimeLeft[client] = infected ? GetConVarInt(g_hCvarsList[CVAR_ZTELE_DELAY_ZOMBIE]) : GetConVarInt(g_hCvarsList[CVAR_ZTELE_DELAY_HUMAN]); g_iZTeleTimeLeft[client] = infected ? GetConVarInt(g_hCvarsList[CVAR_ZTELE_DELAY_ZOMBIE]) : GetConVarInt(g_hCvarsList[CVAR_ZTELE_DELAY_HUMAN]);
if (g_iZTeleTimeLeft[client] > 0) if (g_iZTeleTimeLeft[client] > 0)
@ -199,12 +211,10 @@ bool:ZTeleClient(client)
} }
else else
{ {
// Reset timer handle.
tZTele[client] = INVALID_HANDLE;
// Teleport client to spawn. // Teleport client to spawn.
ZTeleTeleportClient(client); ZTeleTeleportClient(client);
// If we're forcing the ZTele, then don't increment the count or print how many teleports they have used.
// Tell client they've been teleported. // Tell client they've been teleported.
TranslationPrintCenterText(client, "ZTele countdown end", g_iZTeleCount[client], ztelemax); TranslationPrintCenterText(client, "ZTele countdown end", g_iZTeleCount[client], ztelemax);
@ -227,7 +237,116 @@ ZTeleTeleportClient(client)
} }
/** /**
* Command callback (zmenu) * Menu callback (ztele_force)
* Forces ZTele on a client.
*
* @param menu The menu handle.
* @param action Action client is doing in menu.
* @param client The client index.
* @param slot The menu slot selected. (starting from 0)
*/
public ZTeleForceHandle(Handle:menu_ztele_force, MenuAction:action, client, slot)
{
// Client selected an option.
if (action == MenuAction_Select)
{
// Get the client index of the selected client.
new target = MenuGetClientIndex(menu_ztele_force, slot);
// Get the target's name for future use.
decl String:targetname[MAX_NAME_LENGTH];
GetClientName(target, targetname, sizeof(targetname));
// Force ZSpawn on the target.
new bool:success = ZTeleClient(target, true);
// Tell admin the outcome of the action.
if (success)
{
TranslationReplyToCommand(client, "ZTele command force successful", targetname);
}
else
{
TranslationReplyToCommand(client, "ZTele command force unsuccessful", targetname);
}
// Re-send the menu.
MenuClientList(client, ZTeleForceHandle, "ZTele clients title");
}
// Client closed the menu.
if (action == MenuAction_Cancel)
{
// Client hit "Back" button.
if (slot == MenuCancel_ExitBack)
{
// Re-open admin menu.
ZAdminMenu(client);
}
}
// Client exited menu.
if (action == MenuAction_End)
{
CloseHandle(menu_ztele_force);
}
}
/**
* Command callback (zr_ztele_force)
* Force ZSpawn on a client.
*
* @param client The client index.
* @param argc Argument count.
*/
public Action:ZTeleForceCommand(client, argc)
{
// If not enough arguments given, then stop.
if (argc < 1)
{
TranslationReplyToCommand(client, "ZTele command force syntax");
return Plugin_Handled;
}
decl String:target[MAX_NAME_LENGTH], String:targetname[MAX_NAME_LENGTH];
new targets[MAXPLAYERS], bool:tn_is_ml, result;
// Get targetname.
GetCmdArg(1, target, sizeof(target));
// Find a target.
result = ProcessTargetString(target, client, targets, sizeof(targets), COMMAND_FILTER_ALIVE, targetname, sizeof(targetname), tn_is_ml);
// Check if there was a problem finding a client.
if (result <= 0)
{
ZRReplyToTargetError(client, result);
return Plugin_Handled;
}
// x = Client index.
for (new x = 0; x < result; x++)
{
// Give client the item.
new bool:success = ZTeleClient(targets[x], true);
// Tell admin the outcome of the command if only 1 client was targetted.
if (result == 1)
{
if (success)
{
TranslationReplyToCommand(client, "ZTele command force successful", targetname);
}
else
{
TranslationReplyToCommand(client, "ZTele command force unsuccessful", targetname);
}
}
}
return Plugin_Handled;
}
/**
* Command callback (ztele)
* Teleport back to spawn if you are stuck. * Teleport back to spawn if you are stuck.
* *
* @param client The client index. * @param client The client index.