25.10.2012, 17:31
I don't know if this helps but I made something similiar for something else and edited the code a bit to fit for this purpose, not sure if it works as I don't have time (and testers) to go in a test server to test.
How to view (for updating the text draw) the issuer list:
How to remove a specific ID from the issuer list:
pawn Код:
#define MAX_ISSUERS 5
new issuerCount[MAX_PLAYERS], issuerIDs[MAX_PLAYERS][MAX_ISSUERS];
public OnPlayerConnect(playerid)
{
// Reset all arrays
for(new i; i < MAX_ISSUERS; i++)
{
issuerIDs[playerid][i] = INVALID_PLAYER_ID;
}
issuerCount[playerid] = 0;
return 1;
}
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
{
if(issuerid != INVALID_PLAYER_ID)
{ // Player just got damaged by someone
if(issuerCount[playerid] < MAX_ISSUERS)
{ // The list isn't full yet.
issuerIDs[playerid][issuerCount[playerid]] = issuerid;
issuerCount[playerid]++;
}
else
{ // The list is full, gotta update the list and drop the oldest one out of it.
for(new i; i < (MAX_ISSUERS - 1); i++)
{ // (MAX_ISSUERS - 1) so the array won't overflow.
issuerIDs[playerid][i] = issuerIDs[playerid][i + 1];
}
issuerIDs[playerid][(MAX_ISSUERS - 1)] = issuerid; // Set the last slot for the new issuer
}
}
return 1;
}
pawn Код:
stock ListIssuers(playerid)
{
for(new i; i < issuerCount[playerid]; i++)
{
printf("%d's issuer in slot %d: Player %d.", playerid, i, issuerIDs[playerid][i]);
}
return 1;
}
pawn Код:
stock RemoveIssuer(playerid, issuerid)
{
for(new i; i < issuerCount[playerid]; i++)
{
if(issuerIDs[playerid][i] == issuerid)
{ // The issuer is in the list.
RemoveIssuerSlot(playerid, i); // Clear the slot.
return 1;
}
}
return 0; // There wasn't such issuer in the list
}
stock RemoveIssuerSlot(playerid, slot)
{ // This function requires a valid slot ALWAYS
issuerCount[playerid]--;
while(slot < issuerCount[playerid])
{
issuerIDs[playerid][slot] = issuerIDs[playerid][slot + 1];
slot++;
}
return 1;
}