diff --git a/VIP_Test/scripting/VIP_Test.sp b/VIP_Test/scripting/VIP_Test.sp index fb662bc0..67888866 100644 --- a/VIP_Test/scripting/VIP_Test.sp +++ b/VIP_Test/scripting/VIP_Test.sp @@ -1,18 +1,33 @@ +#pragma semicolon 1 + #include -char g_sAdmGroup[32] = "Game-Donator"; +#pragma newdecls required +/* STRINGS */ +char g_sAdmGroup[32] = "Game-Donator"; +char g_sGroup[MAXPLAYERS+1][64]; + +/* CONVARS */ ConVar g_cvFreeVIPDuration; +/* DATABASE */ +Database g_hDatabase; + +/* BOOLS */ +bool g_bPreAdminChecked[MAXPLAYERS+1]; +bool g_bResponseFailed[MAXPLAYERS+1]; +bool g_bResponsePassed[MAXPLAYERS+1]; + //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public Plugin myinfo = { - name = "Unloze_VIP_Test", + name = "UNLOZE_VIP_Test", author = "Neon", description = "", - version = "1.0", + version = "2.0", url = "https://steamcommunity.com/id/n3ontm" } @@ -26,18 +41,15 @@ public void OnPluginStart() RegConsoleCmd("sm_viptest", Command_VIP, "Activate free VIP period"); RegConsoleCmd("sm_testvip", Command_VIP, "Activate free VIP period"); RegConsoleCmd("sm_vip", Command_VIP, "Activate free VIP period"); -} -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public Action Command_VIP(int iClient, int iArgs) -{ - if (!IsValidClient(iClient)) - return Plugin_Handled; + AutoExecConfig(); - CheckMYSQL(iClient, true); - return Plugin_Handled; + char sError[256]; + if (SQL_CheckConfig("testvip")) + g_hDatabase = SQL_Connect("testvip", true, sError, sizeof(sError)); + + if (g_hDatabase == null) + LogError("Could not connect to database: %s", sError); } //---------------------------------------------------------------------------------------------------- @@ -54,120 +66,169 @@ public void OnRebuildAdminCache(AdminCachePart part) //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- -public void OnClientPostAdminFilter(int client) +public Action OnRebuildAdminCachePost(Handle hTimer) { - CheckMYSQL(client); + for (int client = 1; client <= MaxClients; client++) + { + if(g_bResponsePassed[client] && g_bPreAdminChecked[client]) + ApplyGroupFlags(client); + } } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- -bool CheckMYSQL(int client, bool add = false) +public void OnClientConnected(int client) { - if (client == 0) - return false; + g_bPreAdminChecked[client] = false; + g_bResponseFailed[client] = false; + g_bResponsePassed[client] = false; - char error[255]; - Database db; + g_sGroup[client][0] = 0; +} - if (SQL_CheckConfig("testvip")) +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientDisconnect(int client) +{ + g_bPreAdminChecked[client] = false; + g_bResponseFailed[client] = false; + g_bResponsePassed[client] = false; + + g_sGroup[client][0] = 0; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientAuthorized(int client, const char[] sSteamID32) +{ + if (IsFakeClient(client)) + return; + + char sSteamID[32]; + GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); + + char sQuery[256]; + Format(sQuery, sizeof(sQuery), "SELECT * FROM testvip_table WHERE steam_auth = '%s'", sSteamID); + SQL_TQuery(g_hDatabase, TQueryCBConnect, sQuery, GetClientUserId(client)); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void TQueryCBConnect(Handle owner, Handle rs, const char[] error, any data) +{ + int client = 0; + + if ((client = GetClientOfUserId(data)) == 0) + return; + + if (SQL_GetRowCount(rs) > 0) { - db = SQL_Connect("testvip", true, error, sizeof(error)); - } - - if (db == null) - { - LogError("Could not connect to database: %s", error); - delete db; - return false; - } - - if (!IsFakeClient(client) && !IsClientSourceTV(client)) - { - char sSID[64]; - GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); - - char sQuery[255]; - Format(sQuery, sizeof(sQuery), "SELECT * FROM testvip_table WHERE steam_auth = '%s'", sSID); - DBResultSet rs; - if ((rs = SQL_Query(db, sQuery)) == null) - { - delete db; - delete rs; - LogError("Database Error: %s", error); - return false; - } + int iField; + SQL_FetchRow(rs); + SQL_FieldNameToNum(rs, "activated", iField); + int iTimestampActivated = SQL_FetchInt(rs, iField); int iTimestamp = GetTime(); - int iTimestampActivated = GetTime(); - bool bFound = false; - - if (!(rs.RowCount > 0)) - { - if (add) - { - bool bHasVIP = false; - AdminId AdmID; - - if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID) - bHasVIP = false; - else - { - for (int i = 0; i <= GetAdminGroupCount(AdmID); i++) - { - char sGroup[32]; - if ((GetAdminGroup(AdmID, i, sGroup, sizeof(sGroup)) != INVALID_GROUP_ID)) - { - if (StrEqual(sGroup, g_sAdmGroup)) - bHasVIP = true; - } - } - } - - if (!bHasVIP) - { - Format(sQuery, sizeof(sQuery), "INSERT INTO testvip_table (steam_auth, activated) VALUES ('%s', '%d')", sSID, iTimestamp); - SQL_FastQuery(db, sQuery); - - ApplyGroupFlags(client); - PrintToChat(client, "[Unloze] Your TEST VIP will expire in %d minutes!", g_cvFreeVIPDuration.IntValue - (iTimestamp - iTimestampActivated) / 60); - PrintToChat(client, "[Unloze] You have now access to !zclass, !tag and !glow."); - } - else - { - PrintToChat(client, "[Unloze] You already have VIP activated!"); - delete db; - delete rs; - return false; - } - - } - } - else - { - int iField; - rs.FetchRow(); - rs.FieldNameToNum("activated", iField); - iTimestampActivated = rs.FetchInt(iField); - bFound = true; - } delete rs; - if (bFound) + if ((iTimestamp - iTimestampActivated) < g_cvFreeVIPDuration.IntValue *60) { - if ((iTimestamp - iTimestampActivated) < g_cvFreeVIPDuration.IntValue *60) - { - ApplyGroupFlags(client); - PrintToChat(client, "[Unloze] Your TEST VIP will expire in %d minutes!", g_cvFreeVIPDuration.IntValue - (iTimestamp - iTimestampActivated) / 60); - } - else - { - if (add) - PrintToChat(client, "[Unloze] Your TEST VIP expired already!", g_cvFreeVIPDuration.IntValue - (iTimestamp - iTimestampActivated) / 60); - } + strcopy(g_sGroup[client], sizeof(g_sGroup[]), g_sAdmGroup); } } - delete db; - return true; + + g_bResponsePassed[client] = true; + if (g_bPreAdminChecked[client]) + NotifyPostAdminCheck(client); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action OnClientPreAdminCheck(int client) +{ + g_bPreAdminChecked[client] = true; + + if (g_bResponsePassed[client] || g_bResponseFailed[client]) + return Plugin_Continue; + + RunAdminCacheChecks(client); + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientPostAdminFilter(int client) +{ + ApplyGroupFlags(client); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action Command_VIP(int client, int iArgs) +{ + if (!IsValidClient(client)) + return Plugin_Handled; + + char sSteamID[32]; + GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); + + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "SELECT * FROM testvip_table WHERE steam_auth = '%s'", sSteamID); + SQL_TQuery(g_hDatabase, TQueryCBCommand, sQuery, GetClientUserId(client)); + + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void TQueryCBCommand(Handle owner, Handle rs, const char[] error, any data) +{ + int client = 0; + + if ((client = GetClientOfUserId(data)) == 0) + return; + + int iTimestamp = GetTime(); + + if (SQL_GetRowCount(rs) > 0) + { + int iField; + SQL_FetchRow(rs); + SQL_FieldNameToNum(rs, "activated", iField); + int iTimestampActivated = SQL_FetchInt(rs, iField); + delete rs; + + if ((iTimestamp - iTimestampActivated) < g_cvFreeVIPDuration.IntValue *60) + PrintToChat(client, "[UNLOZE] Your TEST VIP will expire in %d minutes!", g_cvFreeVIPDuration.IntValue - (iTimestamp - iTimestampActivated) / 60); + else + PrintToChat(client, "[UNLOZE] Your TEST VIP expired already!"); + } + else + { + if (IsVIP(client)) + { + PrintToChat(client, "[UNLOZE] You already have VIP activated!"); + return; + } + + char sSteamID[32]; + GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); + + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "INSERT INTO testvip_table (steam_auth, activated) VALUES ('%s', '%d')", sSteamID, iTimestamp); + SQL_FastQuery(g_hDatabase, sQuery); + strcopy(g_sGroup[client], sizeof(g_sGroup[]), g_sAdmGroup); + ApplyGroupFlags(client); + PrintToChat(client, "[UNLOZE] You have now access to !zclass, !tag and !glow and other VIP-Perks."); + PrintToChat(client, "[UNLOZE] Your TEST VIP will expire in %d minutes!", g_cvFreeVIPDuration.IntValue); + } } //---------------------------------------------------------------------------------------------------- @@ -175,6 +236,12 @@ bool CheckMYSQL(int client, bool add = false) //---------------------------------------------------------------------------------------------------- stock void ApplyGroupFlags(int client) { + if (!g_bResponsePassed[client]) + return; + + if (g_sGroup[client][0] == 0) + return; + AdminId AdmID; GroupId GrpID; @@ -186,27 +253,13 @@ stock void ApplyGroupFlags(int client) SetUserAdmin(client, AdmID, true); } - if ((GrpID = FindAdmGroup(g_sAdmGroup)) != INVALID_GROUP_ID) + if ((GrpID = FindAdmGroup(g_sGroup[client])) != INVALID_GROUP_ID) { if (AdminInheritGroup(AdmID, GrpID)) - LogMessage("%L added to group %s", client, g_sAdmGroup); + LogMessage("%L added to group %s", client, g_sGroup[client]); } else - { - LogMessage("%L group not found %s", client, g_sAdmGroup); - } -} - -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public Action OnRebuildAdminCachePost(Handle hTimer) -{ - for (int client = 1; client <= MaxClients; client++) - { - if (IsValidClient(client)) - CheckMYSQL(client); - } + LogMessage("%L group not found %s", client, g_sGroup[client]); } //---------------------------------------------------------------------------------------------------- @@ -215,8 +268,31 @@ public Action OnRebuildAdminCachePost(Handle hTimer) stock int IsValidClient(int client, bool nobots = true) { if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client))) - { return false; - } + return IsClientInGame(client); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public bool IsVIP(int client) +{ + AdminId AdmID; + + if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID) + return false; + else + { + for (int i = 0; i <= GetAdminGroupCount(AdmID); i++) + { + char sGroup[32]; + if ((GetAdminGroup(AdmID, i, sGroup, sizeof(sGroup)) != INVALID_GROUP_ID)) + { + if (StrEqual(sGroup, g_sAdmGroup)) + return true; + } + } + } + return false; } \ No newline at end of file diff --git a/xmas/scripting/xmas.sp b/xmas/scripting/xmas.sp index 56d7d57b..a8685ea7 100644 --- a/xmas/scripting/xmas.sp +++ b/xmas/scripting/xmas.sp @@ -1,62 +1,90 @@ +#pragma semicolon 1 + #include #include #include -#include +#include #include -#include -#pragma semicolon 1 #pragma newdecls required -Handle g_hCVar_CollectablesEnabled = INVALID_HANDLE; -Handle g_hCVar_RandomIntervalMin = INVALID_HANDLE; -Handle g_hCVar_RandomIntervalMax = INVALID_HANDLE; -Handle g_hCVar_InfectionEffectEnabled = INVALID_HANDLE; -Handle g_hCVar_MilestoneInfection = INVALID_HANDLE; -Handle g_hCVar_MilestoneGrenade = INVALID_HANDLE; -Handle g_hCVar_MilestoneSkin = INVALID_HANDLE; -Handle g_hCVar_HighscoreDisplay = INVALID_HANDLE; -Handle g_hCVar_PlayerRequirement = INVALID_HANDLE; -Handle g_hCVar_EntityLimit = INVALID_HANDLE; +/* CONVARS */ +ConVar g_hCVar_CollectablesEnabled; +ConVar g_hCVar_RandomIntervalMin; +ConVar g_hCVar_RandomIntervalMax; +ConVar g_hCVar_InfectionEffectEnabled; +ConVar g_hCVar_MilestoneInfection; +ConVar g_hCVar_MilestoneGrenade; +ConVar g_hCVar_MilestoneSkin; +ConVar g_hCVar_HighscoreDisplay; +ConVar g_hCVar_PlayerRequirement; +ConVar g_hCVar_EntityLimit; +/* DATABASE */ +Database g_hDatabase; + +/* BOOLS */ bool g_bEnabled = true; -float g_fPropOrigin[3]; +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; + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public Plugin myinfo = { name = "Unloze Season Event", author = "Neon", description = "Unloze Season Event", - version = "1.2", + version = "2.0", url = "https://steamcommunity.com/id/n3ontm" }; +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public void OnPluginStart() { - g_hCVar_CollectablesEnabled = CreateConVar("sm_unloze_season_collectables_enabled", "1", "Spawn Collectables.", 0, true, 0.0, true, 1.0); - g_hCVar_RandomIntervalMin = CreateConVar("sm_unloze_season_random_interval_min", "60", "Minimum Interval between spawning Collectables.", 0, true, 0.0); - g_hCVar_RandomIntervalMax = CreateConVar("sm_unloze_season_random_interval_max", "120", "Maximum Interval between spawning Collectables.", 0, true, 0.0); - g_hCVar_InfectionEffectEnabled = CreateConVar("sm_unloze_season_infection_effect_enabled", "1", "Spawn Props on Infection.", 0, true, 0.0, true, 1.0); - g_hCVar_MilestoneInfection = CreateConVar("sm_unloze_season_milestone_infection", "25", "Amount of Collectables you need to unlock the Infection Effect.", 0, true, 0.0); - g_hCVar_MilestoneGrenade = CreateConVar("sm_unloze_season_milestone_grenade", "75", "Amount of Collectables you need to unlock the Grenade Skin.", 0, true, 0.0); - g_hCVar_MilestoneSkin = CreateConVar("sm_unloze_season_milestone_skin", "150", "Amount of Collectables you need to unlock the Skin(s).", 0, true, 0.0); - g_hCVar_HighscoreDisplay = CreateConVar("sm_unloze_season_highscore_display", "5", "Amount of Players to display via sm_highscore", 0, true, 0.0); - g_hCVar_PlayerRequirement = CreateConVar("sm_unloze_season_player_requirement", "10", "Amount of Players needed to spawn Collectables.", 0, true, 0.0); - g_hCVar_EntityLimit = CreateConVar("sm_unloze_season_entity_limit", "2000", "Entity Safety Limit.", 0, true, 0.0); + g_hCVar_CollectablesEnabled = CreateConVar("sm_unloze_season_collectables_enabled", "1", "Spawn Collectables.", 0, true, 0.0, true, 1.0); + g_hCVar_RandomIntervalMin = CreateConVar("sm_unloze_season_random_interval_min", "60", "Minimum Interval between spawning Collectables.", 0, true, 0.0); + g_hCVar_RandomIntervalMax = CreateConVar("sm_unloze_season_random_interval_max", "120", "Maximum Interval between spawning Collectables.", 0, true, 0.0); + g_hCVar_InfectionEffectEnabled = CreateConVar("sm_unloze_season_infection_effect_enabled", "1", "Spawn Props on Infection.", 0, true, 0.0, true, 1.0); + g_hCVar_MilestoneInfection = CreateConVar("sm_unloze_season_milestone_infection", "25", "Amount of Collectables you need to unlock the Infection Effect.", 0, true, 0.0); + g_hCVar_MilestoneGrenade = CreateConVar("sm_unloze_season_milestone_grenade", "75", "Amount of Collectables you need to unlock the Grenade Skin.", 0, true, 0.0); + g_hCVar_MilestoneSkin = CreateConVar("sm_unloze_season_milestone_skin", "150", "Amount of Collectables you need to unlock the Skin(s).", 0, true, 0.0); + g_hCVar_HighscoreDisplay = CreateConVar("sm_unloze_season_highscore_display", "5", "Amount of Players to display via sm_highscore", 0, true, 0.0); + g_hCVar_PlayerRequirement = CreateConVar("sm_unloze_season_player_requirement", "10", "Amount of Players needed to spawn Collectables.", 0, true, 0.0); + g_hCVar_EntityLimit = CreateConVar("sm_unloze_season_entity_limit", "2000", "Entity Safety Limit.", 0, true, 0.0); - for(int client = 1; client <= MaxClients; client++) - { - if(IsClientInGame(client) && !IsFakeClient(client) && IsClientAuthorized(client)) - OnClientPostAdminFilter(client); - } HookEvent("round_start", OnRoundStart, EventHookMode_Post); + RegConsoleCmd("sm_presents", Command_Collected, "Shows the total amount of presents you have collected so far"); RegConsoleCmd("sm_highscore", Command_HighScore, "Shows the HighScore"); - RegAdminCmd("sm_reload_season", Command_ReloadFlags, ADMFLAG_ROOT); + + 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); } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public void OnMapStart() { + // Yeeaass (Physbox model) + PrecacheModel("models/props/cs_militia/crate_extrasmallmill.mdl"); + AddFileToDownloadsTable("models/player/stenli/smite/fenrir.phy"); AddFileToDownloadsTable("models/player/stenli/smite/fenrir.sw.vtx"); AddFileToDownloadsTable("models/player/stenli/smite/fenrir.vvd"); @@ -215,189 +243,361 @@ public void OnMapStart() CreateTimer(fRandomInterval, SpawnCollectable, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); } -public void OnClientPostAdminFilter(int client) +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnRebuildAdminCache(AdminCachePart part) { - CheckMYSQL(client); + if (part != AdminCache_Admins) + return; + + CreateTimer(1.0, OnRebuildAdminCachePost, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action OnRebuildAdminCachePost(Handle hTimer) +{ + for (int client = 1; client <= MaxClients; client++) + { + if(g_bResponsePassed[client] && g_bPreAdminChecked[client]) + CheckAndAddFlag(client); + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientConnected(int client) +{ + g_bPreAdminChecked[client] = false; + g_bResponseFailed[client] = false; + g_bResponsePassed[client] = false; + + g_iCollected[client] = 0; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientDisconnect(int client) +{ + g_bPreAdminChecked[client] = false; + g_bResponseFailed[client] = false; + g_bResponsePassed[client] = false; + + g_iCollected[client] = 0; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientAuthorized(int client, const char[] sSteamID32) +{ + if (IsFakeClient(client)) + return; + + char sSteamID[32]; + GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); + + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "SELECT collected FROM season_table WHERE steam_auth = '%s'", sSteamID); + SQL_TQuery(g_hDatabase, TQueryCBConnect, sQuery, GetClientUserId(client)); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void TQueryCBConnect(Handle owner, Handle rs, const char[] error, any data) +{ + int client = 0; + + if ((client = GetClientOfUserId(data)) == 0) + return; + + if (SQL_GetRowCount(rs) > 0) + { + int iField; + SQL_FetchRow(rs); + SQL_FieldNameToNum(rs, "collected", iField); + g_iCollected[client] = SQL_FetchInt(rs, iField); + delete rs; + } + + g_bResponsePassed[client] = true; + if (g_bPreAdminChecked[client]) + NotifyPostAdminCheck(client); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action OnClientPreAdminCheck(int client) +{ + g_bPreAdminChecked[client] = true; + + if (g_bResponsePassed[client] || g_bResponseFailed[client]) + return Plugin_Continue; + + RunAdminCacheChecks(client); + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientPostAdminFilter(int client) +{ + CheckAndAddFlag(client); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public void OnRoundStart(Event hEvent, const char[] sEvent, bool bDontBroadcast) { + g_iCounter = 0; CreateTimer(10.0, CheckPlayerCount, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public Action CheckPlayerCount(Handle timer) { g_bEnabled = true; - if (GetClientCount(true) < GetConVarInt(g_hCVar_PlayerRequirement)) + if (GetClientCount(true) < g_hCVar_PlayerRequirement.IntValue) { g_bEnabled = false; - CPrintToChatAll("{green}[Unloze XMAS] {white}Minimum Player Requirement to spawn Presents: {green}%d {white} - Currently online: {red}%d{white}.", GetConVarInt(g_hCVar_PlayerRequirement), GetClientCount(true)); + CPrintToChatAll("{green}[UNLOZE XMAS] {white}Minimum Player Requirement to spawn Presents: {green}%d {white} - Currently online: {red}%d{white}.", g_hCVar_PlayerRequirement.IntValue, GetClientCount(true)); } } -public Action Command_ReloadFlags(int client, int args) +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action Command_HighScore(int client, int args) { - for(int i = 1; i <= MaxClients; i++) - { - if(IsClientInGame(i) && !IsFakeClient(i) && IsClientAuthorized(i)) - OnClientPostAdminFilter(i); - } - CPrintToChat(client, "{green}[Unloze XMAS] {white}Flags have been reloaded!"); + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "SELECT * from season_table order by collected desc limit %d", g_hCVar_HighscoreDisplay.IntValue); + SQL_TQuery(g_hDatabase, TQueryCBHighscore, sQuery, GetClientUserId(client)); return Plugin_Handled; } -public Action Command_HighScore(int client, int args) +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void TQueryCBHighscore(Handle owner, Handle rs, const char[] error, any data) { - char error[255]; - Database db; - if (SQL_CheckConfig("season")) - { - db = SQL_Connect("season", true, error, sizeof(error)); - } - if (db == null) - { - LogError("Could not connect to database: %s", error); - delete db; - return Plugin_Handled; - } + int client = 0; + + if ((client = GetClientOfUserId(data)) == 0) + return; char sName[MAX_NAME_LENGTH]; - char sQuery[255]; - char sBuffer[2048] = "{green}[Unloze XMAS] {white}TOP COLLECTORS:\n"; + char sBuffer[2048] = "{green}[UNLOZE XMAS] {white}TOP COLLECTORS:\n"; char sTempBuffer[1024] = ""; - int iCollected; - int iField; - Format(sQuery, sizeof(sQuery), "SELECT * from season_table order by collected desc limit %d", GetConVarInt(g_hCVar_HighscoreDisplay)); - DBResultSet rs; - if ((rs = SQL_Query(db, sQuery)) == null) + for(int i = 1; i <= g_hCVar_HighscoreDisplay.IntValue; i++) { - CPrintToChat(client, "{green}[Unloze XMAS] {white}Error! Could not connect to MYSQL-DB!"); - delete db; - delete rs; - return Plugin_Handled; - } + int iField; + SQL_FetchRow(rs); + + SQL_FieldNameToNum(rs, "name", iField); + SQL_FetchString(rs, iField, sName, sizeof(sName)); + + SQL_FieldNameToNum(rs, "collected", iField); + int iCollected = SQL_FetchInt(rs, iField); - for(int i = 1; i <= GetConVarInt(g_hCVar_HighscoreDisplay); i++) - { - rs.FetchRow(); - rs.FieldNameToNum("name", iField); - rs.FetchString(iField, sName , sizeof(sName)); - rs.FieldNameToNum("collected", iField); - iCollected = rs.FetchInt(iField); Format(sTempBuffer, sizeof(sTempBuffer), "{green}%d: %s - {red}%d \n", i, sName, iCollected); StrCat(sBuffer, sizeof(sBuffer), sTempBuffer); } - CPrintToChat(client, sBuffer); - delete db; delete rs; - return Plugin_Handled; + + CPrintToChat(client, sBuffer); } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public Action Command_Collected(int client, int args) { - int iCollected = CheckMYSQL(client); - CPrintToChat(client, "{green}[Unloze XMAS] {white}You have collected {green}%d {white}presents so far.", iCollected); - - if ((iCollected > GetConVarInt(g_hCVar_MilestoneInfection)) && (iCollected > GetConVarInt(g_hCVar_MilestoneSkin))) - CPrintToChat(client, "{green}[Unloze XMAS] {white}You have unlocked {red}all rewards{white} already."); - if (iCollected < GetConVarInt(g_hCVar_MilestoneInfection)) - CPrintToChat(client, "{green}[Unloze XMAS] {white}You need to collect {green}%d {white}more presents to unlock {red}INFECTION EFFECTS{white}.", GetConVarInt(g_hCVar_MilestoneInfection) - iCollected); - if (iCollected < GetConVarInt(g_hCVar_MilestoneGrenade)) - CPrintToChat(client, "{green}[Unloze XMAS] {white}You need to collect {green}%d {white}more presents to unlock {red}GRENADE SKINS{white}.", GetConVarInt(g_hCVar_MilestoneGrenade) - iCollected); - if (iCollected < GetConVarInt(g_hCVar_MilestoneSkin)) - CPrintToChat(client, "{green}[Unloze XMAS] {white}You need to collect {green}%d {white}more presents to unlock {red}XMAS PLAYER SKINS{white}.", GetConVarInt(g_hCVar_MilestoneSkin) - iCollected); + char sSteamID[32]; + GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); + char sQuery[255]; + Format(sQuery, sizeof(sQuery), "SELECT collected FROM season_table WHERE steam_auth = '%s'", sSteamID); + SQL_TQuery(g_hDatabase, TQueryCBCollected, sQuery, GetClientUserId(client)); return Plugin_Handled; } -public int CheckMYSQL(int client) +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void TQueryCBCollected(Handle owner, Handle rs, const char[] error, any data) { - if (client == -1) - return -1; + int client = 0; - char error[255]; - Database db; - if (SQL_CheckConfig("season")) - { - db = SQL_Connect("season", true, error, sizeof(error)); - } - if (db == null) - { - CPrintToChat(client, "{green}[Unloze XMAS] {white}Error! Could not connect to MYSQL-DB!"); - delete db; - return -1; - } - - char sSID[64]; - GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); - char sQuery[255]; - Format(sQuery, sizeof(sQuery), "SELECT collected FROM season_table WHERE steam_auth = '%s'", sSID); - DBResultSet rs; - if ((rs = SQL_Query(db, sQuery)) == null) - { - delete db; - delete rs; - return -1; - - } - int iCollected; - if (!(rs.RowCount > 0)) - { - iCollected = 0; - } - else - { - int iField; - rs.FetchRow(); - rs.FieldNameToNum("collected", iField); - iCollected = rs.FetchInt(iField); - } - delete rs; - delete db; - CheckAndAddFlag(client, iCollected); - return iCollected; -} - -public Action SpawnCollectable(Handle timer) -{ - - float fRandomInterval = GetRandomFloat(GetConVarFloat(g_hCVar_RandomIntervalMin), GetConVarFloat(g_hCVar_RandomIntervalMax)); - CreateTimer(fRandomInterval, SpawnCollectable, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); - - if (!GetConVarBool(g_hCVar_CollectablesEnabled) || !(g_bEnabled)) + if ((client = GetClientOfUserId(data)) == 0) return; - int target = GetTargetClient(); - GetClientAbsOrigin(target, g_fPropOrigin); - int iRotating = SpawnRotating(); - int iParticle = SpawnParticle(); - int iProp = SpawnProp(); - int iHitbox = SpawnHitbox(iRotating, iParticle); - int iTrigger = SpawnTrigger(iHitbox); - int iAmbient = SpawnAmbientHohohoho(); - SetVariantString("!activator"); - AcceptEntityInput(iProp, "SetParent", iRotating); - SetVariantString("!activator"); - AcceptEntityInput(iHitbox, "SetParent", iRotating); - SetVariantString("!activator"); - AcceptEntityInput(iTrigger, "SetParent", iRotating); + if (SQL_GetRowCount(rs) > 0) + { + int iField; + SQL_FetchRow(rs); + SQL_FieldNameToNum(rs, "collected", iField); + g_iCollected[client] = SQL_FetchInt(rs, iField); + } + else + g_iCollected[client] = 0; + delete rs; + + CPrintToChat(client, "{green}[UNLOZE XMAS] {white}You have collected {green}%d {white}presents so far.", g_iCollected[client]); + + if ((g_iCollected[client] > g_hCVar_MilestoneInfection.IntValue) && (g_iCollected[client] > g_hCVar_MilestoneSkin.IntValue)) + CPrintToChat(client, "{green}[UNLOZE XMAS] {white}You have unlocked {red}all rewards{white} already."); + if (g_iCollected[client] < g_hCVar_MilestoneInfection.IntValue) + CPrintToChat(client, "{green}[UNLOZE XMAS] {white}You need to collect {green}%d {white}more presents to unlock {red}INFECTION EFFECTS{white}.", g_hCVar_MilestoneInfection.IntValue - g_iCollected[client]); + if (g_iCollected[client] < g_hCVar_MilestoneGrenade.IntValue) + CPrintToChat(client, "{green}[UNLOZE XMAS] {white}You need to collect {green}%d {white}more presents to unlock {red}GRENADE SKINS{white}.", g_hCVar_MilestoneGrenade.IntValue - g_iCollected[client]); + if (g_iCollected[client] < g_hCVar_MilestoneSkin.IntValue) + CPrintToChat(client, "{green}[UNLOZE XMAS] {white}You need to collect {green}%d {white}more presents to unlock {red}XMAS PLAYER SKINS{white}.", g_hCVar_MilestoneSkin.IntValue - g_iCollected[client]); + +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action SpawnCollectable(Handle timer) +{ + float fRandomInterval = GetRandomFloat(g_hCVar_RandomIntervalMin.FloatValue, g_hCVar_RandomIntervalMax.FloatValue); + CreateTimer(fRandomInterval, SpawnCollectable, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); + + if (!(g_hCVar_CollectablesEnabled.BoolValue) || !(g_bEnabled)) + return; + + int iTarget = GetTargetClient(); + float fOrigin[3]; + GetClientAbsOrigin(iTarget, fOrigin); + + // Rotating + int iRotating = CreateEntityAtOrigin("func_rotating", fOrigin); + DispatchKeyFormat(iRotating, "targetname", "season_rotating_%d", g_iCounter); + DispatchKeyFormat(iRotating, "maxspeed", "20"); + DispatchKeyFormat(iRotating, "spawnflags", "65"); + SpawnAndActivate(iRotating); + + // make the trigger work. + SetEntityBBox(iRotating, view_as({-10.0, -1.0, -1.0}), view_as({1.0, 1.0, 1.0})); + SetEntityProps(iRotating); + + + // Model + int iModel = CreateEntityAtOrigin("prop_dynamic_override", fOrigin); + DispatchKeyFormat(iModel, "targetname", "season_prop_%d", g_iCounter); + DispatchKeyFormat(iModel, "model", "models/zombieden/xmas/giftbox.mdl"); + DispatchKeyFormat(iModel, "modelscale", "0.8"); + DispatchKeyFormat(iModel, "disablebonefollowers", "1"); + SpawnAndActivate(iModel); + ParentToEntity(iModel, iRotating); + + int iRandomSkin = GetRandomInt(0, 1); + if (iRandomSkin == 0) + SetVariantString("0"); + else if (iRandomSkin == 1) + SetVariantString("1"); + AcceptEntityInput(iModel, "Skin"); + + + // Particle + int iParticle = CreateEntityAtOrigin("info_particle_system", fOrigin); + DispatchKeyFormat(iParticle, "targetname", "season_particle_%d", g_iCounter); + DispatchKeyFormat(iParticle, "effect_name", "achieved"); + SpawnAndActivate(iParticle); + ParentToEntity(iParticle, iRotating); + + + // Trigger + int iTrigger = CreateEntityAtOrigin("trigger_multiple", fOrigin); + DispatchKeyFormat(iTrigger, "targetname", "season_trigger_%d", g_iCounter); + DispatchKeyFormat(iTrigger, "spawnflags", "1"); + DispatchKeyFormat(iTrigger, "startdisabled", "1"); + DispatchKeyFormat(iTrigger, "OnUser1", "season_hitbox_%d,FireUser2,,0,1", g_iCounter); + SpawnAndActivate(iTrigger); + ParentToEntity(iTrigger, iRotating); + + // make the trigger work. + SetEntityBBox(iTrigger, view_as({-16.0, -16.0, -1.0}), view_as({16.0, 16.0, 32.0})); + SetEntityProps(iTrigger); + + HookSingleEntityOutput(iTrigger, "OnStartTouch", HookCallbackTrigger, false); + + + // Ambient + int iSound = CreateEntityAtOrigin("ambient_generic", fOrigin); + DispatchKeyFormat(iSound, "targetname", "season_sound_%d", g_iCounter); + DispatchKeyFormat(iSound, "spawnflags", "49"); + DispatchKeyFormat(iSound, "radius", "2000"); + DispatchKeyFormat(iSound, "message", "unl1/season/hohohoho.wav"); + DispatchKeyFormat(iSound, "volume", "10"); + DispatchKeyFormat(iSound, "health", "10"); + DispatchKeyFormat(iSound, "pitch", "100"); + DispatchKeyFormat(iSound, "pitchstart", "100"); + SpawnAndActivate(iSound); + ParentToEntity(iSound, iRotating); + + + // Hitbox + int iHitbox = CreateEntityAtOrigin("func_physbox_multiplayer", fOrigin); + DispatchKeyFormat(iHitbox, "targetname", "season_hitbox_%d", g_iCounter); + DispatchKeyFormat(iHitbox, "model", "models/zombieden/xmas/giftbox.mdl"); + DispatchKeyFormat(iHitbox, "modelscale", "0.8"); + DispatchKeyFormat(iHitbox, "disableshadows", "1"); + DispatchKeyFormat(iHitbox, "disablereceiveshadows", "1"); + DispatchKeyFormat(iHitbox, "DisableBoneFollowers", "1"); + DispatchKeyFormat(iHitbox, "rendermode", "10"); + DispatchKeyFormat(iHitbox, "PerformanceMode", "1"); + DispatchKeyFormat(iHitbox, "material", "3"); + DispatchKeyFormat(iHitbox, "health", "200"); + DispatchKeyFormat(iHitbox, "physdamagescale", "1.0"); + DispatchKeyFormat(iHitbox, "OnBreak", "season_rotating_%d,KillHierarchy,,2.5,1", g_iCounter); + DispatchKeyFormat(iHitbox, "OnBreak", "season_particle_%d,Start,,0,1", g_iCounter); + DispatchKeyFormat(iHitbox, "OnBreak", "season_sound_%d,Start,PlaySound,,0,1", g_iCounter); + DispatchKeyFormat(iHitbox, "OnBreak", "season_sound_%d,Start,Kill,,2.4,1", g_iCounter); + DispatchKeyFormat(iHitbox, "OnUser1", "season_rotating_%d,KillHierarchy,,59.0,1", g_iCounter); + DispatchKeyFormat(iHitbox, "OnUser1", "season_sound_%d,Start,Kill,,59.0,1", g_iCounter); + DispatchKeyFormat(iHitbox, "OnUser2", "season_rotating_%d,KillHierarchy,,0,1", g_iCounter); + DispatchKeyFormat(iHitbox, "OnUser2", "season_sound_%d,Start,Kill,,0,1", g_iCounter); + SpawnAndActivate(iHitbox); + ParentToEntity(iHitbox, iRotating); + + HookSingleEntityOutput(iHitbox, "OnBreak", HookCallback, true); + + + AcceptEntityInput(iHitbox, "FireUser1"); AcceptEntityInput(iTrigger, "Enable"); - int iEntityLimit = GetConVarInt(g_hCVar_EntityLimit); + int iEntityLimit = g_hCVar_EntityLimit.IntValue; - if ((iRotating > iEntityLimit) || (iParticle > iEntityLimit) || (iProp > iEntityLimit) || (iHitbox > iEntityLimit) || (iTrigger > iEntityLimit) || (iAmbient > iEntityLimit)) + if ((iRotating > iEntityLimit) || (iParticle > iEntityLimit) || (iModel > iEntityLimit) || (iHitbox > iEntityLimit) || (iTrigger > iEntityLimit) || (iSound > iEntityLimit)) { AcceptEntityInput(iHitbox, "FireUser2"); CPrintToChatAll("{green}[Unloze XMAS] {white}Present removed due to {red}critical amount of entities{white}!"); } + + g_iCounter += 1; } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public int GetTargetClient() { - int[] iEligibleClients = new int[MaxClients]; + int iEligibleClients[MAXPLAYERS+1]; int iClientCount = 0; + for(int i = 1; i <= MaxClients; i++) { if(IsClientInGame(i) && IsPlayerAlive(i) && (ZR_IsClientHuman(i))) @@ -406,382 +606,168 @@ public int GetTargetClient() iClientCount += 1; } } + if (iClientCount == 0) return -1; + int randomIndex = GetRandomInt(0, iClientCount - 1); return iEligibleClients[randomIndex]; } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public void HookCallbackTrigger(const char[] output, int caller, int activator, float delay) { - if (!ZR_IsClientHuman(activator)) + if (ZR_IsClientZombie(activator)) { UnhookSingleEntityOutput(caller, "OnStartTouch", HookCallbackTrigger); AcceptEntityInput(caller, "FireUser1"); - CPrintToChatAll("{green}[Unloze XMAS] {white}Zombies {red}destroyed{white} a present!"); - + CPrintToChatAll("{green}[UNLOZE XMAS] {white}Zombies {red}destroyed{white} a present!"); } } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public void HookCallback(const char[] output, int caller, int activator, float delay) { - UpdateMYSQL(); -} - -public bool UpdateMYSQL() -{ - char error[255]; - Database db; - if (SQL_CheckConfig("season")) - { - db = SQL_Connect("season", true, error, sizeof(error)); - } - if (db == null) - { - LogError("Could not connect to database: %s", error); - delete db; - return false; - } for (int client = 1; client <= MaxClients; client++) { - if (Client_IsValid(client) && IsClientInGame(client) && IsPlayerAlive(client) && !IsFakeClient(client) && !IsClientSourceTV(client)&& ZR_IsClientHuman(client)) + if (IsValidClient(client) && !IsClientSourceTV(client) && IsPlayerAlive(client) && ZR_IsClientHuman(client)) { - char sSID[64]; - char sName[MAX_NAME_LENGTH]; - GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); - GetClientName(client, sName, sizeof(sName)); + char sSteamID[32]; + GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); char sQuery[255]; - Format(sQuery, sizeof(sQuery), "SELECT collected FROM season_table WHERE steam_auth = '%s'", sSID); - DBResultSet rs; - if ((rs = SQL_Query(db, sQuery)) == null) - { - delete db; - delete rs; - return false; - - } - int iCollected; - if (!(rs.RowCount > 0)) - { - iCollected = 0; - Format(sQuery, sizeof(sQuery), "INSERT INTO season_table (steam_auth, name, collected) VALUES ('%s', '%s', '%d')", sSID, sName, iCollected); - SQL_FastQuery(db, sQuery); - } - else - { - int iField; - rs.FetchRow(); - rs.FieldNameToNum("collected", iField); - iCollected = rs.FetchInt(iField); - } - iCollected += 1; - Format(sQuery, sizeof(sQuery), "UPDATE season_table SET name='%s', collected='%d' WHERE steam_auth='%s'", sName, iCollected, sSID); - SQL_FastQuery(db, sQuery); - delete rs; - CheckAndAddFlag(client, iCollected); - CPrintToChat(client, "{green}[Unloze XMAS] {white}Your Team opened a present! You have collected {green}%d {white}presents so far.", iCollected); - if (iCollected == GetConVarInt(g_hCVar_MilestoneInfection)) - CPrintToChat(client, "{green}[Unloze XMAS] {white}Congratulations! You have unlocked {red}INFECTION EFFECTS{white}!"); - - if (iCollected == GetConVarInt(g_hCVar_MilestoneGrenade)) - CPrintToChat(client, "{green}[Unloze XMAS] {white}Congratulations! You have unlocked {red}GRENADE SKINS{white}!"); - - if (iCollected == GetConVarInt(g_hCVar_MilestoneSkin)) - CPrintToChat(client, "{green}[Unloze XMAS] {white}Congratulations! You have unlocked {red}XMAS SKINS{white}!"); + Format(sQuery, sizeof(sQuery), "SELECT collected FROM season_table WHERE steam_auth = '%s'", sSteamID); + SQL_TQuery(g_hDatabase, TQueryCBUpdate, sQuery, GetClientUserId(client)); } } - delete db; - return true; } -public void CheckAndAddFlag(int client, int iCollected) +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void TQueryCBUpdate(Handle owner, Handle rs, const char[] error, any data) { - if (iCollected >= GetConVarInt(g_hCVar_MilestoneSkin)) + int client = 0; + + if ((client = GetClientOfUserId(data)) == 0) + return; + + char sQuery[255]; + char sName[MAX_NAME_LENGTH]; + GetClientName(client, sName, sizeof(sName)); + char sSteamID[32]; + GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); + + if (SQL_GetRowCount(rs) > 0) { - AddUserFlags(client, Admin_Custom4); + int iField; + SQL_FetchRow(rs); + SQL_FieldNameToNum(rs, "collected", iField); + g_iCollected[client] = SQL_FetchInt(rs, iField); + g_iCollected[client] += 1; + Format(sQuery, sizeof(sQuery), "UPDATE season_table SET name='%s', collected='%d' WHERE steam_auth='%s'", sName, g_iCollected[client], sSteamID); + SQL_FastQuery(g_hDatabase, sQuery); } -} - -public int SpawnTrigger(int iHitbox) -{ - char StrOutput1[128]; - Format(StrOutput1, sizeof(StrOutput1), "season_hitbox_%i,FireUser2,,0,1", iHitbox); - - int Entity; - // Spawn dynamic prop entity - if ((Entity = CreateEntityByName("trigger_multiple")) == INVALID_ENT_REFERENCE) - return -1; - - // Generate unique id for the entity - char StrEntityName[64]; - Format(StrEntityName, sizeof(StrEntityName), "trigger_multiple_%i", Entity); - - // Setup entity - DispatchKeyValue(Entity, "targetname", StrEntityName); - DispatchKeyValue(Entity, "spawnflags", "1"); - DispatchKeyValue(Entity, "startdisabled", "1"); - DispatchKeyValueVector(Entity, "origin", g_fPropOrigin); - DispatchKeyValue(Entity, "OnUser1", StrOutput1); - DispatchSpawn(Entity); - ActivateEntity(Entity); - - SetEntityModel(Entity, "models/zombieden/xmas/giftbox.mdl"); - float fMinbounds[3] = {-16.0, -16.0, -1.0}; - float fMaxbounds[3] = {16.0, 16.0, 32.0}; - SetEntPropVector(Entity, Prop_Send, "m_vecMins", fMinbounds); - SetEntPropVector(Entity, Prop_Send, "m_vecMaxs", fMaxbounds); - SetEntProp(Entity, Prop_Send, "m_nSolidType", 2); - int enteffects = GetEntProp(Entity, Prop_Send, "m_fEffects"); - enteffects |= 32; - SetEntProp(Entity, Prop_Send, "m_fEffects", enteffects); - HookSingleEntityOutput(Entity, "OnStartTouch", HookCallbackTrigger, false); - return Entity; -} - -public int SpawnRotating() -{ - int Entity; - // Spawn dynamic prop entity - if ((Entity = CreateEntityByName("func_rotating")) == INVALID_ENT_REFERENCE) - return -1; - - // Generate unique id for the entity - char StrEntityName[64]; - Format(StrEntityName, sizeof(StrEntityName), "season_rotating_%i", Entity); - - // Setup entity - DispatchKeyValue(Entity, "targetname", StrEntityName); - DispatchKeyValue(Entity, "maxspeed", "20"); - DispatchKeyValue(Entity, "spawnflags", "65"); - DispatchKeyValueVector(Entity, "origin", g_fPropOrigin); - DispatchSpawn(Entity); - ActivateEntity(Entity); - - SetEntityModel(Entity, "models/zombieden/xmas/giftbox.mdl"); - float fMinbounds[3] = {-1.00, -1.00, -1.00}; - float fMaxbounds[3] = {1.00, 1.00, 1.00}; - SetEntPropVector(Entity, Prop_Send, "m_vecMins", fMinbounds); - SetEntPropVector(Entity, Prop_Send, "m_vecMaxs", fMaxbounds); - SetEntProp(Entity, Prop_Send, "m_nSolidType", 2); - int enteffects = GetEntProp(Entity, Prop_Send, "m_fEffects"); - enteffects |= 32; - SetEntProp(Entity, Prop_Send, "m_fEffects", enteffects); - return Entity; -} - -public int SpawnProp() -{ - int Entity; - // Spawn dynamic prop entity - if ((Entity = CreateEntityByName("prop_dynamic_override")) == INVALID_ENT_REFERENCE) - return -1; - - // Setup entity - DispatchKeyValue(Entity, "targetname", "season_prop"); - DispatchKeyValue(Entity, "model", "models/zombieden/xmas/giftbox.mdl"); - DispatchKeyValue(Entity, "modelscale", "0.8"); - DispatchKeyValue(Entity, "disableshadows", "1"); - DispatchKeyValue(Entity, "disablereceiveshadows", "1"); - DispatchKeyValue(Entity, "DisableBoneFollowers", "1"); - DispatchKeyValueVector(Entity, "origin", g_fPropOrigin); - - DispatchSpawn(Entity); - ActivateEntity(Entity); - - int iRandomSkin = GetRandomInt(0, 1); - if (iRandomSkin == 0) + else { - SetVariantString("0"); + Format(sQuery, sizeof(sQuery), "INSERT INTO season_table (steam_auth, name, collected) VALUES ('%s', '%s', '%d')", sSteamID, sName, 1); + SQL_FastQuery(g_hDatabase, sQuery); + g_iCollected[client] = 1; } - else if (iRandomSkin == 1) - { - SetVariantString("1"); - } - AcceptEntityInput(Entity, "Skin"); - return Entity; -} + delete rs; + CheckAndAddFlag(client); -public int SpawnParticle() -{ - int Entity; - // Spawn dynamic prop entity - if ((Entity = CreateEntityByName("info_particle_system")) == INVALID_ENT_REFERENCE) - return -1; + CPrintToChat(client, "{green}[UNLOZE XMAS] {white}Your Team opened a present! You have collected {green}%d {white}presents so far.", g_iCollected[client]); + if (g_iCollected[client] == g_hCVar_MilestoneInfection.IntValue) + CPrintToChat(client, "{green}[UNLOZE XMAS] {white}Congratulations! You have unlocked {red}INFECTION EFFECTS{white}!"); - // Generate unique id for the entity - char StrEntityName[64]; - Format(StrEntityName, sizeof(StrEntityName), "season_particle_%i", Entity); + if (g_iCollected[client] == g_hCVar_MilestoneGrenade.IntValue) + CPrintToChat(client, "{green}[UNLOZE XMAS] {white}Congratulations! You have unlocked {red}GRENADE SKINS{white}!"); - // Setup entity - DispatchKeyValue(Entity, "targetname", StrEntityName); - DispatchKeyValue(Entity, "effect_name", "achieved"); - DispatchKeyValueVector(Entity, "origin", g_fPropOrigin); - DispatchSpawn(Entity); - ActivateEntity(Entity); - return Entity; -} - -public int SpawnHitbox(int iRotatingParent, int iParticleParent) -{ - char StrOutput1[128]; - Format(StrOutput1, sizeof(StrOutput1), "season_rotating_%i,KillHierarchy,,2.5,1", iRotatingParent); - - char StrOutput2[128]; - Format(StrOutput2, sizeof(StrOutput2), "season_particle_%i,Start,,0,1", iParticleParent); - - char StrOutput3[128]; - Format(StrOutput3, sizeof(StrOutput3), "season_rotating_%i,KillHierarchy,,59.0,1", iRotatingParent); - - char StrOutput4[128]; - Format(StrOutput4, sizeof(StrOutput4), "season_sound_hohohoho,Kill,,59.0,1"); - - char StrOutput5[128]; - Format(StrOutput5, sizeof(StrOutput5), "season_rotating_%i,KillHierarchy,,0,1", iRotatingParent); - - char StrOutput6[128]; - Format(StrOutput6, sizeof(StrOutput6), "season_sound_hohohoho,Kill,,0,1"); - - int Entity; - // Spawn dynamic prop entity - if ((Entity = CreateEntityByName("func_physbox_multiplayer")) == INVALID_ENT_REFERENCE) - return -1; - - // Generate unique id for the entity - char StrEntityName[64]; - Format(StrEntityName, sizeof(StrEntityName), "season_hitbox_%i", Entity); - - // Setup entity - DispatchKeyValue(Entity, "targetname", StrEntityName); - DispatchKeyValue(Entity, "model", "models/zombieden/xmas/giftbox.mdl"); - DispatchKeyValue(Entity, "modelscale", "0.8"); - DispatchKeyValue(Entity, "disableshadows", "1"); - DispatchKeyValue(Entity, "disablereceiveshadows", "1"); - DispatchKeyValue(Entity, "DisableBoneFollowers", "1"); - DispatchKeyValue(Entity, "rendermode", "10"); - DispatchKeyValue(Entity, "PerformanceMode", "1"); - DispatchKeyValue(Entity, "material", "3"); - DispatchKeyValue(Entity, "health", "200"); - DispatchKeyValue(Entity, "physdamagescale", "1.0"); - DispatchKeyValueVector(Entity, "origin", g_fPropOrigin); - DispatchKeyValue(Entity, "OnBreak", StrOutput1); - DispatchKeyValue(Entity, "OnBreak", StrOutput2); - DispatchKeyValue(Entity, "OnBreak", "season_sound_hohohoho,PlaySound,,0,1"); - DispatchKeyValue(Entity, "OnBreak", "season_sound_hohohoho,Kill,,2.4,1"); - DispatchKeyValue(Entity, "OnUser1", StrOutput3); - DispatchKeyValue(Entity, "OnUser1", StrOutput4); - DispatchKeyValue(Entity, "OnUser2", StrOutput5); - DispatchKeyValue(Entity, "OnUser2", StrOutput6); - DispatchSpawn(Entity); - ActivateEntity(Entity); - AcceptEntityInput(Entity, "FireUser1"); - HookSingleEntityOutput(Entity, "OnBreak", HookCallback, true); - return Entity; -} - -public int SpawnAmbientHohohoho() -{ - int Entity; - // Spawn dynamic prop entity - if ((Entity = CreateEntityByName("ambient_generic")) == INVALID_ENT_REFERENCE) - return -1; - - // Setup entity - DispatchKeyValue(Entity, "targetname", "season_sound_hohohoho"); - DispatchKeyValueVector(Entity, "origin", g_fPropOrigin); - DispatchKeyValue(Entity, "spawnflags", "49"); - DispatchKeyValue(Entity, "radius", "2000"); - DispatchKeyValue(Entity, "message", "unl1/season/hohohoho.wav"); - DispatchKeyValue(Entity, "volume", "10"); - DispatchKeyValue(Entity, "health", "10"); - DispatchKeyValue(Entity, "pitch", "100"); - DispatchKeyValue(Entity, "pitchstart", "100"); - DispatchSpawn(Entity); - ActivateEntity(Entity); - return Entity; + if (g_iCollected[client] == g_hCVar_MilestoneSkin.IntValue) + CPrintToChat(client, "{green}[UNLOZE XMAS] {white}Congratulations! You have unlocked {red}XMAS SKINS{white}!"); } public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn) { - if (GetConVarBool(g_hCVar_InfectionEffectEnabled) && ((CheckMYSQL(client) >= GetConVarInt(g_hCVar_MilestoneInfection)) || CheckMYSQL(attacker) >= GetConVarInt(g_hCVar_MilestoneInfection))) + if (g_hCVar_InfectionEffectEnabled.BoolValue && ((g_iCollected[client] >= g_hCVar_MilestoneInfection.IntValue) || g_iCollected[attacker] >= g_hCVar_MilestoneInfection.IntValue)) { float fInfectionOrigin[3]; GetClientAbsOrigin(client, fInfectionOrigin); - int EntityProp; - EntityProp = CreateEntityByName("prop_dynamic_override"); - DispatchKeyValue(EntityProp, "targetname", "season_infection_prop"); + + // Rotating + int iRotating = CreateEntityAtOrigin("func_rotating", fInfectionOrigin); + DispatchKeyFormat(iRotating, "targetname", "season_infection_rotating_%d", g_iCounter); + DispatchKeyFormat(iRotating, "maxspeed", "13"); + DispatchKeyFormat(iRotating, "spawnflags", "65"); + DispatchKeyFormat(iRotating, "OnUser1", "!self,KillHierarchy,,45,1"); + DispatchKeyFormat(iRotating, "OnUser2", "!self,KillHierarchy,,0,1"); + SpawnAndActivate(iRotating); + + // make the trigger work. + SetEntityBBox(iRotating, view_as({-10.0, -1.0, -1.0}), view_as({1.0, 1.0, 1.0})); + SetEntityProps(iRotating); + + + int iModel = CreateEntityAtOrigin("prop_dynamic_override", fInfectionOrigin); + DispatchKeyFormat(iModel, "targetname", "season_infection_prop_%d", g_iCounter); int iRandomSkin = GetRandomInt(0, 4); if (iRandomSkin == 0) { - DispatchKeyValue(EntityProp, "model", "models/models_kit/xmas/xmastree_mini.mdl"); - DispatchKeyValue(EntityProp, "modelscale", "0.35"); - DispatchKeyValue(EntityProp, "angles", "0 0 0"); + DispatchKeyFormat(iModel, "model", "models/models_kit/xmas/xmastree_mini.mdl"); + DispatchKeyFormat(iModel, "modelscale", "0.35"); + DispatchKeyFormat(iModel, "angles", "0 0 0"); } else if (iRandomSkin == 1) { - DispatchKeyValue(EntityProp, "model", "models/weapons/w_revenge_xmas_candy.mdl"); - DispatchKeyValue(EntityProp, "modelscale", "1.2"); - DispatchKeyValue(EntityProp, "angles", "-27 0 0"); + DispatchKeyFormat(iModel, "model", "models/weapons/w_revenge_xmas_candy.mdl"); + DispatchKeyFormat(iModel, "modelscale", "1.2"); + DispatchKeyFormat(iModel, "angles", "-27 0 0"); } else if (iRandomSkin == 2) { - DispatchKeyValue(EntityProp, "model", "models/johny-srka/snowman.mdl"); - DispatchKeyValue(EntityProp, "modelscale", "0.45"); - DispatchKeyValue(EntityProp, "angles", "0 0 0"); + DispatchKeyFormat(iModel, "model", "models/johny-srka/snowman.mdl"); + DispatchKeyFormat(iModel, "modelscale", "0.45"); + DispatchKeyFormat(iModel, "angles", "0 0 0"); + } else if (iRandomSkin == 3) { - DispatchKeyValue(EntityProp, "model", "models/weapons/w_santa_hat_thrown.mdl"); - DispatchKeyValue(EntityProp, "modelscale", "2.7"); - DispatchKeyValue(EntityProp, "angles", "0 0 -90"); + DispatchKeyFormat(iModel, "model", "models/weapons/w_santa_hat_thrown.mdl"); + DispatchKeyFormat(iModel, "modelscale", "2.7"); + DispatchKeyFormat(iModel, "angles", "0 0 -90"); fInfectionOrigin[2] += 7; } else if (iRandomSkin == 4) { - DispatchKeyValue(EntityProp, "model", "models/models_kit/xmas/xmas_teddybear.mdl"); - DispatchKeyValue(EntityProp, "modelscale", "0.7"); + DispatchKeyFormat(iModel, "model", "models/models_kit/xmas/xmas_teddybear.mdl"); + DispatchKeyFormat(iModel, "modelscale", "0.7"); + DispatchKeyFormat(iModel, "angles", "0 0 0"); } - DispatchKeyValue(EntityProp, "disableshadows", "1"); - DispatchKeyValue(EntityProp, "disablereceiveshadows", "1"); - DispatchKeyValue(EntityProp, "DisableBoneFollowers", "1"); - DispatchKeyValueVector(EntityProp, "origin", fInfectionOrigin); - DispatchSpawn(EntityProp); - ActivateEntity(EntityProp); + DispatchKeyFormat(iModel, "disableshadows", "1"); + DispatchKeyFormat(iModel, "disablereceiveshadows", "1"); + DispatchKeyFormat(iModel, "DisableBoneFollowers", "1"); + DispatchKeyValueVector(iModel, "origin", fInfectionOrigin); + SpawnAndActivate(iModel); + ParentToEntity(iModel, iRotating); - int EntityRotating; - EntityRotating = CreateEntityByName("func_rotating"); - DispatchKeyValue(EntityRotating, "targetname", "season_infection_rotating"); - DispatchKeyValue(EntityRotating, "maxspeed", "13"); - DispatchKeyValue(EntityRotating, "spawnflags", "65"); - DispatchKeyValueVector(EntityRotating, "origin", fInfectionOrigin); - DispatchKeyValue(EntityRotating, "OnUser1", "!self,KillHierarchy,,45,1"); - DispatchKeyValue(EntityRotating, "OnUser2", "!self,KillHierarchy,,0,1"); - DispatchSpawn(EntityRotating); - ActivateEntity(EntityRotating); + AcceptEntityInput(iRotating, "FireUser1"); - SetEntityModel(EntityRotating, "models/models_kit/xmas/xmastree_mini.mdl"); - float fMinbounds[3] = {-1.00, -1.00, -1.00}; - float fMaxbounds[3] = {1.00, 1.00, 1.00}; - SetEntPropVector(EntityRotating, Prop_Send, "m_vecMins", fMinbounds); - SetEntPropVector(EntityRotating, Prop_Send, "m_vecMaxs", fMaxbounds); - SetEntProp(EntityRotating, Prop_Send, "m_nSolidType", 2); - int enteffects = GetEntProp(EntityRotating, Prop_Send, "m_fEffects"); - enteffects |= 32; - SetEntProp(EntityRotating, Prop_Send, "m_fEffects", enteffects); - - SetVariantString("!activator"); - AcceptEntityInput(EntityProp, "SetParent", EntityRotating); - AcceptEntityInput(EntityRotating, "FireUser1"); - - int iEntityLimit = GetConVarInt(g_hCVar_EntityLimit); - if ((EntityRotating > iEntityLimit) || (EntityProp > iEntityLimit)) + int iEntityLimit = g_hCVar_EntityLimit.IntValue; + if ((iModel > iEntityLimit) || (iRotating > iEntityLimit)) { - AcceptEntityInput(EntityRotating, "FireUser2"); + AcceptEntityInput(iRotating, "FireUser2"); CPrintToChatAll("{green}[Unloze XMAS] {white}Infection Effect removed due to {red}critical amount of entities{white}!"); } + + g_iCounter += 1; } } @@ -795,54 +781,124 @@ public void OnEntityCreated(int entity, const char[] classname) public void ProjectileSpawned(int Entity) { int iOwner = GetEntPropEnt(Entity, Prop_Data, "m_hOwnerEntity"); - if(0 < iOwner <= MaxClients && IsClientInGame(iOwner)) + if(!IsValidClient(iOwner)) + return; + + if (g_iCollected[iOwner] >= g_hCVar_MilestoneGrenade.IntValue) { - if (CheckMYSQL(iOwner) >= GetConVarInt(g_hCVar_MilestoneGrenade)) + int iRandomSkin = GetRandomInt(0, 3); + if (iRandomSkin == 0) { - int iRandomSkin = GetRandomInt(0, 3); + SetEntityModel(Entity, "models/weapons/w_snowball_thrown.mdl"); + SetVariantString("modelscale 3.0"); + AcceptEntityInput(Entity, "AddOutput"); + } + else if (iRandomSkin == 1) + { + SetEntityModel(Entity, "models/zombieden/xmas/giftbox.mdl"); + SetVariantString("modelscale 0.6"); + AcceptEntityInput(Entity, "AddOutput"); + iRandomSkin = GetRandomInt(0, 1); if (iRandomSkin == 0) { - SetEntityModel(Entity, "models/weapons/w_snowball_thrown.mdl"); - SetVariantString("modelscale 3.0"); - AcceptEntityInput(Entity, "AddOutput"); + SetVariantString("0"); } else if (iRandomSkin == 1) { - SetEntityModel(Entity, "models/zombieden/xmas/giftbox.mdl"); - SetVariantString("modelscale 0.6"); - AcceptEntityInput(Entity, "AddOutput"); - iRandomSkin = GetRandomInt(0, 1); - if (iRandomSkin == 0) - { - SetVariantString("0"); - } - else if (iRandomSkin == 1) - { - SetVariantString("1"); - } - AcceptEntityInput(Entity, "Skin"); - } - else if (iRandomSkin == 2) - { - SetEntityModel(Entity, "models/weapons/w_ornament_thrown.mdl"); - SetVariantString("modelscale 2.0"); - AcceptEntityInput(Entity, "AddOutput"); - } - else if (iRandomSkin == 3) - { - SetEntityModel(Entity, "models/weapons/w_santa_hat_thrown.mdl"); - SetVariantString("modelscale 2.3"); - AcceptEntityInput(Entity, "AddOutput"); + SetVariantString("1"); } + AcceptEntityInput(Entity, "Skin"); + } + else if (iRandomSkin == 2) + { + SetEntityModel(Entity, "models/weapons/w_ornament_thrown.mdl"); + SetVariantString("modelscale 2.0"); + AcceptEntityInput(Entity, "AddOutput"); + } + else if (iRandomSkin == 3) + { + SetEntityModel(Entity, "models/weapons/w_santa_hat_thrown.mdl"); + SetVariantString("modelscale 2.3"); + AcceptEntityInput(Entity, "AddOutput"); } } } -int IsValidClient(int client, bool nobots = true) +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock int IsValidClient(int client, bool nobots = true) { if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client))) - { return false; - } + return IsClientInGame(client); -} \ No newline at end of file +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void CheckAndAddFlag(int client) +{ + if (g_iCollected[client] >= g_hCVar_MilestoneSkin.IntValue) + AddUserFlags(client, Admin_Custom4); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock int CreateEntityAtOrigin(const char[] classname, const float origin[3]) +{ + int entity = CreateEntityByName(classname); + + TeleportEntity(entity, origin, NULL_VECTOR, NULL_VECTOR); + + return entity; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock bool DispatchKeyFormat(int entity, const char[] key, const char[] value, any ...) +{ + char buffer[1024]; + VFormat(buffer, sizeof(buffer), value, 4); + + DispatchKeyValue(entity, key, buffer); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock void SpawnAndActivate(int entity) +{ + DispatchSpawn(entity); + ActivateEntity(entity); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock void ParentToEntity(int entity, int parent) +{ + SetVariantString("!activator"); + AcceptEntityInput(entity, "SetParent", parent, parent); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock void SetEntityBBox(int entity, const float mins[3], const float maxs[3]) +{ + SetEntPropVector(entity, Prop_Send, "m_vecMins", mins); + SetEntPropVector(entity, Prop_Send, "m_vecMaxs", maxs); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock void SetEntityProps(int entity) +{ + SetEntProp(entity, Prop_Send, "m_nSolidType", 3); + SetEntProp(entity, Prop_Send, "m_fEffects", 32); +}