Created serial number api, put client serials in adt array instead of 64-slot array.
This commit is contained in:
parent
0ca296731b
commit
77fd4b00a8
@ -26,6 +26,7 @@
|
|||||||
#include "zr/log"
|
#include "zr/log"
|
||||||
#include "zr/cvars"
|
#include "zr/cvars"
|
||||||
#include "zr/config"
|
#include "zr/config"
|
||||||
|
#include "zr/serial"
|
||||||
#include "zr/translation"
|
#include "zr/translation"
|
||||||
#include "zr/sayhooks"
|
#include "zr/sayhooks"
|
||||||
#include "zr/tools"
|
#include "zr/tools"
|
||||||
@ -169,6 +170,7 @@ public OnLibraryAdded(const String:name[])
|
|||||||
public OnMapStart()
|
public OnMapStart()
|
||||||
{
|
{
|
||||||
// Forward event to modules.
|
// Forward event to modules.
|
||||||
|
SerialOnMapStart();
|
||||||
RoundEndOnMapStart();
|
RoundEndOnMapStart();
|
||||||
InfectOnMapStart();
|
InfectOnMapStart();
|
||||||
SEffectsOnMapStart();
|
SEffectsOnMapStart();
|
||||||
|
85
src/zr/serial.inc
Normal file
85
src/zr/serial.inc
Normal file
@ -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);
|
||||||
|
}
|
@ -15,11 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
new Handle:tZSpawn = INVALID_HANDLE;
|
new Handle:tZSpawn = INVALID_HANDLE;
|
||||||
|
|
||||||
/**
|
|
||||||
* Array to block zspawn for a unique client serial number.
|
|
||||||
*/
|
|
||||||
new bool:g_bZSpawnBlock[MAXPLAYERS + 1];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map is starting.
|
* Map is starting.
|
||||||
*/
|
*/
|
||||||
@ -42,11 +37,8 @@ ZSpawnOnClientDisconnect(client)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get client's unique serial number.
|
// Add client serial to global array.
|
||||||
new serial = GetClientSerial(client);
|
SerialAddClient(client);
|
||||||
|
|
||||||
// Block zspawn.
|
|
||||||
g_bZSpawnBlock[serial] = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,11 +48,8 @@ ZSpawnOnClientDisconnect(client)
|
|||||||
*/
|
*/
|
||||||
ZSpawnOnClientDeath(client)
|
ZSpawnOnClientDeath(client)
|
||||||
{
|
{
|
||||||
// Get client's unique serial number.
|
// Add client serial to global array.
|
||||||
new serial = GetClientSerial(client);
|
SerialAddClient(client);
|
||||||
|
|
||||||
// Block zspawn.
|
|
||||||
g_bZSpawnBlock[serial] = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,13 +57,8 @@ ZSpawnOnClientDeath(client)
|
|||||||
*/
|
*/
|
||||||
ZSpawnOnRoundStart()
|
ZSpawnOnRoundStart()
|
||||||
{
|
{
|
||||||
// Disable flag that blocks zspawn for all clients.
|
// Reset serial number array.
|
||||||
// x = client index.
|
SerialReset();
|
||||||
for (new x = 1; x <= MaxClients; x++)
|
|
||||||
{
|
|
||||||
// Unblock zspawn.
|
|
||||||
g_bZSpawnBlock[x] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If zspawn timer is running, then kill it.
|
// If zspawn timer is running, then kill it.
|
||||||
if (tZSpawn != INVALID_HANDLE)
|
if (tZSpawn != INVALID_HANDLE)
|
||||||
@ -169,8 +153,7 @@ bool:ZSpawnClient(client)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Block if client has already played during this round.
|
// Block if client has already played during this round.
|
||||||
new serial = GetClientSerial(client);
|
if (SerialClientExists(client))
|
||||||
if (g_bZSpawnBlock[serial])
|
|
||||||
{
|
{
|
||||||
// Tell client the command may only be used when joining late.
|
// Tell client the command may only be used when joining late.
|
||||||
ZR_PrintToChat(client, "ZSpawn double spawn");
|
ZR_PrintToChat(client, "ZSpawn double spawn");
|
||||||
|
Loading…
Reference in New Issue
Block a user