added lvl command to hide lvl, also added colors and chat tag for lvl
This commit is contained in:
parent
f9e03adff1
commit
f6a44654b2
@ -1,26 +1,120 @@
|
||||
#include <sourcemod>
|
||||
#include <SteamWorks>
|
||||
#include <json>
|
||||
#include <ccc>
|
||||
#include <cstrike>
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "Racetimer Rank",
|
||||
author = "jenz",
|
||||
description = "Give racetimer points as a level clan tag to players",
|
||||
description = "Give racetimer points as a level clan tag to players, also for chat tag",
|
||||
version = "1.0",
|
||||
url = ""
|
||||
};
|
||||
|
||||
bool g_b_ignoring_tags[MAXPLAYERS + 1];
|
||||
Database g_hDatabase;
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
for(int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if(IsClientInGame(client))
|
||||
{
|
||||
OnClientPostAdminFilter(client);
|
||||
}
|
||||
}
|
||||
RegConsoleCmd("sm_lvl", Command_LVLTag, "Turns the LVL tag feature on or off");
|
||||
if (!g_hDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
|
||||
return;
|
||||
}
|
||||
|
||||
for(int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if(IsClientInGame(client))
|
||||
{
|
||||
OnClientPostAdminFilter(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
if (!g_hDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
}
|
||||
g_hDatabase = db;
|
||||
|
||||
for(int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if(IsClientInGame(client))
|
||||
{
|
||||
OnClientPostAdminFilter(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Action Command_LVLTag(int client, int args)
|
||||
{
|
||||
if (!g_hDatabase)
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
//i am only adding this shit because lighty wanted it to be turn-off able, after half a year probably only 7 people will have made use of it.
|
||||
//kinda hate wasting time on pointless stuff like this.
|
||||
char sSID[64];
|
||||
char sQuery[512];
|
||||
if (g_b_ignoring_tags[client])
|
||||
{
|
||||
g_b_ignoring_tags[client] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_b_ignoring_tags[client] = true;
|
||||
}
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
Format(sQuery, sizeof(sQuery), "insert into zetimer_table_ignore_tag (`steam_auth`, `is_ignoring`) values ('%s', '%i') ON DUPLICATE KEY UPDATE `is_ignoring` = '%i'", sSID, g_b_ignoring_tags[client], g_b_ignoring_tags[client]);
|
||||
g_hDatabase.Query(SQL_FinishedQuery, sQuery, GetClientSerial(client), DBPrio_Low);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, int iSerial)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error 3: %s", error);
|
||||
}
|
||||
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(iSerial)) == 0)
|
||||
{
|
||||
delete results;
|
||||
return;
|
||||
}
|
||||
delete results;
|
||||
|
||||
if (g_b_ignoring_tags[client])
|
||||
{
|
||||
PrintToChat(client, "Now hiding LVL tag.");
|
||||
CS_SetClientClanTag(client, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintToChat(client, "Now displaying LVL tag again.");
|
||||
OnClientPostAdminFilter(client);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
g_b_ignoring_tags[client] = false;
|
||||
}
|
||||
|
||||
public void OnClientPostAdminFilter(int client)
|
||||
@ -36,9 +130,10 @@ public void OnClientPostAdminFilter(int client)
|
||||
return;
|
||||
}
|
||||
|
||||
g_b_ignoring_tags[client] = false;
|
||||
if (!HasClanTag(client))
|
||||
{
|
||||
check_client_racetimer_rank(client);
|
||||
check_ignoring_tags(client);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +144,49 @@ public bool HasClanTag(int client)
|
||||
return strlen(sClanID) > 1; //without a tag the len is 1.
|
||||
}
|
||||
|
||||
public void check_ignoring_tags(int client)
|
||||
{
|
||||
char sQuery[512];
|
||||
char sSID[64];
|
||||
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
Format(sQuery, sizeof(sQuery), "select is_ignoring from zetimer_table_ignore_tag where steam_auth = '%s'", sSID);
|
||||
g_hDatabase.Query(SQL_OnQueryCompletedIgnoreTag, sQuery, GetClientSerial(client), DBPrio_Low);
|
||||
}
|
||||
|
||||
public void SQL_OnQueryCompletedIgnoreTag(Database db, DBResultSet results, const char[] error, int iSerial)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
delete results;
|
||||
LogError("Query error 3: %s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(iSerial)) == 0)
|
||||
{
|
||||
delete results;
|
||||
return;
|
||||
}
|
||||
|
||||
int val = 0;
|
||||
if (results.RowCount && results.FetchRow())
|
||||
{
|
||||
val = results.FetchInt(0);
|
||||
}
|
||||
|
||||
delete results;
|
||||
if (val == 1)
|
||||
{
|
||||
g_b_ignoring_tags[client] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
check_client_racetimer_rank(client);
|
||||
}
|
||||
}
|
||||
|
||||
public void check_client_racetimer_rank(int client)
|
||||
{
|
||||
char sSID[64];
|
||||
@ -104,6 +242,36 @@ public int OnTransferResponse(char[] sData, int iSerial)
|
||||
char tag[64];
|
||||
Format(tag, sizeof(tag), "[LVL %i]", I_player_points/1000);
|
||||
CS_SetClientClanTag(client, tag);
|
||||
|
||||
int I_rank = obj.GetInt("Rank") //if no endpoint for steamID default value is -1
|
||||
if (0 < I_rank < 1000) //only give chat tag to top 1000
|
||||
{
|
||||
if (player_has_no_chattag(client))
|
||||
{
|
||||
set_level_tag(client, I_player_points/1000);
|
||||
}
|
||||
}
|
||||
json_cleanup_and_delete(obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public bool player_has_no_chattag(int client)
|
||||
{
|
||||
char tag[256];
|
||||
CCC_GetTag(client, tag, sizeof(tag));
|
||||
return strlen(tag) < 2;
|
||||
}
|
||||
|
||||
public void set_level_tag(int client, int lvl)
|
||||
{
|
||||
char tag[64];
|
||||
Format(tag, sizeof(tag), "[LVL %i] ", lvl);
|
||||
CCC_SetTag(client, tag);
|
||||
|
||||
char hexadecimals[16];
|
||||
int red = (lvl * 17) % 256;
|
||||
int green = ((lvl + 50) * 13) % 256;
|
||||
int blue = ((lvl + 100) * 19) % 256;
|
||||
Format(hexadecimals, sizeof(hexadecimals), "%02X%02X%02X", red, green, blue);
|
||||
CCC_SetColor(client, CCC_TagColor, StringToInt(hexadecimals, 16), false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user