halloween: update

This commit is contained in:
neon 2019-09-11 13:34:25 +02:00
parent f5e17c4e9f
commit 38f6bf8bea
2 changed files with 221 additions and 173 deletions

Binary file not shown.

View File

@ -1,11 +1,10 @@
#pragma semicolon 1
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#include <multicolors>
#include <zombiereloaded>
#pragma semicolon 1
#pragma newdecls required
/* CONVARS */
@ -29,7 +28,6 @@ bool g_bPreAdminChecked[MAXPLAYERS+1];
bool g_bResponseFailed[MAXPLAYERS+1];
bool g_bResponsePassed[MAXPLAYERS+1];
/* INTEGERS */
int g_iCollected[MAXPLAYERS+1];
int g_iCounter = 0;
@ -42,7 +40,7 @@ public Plugin myinfo =
name = "UNLOZE Season Event (Halloween)",
author = "Neon",
description = "UNLOZE Season Event (Halloween)",
version = "2.0",
version = "2.1",
url = "https://steamcommunity.com/id/n3ontm"
};
@ -70,13 +68,6 @@ public void OnPluginStart()
RegConsoleCmd("sm_highscore", Command_HighScore, "Shows the Pumpkin HighScore");
AutoExecConfig();
char sError[256];
if (SQL_CheckConfig("season"))
g_hDatabase = SQL_Connect("season", true, sError, sizeof(sError));
if (g_hDatabase == null)
LogError("Could not connect to database: %s", sError);
}
//----------------------------------------------------------------------------------------------------
@ -212,13 +203,52 @@ public void OnMapStart()
AddFileToDownloadsTable("materials/models/unloze/cute_skeleton/skull3.vtf");
PrecacheModel("models/unloze/cute_skeleton.mdl");
AddFileToDownloadsTable("sound/unl1/season/witch.wav");
PrecacheSound("sound/unl1/season/witch.wav");
AddFileToDownloadsTable("sound/unloze/season/witch.wav");
PrecacheSound("unloze/season/witch.wav");
float fRandomInterval = GetRandomFloat(GetConVarFloat(g_hCVar_RandomIntervalMin), GetConVarFloat(g_hCVar_RandomIntervalMax));
CreateTimer(fRandomInterval, SpawnCollectable, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnConfigsExecuted()
{
Database.Connect(SQL_OnDatabaseConnect, "season");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
{
if(!db || strlen(error))
{
LogError("Database error: %s", error);
return;
}
g_hDatabase = db;
char sQuery[256];
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS halloween_table (`steam_auth` varchar(64), `name` int varchar(256), `collected` int(16), PRIMARY KEY (`steam_auth`))");
g_hDatabase.Query(SQL_OnTableCreated, sQuery, _, DBPrio_High);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void SQL_OnTableCreated(Database db, DBResultSet results, const char[] error, any data)
{
if(!db || strlen(error))
{
LogError("Database error: %s", error);
return;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -242,18 +272,6 @@ public Action OnRebuildAdminCachePost(Handle hTimer)
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientConnected(int client)
{
g_bPreAdminChecked[client] = false;
g_bResponseFailed[client] = false;
g_bResponsePassed[client] = false;
g_iCollected[client] = 0;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -277,30 +295,35 @@ public void OnClientAuthorized(int client, const char[] sSteamID32)
char sSteamID[32];
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
char sQuery[255];
char sQuery[256];
Format(sQuery, sizeof(sQuery), "SELECT collected FROM halloween_table WHERE steam_auth = '%s'", sSteamID);
SQL_TQuery(g_hDatabase, TQueryCBConnect, sQuery, GetClientUserId(client));
g_hDatabase.Query(SQL_OnQueryCompletedFetch, sQuery, GetClientSerial(client));
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void TQueryCBConnect(Handle owner, Handle rs, const char[] error, any data)
public void SQL_OnQueryCompletedFetch(Database db, DBResultSet results, const char[] error, int iSerial)
{
int client = 0;
if ((client = GetClientOfUserId(data)) == 0)
int client;
if ((client = GetClientFromSerial(iSerial)) == 0)
return;
if (SQL_GetRowCount(rs) > 0)
if (!db || strlen(error))
{
int iField;
SQL_FetchRow(rs);
SQL_FieldNameToNum(rs, "collected", iField);
g_iCollected[client] = SQL_FetchInt(rs, iField);
LogError("Query error: %s", error);
return;
}
delete rs;
if (results.RowCount && results.FetchRow())
{
int iFieldNum;
results.FieldNameToNum("collected", iFieldNum);
g_iCollected[client] = results.FetchInt(iFieldNum);
}
else
g_iCollected[client] = 0;
g_bResponsePassed[client] = true;
if (g_bPreAdminChecked[client])
@ -358,39 +381,44 @@ public Action Command_HighScore(int client, int args)
{
char sQuery[255];
Format(sQuery, sizeof(sQuery), "SELECT * from halloween_table order by collected desc limit %d", g_hCVar_HighscoreDisplay.IntValue);
SQL_TQuery(g_hDatabase, TQueryCBHighscore, sQuery, GetClientUserId(client));
g_hDatabase.Query(SQL_OnQueryCompletedCheck, sQuery, GetClientSerial(client));
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void TQueryCBHighscore(Handle owner, Handle rs, const char[] error, any data)
public void SQL_OnQueryCompletedHighscore(Database db, DBResultSet results, const char[] error, int iSerial)
{
int client = 0;
if ((client = GetClientOfUserId(data)) == 0)
int client;
if ((client = GetClientFromSerial(iSerial)) == 0)
return;
if (!db || strlen(error))
{
LogError("Query error: %s", error);
return;
}
char sName[MAX_NAME_LENGTH];
char sBuffer[2048] = "{darkorange}[UNLOZE HALLOWEEN] {white}TOP COLLECTORS:\n";
char sTempBuffer[1024] = "";
for(int i = 1; i <= g_hCVar_HighscoreDisplay.IntValue; i++)
{
int iField;
SQL_FetchRow(rs);
int iFieldNum;
if (!results.FetchRow())
break;
SQL_FieldNameToNum(rs, "name", iField);
SQL_FetchString(rs, iField, sName, sizeof(sName));
results.FieldNameToNum("name", iFieldNum);
results.FetchString(iFieldNum, sName, sizeof(sName));
SQL_FieldNameToNum(rs, "collected", iField);
int iCollected = SQL_FetchInt(rs, iField);
results.FieldNameToNum("collected", iFieldNum);
int iCollected = results.FetchInt(iFieldNum);
Format(sTempBuffer, sizeof(sTempBuffer), "{green}%d: %s - {red}%d \n", i, sName, iCollected);
StrCat(sBuffer, sizeof(sBuffer), sTempBuffer);
}
delete rs;
CPrintToChat(client, sBuffer);
}
@ -403,34 +431,37 @@ public Action Command_Collected(int client, int args)
char sSteamID[32];
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
char sQuery[255];
char sQuery[256];
Format(sQuery, sizeof(sQuery), "SELECT collected FROM halloween_table WHERE steam_auth = '%s'", sSteamID);
SQL_TQuery(g_hDatabase, TQueryCBCollected, sQuery, GetClientUserId(client));
g_hDatabase.Query(SQL_OnQueryCompletedCheck, sQuery, GetClientSerial(client));
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void TQueryCBCollected(Handle owner, Handle rs, const char[] error, any data)
public void SQL_OnQueryCompletedCheck(Database db, DBResultSet results, const char[] error, int iSerial)
{
int client = 0;
if ((client = GetClientOfUserId(data)) == 0)
int client;
if ((client = GetClientFromSerial(iSerial)) == 0)
return;
if (SQL_GetRowCount(rs) > 0)
if (!db || strlen(error))
{
int iField;
SQL_FetchRow(rs);
SQL_FieldNameToNum(rs, "collected", iField);
g_iCollected[client] = SQL_FetchInt(rs, iField);
LogError("Query error: %s", error);
return;
}
if (results.RowCount && results.FetchRow())
{
int iFieldNum;
results.FieldNameToNum("collected", iFieldNum);
g_iCollected[client] = results.FetchInt(iFieldNum);
}
else
g_iCollected[client] = 0;
delete rs;
CPrintToChat(client, "{darkorange}[UNLOZE HALLOWEEN] {white}You have collected {green}%d {white}pumpkins so far.", g_iCollected[client]);
if ((g_iCollected[client] > g_hCVar_MilestoneInfection.IntValue) && (g_iCollected[client] > g_hCVar_MilestoneSkin.IntValue))
@ -627,9 +658,9 @@ public void HookCallback(const char[] output, int caller, int activator, float d
char sName[MAX_NAME_LENGTH];
GetClientName(client, sName, sizeof(sName));
char sQuery[255];
char sQuery[256];
Format(sQuery, sizeof(sQuery), "INSERT INTO halloween_table (steam_auth,name,collected) VALUES ('%s','%s',1) ON DUPLICATE KEY UPDATE collected=collected+1;", sSteamID, sName);
SQL_FastQuery(g_hDatabase, sQuery);
g_hDatabase.Query(SQL_OnQueryCompletedUpdate, sQuery);
g_iCollected[client] += 1;
CheckAndAddFlag(client);
@ -647,15 +678,30 @@ public void HookCallback(const char[] output, int caller, int activator, float d
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void SQL_OnQueryCompletedUpdate(Database db, DBResultSet results, const char[] error, any data)
{
if (!db || strlen(error))
{
LogError("Query error: %s", error);
return;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
{
if (!g_hCVar_InfectionEffectEnabled.BoolValue)
return;
if (!IsValidClient(attacker))
return;
if (g_hCVar_InfectionEffectEnabled.BoolValue && ((g_iCollected[client] >= g_hCVar_MilestoneInfection.IntValue) || g_iCollected[attacker] >= g_hCVar_MilestoneInfection.IntValue))
if (g_iCollected[client] >= g_hCVar_MilestoneInfection.IntValue || g_iCollected[attacker] >= g_hCVar_MilestoneInfection.IntValue)
{
float fInfectionOrigin[3];
GetClientAbsOrigin(client, fInfectionOrigin);
@ -665,9 +711,9 @@ public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, boo
DispatchKeyFormat(iRotating, "targetname", "season_infection_rotating_%d", g_iCounter);
DispatchKeyFormat(iRotating, "maxspeed", "13");
DispatchKeyFormat(iRotating, "spawnflags", "64");
DispatchKeyFormat(iRotating, "OnUser1", "season_infection_prop_%d,FireUser1,,0,1", g_iCounter);
DispatchKeyFormat(iRotating, "OnUser1", "!self,KillHierarchy,,45,1");
DispatchKeyFormat(iRotating, "OnUser2", "!self,KillHierarchy,,0,1");
DispatchKeyFormat(iRotating, "OnUser3", "!self,Start,,0,1");
SpawnAndActivate(iRotating);
// make the trigger work.
@ -756,9 +802,9 @@ public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, boo
DispatchKeyFormat(iModel, "disablereceiveshadows", "1");
DispatchKeyFormat(iModel, "DisableBoneFollowers", "1");
DispatchKeyValueVector(iModel, "origin", fInfectionOrigin);
SpawnAndActivate(iModel);
ParentToEntity(iModel, iRotating);
AcceptEntityInput(iModel, "FireUser1");
AcceptEntityInput(iRotating, "FireUser1");
int iEntityLimit = g_hCVar_EntityLimit.IntValue;
@ -777,12 +823,16 @@ public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, boo
//----------------------------------------------------------------------------------------------------
public void OnEntitySpawned(int Entity, const char[] sClassname)
{
if (StrContains(sClassname, "_projectile", false) == -1)
return;
int iOwner = GetEntPropEnt(Entity, Prop_Data, "m_hOwnerEntity");
if(!IsValidClient(iOwner))
return;
if (g_iCollected[iOwner] >= g_hCVar_MilestoneGrenade.IntValue)
{
if (g_iCollected[iOwner] < g_hCVar_MilestoneGrenade.IntValue)
return;
SetEntityRenderMode(Entity, RENDER_NONE);
float fNadeOrigin[3];
@ -790,7 +840,6 @@ public void OnEntitySpawned(int Entity, const char[] sClassname)
int iNadeProp = CreateEntityAtOrigin("prop_dynamic_override", fNadeOrigin);
DispatchKeyFormat(iNadeProp, "targetname", "season_nade_prop_%d", g_iCounter);
DispatchKeyFormat(iNadeProp, "model", "models/models_kit/hallo_pumpkin_l.mdl");
DispatchKeyFormat(iNadeProp, "disableshadows", "1");
DispatchKeyFormat(iNadeProp, "disablereceiveshadows", "1");
@ -800,7 +849,6 @@ public void OnEntitySpawned(int Entity, const char[] sClassname)
SpawnAndActivate(iNadeProp);
ParentToEntity(iNadeProp, Entity);
}
}
//----------------------------------------------------------------------------------------------------
// Purpose: