Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdktools>
- #include <colors>
- #include <smlib>
- #include <hosties>
- #include <lastrequest>
- #define PLUGIN_NAME "terrodumois"
- #define PLUGIN_AUTHOR "Dertione"
- #define PLUGIN_DESCRIPTION "terrodumois"
- #define PLUGIN_VERSION "1.0"
- #define PLUGIN_URL "http://www.supreme-elite.fr/"
- #define DATABASE_NAME "dertione"
- new kill_knife[MAXPLAYERS+1];
- new flag1[MAXPLAYERS+1] = 0;
- new id_client[MAXPLAYERS+1];
- new onDV;
- new Handle:g_hDatabase = INVALID_HANDLE;
- public Plugin:myinfo =
- {
- name = PLUGIN_NAME,
- author = PLUGIN_AUTHOR,
- description = PLUGIN_DESCRIPTION,
- version = PLUGIN_VERSION,
- url = PLUGIN_URL,
- };
- public OnPluginStart()
- {
- new iFcvar = FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_DEMO|FCVAR_DONTRECORD;
- CreateConVar("se_point_base_description", PLUGIN_DESCRIPTION, "Description", iFcvar);
- CreateConVar("se_point_base_version", PLUGIN_VERSION, "Version", iFcvar);
- CreateConVar("se_point_base_author", PLUGIN_AUTHOR, "Author", iFcvar);
- CreateConVar("se_point_base_url", PLUGIN_URL, "URL", iFcvar);
- HookEvent("player_spawn", Event_PlayerSpawn);
- HookEvent("player_hurt", Event_PlayerHurt);
- RegConsoleCmd("say", Client_Say, "", 0);
- RegConsoleCmd("rank", Command_Rank, "Commande pour voir le rank, son score");
- RegConsoleCmd("top10", Command_Rank10, "Commande pour voir le top 10 du rank, son score");
- }
- public OnMapStart()
- {
- ConnectBDD();
- CheckJour();
- PrecacheModel("models/player/slow/50cent/slow.mdl",true);
- onDV=0;
- }
- public OnMapEnd()
- {
- DisconnectSQL();
- }
- public OnClientPutInServer(client)
- {
- id_client[client]=GetClientId(client);
- kill_knife[client]=0;
- updatename(client);
- PrintToChat(client, "Votre id client dans la base de donnee est %i", id_client[client]);
- CPrintToChat(client, "{green}[RankTerro] {red} Rank terro activer !");
- CPrintToChat(client, "{green}[RankTerro] {red} Rank terro activer !");
- }
- public OnClientDisconnect(client)
- {
- GiveClientPoint(client, kill_knife[client], "ajout quand le joueur se déconnecte");
- }
- //////////////////////////////////////////////////////////////////////////////
- //Detection du dernier terroristes///////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- public Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
- {
- new client = GetClientOfUserId(GetEventInt(event,"userid"));
- new attacker = GetClientOfUserId(GetEventInt(event,"attacker"));
- new health = GetClientHealth(client);
- decl String:weapon[10];
- GetEventString(event,"weapon", weapon, sizeof(weapon));
- if (IsClientConnected(client) && IsClientInGame(client) && health<=0)
- if (!(GetClientTeam(client)==2) && StrEqual(weapon, "knife") && !IsClientInLastRequest(client))
- {
- CPrintToChat(attacker,"{green}[RANK] {red} Tu as gagner 1 points grace a ton cut, ton rank s'actualisera a ta deconnexion");
- kill_knife[attacker]++;
- flag1[client]=1;
- }
- }
- public Event_PlayerSpawn(Handle:event,String:name[], bool:dontBroadcast)
- {
- new client = GetClientOfUserId(GetEventInt(event,"userid"));
- new idwinner=0;
- flag1[client]=0;
- new team = GetClientTeam(client);
- if(CheckSQL())
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- Format(sQuery, sizeof(sQuery), "SELECT id FROM terrodumois_clients WHERE terrodumois=1");
- hQuery = SQL_Query(g_hDatabase, sQuery);
- SQL_FetchRow(hQuery);
- idwinner = SQL_FetchInt(hQuery, 0);
- CPrintToChat(client,"{red}[RANK]{green} Tape !rank pour connaitre ton nombre de point et ta position ");
- CPrintToChat(client,"{red}[RANK]{green} Tape !top10 pour connaitre le top 10 ");
- if(idwinner==id_client[client]&&team==2)
- {
- CreateTimer(2.0, TimerSpawn, client);
- }
- }
- else
- {
- DisconnectSQL();
- }
- }
- public Action:TimerSpawn(Handle:timer, any:client)
- {
- SetEntityModel(client, "models/player/slow/50cent/slow.mdl");
- CPrintToChat(client,"{green} TU ES LE NUMBER ONE");
- }
- public Action:Client_Say(client, args)
- {
- decl String:Cmd[128];
- GetCmdArgString(Cmd, 127);
- StripQuotes(Cmd);
- TrimString(Cmd);
- if(IsClientInLastRequest(client)&&IsPlayerAlive(client))
- {
- if(flag1[client]==0)
- {
- if (StrEqual(Cmd, "!lr", true) || StrEqual(Cmd, "/lr", true))
- {
- CPrintToChat(client,"{green}[RANK] {red} TU as gagner 3 points grace a ta lr");
- kill_knife[client]=kill_knife[client]+3;
- GiveClientPoint(client, kill_knife[client], "Ce terroriste a eu sa DV !");
- kill_knife[client]=0;
- flag1[client]= 1;
- }
- }
- }
- }
- public menuHandler1(Handle:menu, MenuAction:action, client, param2)
- {
- if (action == MenuAction_Select)
- {
- }
- /* If the menu was cancelled, print a message to the server about it. */
- else if (action == MenuAction_Cancel)
- {
- PrintToServer("Client %d's menu was cancelled. Reason: %d", client, param2);
- }
- /* If the menu has ended, destroy it */
- else if (action == MenuAction_End)
- {
- CloseHandle(menu);
- }
- }
- public Action:Command_Rank(client, args)
- {
- new Nombre_de_point = GetClientPoint(client);
- new Position_total = GetClientTotal(client);
- new Position_joueur = GetClientPosition(client);
- new String:point[4];
- new String:point2[10]="vous avez ";
- new String:point3[10]=" point";
- new String:point4[24];
- Position_joueur++;
- IntToString(Nombre_de_point,point,sizeof(point));
- Format(point4, sizeof(point4), "%s%s", point2, point);
- Format(point4, sizeof(point4), "%s%s", point4, point3);
- new Handle:menu = CreateMenu(menuHandler1);
- SetMenuTitle(menu, "Vous etes : %i/%i", Position_joueur, Position_total);
- AddMenuItem(menu, point4, point4 );
- SetMenuExitButton(menu, true);
- DisplayMenu(menu, client, 20);
- return Plugin_Handled;
- }
- public menuHandler10(Handle:menu, MenuAction:action, client, param2)
- {
- if (action == MenuAction_Select)
- {
- }
- /* If the menu was cancelled, print a message to the server about it. */
- else if (action == MenuAction_Cancel)
- {
- PrintToServer("Client %d's menu was cancelled. Reason: %d", client, param2);
- }
- /* If the menu has ended, destroy it */
- else if (action == MenuAction_End)
- {
- CloseHandle(menu);
- }
- }
- public Action:Command_Rank10(client, args)
- {
- ShowMOTDPanel(client, "Top10", "http://s.supreme-elite.fr/regle/Rank/index.php", MOTDPANEL_TYPE_URL);
- }
- public updatename(iClient)
- {
- if(CheckSQL())
- {
- decl String:sAuth[20];
- GetClientAuthString(iClient, sAuth, sizeof(sAuth));
- if(GetClientAuthString(iClient, sAuth, sizeof(sAuth)) == false)
- {
- ThrowNativeError(2, "User auth ID not availlable yet, please try later.");
- }
- decl String:szClientName[100];
- decl String:szClientNameSQL[64];
- GetClientName(iClient, szClientName, sizeof(szClientName));
- SQL_EscapeString(g_hDatabase, szClientName, szClientNameSQL, sizeof(szClientNameSQL));
- new String:sQuery[255];
- Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET name='%s' WHERE authid='%s'", szClientNameSQL, sAuth);
- SQL_FastQuery(g_hDatabase, sQuery);
- }
- else
- {
- DisconnectSQL();
- }
- }
- public CheckJour()
- {
- new String:buffer[10];
- FormatTime(buffer, sizeof(buffer), "%w", GetTime());
- new day = StringToInt(buffer);
- FormatTime(buffer, sizeof(buffer), "%H", GetTime());
- new hour = StringToInt(buffer);
- FormatTime(buffer, sizeof(buffer), "%M", GetTime());
- new minute = StringToInt(buffer);
- if(day==5)
- {
- PrintToServer("%i",day);
- if(hour==20)
- {
- PrintToServer("%i",hour);
- if(minute<=45&&minute>=0)
- {
- ResetTerro();
- }
- }
- }
- }
- public ResetTerro()
- {
- if(CheckSQL())
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- new id;
- Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET terrodumois=0 ");
- hQuery = SQL_Query(g_hDatabase, sQuery);
- Format(sQuery, sizeof(sQuery), "SELECT id FROM terrodumois_clients ORDER BY credit DESC LIMIT 0,1");
- hQuery = SQL_Query(g_hDatabase, sQuery);
- SQL_FetchRow(hQuery);
- id = SQL_FetchInt(hQuery, 0);
- Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET terrodumois = 1 WHERE id=%i ", id);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET credit=0 ");
- hQuery = SQL_Query(g_hDatabase, sQuery);
- CloseHandle(hQuery);
- }
- else
- {
- DisconnectSQL();
- }
- }
- public SetWinner(id)
- {
- if(CheckSQL())
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET terrodumois = 1 WHERE id=%i ", id);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- CloseHandle(hQuery);
- }
- else
- {
- DisconnectSQL();
- }
- }
- public ResetTable()
- {
- if(CheckSQL())
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET credit=0 ");
- hQuery = SQL_Query(g_hDatabase, sQuery);
- CloseHandle(hQuery);
- }
- else
- {
- DisconnectSQL();
- }
- }
- public GetClientIdWinner()
- {
- if(CheckSQL())
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- Format(sQuery, sizeof(sQuery), "SELECT id FROM terrodumois_clients ORDER BY credit DESC LIMIT 0,1");
- hQuery = SQL_Query(g_hDatabase, sQuery);
- SQL_FetchRow(hQuery);
- return SQL_FetchInt(hQuery, 0);
- }
- else
- {
- DisconnectSQL();
- }
- return false;
- }
- public GetClientId(iClient)
- {
- if(CheckSQL())
- {
- new String:sAuth[20];
- new String:szClientName[100];
- new String:szClientNameSQL[100];
- GetClientName(iClient, szClientName, sizeof(szClientName));
- SQL_EscapeString(g_hDatabase, szClientName, szClientNameSQL, sizeof(szClientNameSQL));
- if(GetClientAuthString(iClient, sAuth, sizeof(sAuth)) == false)
- {
- ThrowNativeError(2, "User auth ID not availlable yet, please try later.");
- }
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- Format(sQuery, sizeof(sQuery), "SELECT id FROM terrodumois_clients WHERE authid='%s'", sAuth);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- if(SQL_GetRowCount(hQuery) == 0)
- {
- Format(sQuery, sizeof(sQuery), "INSERT INTO terrodumois_clients (authid, name, credit, terrodumois) VALUES('%s', '%s', 0, 0)", sAuth, szClientNameSQL );
- hQuery = SQL_Query(g_hDatabase, sQuery);
- return SQL_GetInsertId(hQuery);
- } else {
- SQL_FetchRow(hQuery);
- return SQL_FetchInt(hQuery, 0);
- }
- }
- else
- {
- DisconnectSQL();
- }
- return false;
- }
- public GetClientPosition(iClient)
- {
- if(CheckSQL())
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- new pointjoueur= GetClientPoint(iClient);
- Format(sQuery, sizeof(sQuery), "SELECT count(*) FROM terrodumois_clients WHERE credit > %i ", pointjoueur);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- SQL_FetchRow(hQuery);
- return SQL_FetchInt(hQuery, 0);
- }
- else
- {
- DisconnectSQL();
- }
- return false;
- }
- public GetClientTotal(iClient)
- {
- if(CheckSQL())
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- Format(sQuery, sizeof(sQuery), "SELECT count(*) FROM terrodumois_clients");
- hQuery = SQL_Query(g_hDatabase, sQuery);
- SQL_FetchRow(hQuery);
- return SQL_FetchInt(hQuery, 0);
- }
- else
- {
- DisconnectSQL();
- }
- return false;
- }
- public GetClientPoint(iClient)
- {
- if(CheckSQL())
- {
- new iClientId = GetClientId(iClient);
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- Format(sQuery, sizeof(sQuery), "SELECT credit FROM terrodumois_clients WHERE id=%i", iClientId);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- SQL_FetchRow(hQuery);
- return SQL_FetchInt(hQuery, 0);
- }
- else
- {
- DisconnectSQL();
- }
- return false;
- }
- public bool:GiveClientPoint(iClient, ipoint, const String:sMessage[])
- {
- if(CheckSQL())
- {
- new iTotal = ipoint + GetClientPoint(iClient);
- new iClientId = GetClientId(iClient);
- new String:sQuery[255];
- Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET credit = %i WHERE id=%i", iTotal, iClientId);
- SQL_Query(g_hDatabase, sQuery);
- Format(sQuery, sizeof(sQuery), "INSERT INTO terrodumois_operations (client_id, amount, date, message) VALUES(%i, %i, NOW(), '%s')", iClientId, ipoint, sMessage);
- SQL_Query(g_hDatabase, sQuery);
- return true;
- }
- else
- {
- DisconnectSQL();
- }
- return false;
- }
- public bool:TakeClientPoint(iClient, ipoint, const String:sMessage[])
- {
- if(CheckSQL())
- {
- new iTotal = GetClientPoint(iClient) - ipoint;
- if(iTotal < 0)
- {
- iTotal = 0;
- }
- new iClientId = id_client[iClient];
- new String:sQuery[255];
- new String:sMessageBuffer[strlen(sMessage)+10];
- SQL_EscapeString(g_hDatabase, sMessage, sMessageBuffer, strlen(sMessageBuffer));
- Format(sQuery, sizeof(sQuery), "UPDATE terrodumois_clients SET credit = %i WHERE id=%i", iTotal, iClientId);
- SQL_Query(g_hDatabase, sQuery);
- Format(sQuery, sizeof(sQuery), "INSERT INTO terrodumois_operations (client_id, amount, date, message) VALUES(%i, -%i, NOW(), '%s')", iClientId, ipoint, sMessageBuffer);
- SQL_Query(g_hDatabase, sQuery);
- return true;
- }
- else
- {
- DisconnectSQL();
- }
- return false;
- }
- stock Team_GetPlayerAlive(team)
- {
- new count;
- for(new i=1; i <= GetMaxClients(); i++)
- {
- if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == team)
- {
- count++;
- }
- }
- return count ;
- }
- stock All_GetPlayer()
- {
- new count;
- for(new i=1; i <= GetMaxClients(); i++)
- {
- if (IsClientInGame(i) && GetClientTeam(i) > 1)
- {
- count++;
- }
- }
- return count;
- }
- public ConnectBDD()
- {
- // On check la config présente dans database.cfg
- if (SQL_CheckConfig(DATABASE_NAME))
- {
- new String:error[255];
- // On créé une connexion à la base de donné via la config présente dans database.cfg
- g_hDatabase = SQL_Connect(DATABASE_NAME,true,error, sizeof(error));
- if (g_hDatabase == INVALID_HANDLE)
- {
- LogMessage("Erreur de connexion: %s", error);
- }
- else
- {
- LogMessage("Connexion à la BDD MySQL réussie");
- }
- }
- else
- {
- LogError("Impossible de trouvé <%s> dans le fichier databases.cfg", DATABASE_NAME);
- }
- }
- stock bool:DisconnectSQL()
- {
- if(g_hDatabase != INVALID_HANDLE)
- {
- CloseHandle(g_hDatabase);
- g_hDatabase = INVALID_HANDLE;
- }
- return true;
- }
- stock bool:CheckSQL()
- {
- if(g_hDatabase == INVALID_HANDLE)
- {
- ConnectBDD();
- return false ;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement