Advertisement
Guest User

ID Estático e Dinâmico

a guest
Mar 3rd, 2022
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.80 KB | None | 0 0
  1. // Um exemplo de tabela
  2. // --------------------
  3. // Nome da tabela: Identity
  4. // Coluna n°1: Static_Id | Interger | Primary Key |Auto_Increment
  5. // Coluna n°2: Normal_Id | Interger | Not Null
  6. // Coluna n°3: Username | Varchar | Not Null
  7.  
  8.  
  9. stock GetNormalId(static_id) {
  10.     new query[128], normal_id = INVALID_PLAYER_ID;
  11.     format(query, sizeof query, "select Normal_Id from Identity where Static_Id = '%d'", static_id);
  12.     cache = db_query(handle, query);
  13.     if(db_num_rows(cache) == 1)
  14.     {
  15.         normal_id = db_get_field_int(cache);
  16.         db_free_result(cache);
  17.     }
  18.     return normal_id;
  19. }
  20.  
  21. stock GetStaticId(normal_id) {
  22.     new query[128], static_id = INVALID_PLAYER_ID;
  23.     format(query, sizeof query, "select Static_Id from Identity where Normal_Id = '%d'", normal_id);
  24.     cache = db_query(handle, query);
  25.     if(db_num_rows(cache) == 1)
  26.     {
  27.         static_id = db_get_field_int(cache);
  28.         db_free_result(cache);
  29.     }
  30.     return static_id;
  31. }
  32.  
  33. public OnPlayerConnect(playerid) {
  34.     new pname[24], query[128];
  35.     GetPlayerName(playerid, pname, sizeof pname);
  36.     format(query, sizeof query, "select * from Identity where Username = '%s';", pname);
  37.     cache = db_query(handle, query);
  38.     if(!db_num_rows(cache))
  39.     {
  40.         format(query, sizeof query, "insert into Identity ('Normal_Id', 'Username') values ('%d', '%s);", playerid, pname);
  41.         cache = db_query(handle, query);
  42.     }
  43.     else
  44.     {
  45.         format(query, sizeof query, "update Identity set Normal_Id = %d where Username = '%s';", playerid, pname);
  46.         cache = db_query(handle, query);
  47.     }
  48.     db_free_result(cache);
  49.     return 1;
  50. }
  51.  
  52. public OnPlayerDisconnect(playerid, reason) {
  53.     new pname[24], query[128];
  54.     GetPlayerName(playerid, pname, sizeof pname);
  55.     format(query, sizeof query, "update Identity set Normal_Id = -1 where Username = '%s';", pname);
  56.     db_free_result(db_query(handle, query));
  57.     return 1;
  58. }
  59.  
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement