Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 14.26 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <colors>
  4. #include <smlib>
  5. #include <hosties>
  6. #include <lastrequest>
  7.  
  8.  
  9. #define PLUGIN_NAME         "terrodumois"
  10. #define PLUGIN_AUTHOR       "Dertione"
  11. #define PLUGIN_DESCRIPTION  "terrodumois"
  12. #define PLUGIN_VERSION      "1.0"
  13. #define PLUGIN_URL          "http://www.supreme-elite.fr/"
  14. #define DATABASE_NAME "dertione"
  15.  
  16.  
  17. new kill_knife[MAXPLAYERS+1];
  18. new flag1[MAXPLAYERS+1] = 0;
  19. new id_client[MAXPLAYERS+1];
  20. new onDV;
  21. new Handle:g_hDatabase = INVALID_HANDLE;
  22.  
  23. public Plugin:myinfo =
  24. {
  25.     name        = PLUGIN_NAME,
  26.     author      = PLUGIN_AUTHOR,
  27.     description = PLUGIN_DESCRIPTION,
  28.     version     = PLUGIN_VERSION,
  29.     url         = PLUGIN_URL,
  30. };
  31.  
  32.  
  33.  
  34. public OnPluginStart()
  35. {
  36.     new iFcvar = FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_DEMO|FCVAR_DONTRECORD;
  37.    
  38.     CreateConVar("se_point_base_description",       PLUGIN_DESCRIPTION, "Description",  iFcvar);
  39.     CreateConVar("se_point_base_version",           PLUGIN_VERSION,     "Version",      iFcvar);
  40.     CreateConVar("se_point_base_author",            PLUGIN_AUTHOR,      "Author",       iFcvar);
  41.     CreateConVar("se_point_base_url",               PLUGIN_URL,         "URL",          iFcvar);
  42.     HookEvent("player_spawn", Event_PlayerSpawn);
  43.     HookEvent("player_hurt", Event_PlayerHurt);
  44.     RegConsoleCmd("say", Client_Say, "", 0);
  45.     RegConsoleCmd("rank", Command_Rank, "Commande pour voir le rank, son score");
  46.     RegConsoleCmd("top10", Command_Rank10, "Commande pour voir le top 10 du rank, son score");
  47. }
  48.  
  49. public OnMapStart()
  50. {
  51.     ConnectBDD();
  52.     CheckJour();
  53.     PrecacheModel("models/player/slow/50cent/slow.mdl",true);
  54.     onDV=0;
  55. }
  56.  
  57. public OnMapEnd()
  58. {
  59.     DisconnectSQL();
  60. }
  61.  
  62. public OnClientPutInServer(client)
  63. {
  64.     id_client[client]=GetClientId(client);
  65.     kill_knife[client]=0;
  66.     updatename(client);
  67.     PrintToChat(client, "Votre id client dans la base de donnee est %i", id_client[client]);
  68.     CPrintToChat(client, "{green}[RankTerro] {red} Rank terro activer !");
  69.     CPrintToChat(client, "{green}[RankTerro] {red} Rank terro activer !");
  70. }
  71.  
  72. public OnClientDisconnect(client)
  73. {
  74.     GiveClientPoint(client, kill_knife[client], "ajout quand le joueur se déconnecte");
  75. }
  76. //////////////////////////////////////////////////////////////////////////////
  77. //Detection du dernier terroristes///////////////////////////////////////////
  78. /////////////////////////////////////////////////////////////////////////////
  79.  
  80.  
  81.  
  82. public Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
  83. {
  84.     new client = GetClientOfUserId(GetEventInt(event,"userid"));
  85.     new attacker = GetClientOfUserId(GetEventInt(event,"attacker"));
  86.    
  87.     new health = GetClientHealth(client);
  88.     decl String:weapon[10];
  89.     GetEventString(event,"weapon", weapon, sizeof(weapon));
  90.  
  91.     if (IsClientConnected(client) && IsClientInGame(client) && health<=0)
  92.     if (!(GetClientTeam(client)==2) && StrEqual(weapon, "knife") && !IsClientInLastRequest(client))
  93.     {
  94.         CPrintToChat(attacker,"{green}[RANK] {red} Tu as gagner 1 points grace a ton cut, ton rank s'actualisera a ta deconnexion");
  95.         kill_knife[attacker]++;
  96.         flag1[client]=1;
  97.     }
  98. }
  99.  
  100.  
  101.  
  102. public Event_PlayerSpawn(Handle:event,String:name[], bool:dontBroadcast)
  103. {
  104.     new client = GetClientOfUserId(GetEventInt(event,"userid"));
  105.     new idwinner=0;
  106.     flag1[client]=0;
  107.     new team = GetClientTeam(client);
  108.     if(CheckSQL())
  109.     {
  110.         new Handle:hQuery = INVALID_HANDLE;
  111.         new String:sQuery[255];
  112.         Format(sQuery, sizeof(sQuery), "SELECT id FROM terrodumois_clients WHERE terrodumois=1");
  113.         hQuery = SQL_Query(g_hDatabase, sQuery);
  114.         SQL_FetchRow(hQuery);
  115.         idwinner = SQL_FetchInt(hQuery, 0);
  116.         CPrintToChat(client,"{red}[RANK]{green} Tape !rank pour connaitre ton nombre de point et ta position ");
  117.         CPrintToChat(client,"{red}[RANK]{green} Tape !top10 pour connaitre le top 10 ");
  118.         if(idwinner==id_client[client]&&team==2)
  119.         {
  120.             CreateTimer(2.0, TimerSpawn, client);
  121.         }
  122.     }
  123.     else
  124.     {
  125.         DisconnectSQL();
  126.     }
  127. }
  128.  
  129. public Action:TimerSpawn(Handle:timer, any:client)
  130. {
  131.     SetEntityModel(client, "models/player/slow/50cent/slow.mdl");
  132.     CPrintToChat(client,"{green} TU ES LE NUMBER ONE");
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139. public Action:Client_Say(client, args)
  140. {
  141.     decl String:Cmd[128];
  142.     GetCmdArgString(Cmd, 127);
  143.     StripQuotes(Cmd);
  144.     TrimString(Cmd);
  145.    
  146.     if(IsClientInLastRequest(client)&&IsPlayerAlive(client))
  147.     {
  148.         if(flag1[client]==0)
  149.         {
  150.             if (StrEqual(Cmd, "!lr", true) || StrEqual(Cmd, "/lr", true))
  151.             {
  152.                 CPrintToChat(client,"{green}[RANK] {red} TU as gagner 3 points grace a ta lr");
  153.                 kill_knife[client]=kill_knife[client]+3;
  154.                 GiveClientPoint(client, kill_knife[client], "Ce terroriste a eu sa DV !");
  155.                 kill_knife[client]=0;
  156.                 flag1[client]= 1;
  157.             }
  158.         }
  159.     }
  160. }
  161.  
  162.  
  163. public menuHandler1(Handle:menu, MenuAction:action, client, param2)
  164. {
  165.     if (action == MenuAction_Select)
  166.     {
  167.        
  168.     }
  169.     /* If the menu was cancelled, print a message to the server about it. */
  170.     else if (action == MenuAction_Cancel)
  171.     {
  172.         PrintToServer("Client %d's menu was cancelled.  Reason: %d", client, param2);
  173.     }
  174.     /* If the menu has ended, destroy it */
  175.     else if (action == MenuAction_End)
  176.     {
  177.         CloseHandle(menu);
  178.     }
  179. }
  180.  
  181.  
  182. public Action:Command_Rank(client, args)
  183. {
  184.     new Nombre_de_point = GetClientPoint(client);
  185.     new Position_total = GetClientTotal(client);
  186.     new Position_joueur = GetClientPosition(client);
  187.     new String:point[4];
  188.     new String:point2[10]="vous avez ";
  189.     new String:point3[10]=" point";
  190.     new String:point4[24];
  191.     Position_joueur++;
  192.     IntToString(Nombre_de_point,point,sizeof(point));
  193.     Format(point4, sizeof(point4), "%s%s", point2, point);
  194.     Format(point4, sizeof(point4), "%s%s", point4, point3);
  195.    
  196.     new Handle:menu = CreateMenu(menuHandler1);
  197.     SetMenuTitle(menu, "Vous etes : %i/%i", Position_joueur, Position_total);
  198.     AddMenuItem(menu, point4, point4 );
  199.     SetMenuExitButton(menu, true);
  200.     DisplayMenu(menu, client, 20);
  201.     return Plugin_Handled;
  202. }
  203.  
  204. public menuHandler10(Handle:menu, MenuAction:action, client, param2)
  205. {
  206.     if (action == MenuAction_Select)
  207.     {
  208.        
  209.     }
  210.     /* If the menu was cancelled, print a message to the server about it. */
  211.     else if (action == MenuAction_Cancel)
  212.     {
  213.         PrintToServer("Client %d's menu was cancelled.  Reason: %d", client, param2);
  214.     }
  215.     /* If the menu has ended, destroy it */
  216.     else if (action == MenuAction_End)
  217.     {
  218.         CloseHandle(menu);
  219.     }
  220. }
  221.  
  222. public Action:Command_Rank10(client, args)
  223. {
  224.     ShowMOTDPanel(client, "Top10", "http://s.supreme-elite.fr/regle/Rank/index.php", MOTDPANEL_TYPE_URL);
  225. }
  226.  
  227.  
  228. public updatename(iClient)
  229. {
  230.     if(CheckSQL())
  231.     {
  232.         decl String:sAuth[20];
  233.         GetClientAuthString(iClient, sAuth, sizeof(sAuth));
  234.  
  235.         if(GetClientAuthString(iClient, sAuth, sizeof(sAuth)) == false)
  236.         {
  237.             ThrowNativeError(2, "User auth ID not availlable yet, please try later.");
  238.         }
  239.  
  240.         decl String:szClientName[100];
  241.         decl String:szClientNameSQL[64];
  242.         GetClientName(iClient, szClientName, sizeof(szClientName));
  243.         SQL_EscapeString(g_hDatabase, szClientName, szClientNameSQL, sizeof(szClientNameSQL));
  244.  
  245.         new String:sQuery[255];
  246.         Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET name='%s' WHERE authid='%s'", szClientNameSQL, sAuth);
  247.         SQL_FastQuery(g_hDatabase, sQuery);
  248.     }
  249.     else
  250.     {
  251.         DisconnectSQL();
  252.     }
  253. }
  254.  
  255. public CheckJour()
  256. {
  257.     new String:buffer[10];
  258.     FormatTime(buffer, sizeof(buffer), "%w", GetTime());
  259.     new day = StringToInt(buffer);
  260.     FormatTime(buffer, sizeof(buffer), "%H", GetTime());
  261.     new hour = StringToInt(buffer);
  262.     FormatTime(buffer, sizeof(buffer), "%M", GetTime());
  263.     new minute = StringToInt(buffer);
  264.    
  265.    
  266.     if(day==5)
  267.     {
  268.         PrintToServer("%i",day);
  269.         if(hour==20)
  270.         {
  271.             PrintToServer("%i",hour);
  272.             if(minute<=45&&minute>=0)
  273.             {
  274.                 ResetTerro();
  275.             }
  276.         }
  277.     }
  278. }
  279.  
  280. public ResetTerro()
  281. {
  282.     if(CheckSQL())
  283.     {
  284.         new Handle:hQuery = INVALID_HANDLE;
  285.         new String:sQuery[255];
  286.         new id;
  287.         Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET terrodumois=0 ");
  288.         hQuery = SQL_Query(g_hDatabase, sQuery);
  289.        
  290.         Format(sQuery, sizeof(sQuery), "SELECT id FROM terrodumois_clients ORDER BY credit DESC LIMIT 0,1");
  291.         hQuery = SQL_Query(g_hDatabase, sQuery);
  292.         SQL_FetchRow(hQuery);
  293.         id = SQL_FetchInt(hQuery, 0);
  294.        
  295.         Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET terrodumois = 1 WHERE id=%i ", id);
  296.         hQuery = SQL_Query(g_hDatabase, sQuery);
  297.        
  298.         Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET credit=0 ");
  299.         hQuery = SQL_Query(g_hDatabase, sQuery);
  300.         CloseHandle(hQuery);
  301.     }
  302.     else
  303.     {
  304.         DisconnectSQL();
  305.     }
  306. }
  307.  
  308. public SetWinner(id)
  309. {
  310.     if(CheckSQL())
  311.     {
  312.         new Handle:hQuery = INVALID_HANDLE;
  313.         new String:sQuery[255];
  314.         Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET terrodumois = 1 WHERE id=%i ", id);
  315.         hQuery = SQL_Query(g_hDatabase, sQuery);
  316.         CloseHandle(hQuery);
  317.     }
  318.     else
  319.     {
  320.         DisconnectSQL();
  321.     }
  322. }
  323.  
  324. public ResetTable()
  325. {
  326.     if(CheckSQL())
  327.     {
  328.         new Handle:hQuery = INVALID_HANDLE;
  329.         new String:sQuery[255];
  330.         Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET credit=0 ");
  331.         hQuery = SQL_Query(g_hDatabase, sQuery);
  332.         CloseHandle(hQuery);
  333.     }
  334.     else
  335.     {
  336.         DisconnectSQL();
  337.     }
  338. }
  339.  
  340.  
  341. public GetClientIdWinner()
  342. {
  343.     if(CheckSQL())
  344.     {
  345.         new Handle:hQuery = INVALID_HANDLE;
  346.         new String:sQuery[255];
  347.         Format(sQuery, sizeof(sQuery), "SELECT id FROM terrodumois_clients ORDER BY credit DESC LIMIT 0,1");
  348.         hQuery = SQL_Query(g_hDatabase, sQuery);
  349.         SQL_FetchRow(hQuery);
  350.         return SQL_FetchInt(hQuery, 0);
  351.     }
  352.     else
  353.     {
  354.         DisconnectSQL();
  355.     }
  356.     return false;
  357. }
  358.  
  359. public GetClientId(iClient)
  360. {
  361.     if(CheckSQL())
  362.     {
  363.         new String:sAuth[20];
  364.         new String:szClientName[100];
  365.         new String:szClientNameSQL[100];
  366.         GetClientName(iClient, szClientName, sizeof(szClientName));
  367.         SQL_EscapeString(g_hDatabase, szClientName, szClientNameSQL, sizeof(szClientNameSQL));
  368.         if(GetClientAuthString(iClient, sAuth, sizeof(sAuth)) == false)
  369.         {
  370.             ThrowNativeError(2, "User auth ID not availlable yet, please try later.");
  371.         }
  372.        
  373.         new Handle:hQuery = INVALID_HANDLE;
  374.         new String:sQuery[255];
  375.         Format(sQuery, sizeof(sQuery), "SELECT id FROM terrodumois_clients WHERE authid='%s'", sAuth);
  376.         hQuery = SQL_Query(g_hDatabase, sQuery);
  377.         if(SQL_GetRowCount(hQuery) == 0)
  378.         {
  379.             Format(sQuery, sizeof(sQuery), "INSERT INTO terrodumois_clients (authid, name, credit, terrodumois) VALUES('%s', '%s', 0, 0)", sAuth, szClientNameSQL );
  380.             hQuery = SQL_Query(g_hDatabase, sQuery);
  381.             return SQL_GetInsertId(hQuery);
  382.         } else {
  383.             SQL_FetchRow(hQuery);
  384.             return SQL_FetchInt(hQuery, 0);
  385.         }
  386.     }
  387.     else
  388.     {
  389.         DisconnectSQL();
  390.     }
  391.     return false;
  392. }
  393.  
  394.  
  395.  
  396. public GetClientPosition(iClient)
  397. {
  398.     if(CheckSQL())
  399.     {
  400.         new Handle:hQuery = INVALID_HANDLE;
  401.         new String:sQuery[255];
  402.         new pointjoueur= GetClientPoint(iClient);
  403.         Format(sQuery, sizeof(sQuery), "SELECT count(*) FROM terrodumois_clients WHERE credit > %i ", pointjoueur);
  404.         hQuery = SQL_Query(g_hDatabase, sQuery);
  405.         SQL_FetchRow(hQuery);
  406.         return SQL_FetchInt(hQuery, 0);
  407.     }
  408.     else
  409.     {
  410.         DisconnectSQL();
  411.     }
  412.     return false;
  413. }
  414.  
  415. public GetClientTotal(iClient)
  416. {
  417.     if(CheckSQL())
  418.     {
  419.         new Handle:hQuery = INVALID_HANDLE;
  420.         new String:sQuery[255];
  421.         Format(sQuery, sizeof(sQuery), "SELECT count(*) FROM terrodumois_clients");
  422.         hQuery = SQL_Query(g_hDatabase, sQuery);
  423.         SQL_FetchRow(hQuery);
  424.         return SQL_FetchInt(hQuery, 0);
  425.     }
  426.     else
  427.     {
  428.         DisconnectSQL();
  429.     }
  430.     return false;
  431. }
  432.  
  433.  
  434. public GetClientPoint(iClient)
  435. {
  436.     if(CheckSQL())
  437.     {
  438.         new iClientId = GetClientId(iClient);
  439.         new Handle:hQuery = INVALID_HANDLE;
  440.         new String:sQuery[255];
  441.         Format(sQuery, sizeof(sQuery), "SELECT credit FROM terrodumois_clients WHERE id=%i", iClientId);
  442.         hQuery = SQL_Query(g_hDatabase, sQuery);
  443.         SQL_FetchRow(hQuery);
  444.         return SQL_FetchInt(hQuery, 0);
  445.     }
  446.     else
  447.     {
  448.         DisconnectSQL();
  449.     }
  450.     return false;
  451. }
  452.  
  453. public bool:GiveClientPoint(iClient, ipoint, const String:sMessage[])
  454. {
  455.     if(CheckSQL())
  456.     {
  457.         new iTotal = ipoint + GetClientPoint(iClient);
  458.         new iClientId = GetClientId(iClient);
  459.        
  460.         new String:sQuery[255];
  461.         Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET credit = %i WHERE id=%i", iTotal, iClientId);
  462.         SQL_Query(g_hDatabase, sQuery);
  463.        
  464.         Format(sQuery, sizeof(sQuery), "INSERT INTO terrodumois_operations (client_id, amount, date, message) VALUES(%i, %i, NOW(), '%s')", iClientId, ipoint, sMessage);
  465.         SQL_Query(g_hDatabase, sQuery);
  466.         return true;
  467.     }
  468.     else
  469.     {
  470.         DisconnectSQL();
  471.     }
  472.     return false;
  473. }
  474.  
  475. public bool:TakeClientPoint(iClient, ipoint, const String:sMessage[])
  476. {
  477.     if(CheckSQL())
  478.     {
  479.         new iTotal = GetClientPoint(iClient) - ipoint;
  480.         if(iTotal < 0)
  481.         {
  482.             iTotal = 0;
  483.         }
  484.         new iClientId = id_client[iClient];
  485.         new String:sQuery[255];
  486.         new String:sMessageBuffer[strlen(sMessage)+10];
  487.        
  488.         SQL_EscapeString(g_hDatabase, sMessage, sMessageBuffer, strlen(sMessageBuffer));
  489.         Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET credit = %i WHERE id=%i", iTotal, iClientId);
  490.         SQL_Query(g_hDatabase, sQuery);
  491.        
  492.         Format(sQuery, sizeof(sQuery), "INSERT INTO terrodumois_operations (client_id, amount, date, message) VALUES(%i, -%i, NOW(), '%s')", iClientId, ipoint, sMessageBuffer);
  493.         SQL_Query(g_hDatabase, sQuery);
  494.         return true;
  495.     }
  496.     else
  497.     {
  498.         DisconnectSQL();
  499.     }
  500.     return false;
  501. }
  502.  
  503. stock Team_GetPlayerAlive(team)
  504. {
  505.     new count;
  506.     for(new i=1; i <= GetMaxClients(); i++)
  507.     {
  508.         if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == team)
  509.         {
  510.             count++;
  511.         }
  512.     }
  513.     return count ;
  514. }
  515.  
  516.  
  517. stock All_GetPlayer()
  518. {
  519.     new count;
  520.     for(new i=1; i <= GetMaxClients(); i++)
  521.     {
  522.         if (IsClientInGame(i) && GetClientTeam(i) > 1)
  523.         {
  524.             count++;
  525.         }
  526.     }
  527.     return count;
  528. }
  529.  
  530.  
  531.  
  532. public ConnectBDD()
  533. {
  534.     // On check la config présente dans database.cfg
  535.     if (SQL_CheckConfig(DATABASE_NAME))
  536.     {
  537.         new String:error[255];
  538.         // On créé une connexion à la base de donné via la config présente dans database.cfg
  539.         g_hDatabase = SQL_Connect(DATABASE_NAME,true,error, sizeof(error));
  540.         if (g_hDatabase == INVALID_HANDLE)
  541.         {
  542.             LogMessage("Erreur de connexion: %s", error);
  543.         }
  544.         else
  545.         {
  546.             LogMessage("Connexion à la BDD MySQL réussie");
  547.         }
  548.     }
  549.     else
  550.     {
  551.         LogError("Impossible de trouvé <%s> dans le fichier databases.cfg", DATABASE_NAME);
  552.     }
  553.  
  554. }
  555.  
  556.  
  557. stock bool:DisconnectSQL()
  558. {
  559.     if(g_hDatabase != INVALID_HANDLE)
  560.     {
  561.         CloseHandle(g_hDatabase);
  562.         g_hDatabase = INVALID_HANDLE;
  563.     }
  564.    
  565.     return true;
  566. }
  567.  
  568. stock bool:CheckSQL()
  569. {
  570.     if(g_hDatabase == INVALID_HANDLE)
  571.     {
  572.         ConnectBDD();
  573.         return false ;
  574.     }
  575.    
  576.     return true;
  577. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement