From 9ddf5504ff9ea6daa2b8b118b22844df7cedc86b Mon Sep 17 00:00:00 2001 From: Michael McKoy Date: Thu, 26 Jul 2007 23:31:58 +0000 Subject: [PATCH] Added FindTarget stock. --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401183 --- plugins/include/helpers.inc | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/plugins/include/helpers.inc b/plugins/include/helpers.inc index 6b1eec15..c88a8341 100644 --- a/plugins/include/helpers.inc +++ b/plugins/include/helpers.inc @@ -178,3 +178,42 @@ stock SearchForClients(const String:pattern[], clients[], maxClients) return total; } + +/** + * Wraps SearchForClients and handles producing error messages for + * bad targets. + * + * @param client Client who issued command + * @param target Client's target argument + * @param nobots Optional. Set to true if bots should NOT be targetted + * @param immunity Optional. Set to false to ignore target immunity. + * @return Index of target client, or -1 on error. + */ +stock FindTarget(client, const String:target[], bool:nobots = false, bool:immunity = true) +{ + new clients[2]; + new numClients = SearchForClients(target, clients, 2); + + if (numClients == 0) + { + ReplyToCommand(client, "[SM] %t", "No matching client"); + return -1; + } + else if (numClients > 1) + { + ReplyToCommand(client, "[SM] %t", "More than one client matches", target); + return -1; + } + else if (immunity && !CanUserTarget(client, clients[0])) + { + ReplyToCommand(client, "[SM] %t", "Unable to target"); + return -1; + } + else if (nobots && IsFakeClient(clients[0])) + { + ReplyToCommand(client, "[SM] %t", "Cannot target bot"); + return -1; + } + + return clients[0]; +}