Advertisement
Papawy

Repertoire By Papawy

Oct 26th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.60 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. /*
  4.  
  5.     Fonctions :
  6.    
  7.         addContact(playerid, contactName[], contactNum)
  8.             - ajoute un contacte, en mettant son nom et son numéro.
  9.                 retour : 1 si créé ; 0 si non créé (plus de place par exemple)
  10.     --------------------------------------------------------------------------------------
  11.        
  12.         getContactNameByID(playerid, contactid, name[], len)
  13.             - avoir le nom d'un contact grâce à son ID dans le REPERTOIRE.
  14.                 retour : 1 si contact trouvé ; 0 si contact pas trouvé
  15.            
  16.         getContactNameByNum(playerid, contactNum, name[], len)
  17.             - avoir le nom d'un contact grâce à son numéro.
  18.                 retour : 1 si contact trouvé ; 0 si contact pas trouvé
  19.     --------------------------------------------------------------------------------------
  20.    
  21.         getContactNumByID(playerid, contactid)
  22.             - avoir le numéro d'un contact par son ID dans le REPERTOIRE.
  23.                 retour : 1 si contact trouvé ; 0 si contact pas trouvé
  24.        
  25.         getContactNumByName(playerid, contactName[])
  26.             - avoir le numéro d'un contact par son nom.
  27.                 retour : 1 si contact trouvé ; 0 si contact pas trouvé
  28.        
  29.     --------------------------------------------------------------------------------------
  30.        
  31.         modifyContactByID(playerid, contactid, newname[], newnum)
  32.             - modifier un contact via son ID. Si newname = "" alors le nom n'est pas modifié. Si newnum = 0 alors le numéro n'est pas modifié.
  33.                 retour : 1 si contact trouvé ; 0 si contact pas trouvé
  34.                
  35.         modifyContactByNum(playerid, contactNum, newname[], newnum)
  36.             - modifier un contact via son numéro. Si newname = "" alors le nom n'est pas modifié. Si newnum = 0 alors le numéro n'est pas modifié.
  37.                 retour : 1 si contact trouvé ; 0 si contact pas trouvé
  38.        
  39.         modifyContactByName(playerid, contactName[], newname[], newnum)
  40.             - modifier un contact via son nom. Si newname = "" alors le nom n'est pas modifié. Si newnum = 0 alors le numéro n'est pas modifié.
  41.                 retour : 1 si contact trouvé ; 0 si contact pas trouvé
  42.                
  43.     --------------------------------------------------------------------------------------
  44.        
  45.         findValidSlot(playerid)
  46.             - trouve un slot valide.
  47.                 retour : le n° du slot valide ; -1 si pas de slots valide trouvé.
  48.        
  49.         isValidSlot(playerid, slotid)
  50.             - permet de savoir si un slot (contact) est valide ou pas.
  51.                 retour : le n° du slot valide ; -1 si pas de slots valide trouvé.
  52.    
  53.     --------------------------------------------------------------------------------------
  54.    
  55.         deleteContactByID(playerid, contactid)
  56.             - efface un contact (remet tout à zéro) grâce à son ID.
  57.                 retour : 1 si contact trouvé ; 0 si contact pas trouvé
  58.                
  59.         deleteContactByNum(playerid, contactNum)
  60.             - efface un contact (remet tout à zéro) grâce à son numéro.
  61.                 retour : 1 si contact trouvé ; 0 si contact pas trouvé
  62.        
  63.         deleteContactByName(playerid, contactName[])
  64.             - efface un contact (remet tout à zéro) grâce à son nom.
  65.                 retour : 1 si contact trouvé ; 0 si contact pas trouvé
  66.  
  67.     --------------------------------------------------------------------------------------
  68.    
  69.         findContactIDByNum(playerid, contactNum)
  70.             - trouve l'id d'un contact dans le REPERTOIRE par son numéro.
  71.                 retour : le n° du contact trouvé ; -1 si contact pas trouvé.
  72.                
  73.         findContactIDByName(playerid, contactName[])
  74.             - trouve l'id d'un contact dans le REPERTOIRE par son nom.
  75.                 retour : le n° du contact trouvé ; -1 si contact pas trouvé.
  76.                
  77. */
  78.  
  79. #define MAX_CONTACTS        50
  80.  
  81. enum REP_CONTACT {
  82.     c_Name[MAX_PLAYER_NAME+1],
  83.     c_Num
  84. };
  85.  
  86. new gRep[MAX_PLAYERS][MAX_CONTACTS][REP_CONTACT];
  87.  
  88. // Ajouter un contact
  89.  
  90. stock addContact(playerid, contactName[], contactNum)
  91. {
  92.     new contactID = findValidSlot(playerid);
  93.     if(contactID != -1)
  94.     {
  95.         strins(gRep[playerid][contactID][c_Name], contactName, 0, MAX_PLAYER_NAME+1);
  96.         gRep[playerid][contactID][c_Num] = contactNum;
  97.         return 1;
  98.     }
  99.     return 0;
  100. }
  101.  
  102. // Avoir le nom d'un contact
  103.  
  104. stock getContactNameByID(playerid, contactid, name[], len)
  105. {
  106.     if(contactid != -1)
  107.     {
  108.         strdel(name, 0, len);
  109.         strins(name, gRep[playerid][contactid][c_Name], 0, len);
  110.         return 1;
  111.     }
  112.     return 0;
  113. }
  114.  
  115. stock getContactNameByNum(playerid, contactNum, name[], len)
  116. {
  117.     return getContactNameByID(playerid, findContactIDByNum(playerid, contactNum), name, len);
  118. }
  119.  
  120. // Avoir le numéro d'un contact
  121.  
  122. stock getContactNumByID(playerid, contactid)
  123. {
  124.     if(contactid != -1)
  125.     {
  126.         return gRep[playerid][contactid][c_Num];
  127.     }
  128.     return -1;
  129. }
  130.  
  131. stock getContactNumByName(playerid, contactName[])
  132. {
  133.     return getContactNumByID(playerid, findContactIDByName(playerid, contactName));
  134. }
  135.  
  136. // Modifier un contact
  137.  
  138. stock modifyContactByID(playerid, contactid, newname[], newnum)
  139. {
  140.     if(contactid != -1)
  141.     {
  142.         if(strlen(newname) != 0)
  143.         {
  144.             strdel(gRep[playerid][contactid][c_Name], 0, MAX_PLAYER_NAME+1);
  145.             strins(gRep[playerid][contactid][c_Name], newname, 0, MAX_PLAYER_NAME+1);
  146.         }
  147.         if(newnum > 0)
  148.         {
  149.             gRep[playerid][contactid][c_Num] = newnum;
  150.         }
  151.         return 1;
  152.     }
  153.     return 0;
  154. }
  155.  
  156. stock modifyContactByName(playerid, name[], newname[], newnum)
  157. {
  158.     return modifyContactByID(playerid, findContactIDByName(playerid, name), newname, newnum);
  159. }
  160.  
  161. stock modifyContactByNum(playerid, contactNum, newname[], newnum)
  162. {
  163.     return modifyContactByID(playerid, findContactIDByNum(playerid, contactNum), newname, newnum);
  164. }
  165.  
  166. // Trouver un slot valid dans le repertoir
  167.  
  168. stock findValidSlot(playerid)
  169. {
  170.     for(new i; i<MAX_CONTACTS; i++)
  171.     {
  172.         if(isValidSlot(playerid, i))
  173.         {
  174.             return i;
  175.         }
  176.     }
  177.     return -1;
  178. }
  179.  
  180. stock isValidSlot(playerid, slotid)
  181. {
  182.     if((strlen(gRep[playerid][slotid][c_Name]) == 0) || (gRep[playerid][slotid][c_Num] == 0))
  183.     {
  184.         return 1;
  185.     }
  186.     return 0;
  187. }
  188.  
  189. // Effacer un contact
  190.  
  191. stock deleteContactByID(playerid, contactid)
  192. {
  193.     if(contactid != -1)
  194.     {
  195.         strdel(gRep[playerid][contactid][c_Name], 0, MAX_PLAYER_NAME+1);
  196.         gRep[playerid][contactid][c_Num] = 0;
  197.         return 1;
  198.     }
  199.     return 0;
  200. }
  201.  
  202. stock deleteContactByName(playerid, contactName[])
  203. {
  204.     return deleteContactByID(playerid, findContactIDByName(playerid, contactName));
  205. }
  206.  
  207. stock deleteContactByNum(playerid, contactNum)
  208. {
  209.     return deleteContactByID(playerid, findContactIDByNum(playerid, contactNum));
  210. }
  211.  
  212. // Trouver un contact
  213.  
  214. stock findContactIDByNum(playerid, contactNum)
  215. {
  216.     for(new i; i<MAX_CONTACTS; i++)
  217.     {
  218.         if(gRep[playerid][i][c_Num] == contactNum)
  219.         {
  220.             return i;
  221.         }
  222.     }
  223.     return -1;
  224. }
  225.  
  226. stock findContactIDByName(playerid, contactName[])
  227. {
  228.     for(new i; i<MAX_CONTACTS; i++)
  229.     {
  230.         if(strcmp(gRep[playerid][i][c_Name], contactName, false, MAX_PLAYER_NAME+1) == 0)
  231.         {
  232.             return i;
  233.         }
  234.     }
  235.     return -1;
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement