Advertisement
Jujuv

[SA:MP | GM] Base-GM

Apr 24th, 2012
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 20.81 KB | None | 0 0
  1. //-----------------------------Inclusion des librairies-------------------------//
  2. #include <a_samp>
  3. #include <dudb>
  4. #include <a_http>
  5.  
  6. //-------------------Directive de preprocesseur particuliéres------------------//
  7. #pragma unused ret_memcpy
  8.  
  9. //---------------------------------Enumérations--------------------------------//
  10. enum
  11. {
  12.     DIALOG_REGISTER,
  13.     DIALOG_LOGIN,
  14.     DIALOG_REGISTER_SECUR,
  15.     DIALOG_AUTO_LOGIN,
  16.     DIALOG_ADMIN_MENU,
  17.     DIALOG_PM_INPUT,
  18.     DIALOG_PM_SENT,
  19.     DIALOG_PM_FAILED,
  20.     DIALOG_VOTE_KICK_CONFIRM,
  21.     DIALOG_VOTE_KICK_SENT,
  22.     DIALOG_VOTE_KICK_FAILED,
  23.     DIALOG_PLAYER_MENU,
  24.     DIALOG_ADMIN_SET,
  25.     DIALOG_BAN_CONFIRM,
  26.     DIALOG_DEL_ACCOUNT_CONFIRM,
  27.     DIALOG_DEL_ACCOUNT_DONE,
  28.     DIALOG_UNBAN_INPUT,
  29.     DIALOG_UNBAN_DONE,
  30.     DIALOG_CFG_MENU,
  31.     DIALOG_CFG_VOTE_KICK_DELAY,
  32.     DIALOG_CFG_VOTE_KICK_NEEDED,
  33.     DIALOG_CFG_DEFAULT_MONEY,
  34.     DIALOG_CFG_MIN_PASS_LEN,
  35.     DIALOG_GLOBAL_OP_DONE_MSG,
  36. }
  37. enum
  38. {
  39.     MEMBER,
  40.     MODO,
  41.     ADMIN
  42. }
  43.  
  44. //-----------------------------Definitions de macros---------------------------//
  45. #define COLOR_YELLOW 0xFFD200FF
  46. #define COLOR_RED 0xFF1E00FF
  47.  
  48. #define CFGFILE "global.cfg"
  49. #define GM_NAME "Simple Base 0.4"
  50. #define playerClickedID GetPVarInt(playerid, "playerClickedID")
  51. #define OP_DONE_MSG ShowPlayerDialog(playerid, DIALOG_GLOBAL_OP_DONE_MSG, DIALOG_STYLE_MSGBOX, "Operation réussie", "Opération réussie !", "Ok", "");//La fénéantise incarnée
  52.  
  53. //-----------------------------Prototype de fonctions publiques-----------------//
  54. forward AbortVoteKick(votedPlayerID);
  55.  
  56. //-----------------------------Definitions de variables globales---------------//
  57. new gAdminsConnected = 0;
  58. new gMaxPlayers = 0;
  59. new gDefaultMoney;
  60. new gVoteKickDelay;
  61. new gNeededVotesToKick;
  62. new gMinPassLen;
  63.  
  64. //------------------------------------Let's go---------------------------------//
  65.  
  66.  
  67. main()
  68. {
  69.     print("\n--------------------------------------");
  70.     print(" (^o^) Simple base-mode by Jujuv (^o^)");
  71.     print("--------------------------------------\n");
  72.     return 1;
  73. }
  74.  
  75. public OnGameModeInit()
  76. {
  77.     SetGameModeText(GM_NAME);
  78.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  79.    
  80.     if(!dini_Exists(CFGFILE))
  81.     {
  82.         dini_Create(CFGFILE);
  83.         dini_IntSet(CFGFILE, "StartingMoney", 500);
  84.         dini_IntSet(CFGFILE, "VoteKickDelay", 60);
  85.         dini_IntSet(CFGFILE, "NeededVotesToKick", 50);
  86.         dini_IntSet(CFGFILE, "MinPassLen", 6);
  87.         print("Fichier de configuration global par défaut, crée");
  88.     }
  89.     else
  90.     {
  91.         gDefaultMoney = dini_Int(CFGFILE, "StartingMoney");
  92.         gVoteKickDelay = dini_Int(CFGFILE, "VoteKickDelay");
  93.         gNeededVotesToKick = dini_Int(CFGFILE, "NeededViotesToKick");
  94.         gMinPassLen = dini_Int(CFGFILE, "MinPassLen");
  95.         print("Configuration chargé");
  96.     }
  97.     return 1;
  98. }
  99.  
  100. public OnPlayerConnect(playerid)
  101. {
  102.     if(gMaxPlayers < playerid)
  103.         gMaxPlayers = playerid;
  104.    
  105.     SetPVarInt(playerid, "logued", 0);//Cette PVar est un booleen indiquant si le joueur esr logué ou non
  106.     new pName[MAX_PLAYER_NAME];
  107.     GetPlayerName(playerid, pName, sizeof(pName));
  108.     if(udb_Exists(pName))//S'il existe dèja un compte ascosié à ce pseudonyme
  109.     {
  110.         if(udb_UserInt(pName, "Banned"))
  111.         {
  112.             SendClientMessage(playerid, COLOR_YELLOW, "Ce nom d'utilisateur est banni");
  113.             Kick(playerid);
  114.         }
  115.        
  116.         else
  117.         {
  118.             new pIp[MAX_STRING];
  119.             GetPlayerIp(playerid, pIp, sizeof(pIp));
  120.            
  121.             if(AreStringsEquals(udb_User(pName, "Last_IP"), udb_User(pName, "Registered_IP")) && AreStringsEquals(pIp, udb_User(pName, "Last_IP")))//Si la derniére IP connue du joueur est egale à celle avec laquelle il s'est inscrit et si celle-ci est egale à son IP actuelle
  122.             {
  123.                 SetPVarInt(playerid, "logued", 1);
  124.                 ShowPlayerDialog(playerid, DIALOG_AUTO_LOGIN, DIALOG_STYLE_MSGBOX, "Login", "Vous avez été connécté automatiquement à votre compte", "Ok", "");
  125.             }
  126.             else
  127.                 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Veuillez entrer votre mot de passe afin de vous connecter", "Ok", "");//On demande au joueur de se loguer en entrant son mot de passe
  128.         }
  129.        
  130.     }
  131.     else//Sinon (le joueur n'a donc pas de compte)
  132.     ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Enregistrement", "Veuillez entrer un mot de passe afin de vous enregistrer", "Ok", "");//On demande au joueur de saisir un mot de passe pour s'inscrire
  133.    
  134.     return 1;
  135. }
  136.  
  137. public OnPlayerDisconnect(playerid, reason)
  138. {
  139.     if(IsAdmin(playerid)) { gAdminsConnected--; }
  140.     if(GetPVarInt(playerid, "VoteCount") > 0) { ResetVoteKick(); }
  141.    
  142.     if(playerid == gMaxPlayers)
  143.     {
  144.         for(new i = gMaxPlayers-1; i >= 0; i--)//TY Mini'.J'ai juste CC et changé le nom d'la var
  145.         {
  146.             if(IsPlayerConnected(i))
  147.             {gMaxPlayers = i; break;}
  148.         }
  149.     }
  150. }
  151.  
  152. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  153. {
  154.     switch(dialogid)
  155.     {
  156.         case DIALOG_LOGIN:
  157.         {
  158.             if(response)//Si le joueur a cliqué sur le bouton de gauche ("ok")
  159.             {
  160.                 new pName[MAX_PLAYER_NAME];
  161.                 GetPlayerName(playerid, pName, sizeof(pName));
  162.                
  163.                 if(udb_CheckLogin(pName, inputtext))//Si le mot de passe est correct
  164.                 OnPlayerLogin(playerid);
  165.                 else//Sinon (le mot de passe est incorrect)
  166.                 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Mot de passe incorrect", "Veuillez entrer votre mot de passe afin de vous connecter", "Ok", "Annuler");//On demande au joueur de rentrer son mot de passe à nouveau
  167.             }
  168.             else
  169.                 Kick(playerid);//Sinon (il a cliqué sur le bouton de droite: "Annuler")
  170.         }
  171.         case DIALOG_REGISTER:
  172.         {
  173.             SetPVarString(playerid, "passCheck", inputtext);//On stocke le mot de passe dans une PVar temporaire
  174.            
  175.             if(strlen(inputtext) >= gMinPassLen)//Si le mot de passe est assez long
  176.             ShowPlayerDialog(playerid, DIALOG_REGISTER_SECUR, DIALOG_STYLE_PASSWORD, "Securité", "Veuillez retaper votre mot de passe à l'identique (sécurité)", "Ok", "");//On demande au joueur de retaper le même mot de passe
  177.             else//Sinon on demande au joueur d'en choisir un autre
  178.             ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Mot de passe trop court", "Veuillez entrer un mot de passe afin de vous enregistrer", "Ok", "");
  179.         }
  180.         case DIALOG_REGISTER_SECUR:
  181.         {
  182.             new pwd[MAX_STRING];
  183.             GetPVarString(playerid, "passCheck", pwd, sizeof(pwd));//On récupére le mot de passe stocké précédament
  184.            
  185.             if(AreStringsEquals(inputtext, pwd))//Si le mot de passe rentré la 1er fois est bien le même que celui rentré la seconde
  186.             {
  187.                 new pName[MAX_PLAYER_NAME];
  188.                 GetPlayerName(playerid, pName, sizeof(pName));
  189.                
  190.                 udb_Create(pName, inputtext);//On créer son compte
  191.                 DeletePVar(playerid, "passCheck");//On supprime la PVar qui stockais temporairement la 1er saisie de son mot de passe
  192.                 SetPVarInt(playerid, "logued", 1);
  193.                 OnPlayerRegister(playerid);
  194.                 OnPlayerLogin(playerid);
  195.             }
  196.             else//Sinon (le mot de passe ne corespond pas au 1er entré)
  197.             ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,  "Mot de passe incorrect", "Le mot de passe entrer ne coresspond pas à celui entrer précédaient\n Veuiller taper deux fois le même mot de passe", "Ok", "");//Retour à la case départ!
  198.         }
  199.         case DIALOG_PM_INPUT:
  200.         {
  201.             if(response)
  202.             {
  203.                 if(!strlen(inputtext)) { ShowPlayerDialog(playerid, DIALOG_PM_FAILED, DIALOG_STYLE_MSGBOX, "Echc de l'envoie", "Echec de l'envoie du message (message vide)", "Ok", ""); }
  204.                 else if(!IsPlayerConnected(playerClickedID)) {ShowPlayerDialog(playerid, DIALOG_PM_FAILED, DIALOG_STYLE_MSGBOX, "Echc de l'envoie", "Echec de l'envoie du message (joueur non connécté ou ID invalide)", "Ok", "");}
  205.                 else
  206.                 {
  207.                     new pName[MAX_PLAYER_NAME], receiverName[MAX_PLAYER_NAME], msgFormated[MAX_STRING];
  208.                     GetPlayerName(playerid, pName, sizeof(pName));
  209.                     GetPlayerName(playerClickedID, receiverName, sizeof(receiverName));
  210.                    
  211.                     format(msgFormated, sizeof(msgFormated), "[Message Privé]%s: %s", pName, inputtext);
  212.                     SendClientMessage(playerClickedID, COLOR_YELLOW, msgFormated);
  213.                     format(msgFormated, sizeof(msgFormated), "[Surveillance] MP de %s à %s: %s", pName, receiverName, inputtext);
  214.                     SendMessageToAdmins(msgFormated);
  215.                     ShowPlayerDialog(playerid, DIALOG_PM_SENT, DIALOG_STYLE_MSGBOX, "Message envoyé", "Message envoyé", "Ok", "");
  216.                 }
  217.             }
  218.         }
  219.         case DIALOG_PLAYER_MENU:
  220.         {
  221.             switch(listitem)
  222.             {
  223.                 case 0:
  224.                 {
  225.                     ShowPlayerDialog(playerid, DIALOG_PM_INPUT, DIALOG_STYLE_INPUT, "Message Privé", "Entrez le texte de votre message:", "Envoyer", "Annuler");
  226.                 }
  227.                 case 1:
  228.                 {
  229.                     ShowPlayerDialog(playerid, DIALOG_VOTE_KICK_CONFIRM, DIALOG_STYLE_MSGBOX, "Confirmation", "Etes vous certain de vouloir faire cela ?", "Oui", "Non");
  230.                 }
  231.             }
  232.            
  233.         }
  234.         case DIALOG_VOTE_KICK_CONFIRM:
  235.         {
  236.             if(response)
  237.             {
  238.                 OnPlayerVoteKick(playerid);
  239.             }
  240.         }
  241.         case DIALOG_ADMIN_MENU:
  242.         {
  243.             switch(listitem)
  244.             {
  245.                 case 0://Mettre Admin
  246.                 {
  247.                     if(GetAdminRank(playerid) >= ADMIN && GetAdminRank(playerClickedID) < ADMIN )
  248.                     {
  249.                         ShowPlayerDialog(playerid, DIALOG_ADMIN_SET, DIALOG_STYLE_LIST, "Choisisez:", "Membre\r\nModerateur\r\nAdministrateur\r\n", "Valider", "Annuler");
  250.                     }
  251.                 }
  252.                 case 1://Expulser
  253.                 {
  254.                     if(GetAdminRank(playerClickedID) == MEMBER)
  255.                     {
  256.                         new msg[MAX_STRING], pName[MAX_PLAYER_NAME];
  257.                         GetPlayerName(playerClickedID, pName, sizeof(pName));
  258.                         format(msg, sizeof(msg), "[Administration]%s a été éxpulsé du serveur par un moderateur ou un administrateur", pName);
  259.                         SendClientMessageToAll(COLOR_YELLOW, msg);
  260.                         Kick(playerid);
  261.                     }
  262.                 }
  263.                 case 2://Bannir
  264.                 {
  265.                     if(GetAdminRank(playerClickedID) == MEMBER)
  266.                     {
  267.                         ShowPlayerDialog(playerid, DIALOG_BAN_CONFIRM, DIALOG_STYLE_MSGBOX, "Confirmation", "Etes vous certains de vouloir bannir ce joueur ?", "Oui", "Non");
  268.                     }
  269.                 }
  270.                 case 3://Supprimer le compte utilisateur
  271.                 {
  272.                     ShowPlayerDialog(playerid, DIALOG_DEL_ACCOUNT_CONFIRM, DIALOG_STYLE_MSGBOX, "Confirmation", "Etes vous certains de vouloir supprimer ce compte utilisateur ?", "Oui", "Non");
  273.                 }
  274.                 case 4:
  275.                 {
  276.                     new Float:x, Float:y, Float:z;
  277.                     GetPlayerPos(playerClickedID, x, y, z);
  278.                     SetPlayerPosFindZ(playerid, x+random(20), y+random(20), z);
  279.                 }
  280.                 case 5:
  281.                 {
  282.                     if(IsPlayerLoguedIn(playerClickedID))
  283.                     {
  284.                         if(playerid == playerClickedID)
  285.                         {
  286.                             TogglePlayerSpectating(playerid, 0);
  287.                         }
  288.                         else
  289.                         {
  290.                             TogglePlayerSpectating(playerid, 1);
  291.                             PlayerSpectatePlayer(playerid, playerClickedID);
  292.                         }
  293.                     }
  294.                 }
  295.             }
  296.         }
  297.         case DIALOG_ADMIN_SET:
  298.         {
  299.             switch(listitem)
  300.             {
  301.                 case 0://membre
  302.                 {
  303.                     SetAdminRank(playerClickedID, MEMBER);
  304.                 }
  305.                 case 1://modo
  306.                 {
  307.                     SetAdminRank(playerClickedID, MODO);
  308.                 }
  309.                 case 2://admin
  310.                 {
  311.                     SetAdminRank(playerClickedID, ADMIN);
  312.                 }
  313.             }
  314.         }
  315.         case DIALOG_BAN_CONFIRM:
  316.         {
  317.             if(response)
  318.             {
  319.                 new pName[MAX_PLAYER_NAME], msg[MAX_STRING];
  320.                 GetPlayerName(playerClickedID, pName, sizeof(pName));
  321.                 format(msg, sizeof(msg), "[Administration]%s a été banni(e) du serveur", pName);
  322.                 udb_UserSetInt(pName, "Banned", 1);
  323.                 Kick(playerClickedID);
  324.             }
  325.         }
  326.         case DIALOG_DEL_ACCOUNT_CONFIRM:
  327.         {
  328.             if(response && !IsAdmin(playerClickedID))
  329.             {
  330.                 new pName[MAX_PLAYER_NAME];
  331.                 GetPlayerName(playerClickedID, pName, sizeof(pName));
  332.                 if(IsPlayerConnected(playerClickedID)) { Kick(playerClickedID); }
  333.                 udb_Remove(pName);
  334.                 ShowPlayerDialog(playerid, DIALOG_DEL_ACCOUNT_DONE, DIALOG_STYLE_MSGBOX, "Tache éfféctué", "Compte supprimé avec succés", "Ok", "");
  335.             }
  336.         }
  337.         case DIALOG_UNBAN_INPUT:
  338.         {
  339.             if(response)
  340.             {
  341.                 if(udb_Exists(inputtext))
  342.                 {
  343.                     if(udb_UserInt(inputtext, "Banned"))
  344.                     {
  345.                         udb_UserSetInt(inputtext, "Banned", 0);
  346.                         ShowPlayerDialog(playerid, DIALOG_UNBAN_DONE, DIALOG_STYLE_MSGBOX, "Debanissement" ,"Joueur débanni avec succés", "Ok", "");
  347.                     }
  348.                     else{ SendClientMessage(playerid, COLOR_YELLOW, "[Erreur] Ce compte n'est pas banni"); }
  349.                 }
  350.                 else{ SendClientMessage(playerid, COLOR_RED, "[Erreur] Ce compte n'est pas enregistré"); }
  351.             }
  352.         }
  353.         case DIALOG_CFG_MENU:
  354.         {
  355.             switch(listitem)
  356.             {
  357.                 case 0://voteKickDelay
  358.                 {
  359.                     ShowPlayerDialog(playerid, DIALOG_CFG_VOTE_KICK_DELAY, DIALOG_STYLE_INPUT, "Configuration", "Entrer une valeur (en secondes):", "Valider", "Annuler");
  360.                 }
  361.                 case 1://VotesKickNeeded
  362.                 {
  363.                     ShowPlayerDialog(playerid, DIALOG_CFG_VOTE_KICK_NEEDED, DIALOG_STYLE_INPUT, "Configuration", "Enttrez une valeur (int):", "Valider", "Annuler");
  364.                 }
  365.                 case 2://MinPassLen
  366.                 {
  367.                     ShowPlayerDialog(playerid, DIALOG_CFG_MIN_PASS_LEN, DIALOG_STYLE_INPUT, "Configuration", "Entrez une valeur (int):", "Valider", "Annuler");
  368.                 }
  369.                 case 3://DefaultMoney
  370.                 {
  371.                     ShowPlayerDialog(playerid, DIALOG_CFG_DEFAULT_MONEY, DIALOG_STYLE_INPUT, "Configuration", "Entrez une valeur (int):", "Valider", "Annuler");
  372.                 }
  373.             }
  374.         }
  375.         case DIALOG_CFG_VOTE_KICK_DELAY:
  376.         {
  377.             if(response)
  378.             {
  379.                 if(strval(inputtext) >= 10)
  380.                 {
  381.                     dini_IntSet(CFGFILE, "VoteKickDelay", strval(inputtext));
  382.                     gVoteKickDelay = strval(inputtext);
  383.                     OP_DONE_MSG
  384.                 }
  385.             }
  386.         }
  387.         case DIALOG_CFG_VOTE_KICK_NEEDED:
  388.         {
  389.             if(response)
  390.             {
  391.                 if(strval(inputtext) >= 10)
  392.                 {
  393.                     dini_IntSet(CFGFILE, "VoteKickNeeded", strval(inputtext));
  394.                     gNeededVotesToKick = strval(inputtext);
  395.                     OP_DONE_MSG
  396.                 }
  397.             }
  398.         }
  399.         case DIALOG_CFG_MIN_PASS_LEN:
  400.         {
  401.             if(response)
  402.             {
  403.                 if(strval(inputtext) >= 5)
  404.                 {
  405.                     dini_IntSet(CFGFILE, "MinPassLen", strval(inputtext));
  406.                     gMinPassLen = strval(inputtext);
  407.                     OP_DONE_MSG
  408.                 }
  409.             }
  410.         }
  411.         case DIALOG_CFG_DEFAULT_MONEY:
  412.         {
  413.             if(response)
  414.             {
  415.                 if(strval(inputtext) >= 0)
  416.                 {
  417.                     dini_IntSet(CFGFILE, "StartingMoney", strval(inputtext));
  418.                     gDefaultMoney = strval(inputtext);
  419.                     OP_DONE_MSG
  420.                 }
  421.             }
  422.         }
  423.     }//Ceci ferme le "switch" principale, faite y bien attention.
  424.     return 1;
  425. }
  426.  
  427.  
  428. public OnPlayerUpdate(playerid)
  429. {
  430.     if(GetPVarInt(playerid, "voteCount") == gNeededVotesToKick)
  431.     {
  432.         new msg[MAX_STRING], pName[MAX_PLAYER_NAME];
  433.         GetPlayerName(playerid, pName, sizeof(pName));
  434.         Kick(playerid);
  435.         format(msg, sizeof(msg), "%s a été éxpulsé du serveur aprés un vote", pName);
  436.         SendClientMessageToAll(COLOR_YELLOW, msg);
  437.     }
  438. }
  439.  
  440. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  441. {
  442.     SetPVarInt(playerid, "clickedplayerID", clickedplayerid);
  443.    
  444.     if(IsAdmin(playerid))
  445.     {
  446.         ShowPlayerDialog(playerid, DIALOG_ADMIN_MENU, DIALOG_STYLE_LIST, "Menu d'Administration", "Mettre Admin\r\nExpulser\r\nBannir\r\nSupprimer le compte\r\nSe TP au joueur\r\nObserver le joueur (Spec)\r\n", "Ok", "Annuler");
  447.     }
  448.     else if(!gAdminsConnected)
  449.     {
  450.         ShowPlayerDialog(playerid, DIALOG_PLAYER_MENU, DIALOG_STYLE_LIST, "Que voulez-vous faire ?", "Envoyer un MP\r\nVoter pour l'expulsion", "Ok", "");
  451.     }
  452.     else
  453.     {
  454.         ShowPlayerDialog(playerid, DIALOG_PM_INPUT, DIALOG_STYLE_INPUT, "Message Privé", "Entrez le texte de votre message:", "Envoyer", "Annuler");
  455.     }
  456.    
  457. }
  458.  
  459. public OnPlayerCommandText(playerid, cmdtext[])
  460. {
  461.     if(AreStringsEquals("/deban", cmdtext))
  462.     {
  463.         if(GetAdminRank(playerid) == ADMIN)
  464.         {
  465.             ShowPlayerDialog(playerid,  DIALOG_UNBAN_INPUT, DIALOG_STYLE_INPUT, "Debanissement",  "Veuillez renseigner le pseudonyme du joueur à debannir:", "Debannir", "Annuler");
  466.         }
  467.         else { SendClientMessage(playerid, COLOR_RED, "[Erreur]Cette commande est résérvé aux administrateurs"); }
  468.     }
  469.     else if(AreStringsEquals("/tp", cmdtext))
  470.     {
  471.         if(IsAdmin(playerid)) { SetPVarInt(playerid, "tpenabled", 1); }
  472.     }
  473.     else if(AreStringsEquals("/cfg", cmdtext))
  474.     {
  475.         if(GetAdminRank(playerid) >= ADMIN) { ShowPlayerDialog(playerid, DIALOG_CFG_MENU, DIALOG_STYLE_LIST, "Configuration:", "VoteKick Delay\r\nVotesKick Neededr\nMin Password Lenght\r\nDefault Money\r\n", "Ok", ""); }
  476.     }
  477.    
  478.     else
  479.     {
  480.         SendClientMessage(playerid, COLOR_RED, "[Erreur]Commande innexistante");
  481.     }
  482.     return 1;
  483. }
  484. stock IsPlayerLoguedIn(playerid)//Cette fonction permet de verifier facilement si un joueurs est logué ou non
  485. {
  486.     /*
  487.     NB: Il est recommandé d'utiliser directement la PVar pour savoir si
  488.     le joueur est logué ou non à partir d'un autre fichier.
  489.     */
  490.    
  491.     if(GetPVarInt(playerid, "logued") && IsPlayerConnected(playerid))
  492.     {
  493.         return true;
  494.     }
  495.     else{ return false;}
  496. }
  497.  
  498. stock AreStringsEquals(string1[], string2[])
  499. {
  500.    
  501.     /*
  502.     NB: la fonction strcmp() retournant egalement 0 si une des deux chaines de carractére est vide, il est important de verigier qu'aucune des deux ne soit vide
  503.     */
  504.     if(!strcmp(string1, string2) && strlen(string1) > 1 && strlen(string2) > 1)//Si les deux chaines de carractéres sont struictements identiques
  505.     {
  506.         return true;//on retourne vrais
  507.     }
  508.     else { return false;}//sinon, on retourne faux
  509.    
  510. }
  511.  
  512. stock SafeGivePlayerMoney(playerid, ammount)
  513. {
  514.     if(IsPlayerLoguedIn(playerid))
  515.     {
  516.         new pName[MAX_PLAYER_NAME];
  517.         GetPlayerName(playerid, pName, sizeof(pName));
  518.         udb_UserSetInt(pName, "Money", udb_UserInt(pName, "Money")+ammount);
  519.        
  520.         SetPlayerMoney(playerid, udb_UserInt(pName, "Money"));
  521.         return udb_UserInt(pName, "Money");
  522.     }
  523.     else{ return false;}
  524. }
  525.  
  526. stock IsAdmin(playerid)
  527. {
  528.     if(GetAdminRank(playerid) > MEMBER)
  529.     {
  530.         return true;
  531.     }
  532.     else{ return false;}
  533. }
  534.  
  535. stock OnPlayerLogin(playerid)
  536. {
  537.     new pName[MAX_PLAYER_NAME];
  538.     GetPlayerName(playerid, pName, sizeof(pName));
  539.    
  540.     new pIp[MAX_STRING];
  541.     GetPlayerIp(playerid, pIp, sizeof(pIp));//On récupére l'adresse IP du joueur
  542.    
  543.     SetPVarInt(playerid, "logued", 1);//Le joueur est connécté
  544.     SetPVarInt(playerid, "Admin", udb_UserInt(pName, "Admin"));
  545.     SetPVarInt(playerid, "VoteCount", 0);
  546.     SetPVarInt(playerid, "Voted", 0);
  547.    
  548.     if(IsAdmin(playerid))
  549.     { gAdminsConnected++; SetPVarInt(playerid, "tpenabled", 0);}
  550.    
  551.     if(!AreStringsEquals(udb_User(pName, "Last_IP"),pIp))//Si son adresse IP est différente de la dérniére
  552.     {
  553.         udb_UserSet(pName, "Last_IP", pIp);//On conserve son adresse IP
  554.     }
  555. }
  556.  
  557. stock OnPlayerRegister(playerid)//Attention: Cette "callback" n'est appelé que si l'inscription a réussie
  558. {
  559.     new pName[MAX_PLAYER_NAME];
  560.     GetPlayerName(playerid, pName, sizeof(pName));
  561.    
  562.     new pIp[MAX_STRING];
  563.     GetPlayerIp(playerid, pIp, sizeof(pIp));//On récupére l'adresse IP du joueur
  564.     udb_UserSet(pName, "Registered_IP", pIp);//On stocke son adresse IP d'enregistrement
  565.     udb_UserSet(pName, "Last_IP", pIp);//Comme il viens de s'enregistrer, c'est à la fois son IP d'enregistrement et sa dérniére IP connue
  566.     udb_UserSetInt(pName, "Money", gDefaultMoney);//On donne au joueur la somme d'argent de depart
  567.     udb_UserSetInt(pName,"Admin", MEMBER);
  568.     udb_UserSetInt(pName, "Banned", 0);
  569. }
  570.  
  571. stock OnPlayerVoteKick(playerid)
  572. {
  573.     if(!GetPVarInt(playerid, "Voted") && IsPlayerLoguedIn(playerid))//Si le joueur n'a pas dèja voyé et qu'il est bien logué
  574.     {
  575.         SetPVarInt(playerid, "Voted", 1);//Cette PVar est un booleen indiquant si le joueur est en trains de participer à un "votekick"
  576.         SetPVarInt(playerClickedID, "voteCount", GetPVarInt(playerClickedID, "voteCount")+1);//Cette PVar recensse le nombre de votes positives pour l'expulsion du joueur
  577.         SetTimerEx("AbortVoteKick", gVoteKickDelay*1000, false, "i", playerClickedID);
  578.         ShowPlayerDialog(playerid,  DIALOG_VOTE_KICK_SENT, DIALOG_STYLE_MSGBOX, "Vote envoyé",  "Votre vote a bien été pris en compte", "Ok", "");
  579.     }
  580.     else { ShowPlayerDialog(playerid, DIALOG_VOTE_KICK_FAILED, DIALOG_STYLE_MSGBOX, "Erreur", "Vous ne pouvez voter que pour un joueur à la fois", "Ok", ""); }
  581. }
  582.  
  583. stock ResetVoteKick()//Cette fonction effectue une R-à-Z des "votekick"
  584. {
  585.     new i;
  586.     for(i = 0; i <= gMaxPlayers;i++)
  587.     {
  588.         if(GetPVarInt(i, "Voted"))
  589.         { SetPVarInt(i, "Voted", 0); }
  590.     }
  591. }
  592.  
  593. public AbortVoteKick(votedPlayerID)//Cette fonction permet d'annuler un "votekick"
  594. {
  595.     SetPVarInt(votedPlayerID, "VoteCount", 0);
  596.     ResetVoteKick();
  597. }
  598.  
  599. stock SetAdminRank(playerid, aRank)//Comme l'indique son nom, cette fonction permet de definire le rang "Admin" d'un joueur
  600. {
  601.     new pName[MAX_PLAYER_NAME];
  602.     GetPlayerName(playerid, pName, sizeof(pName));
  603.     udb_UserSetInt(pName, "Admin", aRank);
  604.     SetPVarInt(playerid, "Admin", aRank);
  605. }
  606.  
  607. stock GetAdminRank(playerid)//Cette fonction permet de récupérer le rang "Admin" d'un joueur
  608. {
  609.     if(IsPlayerLoguedIn(playerid))
  610.     {
  611.         new pName[MAX_PLAYER_NAME];
  612.         GetPlayerName(playerid, pName, sizeof(pName));
  613.        
  614.        
  615.        
  616.         if(udb_UserInt(pName, "Admin") != GetPVarInt(playerid, "Admin"))//Au cas où il y aurais un probléme
  617.         { SetPVarInt(playerid, "Admin", udb_UserInt(pName, "Admin")); }
  618.         return GetPVarInt(playerid, "Admin");
  619.     }
  620.     else{ return -1; }
  621.    
  622. }
  623.  
  624. stock OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ)
  625. {
  626.     if(IsAdmin(playerid) && GetPVarInt(playerid, "tpenabled"))
  627.     {
  628.         SetPlayerPosFindZ(playerid, fX, fY, fZ);
  629.     }
  630.    
  631. }
  632.  
  633. stock SendMessageToAdmins(msg[])
  634. {
  635.     new i;
  636.     for(i = 0; i <= gMaxPlayers; i++)
  637.     {
  638.         if(IsAdmin(i))
  639.         { SendClientMessage(i, COLOR_YELLOW, msg); }
  640.     }
  641. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement