diff --git a/src/zombiereloaded.sp b/src/zombiereloaded.sp index e526886..d0becc7 100644 --- a/src/zombiereloaded.sp +++ b/src/zombiereloaded.sp @@ -26,6 +26,7 @@ #include "zr/log" #include "zr/cvars" #include "zr/config" +#include "zr/serial" #include "zr/translation" #include "zr/sayhooks" #include "zr/tools" @@ -169,6 +170,7 @@ public OnLibraryAdded(const String:name[]) public OnMapStart() { // Forward event to modules. + SerialOnMapStart(); RoundEndOnMapStart(); InfectOnMapStart(); SEffectsOnMapStart(); diff --git a/src/zr/serial.inc b/src/zr/serial.inc new file mode 100644 index 0000000..9e347ef --- /dev/null +++ b/src/zr/serial.inc @@ -0,0 +1,85 @@ +/* + * ============================================================================ + * + * Zombie:Reloaded + * + * File: serial.inc + * Type: Core + * Description: Client serial number tracking API. + * + * ============================================================================ + */ + +/** + * Maximum length of a client's serial number. + */ +#define SERIAL_MAX_LENGTH 8 + +/** + * Array to store client serial numbers. + */ +new Handle:arraySerial = INVALID_HANDLE; + +/** + * Map is starting. +*/ +SerialOnMapStart() +{ + // If array exists, destroy before recreating. + if (arraySerial != INVALID_HANDLE) + { + CloseHandle(arraySerial); + } + + // Create array. + arraySerial = CreateArray(); +} + +/** + * Add client serial number to global array. + * + * @param client The client index. + * @return True if the client was added successfully, false if the client already exists. + */ +bool:SerialAddClient(client) +{ + // Check if client is already added. + new bool:exists = SerialClientExists(client); + if (exists) + { + return false; + } + + // Get client's serial number. + new serial = GetClientSerial(client); + + // Push serial number into the global array. + PushArrayCell(arraySerial, serial); + + // Client added successfully. + return true; +} + +/** + * Check if a client has been added to the global array. + * + * @param client The client index. + * @return True if the client exists, false otherwise. + */ +bool:SerialClientExists(client) +{ + // Get client's serial number. + new serial = GetClientSerial(client); + + // Return true if value was found, false otherwise. + return (FindValueInArray(arraySerial, serial) != -1); +} + +/** + * Reset serial number array. + */ +SerialReset() +{ + // Clear array. + ClearArray(arraySerial); +} \ No newline at end of file diff --git a/src/zr/zspawn.inc b/src/zr/zspawn.inc index a3e2e46..0d13abd 100644 --- a/src/zr/zspawn.inc +++ b/src/zr/zspawn.inc @@ -15,11 +15,6 @@ */ new Handle:tZSpawn = INVALID_HANDLE; -/** - * Array to block zspawn for a unique client serial number. - */ -new bool:g_bZSpawnBlock[MAXPLAYERS + 1]; - /** * Map is starting. */ @@ -42,11 +37,8 @@ ZSpawnOnClientDisconnect(client) return; } - // Get client's unique serial number. - new serial = GetClientSerial(client); - - // Block zspawn. - g_bZSpawnBlock[serial] = true; + // Add client serial to global array. + SerialAddClient(client); } /** @@ -56,11 +48,8 @@ ZSpawnOnClientDisconnect(client) */ ZSpawnOnClientDeath(client) { - // Get client's unique serial number. - new serial = GetClientSerial(client); - - // Block zspawn. - g_bZSpawnBlock[serial] = true; + // Add client serial to global array. + SerialAddClient(client); } /** @@ -68,13 +57,8 @@ ZSpawnOnClientDeath(client) */ ZSpawnOnRoundStart() { - // Disable flag that blocks zspawn for all clients. - // x = client index. - for (new x = 1; x <= MaxClients; x++) - { - // Unblock zspawn. - g_bZSpawnBlock[x] = false; - } + // Reset serial number array. + SerialReset(); // If zspawn timer is running, then kill it. if (tZSpawn != INVALID_HANDLE) @@ -169,8 +153,7 @@ bool:ZSpawnClient(client) } // Block if client has already played during this round. - new serial = GetClientSerial(client); - if (g_bZSpawnBlock[serial]) + if (SerialClientExists(client)) { // Tell client the command may only be used when joining late. ZR_PrintToChat(client, "ZSpawn double spawn");