06.06.2016, 21:04
(
Последний раз редактировалось Sime30; 10.06.2016 в 13:34.
)
Hi everyone
I haven't been scripting nor playing SA:MP for over a year now, just doing other stuff in my life.
Recently I found some old gamemodes and scripts on a CD which I thought I lost a long time ago. After some thinking, I updated all plugins, includes etc.
And now comes the important part...
I have a working Y_INI based Phonebook system made by Larzi - https://sampforum.blast.hk/showthread.php?tid=406221
Well, I edited it and removed everything but the phonebook. It works well.
BUT now I want that in MySQL database, not in file ini system.
What would be the best approach? I wanted to make fixed slots in a MySQL table but that's not how it works like now. I want it to insert new rows when a player adds a contact, similiar to Vince's weapon saving/loading - https://sampforum.blast.hk/showthread.php?tid=505081
I'll show you some code of course but most variable names are in my native language. Sorry for that.
I'll add more code when needed. For now, I just need an example of doing this dynamic adding & removing contacts in MySQL. Thanks!
I haven't been scripting nor playing SA:MP for over a year now, just doing other stuff in my life.
Recently I found some old gamemodes and scripts on a CD which I thought I lost a long time ago. After some thinking, I updated all plugins, includes etc.
And now comes the important part...
I have a working Y_INI based Phonebook system made by Larzi - https://sampforum.blast.hk/showthread.php?tid=406221
Well, I edited it and removed everything but the phonebook. It works well.
BUT now I want that in MySQL database, not in file ini system.
What would be the best approach? I wanted to make fixed slots in a MySQL table but that's not how it works like now. I want it to insert new rows when a player adds a contact, similiar to Vince's weapon saving/loading - https://sampforum.blast.hk/showthread.php?tid=505081
I'll show you some code of course but most variable names are in my native language. Sorry for that.
pawn Код:
forward ImenikLoad(playerid);
public ImenikLoad(playerid) // on player connect
{
if( !fexist( PutanjaImenika( playerid )))
{
new
INI:ImennikFile = INI_Open( PutanjaImenika( playerid ));
INI_SetTag( ImennikFile, "statistika" );
INI_WriteInt( ImennikFile, "kontakti", 0 );
INI_Close( ImennikFile );
}
else
{
INI_ParseFile( PutanjaImenika( playerid ), "Imenik", .bExtra = true, .extra = playerid, .bPassTag = true );
for( new i = 0; i < MAX_KONTAKATA; i ++ )
{
if( isnull( g_Imenik[ playerid ][ i ][ ImenikPlayerName ] ))
{
format( g_Imenik[ playerid ][ i ][ ImenikPlayerName ], MAX_PLAYER_NAME, "- empty -" );
}
}
}
return 1;
}
forward ImenikUnload(playerid);
public ImenikUnload(playerid) // on player disonnect
{
fremove( PutanjaImenika( playerid ));
new
INI:File = INI_Open( PutanjaImenika( playerid ));
INI_SetTag( File, "statistika" );
INI_WriteInt( File, "kontakti", g_Kontakti[ playerid ] );
for( new i = 0; i < g_Kontakti[ playerid ]; i ++ )
{
if( !strcmp( g_Imenik[ playerid ][ i ][ ImenikPlayerName ], "- empty -" ))
{
INI_DeleteTag( File, valstr2( i ));
}
else
{
INI_SetTag( File, valstr2( i ));
INI_WriteString( File, "name", g_Imenik[ playerid ][ i ][ ImenikPlayerName ] );
INI_WriteString( File, "number", g_Imenik[ playerid ][ i ][ ImenikPlayerNumber ] );
}
}
INI_Close( File );
g_Kontakti[ playerid ] = 0;
for( new i = 0; i < MAX_KONTAKATA; i ++ )
{
format( g_Imenik[ playerid ][ i ][ ImenikPlayerName ], MAX_PLAYER_NAME, "" );
format( g_Imenik[ playerid ][ i ][ ImenikPlayerNumber ], MAX_NUMBERS, "" );
}
if(KupnjaImenika[playerid] == 1)
{
SetTimerEx("ImenikLoad", 700, false , "i" , playerid);
KupnjaImenika[playerid] = 0;
}
return 1;
}