Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Um exemplo de tabela
- // --------------------
- // Nome da tabela: Identity
- // Coluna n°1: Static_Id | Interger | Primary Key |Auto_Increment
- // Coluna n°2: Normal_Id | Interger | Not Null
- // Coluna n°3: Username | Varchar | Not Null
- stock GetNormalId(static_id) {
- new query[128], normal_id = INVALID_PLAYER_ID;
- format(query, sizeof query, "select Normal_Id from Identity where Static_Id = '%d'", static_id);
- cache = db_query(handle, query);
- if(db_num_rows(cache) == 1)
- {
- normal_id = db_get_field_int(cache);
- db_free_result(cache);
- }
- return normal_id;
- }
- stock GetStaticId(normal_id) {
- new query[128], static_id = INVALID_PLAYER_ID;
- format(query, sizeof query, "select Static_Id from Identity where Normal_Id = '%d'", normal_id);
- cache = db_query(handle, query);
- if(db_num_rows(cache) == 1)
- {
- static_id = db_get_field_int(cache);
- db_free_result(cache);
- }
- return static_id;
- }
- public OnPlayerConnect(playerid) {
- new pname[24], query[128];
- GetPlayerName(playerid, pname, sizeof pname);
- format(query, sizeof query, "select * from Identity where Username = '%s';", pname);
- cache = db_query(handle, query);
- if(!db_num_rows(cache))
- {
- format(query, sizeof query, "insert into Identity ('Normal_Id', 'Username') values ('%d', '%s);", playerid, pname);
- cache = db_query(handle, query);
- }
- else
- {
- format(query, sizeof query, "update Identity set Normal_Id = %d where Username = '%s';", playerid, pname);
- cache = db_query(handle, query);
- }
- db_free_result(cache);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason) {
- new pname[24], query[128];
- GetPlayerName(playerid, pname, sizeof pname);
- format(query, sizeof query, "update Identity set Normal_Id = -1 where Username = '%s';", pname);
- db_free_result(db_query(handle, query));
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement