Mobile system
#1

Hello

I am trying to do a mobile system with call register and contact saving.

My first question is, when i have 5 contacts(Contact1, Contact2, Contact3, Contact4, Contact5) and i watch them by Dialog, and i want to DELETE contact number three(Contact3) then i want that Contact4 will be the missing Contact3, and Contact5 will be the Contact4. I hope you did understand.

My second question is, how i do the code which have to show Contact1, Contact2, Contact3, Contact4, Contact5 stats to me, IF they aren`t "0"(0, if there isn`t writed anything).


Smart ones over here and help me to think:P

Thanks,
Larry
Reply
#2

if u r using dialogs to enter the contact, then u can use format() for the stats
Reply
#3

I have made similar to the first that I should rename race4 to race3 because I deleted the 3rd race.
What do you use for saving them?
Reply
#4

I use mysql, but can you give me examples how i show them by dialog?
Reply
#5

Well, I just gave you an example of how to do it. It depends on if you are using it as a table or field.
pawn Код:
// An example of how I used it
    // Deleting..
    format( Query, sizeof( Query ), "DROP TABLE `CONTACT%d`", contact_id ); // It is supposed by a command or dialog (read it from there)
    db_free_result( db_query( Database, Query ) );
   
    for( new x = 0; x < Loaded_Contacts; x++ )
    {
        if( Loaded_Contacts == 1 ) break;
        if( Loaded_Contacts == Is_Last_Contact ) break; // Is_Last_Contact = number of rows from a db_query or what MySQL uses
        // Renaming `CONTACTS`
        format( Query, sizeof( Query ), "SELECT * FROM `MOBILES` WHERE `CONTACT` = '%d'", x );
        Result = db_query( Database, Query );
        if( db_num_rows( Result ) )
        {
            print( "Results were found for loading contacts from database! Skipping.." );
            continue;
        }
        else
        {
            print( "No results were found from database! Updating.." );
            format( Query, sizeof( Query ), "UPDATE `MOBILES` SET CONTACT = '%d' WHERE `CONTACT` = '%d'", x, x + 1 );
            db_free_result( db_query( Database, Query ) );
            format( Query, sizeof( Query ), "ALTER TABLE `CONTACT%d` RENAME TO `CONTACT%d`", x + 1, x );
            db_free_result( db_query( Database, Query ) );
        }
    }
Reply
#6

Hmm, and if i use it as field then i change these Query`s a little bit, right?
Also there is a way to load stuff from mysql to enum-s, and then i can change enum's and later update database?

So i can do like this?

Код:
enum mInfo
{
     ContactNumber[15], // I have now 15 variables 
     ContactName[30][15], // I have now 15 string variables
};
new Mobiles[50][mInfo];
Thats the way i show dialog.

Код:
	szHugeString[0] = '\0';
 	for(new i = 0; i < 15; i++)
 	{
 	        if(Mobile[PlayerInfo[playerid][pPhoneID]][ContactNumber][i] != 0)
		{
        	     format(stri, sizeof(stri), "%i - %s\n", Mobile[PlayerInfo[playerid][pPhoneID]][ContactNumber][i], Mobile[PlayerInfo[playerid][pPhoneID][ContactName][i]);
		}
        strcat(szHugeString, stri);
 	}
 	ShowPlayerDialog(playerid, 9889, DIALOG_STYLE_LIST, "Contacts", szHugeString, "OK", "Delete");
DELETING PART:

Код:
if(dialogid == 9889)
{
     if(response) return 1;
     else
     {
          Mobiles[PlayerInfo[playerid][pPhoneID][ContactNumber][listitem] = 0;
          Mobiles[PlayerInfo[playerid][pPhoneID][ContactName][listitem] = "None";

	  szHugeString[0] = '\0';
 	  for(new i = 0; i < 15; i++)
 	  {
 	        if(Mobile[PlayerInfo[playerid][pPhoneID]][ContactNumber][i] != 0)
		{
        	     format(stri, sizeof(stri), "%i - %s\n", Mobile[PlayerInfo[playerid][pPhoneID]][ContactNumber][i], Mobile[PlayerInfo[playerid][pPhoneID][ContactName][i]);
		}
             strcat(szHugeString, stri);
 	     }
 	 ShowPlayerDialog(playerid, 9889, DIALOG_STYLE_LIST, "Contacts", szHugeString, "OK", "Delete");
        }
}
What do you think? Is it good way aswell?
Reply
#7

It depends on your decision, if the way you made works then it is not needed to change anything.
I just gave you an example, because I use something close to yours about removing races. I used tables for each race to store the checkpoints, etc.

But as I said, it's up to you!
Reply
#8

Okay thank you very much, i got good information and now i start with it.
Reply
#9

But deleting contact, in my way(with enum's and stuff), for example i delete Contact3, then how i replace Contact3 with Contact4, Contact 4 with Contact5 etc?

You saw my code few posts before :P
Reply
#10

use a constant / define for your max contacts
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];
than create a stock for your dialog
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");
}
and for the deletion part, you only need to move the others one place down
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);
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)