Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- /*
- Fonctions :
- addContact(playerid, contactName[], contactNum)
- - ajoute un contacte, en mettant son nom et son numéro.
- retour : 1 si créé ; 0 si non créé (plus de place par exemple)
- --------------------------------------------------------------------------------------
- getContactNameByID(playerid, contactid, name[], len)
- - avoir le nom d'un contact grâce à son ID dans le REPERTOIRE.
- retour : 1 si contact trouvé ; 0 si contact pas trouvé
- getContactNameByNum(playerid, contactNum, name[], len)
- - avoir le nom d'un contact grâce à son numéro.
- retour : 1 si contact trouvé ; 0 si contact pas trouvé
- --------------------------------------------------------------------------------------
- getContactNumByID(playerid, contactid)
- - avoir le numéro d'un contact par son ID dans le REPERTOIRE.
- retour : 1 si contact trouvé ; 0 si contact pas trouvé
- getContactNumByName(playerid, contactName[])
- - avoir le numéro d'un contact par son nom.
- retour : 1 si contact trouvé ; 0 si contact pas trouvé
- --------------------------------------------------------------------------------------
- modifyContactByID(playerid, contactid, newname[], newnum)
- - 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é.
- retour : 1 si contact trouvé ; 0 si contact pas trouvé
- modifyContactByNum(playerid, contactNum, newname[], newnum)
- - 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é.
- retour : 1 si contact trouvé ; 0 si contact pas trouvé
- modifyContactByName(playerid, contactName[], newname[], newnum)
- - 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é.
- retour : 1 si contact trouvé ; 0 si contact pas trouvé
- --------------------------------------------------------------------------------------
- findValidSlot(playerid)
- - trouve un slot valide.
- retour : le n° du slot valide ; -1 si pas de slots valide trouvé.
- isValidSlot(playerid, slotid)
- - permet de savoir si un slot (contact) est valide ou pas.
- retour : le n° du slot valide ; -1 si pas de slots valide trouvé.
- --------------------------------------------------------------------------------------
- deleteContactByID(playerid, contactid)
- - efface un contact (remet tout à zéro) grâce à son ID.
- retour : 1 si contact trouvé ; 0 si contact pas trouvé
- deleteContactByNum(playerid, contactNum)
- - efface un contact (remet tout à zéro) grâce à son numéro.
- retour : 1 si contact trouvé ; 0 si contact pas trouvé
- deleteContactByName(playerid, contactName[])
- - efface un contact (remet tout à zéro) grâce à son nom.
- retour : 1 si contact trouvé ; 0 si contact pas trouvé
- --------------------------------------------------------------------------------------
- findContactIDByNum(playerid, contactNum)
- - trouve l'id d'un contact dans le REPERTOIRE par son numéro.
- retour : le n° du contact trouvé ; -1 si contact pas trouvé.
- findContactIDByName(playerid, contactName[])
- - trouve l'id d'un contact dans le REPERTOIRE par son nom.
- retour : le n° du contact trouvé ; -1 si contact pas trouvé.
- */
- #define MAX_CONTACTS 50
- enum REP_CONTACT {
- c_Name[MAX_PLAYER_NAME+1],
- c_Num
- };
- new gRep[MAX_PLAYERS][MAX_CONTACTS][REP_CONTACT];
- // Ajouter un contact
- stock addContact(playerid, contactName[], contactNum)
- {
- new contactID = findValidSlot(playerid);
- if(contactID != -1)
- {
- strins(gRep[playerid][contactID][c_Name], contactName, 0, MAX_PLAYER_NAME+1);
- gRep[playerid][contactID][c_Num] = contactNum;
- return 1;
- }
- return 0;
- }
- // Avoir le nom d'un contact
- stock getContactNameByID(playerid, contactid, name[], len)
- {
- if(contactid != -1)
- {
- strdel(name, 0, len);
- strins(name, gRep[playerid][contactid][c_Name], 0, len);
- return 1;
- }
- return 0;
- }
- stock getContactNameByNum(playerid, contactNum, name[], len)
- {
- return getContactNameByID(playerid, findContactIDByNum(playerid, contactNum), name, len);
- }
- // Avoir le numéro d'un contact
- stock getContactNumByID(playerid, contactid)
- {
- if(contactid != -1)
- {
- return gRep[playerid][contactid][c_Num];
- }
- return -1;
- }
- stock getContactNumByName(playerid, contactName[])
- {
- return getContactNumByID(playerid, findContactIDByName(playerid, contactName));
- }
- // Modifier un contact
- stock modifyContactByID(playerid, contactid, newname[], newnum)
- {
- if(contactid != -1)
- {
- if(strlen(newname) != 0)
- {
- strdel(gRep[playerid][contactid][c_Name], 0, MAX_PLAYER_NAME+1);
- strins(gRep[playerid][contactid][c_Name], newname, 0, MAX_PLAYER_NAME+1);
- }
- if(newnum > 0)
- {
- gRep[playerid][contactid][c_Num] = newnum;
- }
- return 1;
- }
- return 0;
- }
- stock modifyContactByName(playerid, name[], newname[], newnum)
- {
- return modifyContactByID(playerid, findContactIDByName(playerid, name), newname, newnum);
- }
- stock modifyContactByNum(playerid, contactNum, newname[], newnum)
- {
- return modifyContactByID(playerid, findContactIDByNum(playerid, contactNum), newname, newnum);
- }
- // Trouver un slot valid dans le repertoir
- stock findValidSlot(playerid)
- {
- for(new i; i<MAX_CONTACTS; i++)
- {
- if(isValidSlot(playerid, i))
- {
- return i;
- }
- }
- return -1;
- }
- stock isValidSlot(playerid, slotid)
- {
- if((strlen(gRep[playerid][slotid][c_Name]) == 0) || (gRep[playerid][slotid][c_Num] == 0))
- {
- return 1;
- }
- return 0;
- }
- // Effacer un contact
- stock deleteContactByID(playerid, contactid)
- {
- if(contactid != -1)
- {
- strdel(gRep[playerid][contactid][c_Name], 0, MAX_PLAYER_NAME+1);
- gRep[playerid][contactid][c_Num] = 0;
- return 1;
- }
- return 0;
- }
- stock deleteContactByName(playerid, contactName[])
- {
- return deleteContactByID(playerid, findContactIDByName(playerid, contactName));
- }
- stock deleteContactByNum(playerid, contactNum)
- {
- return deleteContactByID(playerid, findContactIDByNum(playerid, contactNum));
- }
- // Trouver un contact
- stock findContactIDByNum(playerid, contactNum)
- {
- for(new i; i<MAX_CONTACTS; i++)
- {
- if(gRep[playerid][i][c_Num] == contactNum)
- {
- return i;
- }
- }
- return -1;
- }
- stock findContactIDByName(playerid, contactName[])
- {
- for(new i; i<MAX_CONTACTS; i++)
- {
- if(strcmp(gRep[playerid][i][c_Name], contactName, false, MAX_PLAYER_NAME+1) == 0)
- {
- return i;
- }
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement