2009-04-22 04:53:19 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2008-10-04 22:59:11 +02:00
|
|
|
* Zombie:Reloaded
|
2009-04-22 04:53:19 +02:00
|
|
|
*
|
2009-05-06 02:28:09 +02:00
|
|
|
* File: zombiereloaded.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: General plugin functions and defines.
|
2009-04-22 04:53:19 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
/**
|
|
|
|
* Index of server console.
|
|
|
|
*/
|
|
|
|
#define ZR_CONSOLE_INDEX 0
|
|
|
|
|
2009-05-05 06:56:34 +02:00
|
|
|
/**
|
|
|
|
* @section Conversion factors.
|
|
|
|
*/
|
|
|
|
#define CONVERSION_UNITS_TO_FEET 16.000
|
|
|
|
#define CONVERSION_FEET_TO_UNITS 0.0625
|
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
2009-04-17 12:16:44 +02:00
|
|
|
/**
|
|
|
|
* Global variable set to true when the first zombie(s) is/are spawned.
|
|
|
|
*/
|
|
|
|
new bool:g_bZombieSpawned;
|
|
|
|
|
2009-05-05 06:56:34 +02:00
|
|
|
/**
|
|
|
|
* Function to convert numbers to defined units.
|
|
|
|
*
|
|
|
|
* @param number The number to convert.
|
|
|
|
* @param conversion The conversion factor to multiply by. (See defines above)
|
|
|
|
* @return The converted number.
|
|
|
|
*/
|
|
|
|
Float:ZRConvertUnitsFloat(Float:number, Float:conversion)
|
|
|
|
{
|
|
|
|
return number / conversion;
|
|
|
|
}
|
|
|
|
|
2009-04-22 04:53:19 +02:00
|
|
|
/**
|
|
|
|
* Create an array populated with eligible clients to be zombie.
|
|
|
|
*
|
|
|
|
* @param arrayEligibleClients The handle of the array, don't forget to call CloseHandle
|
|
|
|
* on it when finished!
|
|
|
|
* @param immunity True to ignore clients immune from mother infect, false to count them.
|
|
|
|
*/
|
2009-05-14 09:32:01 +02:00
|
|
|
stock ZRCreateEligibleClientList(&Handle:arrayEligibleClients, bool:team = false, bool:alive = false, bool:human = false)
|
2009-04-22 04:53:19 +02:00
|
|
|
{
|
|
|
|
// Create array.
|
|
|
|
arrayEligibleClients = CreateArray();
|
|
|
|
|
|
|
|
// Populate list with eligible clients.
|
|
|
|
// x = client index.
|
|
|
|
for (new x = 1; x <= MaxClients; x++)
|
|
|
|
{
|
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If client isn't on a team, then stop.
|
|
|
|
if (team && !ZRIsClientOnTeam(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If client is dead, then stop.
|
|
|
|
if (alive && !IsPlayerAlive(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If client is already zombie (via admin), then stop.
|
2009-04-24 05:02:19 +02:00
|
|
|
if (human && !InfectIsClientHuman(x))
|
2009-04-22 04:53:19 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add eligible client to array.
|
|
|
|
PushArrayCell(arrayEligibleClients, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetArraySize(arrayEligibleClients);
|
|
|
|
}
|
|
|
|
|
2009-04-17 12:16:44 +02:00
|
|
|
/**
|
2009-04-18 01:44:41 +02:00
|
|
|
* Check if a client index is a valid player.
|
2009-04-17 12:16:44 +02:00
|
|
|
*
|
|
|
|
* @param client The client index.
|
2009-04-18 01:44:41 +02:00
|
|
|
* @param console True to include console (index 0), false if not.
|
|
|
|
* @return True if client is valid, false otherwise.
|
|
|
|
*/
|
2009-05-14 09:32:01 +02:00
|
|
|
stock bool:ZRIsClientValid(client, bool:console = false)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-18 01:44:41 +02:00
|
|
|
// If index is greater than max number of clients, then return false.
|
|
|
|
if (client > MaxClients)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-18 01:44:41 +02:00
|
|
|
return false;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 01:44:41 +02:00
|
|
|
// If console is true, return if client is >= 0, if not, then return client > 0.
|
|
|
|
return console ? (client >= 0) : (client > 0);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
/**
|
|
|
|
* Check if a given index is console.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param console True to include console (index 0), false if not.
|
|
|
|
* @return True if client is valid, false otherwise.
|
|
|
|
*/
|
|
|
|
stock bool:ZRIsConsole(index)
|
|
|
|
{
|
2009-05-30 04:17:01 +02:00
|
|
|
// Return true if index is equal to console's index.
|
2009-05-14 09:32:01 +02:00
|
|
|
return (index == ZR_CONSOLE_INDEX);
|
|
|
|
}
|
|
|
|
|
2009-04-17 12:16:44 +02:00
|
|
|
/**
|
2009-04-18 01:44:41 +02:00
|
|
|
* Count clients on each team.
|
2009-04-17 12:16:44 +02:00
|
|
|
*
|
2009-04-18 01:44:41 +02:00
|
|
|
* @param zombies This is set to the number of clients that are zombies.
|
|
|
|
* @param humans This is set to the number of clients that are humans.
|
|
|
|
* @param alive If true it will only count live players, false will count alive and dead.
|
|
|
|
* @return True if successful (zombie has spawned), false otherwise.
|
|
|
|
*/
|
2009-05-14 09:32:01 +02:00
|
|
|
stock bool:ZRCountValidClients(&zombiecount = 0, &humancount = 0, bool:alive = true, bool:ignorezombiespawned = false)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-22 04:53:19 +02:00
|
|
|
// If zombie hasn't spawned and were not only counting humans, then stop.
|
|
|
|
if (!g_bZombieSpawned && !ignorezombiespawned)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-18 01:44:41 +02:00
|
|
|
return false;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 01:44:41 +02:00
|
|
|
// x = client index.
|
|
|
|
for (new x = 1; x <= MaxClients; x++)
|
2008-10-08 16:05:34 +02:00
|
|
|
{
|
2009-04-18 01:44:41 +02:00
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If client isn't on a team, then stop.
|
|
|
|
if (!ZRIsClientOnTeam(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If player must be alive, and player is dead, then stop.
|
|
|
|
if (alive && !IsPlayerAlive(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If player is a zombie, then increment zombie variable.
|
2009-04-24 05:02:19 +02:00
|
|
|
if (InfectIsClientInfected(x))
|
2009-04-18 01:44:41 +02:00
|
|
|
{
|
|
|
|
zombiecount++;
|
|
|
|
}
|
|
|
|
// If player is a human, then increment human variable.
|
2009-04-24 05:02:19 +02:00
|
|
|
else if (InfectIsClientHuman(x))
|
2009-04-18 01:44:41 +02:00
|
|
|
{
|
|
|
|
humancount++;
|
|
|
|
}
|
2008-10-08 16:05:34 +02:00
|
|
|
}
|
2009-04-15 03:36:19 +02:00
|
|
|
|
2009-04-18 01:44:41 +02:00
|
|
|
return true;
|
2008-10-08 16:05:34 +02:00
|
|
|
}
|
2009-04-15 03:24:02 +02:00
|
|
|
|
2009-04-16 22:21:32 +02:00
|
|
|
/**
|
|
|
|
* Check if a client index is on a team.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param team Team to check if player is on, -1 to check both.
|
|
|
|
* @return True if client is on a team, false otherwise.
|
|
|
|
*/
|
2009-05-14 09:32:01 +02:00
|
|
|
stock bool:ZRIsClientOnTeam(client, team = -1)
|
2009-04-16 22:21:32 +02:00
|
|
|
{
|
|
|
|
// If index is invalid, then stop.
|
2009-04-24 05:02:19 +02:00
|
|
|
if (!ZRIsClientValid(client))
|
2009-04-16 22:21:32 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get client team.
|
|
|
|
new clientteam = GetClientTeam(client);
|
|
|
|
|
|
|
|
if (team == -1)
|
|
|
|
{
|
|
|
|
return (clientteam == CS_TEAM_T || clientteam == CS_TEAM_CT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (clientteam == team);
|
|
|
|
}
|
|
|
|
|
2009-04-17 12:16:44 +02:00
|
|
|
/**
|
|
|
|
* Check if there are clients on a team.
|
|
|
|
*
|
|
|
|
* @param team (Optional) Team to check if there are clients on.
|
|
|
|
*/
|
2009-05-14 09:32:01 +02:00
|
|
|
stock bool:ZRTeamHasClients(team = -1)
|
2009-04-17 12:16:44 +02:00
|
|
|
{
|
|
|
|
// If team is
|
|
|
|
if (team == -1)
|
|
|
|
{
|
|
|
|
// Return true if both teams have at least 1 client.
|
|
|
|
return (GetTeamClientCount(CS_TEAM_T) && GetTeamClientCount(CS_TEAM_CT));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if given team has at least 1 client.
|
2009-04-22 04:53:19 +02:00
|
|
|
return bool:GetTeamClientCount(team);
|
2009-04-17 12:16:44 +02:00
|
|
|
}
|
|
|
|
|
2009-04-15 03:24:02 +02:00
|
|
|
/**
|
|
|
|
* Returns whether a player is a generic admin or not.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @return True if generic admin, false otherwise.
|
|
|
|
*/
|
2009-05-14 09:32:01 +02:00
|
|
|
stock bool:ZRIsClientAdmin(client)
|
2009-04-15 03:24:02 +02:00
|
|
|
{
|
2009-04-17 12:20:01 +02:00
|
|
|
// If index is invalid, then stop.
|
2009-04-24 05:02:19 +02:00
|
|
|
if (!ZRIsClientValid(client))
|
2009-04-15 03:24:02 +02:00
|
|
|
{
|
2009-04-17 12:20:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// If client doesn't have the Admin_Generic flag, then stop.
|
|
|
|
if (!GetAdminFlag(GetUserAdmin(client), Admin_Generic))
|
|
|
|
{
|
|
|
|
return false;
|
2009-04-15 03:24:02 +02:00
|
|
|
}
|
2009-04-15 03:36:19 +02:00
|
|
|
|
2009-04-17 12:20:01 +02:00
|
|
|
// Client is an admin.
|
|
|
|
return true;
|
2009-04-15 03:24:02 +02:00
|
|
|
}
|