Moving everything one step back. -
EV007 - 22.10.2012
Alright, it's really hard to explain what I want.. Lets say two players (Id 5, and id 8 ) hit me in 1 second difference.
pawn Код:
PlayersHit++;
PlayerIDBank[PlayersHit] = playerid;
So basically,
this stores ID 5 in PlayersIDBank[1] = 5;
and ID 8 into PlayersIDBank[2] = 8;.
Everything seems good. Now I want to vanish the first player who hit me after 5seconds (ID: 5), I set a timer whenever someone hits me and it looks like this:
pawn Код:
PlayersHit++;
PlayerIDBank[PlayersHit] = playerid;
SetTimerEx("RemovePlayerID",5000,false,...);
Everything seems great ( please ignore the possible bugs in future and etc.)
So now, this is the problem. I have no idea how to remove the player ID 5 from the slot [1], maybe storing the slot id into a variable and attaching it into player id 5? Might work, but what about the slot [2]? The thing is, after I remove the first slot, the slot 2 MUST overtake slot1 place and become Slot[2]to Slot[1] = 8. I just cant think of a way to do this more efficiently OR AT LEAST DOING IT. Any help is appreciated.
NOTE: I will use multiple player id's up to 5, so I want them to move back.
Re: Moving everything one step back. -
[HK]Ryder[AN] - 22.10.2012
PlayerIDBank[1] = PlayerIDBank[2];
PlayerIDBank[2] = 0;
Re: Moving everything one step back. -
EV007 - 22.10.2012
Yeah, but how can I make that correct loop and switch everything one step back if theres 5slots stored?
Re: Moving everything one step back. -
EV007 - 22.10.2012
I can, but I don't like using IF(... a million times and setting something, i've came up with this code:
the idSlot[playerid] is the banked slot of his id
pawn Код:
for(new i=PlayersHit; i--;)
{
if(PlayerIDBank[i] == -1)
{
ForEach(a,MAX_PLAYERS);
if(i < idSlot[a])
{
PlayerIDBank[idSlot[a]] = -1;
PlayerIDBank[i] = a;
idSlot[a] = i;
}
}
}
Could this work?
EDIT: Should I add PlayersHit--; into the loop where changing is happening/
Re: Moving everything one step back. -
EV007 - 25.10.2012
removed
Re: Moving everything one step back. -
Finn - 25.10.2012
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;
}
Re: Moving everything one step back. -
EV007 - 25.10.2012
Well It's almost the same, I can't see why mine doesn't work. It bugs up after few tries..