Moving everything one step back.
#6

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.

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;
}
How to view (for updating the text draw) the issuer list:
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;
}
How to remove a specific ID from the issuer list:
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;
}
Reply


Messages In This Thread
Moving everything one step back. - by EV007 - 22.10.2012, 15:44
Re: Moving everything one step back. - by [HK]Ryder[AN] - 22.10.2012, 15:48
Re: Moving everything one step back. - by EV007 - 22.10.2012, 16:09
Re: Moving everything one step back. - by EV007 - 22.10.2012, 16:16
Re: Moving everything one step back. - by EV007 - 25.10.2012, 16:55
Re: Moving everything one step back. - by Finn - 25.10.2012, 17:31
Re: Moving everything one step back. - by EV007 - 25.10.2012, 18:42

Forum Jump:


Users browsing this thread: 4 Guest(s)