ID System v1.00
What is this?
As coders, you might have ran into a few problems in the past with the current ID system, which works, but to an extent.
Ex. You have 3 players in a server. Each player assigned a specific ID based on when they joined.
Player 1: ID 1
Player 2: ID 2
Player 3: ID 3
Now let's say Player 2 disconnects, and you're left with the original first and third player. Their ID's will stay the same, but there will only be 2 players, so:
Player 1: ID 1
Player 2: ID 3
See the problem? Now, with this new system, I'm not sure exactly what YOU might use it for, but for me, it was necessary when flipping through the players in order.
Ex: Round 1, player 1 received 150 HP. Round 2, player 2 received 150 HP, etc.
Well if I'm flipping through their ID's, and I get to ID 2 (when player #2 disconnected and there IS no player in that slot, it creates ID problems, which are unneeded)
Why not just skip that ID if the player doesn't exist?
Basically, I want a fair system. With the current system, if a new player joins, they would take the second slot, even though the first and third person were the original two. Which would basically give Player 3, which is ID 2 (now that they've taken the ID 2 because it's available), 150 HP, though they haven't waited as long as ID 3 has.
How EXACTLY does it work?
This system fixes the problem by reassigning ID's (not literally). It creates a new variable to hold new ID's.
Example of the system:
Player 1: ID 1
Player 2: ID 2
Player 3: ID 3
Player 2 disconnects, ID's are now:
Player 1: ID 1
Player 3: ID 2
Converting player 3 to player 2 (technically, because we are switching his ID)
Player 2 reconnects:
Player 1: ID 1
Player 3: ID 2 (Technically player 2 now)
Player 2: ID 3 (Now officially player 3)
I apologize if any of this is confusing.
Code Preview
PHP Code:
/* Bullet Proof ID System by Shadow (aka GXLZPGX) */
#include <amxmodx>
#define PLUGIN "Bullet Proof ID System"
#define AUTHOR "Shadow"
#define VERSION "1.0.0"
new cPlayers;
new aID;
new eID[33];
new pID[33];
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
//deathmsg
register_message( get_user_msgid( "DeathMsg" ) , "pDeathMsg" );
//check id
register_clcmd( "say /id", "pCheckID" )
}
public pCheckID(id)
{
new menu = menu_create("\r[ID List] \wPlayers", "menu_handler");
new iPlayers[32], iNum, tempid;
new szName[32], szTempid[10];
get_players(iPlayers, iNum);
for( new i = 0; i < iNum; i++ )
{
tempid = iPlayers[i];
get_user_name( tempid, szName, charsmax(szName) );
num_to_str( tempid, szTempid, charsmax(szTempid) );
new szMenuItem[64];
formatex( szMenuItem, charsmax(szMenuItem), "%s \rID: %i", szName, eID[tempid] )
menu_additem( menu, szMenuItem, eID[tempid], 0 );
}
menu_display(id, menu, 0);
}
public menu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], szName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data,charsmax(data), szName,charsmax(szName), callback);
new tempid = str_to_num(data);
if( is_user_alive(tempid) )
{
pCheckID(id)
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public client_putinserver(id)
{
aID++;
pID[aID] = id
eID[id] = aID;
cPlayers++;
}
public client_disconnect(id)
{
set_task( 0.1, "pNewIDs" )
cPlayers--;
}
public pNewIDs()
{
new iPlayer[32], iNum, nID;
get_players( iPlayer, iNum )
aID = 0;
for( new i = 0; i < iNum; i++ )
{
nID = iPlayer[i];
aID++
pID[aID] = nID;
eID[nID] = aID;
}
}