10.11.2012, 18:09
use a constant / define for your max contacts
than create a stock for your dialog
and for the deletion part, you only need to move the others one place down
pawn Код:
#define MAX_CONTACTS (15)
enum mInfo
{
ContactNumber[MAX_CONTACTS], // I have now 15 variables
ContactName[30][MAX_CONTACTS], // I have now 15 string variables
};
new Mobiles[50][mInfo];
pawn Код:
stock ShowPlayerContactDialog(playerid) { // I expect that szHugeString is a global variable
for(new i = (szHugeString[0] = EOS); i != MAX_CONTACTS; i++) {
if(Mobile[PlayerInfo[playerid][pPhoneID]][ContactNumber][i] != 0) {
format(szHugeString, sizeof(szHugeString), "%s%i - %s\n", szHugeString, Mobile[PlayerInfo[playerid][pPhoneID]][ContactNumber][i], Mobile[PlayerInfo[playerid][pPhoneID][ContactName][i]);
}
}
if(szHugeString[0] == EOS) {
szHugeString = "No contacts!";
}
return ShowPlayerDialog(playerid, 9889, DIALOG_STYLE_LIST, "Contacts", szHugeString, "OK", "Delete");
}
pawn Код:
//
if(dialogid == 9889) {
if(response) return 1;
while(++listitem < MAX_CONTACTS) {
Mobiles[PlayerInfo[playerid][pPhoneID][ContactNumber][listitem - 1] = Mobiles[PlayerInfo[playerid][pPhoneID][ContactNumber][listitem];
Mobiles[PlayerInfo[playerid][pPhoneID][ContactName][listitem - 1] = Mobiles[PlayerInfo[playerid][pPhoneID][ContactName][listitem];
}
Mobiles[PlayerInfo[playerid][pPhoneID][ContactNumber][MAX_CONTACTS - 1] = 0;
Mobiles[PlayerInfo[playerid][pPhoneID][ContactName][MAX_CONTACTS - 1] = "None";
ShowPlayerContactDialog(playerid);
}
}