sm-zombiereloaded-3/src/zr/zombiereloaded.inc
richard 6f032b79b8 Improved class system with support for multipliers. Minior fixes, see details.
Made class attribute multipliers.
Made admin menus for adjusting class attribute multipliers.
Made console command for setting class attribute multipliers.
Fixed health regen amount class attribute not validated.
Fixed health regen not stopping after surviving a round as a zombie.
Improved ZRIsClientAdmin to support admin flags (optional).
Changed permission flag on admin commands to match action type. Like only admins with config access should be able to do ZR configuration.
Changed log formatting to match style in SourceMod. Removed "-" and ":". The result will be "... [plugin.smx] [mod] [event] message".
2009-06-18 02:09:55 +02:00

288 lines
7.9 KiB
SourcePawn

/*
* ============================================================================
*
* Zombie:Reloaded
*
* File: zombiereloaded.inc
* Type: Core
* Description: General plugin functions and defines.
*
* Copyright (C) 2009 Greyscale, Richard Helgeby
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================================
*/
/**
* Index of server console.
*/
#define ZR_CONSOLE_INDEX 0
/**
* @section Conversion factors.
*/
#define CONVERSION_UNITS_TO_FEET 16.000
#define CONVERSION_FEET_TO_UNITS 0.0625
/**
* @endsection
*/
/**
* Global variable set to true when the first zombie(s) is/are spawned.
*/
new bool:g_bZombieSpawned;
/**
* 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;
}
/**
* 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.
*/
stock ZRCreateEligibleClientList(&Handle:arrayEligibleClients, bool:team = false, bool:alive = false, bool:human = false)
{
// 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.
if (human && !InfectIsClientHuman(x))
{
continue;
}
// Add eligible client to array.
PushArrayCell(arrayEligibleClients, x);
}
return GetArraySize(arrayEligibleClients);
}
/**
* Check if a client index is a valid player.
*
* @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:ZRIsClientValid(client, bool:console = false)
{
// If index is greater than max number of clients, then return false.
if (client > MaxClients)
{
return false;
}
// If console is true, return if client is >= 0, if not, then return client > 0.
return console ? (client >= 0) : (client > 0);
}
/**
* 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)
{
// Return true if index is equal to console's index.
return (index == ZR_CONSOLE_INDEX);
}
/**
* Count clients on each team.
*
* @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.
*/
stock bool:ZRCountValidClients(&zombiecount = 0, &humancount = 0, bool:alive = true, bool:ignorezombiespawned = false)
{
// If zombie hasn't spawned and were not only counting humans, then stop.
if (!g_bZombieSpawned && !ignorezombiespawned)
{
return false;
}
// 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 (!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.
if (InfectIsClientInfected(x))
{
zombiecount++;
}
// If player is a human, then increment human variable.
else if (InfectIsClientHuman(x))
{
humancount++;
}
}
return true;
}
/**
* 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.
*/
stock bool:ZRIsClientOnTeam(client, team = -1)
{
// If index is invalid, then stop.
if (!ZRIsClientValid(client))
{
return false;
}
// Get client team.
new clientteam = GetClientTeam(client);
if (team == -1)
{
return (clientteam == CS_TEAM_T || clientteam == CS_TEAM_CT);
}
return (clientteam == team);
}
/**
* Check if there are clients on a team.
*
* @param team (Optional) Team to check if there are clients on.
*/
stock bool:ZRTeamHasClients(team = -1)
{
// 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.
return bool:GetTeamClientCount(team);
}
/**
* Returns whether a player is a generic admin or not.
*
* @param client The client index.
* @param flag Optional. Flag to check. Default is generic admin flag.
* @return True if generic admin, false otherwise.
*/
stock bool:ZRIsClientAdmin(client, AdminFlag:flag = Admin_Generic)
{
// If index is invalid, then stop.
if (!ZRIsClientValid(client))
{
return false;
}
// If client doesn't have the Admin_Generic flag, then stop.
if (!GetAdminFlag(GetUserAdmin(client), flag))
{
return false;
}
// Client is an admin.
return true;
}
/**
* Adds support for printing strings longer than 1 KB to console. Max 4 KB.
*
* Note: 1024 characters is max for the console, including newline and null
* terminator.
*
* @param client The client index.
* @param text Long text to write.
* @param splitsize Optional. Sets the split size. 1022 is default.
* Allowed range: 128 to 1022.
*/
stock ZRPrintToConsoleLong(client, const String:text[], splitsize = 1022)
{
// Validate split size.
if (splitsize < 128 || splitsize > 1022)
{
return;
}
decl String:partbuffer[splitsize];
new pos;
new cellswritten = 1; // Initialize for the loop.
while (cellswritten)
{
cellswritten = strcopy(partbuffer, splitsize, text[pos]);
(client > 0) ? PrintToConsole(client, partbuffer) : PrintToServer(partbuffer);
pos += cellswritten;
}
}