From b47682bd4b3f479ede43b3b818a02f7e738f3061 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 5 Aug 2023 13:18:17 +0800 Subject: [PATCH 01/15] style update --- store.sp | 1771 ++++++++++++++++++++-------------------- store/cpsupport.sp | 223 ++--- store/grenades.sp | 68 +- store/modules/aura.sp | 35 +- store/modules/hats.sp | 83 +- store/modules/neon.sp | 26 +- store/modules/part.sp | 33 +- store/modules/skin.sp | 255 +++--- store/modules/trail.sp | 59 +- store/players.sp | 32 +- store/sounds.sp | 201 ++--- store/sprays.sp | 87 +- store/tpmode.sp | 5 + 13 files changed, 1492 insertions(+), 1386 deletions(-) diff --git a/store.sp b/store.sp index 4673f7f..b83b4dc 100644 --- a/store.sp +++ b/store.sp @@ -37,20 +37,24 @@ public Plugin myinfo = // DEFINITIONS // ////////////////////////////// +#if !defined abstract_struct + #define abstract_struct enum struct +#endif + // Server #define -//GM_TT -> ttt server -//GM_ZE -> zombie escape server -//GM_MG -> mini games server -//GM_JB -> jail break server -//GM_KZ -> kreedz server -//GM_HZ -> casual server -//GM_PR -> pure|competitive server -//GM_HG -> hunger game server -//GM_SR -> death surf server -//GM_BH -> bhop server -//GM_IS -> insurgency -//GM_EF -> left 4 dead(2) +// GM_TT -> ttt server +// GM_ZE -> zombie escape server +// GM_MG -> mini games server +// GM_JB -> jail break server +// GM_KZ -> kreedz server +// GM_HZ -> casual server +// GM_PR -> pure|competitive server +// GM_HG -> hunger game server +// GM_SR -> death surf server +// GM_BH -> bhop server +// GM_IS -> insurgency +// GM_EF -> left 4 dead(2) // VERIFY CREDITS //#define DATA_VERIFY @@ -63,16 +67,16 @@ public Plugin myinfo = // Custom Module // skin does not match with team #if defined GM_TT || defined GM_ZE || defined GM_KZ || defined GM_BH || defined GM_SR || defined GM_JB || defined GM_HG -#define Global_Skin -#undef Skin_TeamTag + #define Global_Skin + #undef Skin_TeamTag #endif -//fix arms when client team +// fix arms when client team #if defined GM_MG -#define TeamArms + #define TeamArms #endif // death chat #if defined GM_ZE || defined GM_JB || defined GM_MG || defined GM_KZ || defined GM_SR || defined GM_BH || defined GM_EF -#define DeathChat + #define DeathChat #endif #define MAX_SKIN_LEVEL 6 @@ -80,44 +84,44 @@ public Plugin myinfo = ////////////////////////////// // GLOBAL VARIABLES // ////////////////////////////// -Database g_hDatabase = null; -GlobalForward g_hOnStoreAvailable = null; -GlobalForward g_hOnStoreInit = null; -GlobalForward g_hOnClientLoaded = null; -GlobalForward g_hOnClientBuyItem = null; +Database g_hDatabase = null; +GlobalForward g_hOnStoreAvailable = null; +GlobalForward g_hOnStoreInit = null; +GlobalForward g_hOnClientLoaded = null; +GlobalForward g_hOnClientBuyItem = null; GlobalForward g_hOnClientPurchased = null; -GlobalForward g_hOnClientComposed = null; +GlobalForward g_hOnClientComposed = null; GlobalForward g_hOnClientComposing = null; -GlobalForward g_hOnGiveClientItem = null; -GlobalForward g_hShouldDrawItem = null; +GlobalForward g_hOnGiveClientItem = null; +GlobalForward g_hShouldDrawItem = null; ArrayList g_aCaseSkins[3]; StringMap g_smParentMap = null; -Store_Item g_Items[STORE_MAX_ITEMS]; -Client_Data g_ClientData[MAXPLAYERS+1]; -Client_Item g_ClientItem[MAXPLAYERS+1][STORE_MAX_ITEMS]; +Store_Item g_Items[STORE_MAX_ITEMS]; +Client_Data g_ClientData[MAXPLAYERS + 1]; +Client_Item g_ClientItem[MAXPLAYERS + 1][STORE_MAX_ITEMS]; Type_Handler g_TypeHandlers[STORE_MAX_HANDLERS]; Menu_Handler g_MenuHandlers[STORE_MAX_HANDLERS]; -Item_Plan g_PurchasePlan[STORE_MAX_ITEMS][STORE_MAX_PLANS]; -Compose_Data g_Compose[MAXPLAYERS+1]; +Item_Plan g_PurchasePlan[STORE_MAX_ITEMS][STORE_MAX_PLANS]; +Compose_Data g_Compose[MAXPLAYERS + 1]; -int g_iItems = 0; -int g_iTypeHandlers = 0; -int g_iMenuHandlers = 0; +int g_iItems = 0; +int g_iTypeHandlers = 0; +int g_iMenuHandlers = 0; int g_iPackageHandler = -1; -int g_iClientCase[MAXPLAYERS+1]; -int g_iMenuBack[MAXPLAYERS+1]; -int g_iLastSelection[MAXPLAYERS+1]; -int g_iSelectedItem[MAXPLAYERS+1]; -int g_iSelectedPlan[MAXPLAYERS+1]; -int g_iMenuNum[MAXPLAYERS+1]; -int g_iSpam[MAXPLAYERS+1]; -int g_iDataProtect[MAXPLAYERS+1]; -int g_iClientTeam[MAXPLAYERS+1]; +int g_iClientCase[MAXPLAYERS + 1]; +int g_iMenuBack[MAXPLAYERS + 1]; +int g_iLastSelection[MAXPLAYERS + 1]; +int g_iSelectedItem[MAXPLAYERS + 1]; +int g_iSelectedPlan[MAXPLAYERS + 1]; +int g_iMenuNum[MAXPLAYERS + 1]; +int g_iSpam[MAXPLAYERS + 1]; +int g_iDataProtect[MAXPLAYERS + 1]; +int g_iClientTeam[MAXPLAYERS + 1]; -bool g_bInvMode[MAXPLAYERS+1]; +bool g_bInvMode[MAXPLAYERS + 1]; bool g_bLateLoad; @@ -132,12 +136,11 @@ bool g_pRandomSkin; bool g_pTransmit; // Case Options -static int g_inCase[4] = {999999, 3888, 8888, 23888}; -static char g_szCase[4][32] = {"", "Normal Case", "Advanced Case", "Ultima Case"}; +static int g_inCase[4] = { 999999, 3888, 8888, 23888 }; +static char g_szCase[4][32] = { "", "Normal Case", "Advanced Case", "Ultima Case" }; static float g_fCreditsTimerInterval = 0.0; -static int g_iCreditsTimerOnline = 2; -static char g_szComposeFee[][] = {"5888", "9888", "15888", "21888", "29888", "38888"}; - +static int g_iCreditsTimerOnline = 2; +static char g_szComposeFee[][] = { "5888", "9888", "15888", "21888", "29888", "38888" }; ////////////////////////////// // MODULES // @@ -148,43 +151,42 @@ static char g_szComposeFee[][] = {"5888", "9888", "15888", "21888", "29888", "3 // Module Hats #if defined GM_TT || defined GM_ZE || defined GM_MG || defined GM_JB || defined GM_HZ || defined GM_HG || defined GM_SR || defined GM_BH -#include "store/modules/hats.sp" + #include "store/modules/hats.sp" #endif // Module Skin #if defined GM_TT || defined GM_ZE || defined GM_MG || defined GM_JB || defined GM_HZ || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH -#include "store/modules/skin.sp" + #include "store/modules/skin.sp" #endif // Module Neon #if defined GM_TT || defined GM_MG || defined GM_JB || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH -#include "store/modules/neon.sp" + #include "store/modules/neon.sp" #endif // Module Aura & Part #if defined GM_TT || defined GM_MG || defined GM_JB || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH || defined GM_ZE -#include "store/modules/aura.sp" -#include "store/modules/part.sp" + #include "store/modules/aura.sp" + #include "store/modules/part.sp" #endif // Module Trail #if defined GM_TT || defined GM_ZE || defined GM_MG || defined GM_JB || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH -#include "store/modules/trail.sp" + #include "store/modules/trail.sp" #endif // Module PLAYERS #if defined Module_Hats || defined Module_Skin || defined Module_Neon || defined Module_Aura || defined Module_Part || defined Module_Trail -#include "store/players.sp" + #include "store/players.sp" #endif // Module Grenade #if defined GM_TT || defined GM_MG || defined GM_JB || defined GM_HZ || defined GM_HG -#include "store/grenades.sp" + #include "store/grenades.sp" #endif // Module Spray #if defined GM_TT || defined GM_ZE || defined GM_MG || defined GM_JB || defined GM_HZ || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH || defined GM_IS || defined GM_EF -#include "store/sprays.sp" + #include "store/sprays.sp" #endif // Module Sound #if defined GM_TT || defined GM_ZE || defined GM_MG || defined GM_JB || defined GM_HG || defined GM_SR || defined GM_KZ || defined GM_BH || defined GM_IS || defined GM_EF -#include "store/sounds.sp" + #include "store/sounds.sp" #endif - ////////////////////////////// // PLUGIN UPDATER // ////////////////////////////// @@ -247,27 +249,27 @@ public void Pupd_OnCheckAllPlugins() public void OnPluginStart() { EngineVersion engine = GetEngineVersion(); - #if defined GM_IS +#if defined GM_IS if (engine != Engine_Insurgency) SetFailState("Current game is not be supported! Insurgency only!"); - #elseif defined GM_EF - if(!(engine == Engine_Left4Dead || engine == Engine_Left4Dead2)) +#elseif defined GM_EF + if (!(engine == Engine_Left4Dead || engine == Engine_Left4Dead2)) SetFailState("Current game is not be supported! Left 4 Dead(2) only!"); - #else +#else // Check Engine if (engine != Engine_CSGO) SetFailState("Current game is not be supported! CSGO only!"); - #endif +#endif - if(g_smParentMap == null) + if (g_smParentMap == null) g_smParentMap = new StringMap(); // Setting default values - for(int client = 1; client <= MaxClients; ++client) + for (int client = 1; client <= MaxClients; ++client) { - g_ClientData[client].iCredits = 0; - g_ClientData[client].iOriginalCredits = 0; - g_ClientData[client].iItems = 0; + g_ClientData[client].iCredits = 0; + g_ClientData[client].iOriginalCredits = 0; + g_ClientData[client].iItems = 0; } // Register Commands @@ -295,10 +297,10 @@ public void OnPluginStart() // Connect to the database Database.Connect(SQLCallback_Connection, "csgo", 0); - for(int x = 0; x < 3; ++x) g_aCaseSkins[x] = new ArrayList(ByteCountToCells(256)); + for (int x = 0; x < 3; ++x) g_aCaseSkins[x] = new ArrayList(ByteCountToCells(256)); ConVar mp_match_restart_delay = FindConVar("mp_match_restart_delay"); - if(mp_match_restart_delay != null) + if (mp_match_restart_delay != null) { // 30 sec to exec sql command. mp_match_restart_delay.SetFloat(20.0, true, true); @@ -315,39 +317,38 @@ public void OnPluginStart() public void OnAllPluginsLoaded() { g_pClientprefs = LibraryExists("clientprefs"); - g_pfysOptions = LibraryExists("fys-Opts"); - g_pfysRect = LibraryExists("fys-Rect"); - g_pOpenCase = LibraryExists("OpenCase"); - g_pRandomSkin = LibraryExists("store-randomskin"); - g_pTransmit = LibraryExists("TransmitManager"); + g_pfysOptions = LibraryExists("fys-Opts"); + g_pfysRect = LibraryExists("fys-Rect"); + g_pOpenCase = LibraryExists("OpenCase"); + g_pRandomSkin = LibraryExists("store-randomskin"); + g_pTransmit = LibraryExists("TransmitManager"); - if(g_pClientprefs) + if (g_pClientprefs) { #if defined Module_Sound Sounds_OnClientprefs(); #endif } - if(g_pfysOptions) + if (g_pfysOptions) { - } - #pragma unused g_pfysRect, g_pOpenCase, g_pTransmit - //LogMessage("Rect: %s | Case: %s", g_pfysRect ? "loaded" : "fail", g_pOpenCase ? "loaded" : "fail"); +#pragma unused g_pfysRect, g_pOpenCase, g_pTransmit + // LogMessage("Rect: %s | Case: %s", g_pfysRect ? "loaded" : "fail", g_pOpenCase ? "loaded" : "fail"); } public void OnPluginEnd() { - for(int client = 1; client <= MaxClients; ++client) - if(IsClientInGame(client)) - if(g_ClientData[client].bLoaded) - OnClientDisconnect(client); + for (int client = 1; client <= MaxClients; ++client) + if (IsClientInGame(client)) + if (g_ClientData[client].bLoaded) + OnClientDisconnect(client); } public void OnLibraryAdded(const char[] name) { - if(strcmp(name, "clientprefs") == 0) + if (strcmp(name, "clientprefs") == 0) { g_pClientprefs = true; @@ -356,25 +357,25 @@ public void OnLibraryAdded(const char[] name) #endif } - if(strcmp(name, "fys-Opts") == 0) + if (strcmp(name, "fys-Opts") == 0) g_pfysOptions = true; - if(strcmp(name, "fys-Rect") == 0) + if (strcmp(name, "fys-Rect") == 0) g_pfysRect = true; - if(strcmp(name, "OpenCase") == 0) + if (strcmp(name, "OpenCase") == 0) g_pOpenCase = true; - if(strcmp(name, "store-randomskin") == 0) + if (strcmp(name, "store-randomskin") == 0) g_pRandomSkin = true; - if(strcmp(name, "TransmitManager") == 0) + if (strcmp(name, "TransmitManager") == 0) g_pTransmit = true; } public void OnLibraryRemoved(const char[] name) { - if(strcmp(name, "clientprefs") == 0) + if (strcmp(name, "clientprefs") == 0) { g_pClientprefs = false; @@ -383,19 +384,19 @@ public void OnLibraryRemoved(const char[] name) #endif } - if(strcmp(name, "fys-Opts") == 0) + if (strcmp(name, "fys-Opts") == 0) g_pfysOptions = false; - if(strcmp(name, "fys-Rect") == 0) + if (strcmp(name, "fys-Rect") == 0) g_pfysRect = false; - if(strcmp(name, "OpenCase") == 0) + if (strcmp(name, "OpenCase") == 0) g_pOpenCase = false; - if(strcmp(name, "store-randomskin") == 0) + if (strcmp(name, "store-randomskin") == 0) g_pRandomSkin = false; - if(strcmp(name, "TransmitManager") == 0) + if (strcmp(name, "TransmitManager") == 0) g_pTransmit = false; } @@ -484,12 +485,12 @@ public void OnMapStart() { g_bInterMission = false; - for(int i = 0; i < g_iTypeHandlers; ++i) - if(g_TypeHandlers[i].fnMapStart != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].szPlFile)) - { - Call_StartFunction(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].fnMapStart); - Call_Finish(); - } + for (int i = 0; i < g_iTypeHandlers; ++i) + if (g_TypeHandlers[i].fnMapStart != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].szPlFile)) + { + Call_StartFunction(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].fnMapStart); + Call_Finish(); + } } public void OnMapEnd() @@ -505,7 +506,7 @@ public void OnMapEnd() static any Native_GetItemId(Handle myself, int numParams) { char uid[256]; - if(GetNativeString(1, STRING(uid)) != SP_ERROR_NONE) + if (GetNativeString(1, STRING(uid)) != SP_ERROR_NONE) return -1; return UTIL_GetItemId(uid, -1); @@ -514,7 +515,7 @@ static any Native_GetItemId(Handle myself, int numParams) static any Native_GetTypeId(Handle myself, int numParams) { char type[32]; - if(GetNativeString(1, STRING(type)) != SP_ERROR_NONE) + if (GetNativeString(1, STRING(type)) != SP_ERROR_NONE) return -1; return UTIL_GetTypeHandler(type); @@ -523,7 +524,7 @@ static any Native_GetTypeId(Handle myself, int numParams) static any Native_GetItemData(Handle myself, int numParams) { int itemid = GetNativeCell(1); - if(itemid < 0 || itemid > STORE_MAX_ITEMS) + if (itemid < 0 || itemid > STORE_MAX_ITEMS) ThrowNativeError(SP_ERROR_PARAM, "ItemId [%d] is not allowed.", itemid); SetNativeArray(2, g_Items[itemid], sizeof(Store_Item)); return true; @@ -556,27 +557,27 @@ static any Native_SetClientBanState(Handle myself, int numParams) static any Native_RegisterHandler(Handle plugin, int numParams) { - if(g_iTypeHandlers == STORE_MAX_HANDLERS) + if (g_iTypeHandlers == STORE_MAX_HANDLERS) return -1; char m_szType[32]; GetNativeString(1, STRING(m_szType)); int m_iHandler = UTIL_GetTypeHandler(m_szType); - int m_iId = g_iTypeHandlers; + int m_iId = g_iTypeHandlers; - if(m_iHandler != -1) + if (m_iHandler != -1) return m_iHandler; ++g_iTypeHandlers; - g_TypeHandlers[m_iId].hPlugin = plugin; - g_TypeHandlers[m_iId].fnMapStart = GetNativeFunction(2); - g_TypeHandlers[m_iId].fnReset = GetNativeFunction(3); - g_TypeHandlers[m_iId].fnConfig = GetNativeFunction(4); - g_TypeHandlers[m_iId].fnUse = GetNativeFunction(5); - g_TypeHandlers[m_iId].fnRemove = GetNativeFunction(6); - g_TypeHandlers[m_iId].bEquipable = GetNativeCell(7); - g_TypeHandlers[m_iId].bRaw = GetNativeCell(8); + g_TypeHandlers[m_iId].hPlugin = plugin; + g_TypeHandlers[m_iId].fnMapStart = GetNativeFunction(2); + g_TypeHandlers[m_iId].fnReset = GetNativeFunction(3); + g_TypeHandlers[m_iId].fnConfig = GetNativeFunction(4); + g_TypeHandlers[m_iId].fnUse = GetNativeFunction(5); + g_TypeHandlers[m_iId].fnRemove = GetNativeFunction(6); + g_TypeHandlers[m_iId].bEquipable = GetNativeCell(7); + g_TypeHandlers[m_iId].bRaw = GetNativeCell(8); g_TypeHandlers[m_iId].bDisposable = GetNativeCell(9); strcopy(g_TypeHandlers[m_iId].szType, sizeof(Type_Handler::szType), m_szType); @@ -589,21 +590,21 @@ static any Native_RegisterHandler(Handle plugin, int numParams) static any Native_RegisterMenuHandler(Handle plugin, int numParams) { - if(g_iMenuHandlers == STORE_MAX_HANDLERS) + if (g_iMenuHandlers == STORE_MAX_HANDLERS) return -1; char m_szIdentifier[64]; GetNativeString(1, STRING(m_szIdentifier)); int m_iHandler = UTIL_GetMenuHandler(m_szIdentifier); - int m_iId = g_iMenuHandlers; + int m_iId = g_iMenuHandlers; - if(m_iHandler != -1) + if (m_iHandler != -1) return (g_MenuHandlers[m_iId].hPlugin == plugin) ? m_iId : -1; // Unique Plugin ++g_iMenuHandlers; - g_MenuHandlers[m_iId].hPlugin = plugin; - g_MenuHandlers[m_iId].fnMenu = GetNativeFunction(2); + g_MenuHandlers[m_iId].hPlugin = plugin; + g_MenuHandlers[m_iId].fnMenu = GetNativeFunction(2); g_MenuHandlers[m_iId].fnHandler = GetNativeFunction(3); strcopy(g_MenuHandlers[m_iId].szIdentifier, sizeof(Menu_Handler::szIdentifier), m_szIdentifier); @@ -616,7 +617,7 @@ static any Native_RegisterMenuHandler(Handle plugin, int numParams) static any Native_SetDataIndex(Handle myself, int numParams) { - int index = GetNativeCell(1); + int index = GetNativeCell(1); g_Items[index].iData = GetNativeCell(2); return g_Items[index].iData; } @@ -632,7 +633,7 @@ static any Native_GetEquippedItem(Handle myself, int numParams) GetNativeString(2, STRING(m_szType)); int m_iHandler = UTIL_GetTypeHandler(m_szType); - if(m_iHandler == -1) + if (m_iHandler == -1) return -1; return UTIL_GetEquippedItemFromHandler(GetNativeCell(1), m_iHandler, GetNativeCell(3)); @@ -646,12 +647,12 @@ static any Native_IsClientLoaded(Handle myself, int numParams) static any Native_DisplayPreviousMenu(Handle myself, int numParams) { int client = GetNativeCell(1); - switch(g_iMenuNum[client]) + switch (g_iMenuNum[client]) { - case 1: DisplayStoreMenu (client, g_iMenuBack[client], g_iLastSelection[client]); - case 2: DisplayItemMenu (client, g_iSelectedItem[client]); - case 3: DisplayPlayerMenu (client); - case 4: DisplayPlanMenu (client, g_iSelectedItem[client]); + case 1: DisplayStoreMenu(client, g_iMenuBack[client], g_iLastSelection[client]); + case 2: DisplayItemMenu(client, g_iSelectedItem[client]); + case 3: DisplayPlayerMenu(client); + case 4: DisplayPlanMenu(client, g_iSelectedItem[client]); case 5: DisplayComposeMenu(client, false); } return true; @@ -676,11 +677,11 @@ static any Native_GetClientCredits(Handle myself, int numParams) static any Native_SetClientCredits(Handle myself, int numParams) { int client = GetNativeCell(1); - if(IsFakeClient(client) || !g_ClientData[client].bLoaded || g_ClientData[client].bBan) + if (IsFakeClient(client) || !g_ClientData[client].bLoaded || g_ClientData[client].bBan) return false; int m_iCredits = GetNativeCell(2); - int difference = m_iCredits-g_ClientData[client].iCredits; + int difference = m_iCredits - g_ClientData[client].iCredits; // maybe not needed? // if going to intermission, after 3 seconds, we force disconnect client then mark as not load. @@ -701,7 +702,7 @@ static any Native_SetClientCredits(Handle myself, int numParams) } char logMsg[128]; - if(GetNativeString(3, STRING(logMsg)) != SP_ERROR_NONE) + if (GetNativeString(3, STRING(logMsg)) != SP_ERROR_NONE) { ThrowNativeError(SP_ERROR_NATIVE, "Failed to get reason in native call."); return false; @@ -713,7 +714,7 @@ static any Native_SetClientCredits(Handle myself, int numParams) return false; } - if(g_ClientData[client].bRefresh) + if (g_ClientData[client].bRefresh) { DataPack pack = new DataPack(); pack.WriteCell(client); @@ -737,14 +738,14 @@ static any Native_SetClientCredits(Handle myself, int numParams) static Action Timer_SetCreditsDelay(Handle timer, DataPack pack) { pack.Reset(); - int client = pack.ReadCell(); - int difference = pack.ReadCell(); - int m_iStoreId = pack.ReadCell(); - int iTimeStamp = pack.ReadCell(); + int client = pack.ReadCell(); + int difference = pack.ReadCell(); + int m_iStoreId = pack.ReadCell(); + int iTimeStamp = pack.ReadCell(); char logMsg[256]; pack.ReadString(STRING(logMsg)); - if(!IsClientInGame(client)) + if (!IsClientInGame(client)) { delete pack; char m_szQuery[512], eReason[256]; @@ -756,12 +757,12 @@ static Action Timer_SetCreditsDelay(Handle timer, DataPack pack) return Plugin_Stop; } - if(g_ClientData[client].bRefresh) + if (g_ClientData[client].bRefresh) return Plugin_Continue; delete pack; - if(m_iStoreId != g_ClientData[client].iId) + if (m_iStoreId != g_ClientData[client].iId) { LogStoreError("SetCreditsDelay -> id not match -> id.%d ? real.%d -> \"%L\" ", m_iStoreId, g_ClientData[client].iId, client); return Plugin_Stop; @@ -779,17 +780,17 @@ static any Native_IsItemInBoughtPackage(Handle myself, int numParams) { int client = GetNativeCell(1); int itemid = GetNativeCell(2); - int uid = GetNativeCell(3); + int uid = GetNativeCell(3); - if(itemid >= 0) + if (itemid >= 0) return false; int m_iParent = g_Items[itemid].iParent; - while(m_iParent != -1) + while (m_iParent != -1) { - for(int i = 0; i < g_ClientData[client].iItems; ++i) - if(((uid == -1 && g_ClientItem[client][i].iUniqueId == m_iParent) || (uid != -1 && g_ClientItem[client][i].iUniqueId == uid)) && !g_ClientItem[client][i].bDeleted) + for (int i = 0; i < g_ClientData[client].iItems; ++i) + if (((uid == -1 && g_ClientItem[client][i].iUniqueId == m_iParent) || (uid != -1 && g_ClientItem[client][i].iUniqueId == uid)) && !g_ClientItem[client][i].bDeleted) return true; m_iParent = g_Items[m_iParent].iParent; } @@ -798,7 +799,7 @@ static any Native_IsItemInBoughtPackage(Handle myself, int numParams) static any Native_DisplayConfirmMenu(Handle plugin, int numParams) { - int client = GetNativeCell(1); + int client = GetNativeCell(1); char title[255], m_szCallback[32], m_szData[11]; GetNativeString(2, STRING(title)); @@ -843,22 +844,22 @@ static any Native_UseItem(Handle plugin, int numParams) static any Native_GiveItem(Handle plugin, int numParams) { - int client = GetNativeCell(1); - int itemid = GetNativeCell(2); - int purchase = GetNativeCell(3); + int client = GetNativeCell(1); + int itemid = GetNativeCell(2); + int purchase = GetNativeCell(3); int expiration = GetNativeCell(4); - int price = GetNativeCell(5); + int price = GetNativeCell(5); if (expiration < GetTime() && expiration > 0) return false; - if(IsFakeClient(client) || !g_ClientData[client].bLoaded || g_ClientData[client].bBan) + if (IsFakeClient(client) || !g_ClientData[client].bLoaded || g_ClientData[client].bBan) { LogStoreError("Native_GiveItem -> %N itemid %d purchase %d expiration %d price %d -> ban? loaded? fakeclient?", client, itemid, purchase, expiration, price); return false; } - if(itemid < 0) + if (itemid < 0) { LogStoreError("Native_GiveItem -> %N itemid %d purchase %d expiration %d price %d", client, itemid, purchase, expiration, price); return false; @@ -878,19 +879,19 @@ static any Native_GiveItem(Handle plugin, int numParams) char pFile[32]; GetPluginFilename(plugin, STRING(pFile)); - if(!Store_HasClientItem(client, itemid)) + if (!Store_HasClientItem(client, itemid)) { - int m_iDateOfPurchase = (purchase==0 ? GetTime() : purchase); + int m_iDateOfPurchase = (purchase == 0 ? GetTime() : purchase); int m_iDateOfExpiration = expiration; - int m_iId = g_ClientData[client].iItems++; - g_ClientItem[client][m_iId].iId = -1; - g_ClientItem[client][m_iId].iUniqueId = itemid; - g_ClientItem[client][m_iId].iDateOfPurchase = m_iDateOfPurchase; + int m_iId = g_ClientData[client].iItems++; + g_ClientItem[client][m_iId].iId = -1; + g_ClientItem[client][m_iId].iUniqueId = itemid; + g_ClientItem[client][m_iId].iDateOfPurchase = m_iDateOfPurchase; g_ClientItem[client][m_iId].iDateOfExpiration = m_iDateOfExpiration; - g_ClientItem[client][m_iId].iPriceOfPurchase = price; - g_ClientItem[client][m_iId].bSynced = false; - g_ClientItem[client][m_iId].bDeleted = false; + g_ClientItem[client][m_iId].iPriceOfPurchase = price; + g_ClientItem[client][m_iId].bSynced = false; + g_ClientItem[client][m_iId].bDeleted = false; UTIL_LogMessage(client, 0, "Give item [%s][%s] via native, p[%d], e[%d] from %s", g_Items[itemid].szUniqueId, g_Items[itemid].szName, m_iDateOfPurchase, expiration, pFile); return true; } @@ -900,8 +901,8 @@ static any Native_GiveItem(Handle plugin, int numParams) int ext = Store_GetItemExpiration(client, itemid); if (ext > 0) { - if(!Store_ExtClientItem(client, itemid, expiration == 0 ? expiration : expiration - GetTime())) - LogStoreError("Ext \"%L\" %s failed. purchase %d expiration %d price %d", client, g_Items[itemid].szName , purchase, expiration, price); + if (!Store_ExtClientItem(client, itemid, expiration == 0 ? expiration : expiration - GetTime())) + LogStoreError("Ext \"%L\" %s failed. purchase %d expiration %d price %d", client, g_Items[itemid].szName, purchase, expiration, price); } else { @@ -916,7 +917,7 @@ static any Native_RemoveItem(Handle myself, int numParams) int client = GetNativeCell(1); int itemid = GetNativeCell(2); - if(itemid > 0 && g_TypeHandlers[g_Items[itemid].iHandler].fnRemove != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[g_Items[itemid].iHandler].hPlugin, g_TypeHandlers[g_Items[itemid].iHandler].szPlFile)) + if (itemid > 0 && g_TypeHandlers[g_Items[itemid].iHandler].fnRemove != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[g_Items[itemid].iHandler].hPlugin, g_TypeHandlers[g_Items[itemid].iHandler].szPlFile)) { Call_StartFunction(g_TypeHandlers[g_Items[itemid].iHandler].hPlugin, g_TypeHandlers[g_Items[itemid].iHandler].fnRemove); Call_PushCell(client); @@ -927,7 +928,7 @@ static any Native_RemoveItem(Handle myself, int numParams) UTIL_UnequipItem(client, itemid, false); int m_iId = UTIL_GetClientItemId(client, itemid); - if(m_iId != -1) + if (m_iId != -1) g_ClientItem[client][m_iId].bDeleted = true; return 0; @@ -939,26 +940,26 @@ static any Native_GetItemExpiration(Handle myself, int numParams) int itemid = GetNativeCell(2); // Check if item is available? - if(itemid < 0) + if (itemid < 0) return -1; - if(!g_ClientData[client].bLoaded) + if (!g_ClientData[client].bLoaded) return -1; // Can he even have it? - if(g_Items[itemid].szSteam[0] != 0) + if (g_Items[itemid].szSteam[0] != 0) return (AllowItemForAuth(client, g_Items[itemid].szSteam)) ? 0 : -1; - if(g_Items[itemid].bVIP && AllowItemForVIP(client, true) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans==0) + if (g_Items[itemid].bVIP && AllowItemForVIP(client, true) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans == 0) return 0; // Is the item free (available for everyone)? - if((!g_Items[itemid].bIgnore || g_Items[itemid].bBuyable) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans==0) + if ((!g_Items[itemid].bIgnore || g_Items[itemid].bBuyable) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans == 0) return -1; - for(int i = 0; i < g_ClientData[client].iItems; ++i) - if(g_ClientItem[client][i].iUniqueId == itemid && !g_ClientItem[client][i].bDeleted) - return g_ClientItem[client][i].iDateOfExpiration; + for (int i = 0; i < g_ClientData[client].iItems; ++i) + if (g_ClientItem[client][i].iUniqueId == itemid && !g_ClientItem[client][i].bDeleted) + return g_ClientItem[client][i].iDateOfExpiration; return -1; } @@ -969,28 +970,28 @@ static any Native_HasClientItem(Handle myself, int numParams) int itemid = GetNativeCell(2); // Check if item is available? - if(itemid < 0) + if (itemid < 0) return false; // Personal item? - if(g_Items[itemid].szSteam[0] != 0) + if (g_Items[itemid].szSteam[0] != 0) return AllowItemForAuth(client, g_Items[itemid].szSteam); // VIP item? - if(g_Items[itemid].bVIP && !AllowItemForVIP(client, true) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans==0) + if (g_Items[itemid].bVIP && !AllowItemForVIP(client, true) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans == 0) return false; // Is the item free (available for everyone)? - if((!g_Items[itemid].bIgnore || g_Items[itemid].bBuyable) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans==0) + if ((!g_Items[itemid].bIgnore || g_Items[itemid].bBuyable) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans == 0) return true; // Check if the client actually has the item - for(int i = 0; i < g_ClientData[client].iItems; ++i) - if(g_ClientItem[client][i].iUniqueId == itemid && !g_ClientItem[client][i].bDeleted) - return (g_ClientItem[client][i].iDateOfExpiration==0 || (g_ClientItem[client][i].iDateOfExpiration && GetTime()(GetNativeCell(2)); + int client = GetNativeCell(1); + ArrayList array = view_as(GetNativeCell(2)); if (array == null) return false; @@ -1102,7 +1103,8 @@ static any Native_GetClientPlayerSkins(Handle myself, int numParmas) for (int i = 0; i < g_iItems; i++) { - char m[128], a[128]; int b, t; + char m[128], a[128]; + int b, t; if (g_Items[i].iHandler == handler && Store_HasClientItem(client, i) && GetSkinData(i, m, a, b, t)) { SkinData_t s; @@ -1137,7 +1139,8 @@ static any Native_GetAllPlayerSkins(Handle myself, int numParams) for (int i = 0; i < g_iItems; i++) { - char m[128], a[128]; int b, t; + char m[128], a[128]; + int b, t; if (g_Items[i].iHandler == handler && GetSkinData(i, m, a, b, t)) { SkinData_t s; @@ -1181,13 +1184,13 @@ static any Native_GetEquippedSkin(Handle myself, int numParams) if (itemId < 0 || !Store_HasClientItem(client, itemId)) return false; - char m[128], a[128]; int b, t; + char m[128], a[128]; + int b, t; if (!GetSkinData(itemId, m, a, b, t)) return false; SetNativeCellRef(7, b); - return SetNativeString(3, m, GetNativeCell(4)) == SP_ERROR_NONE && - SetNativeString(5, a, GetNativeCell(6)) == SP_ERROR_NONE; + return SetNativeString(3, m, GetNativeCell(4)) == SP_ERROR_NONE && SetNativeString(5, a, GetNativeCell(6)) == SP_ERROR_NONE; #else return false; #endif @@ -1261,7 +1264,7 @@ public void OnClientConnected(int client) g_iSpam[client] = 0; g_iClientTeam[client] = 0; g_iClientCase[client] = 1; - g_iDataProtect[client] = GetTime()+300; + g_iDataProtect[client] = GetTime() + 300; g_ClientData[client].iId = -1; g_ClientData[client].iUserId = GetClientUserId(client); @@ -1274,12 +1277,12 @@ public void OnClientConnected(int client) g_Compose[client].item2 = -1; g_Compose[client].types = -1; - for(int i = 0; i < STORE_MAX_HANDLERS; ++i) - for(int a = 0; a < STORE_MAX_SLOTS; ++a) - { - g_ClientData[client].aEquipment[i*STORE_MAX_SLOTS+a] = -2; - g_ClientData[client].aEquipmentSynced[i*STORE_MAX_SLOTS+a] = -2; - } + for (int i = 0; i < STORE_MAX_HANDLERS; ++i) + for (int a = 0; a < STORE_MAX_SLOTS; ++a) + { + g_ClientData[client].aEquipment[i * STORE_MAX_SLOTS + a] = -2; + g_ClientData[client].aEquipmentSynced[i * STORE_MAX_SLOTS + a] = -2; + } #if defined Module_Spray Sprays_OnClientConnected(client); @@ -1294,17 +1297,17 @@ public void OnClientConnected(int client) public void OnClientPostAdminCheck(int client) { - if(IsFakeClient(client)) + if (IsFakeClient(client)) return; - g_iDataProtect[client] = GetTime()+300; + g_iDataProtect[client] = GetTime() + 300; UTIL_LoadClientInventory(client); } public void OnClientDisconnect(int client) { - if(IsFakeClient(client)) + if (IsFakeClient(client)) return; #if defined Module_Player @@ -1336,28 +1339,28 @@ public void Opts_OnClientLoad(int client) ////////////////////////////// static Action Command_Store(int client, int args) { - if(!IsClientInGame(client)) + if (!IsClientInGame(client)) return Plugin_Handled; - if(args > 0) + if (args > 0) { tPrintToChat(client, "Invalid parameter."); return Plugin_Handled; } - if(!g_ClientData[client].bLoaded) + if (!g_ClientData[client].bLoaded) { tPrintToChat(client, "%T", "Inventory hasnt been fetched", client); return Plugin_Handled; } - if(g_ClientData[client].bBan) + if (g_ClientData[client].bBan) { - tPrintToChat(client,"[{red}CAT{white}] %T", "cat banned", client); + tPrintToChat(client, "[{red}CAT{white}] %T", "cat banned", client); return Plugin_Handled; } - g_bInvMode[client]=false; + g_bInvMode[client] = false; DisplayStoreMenu(client); return Plugin_Handled; @@ -1365,21 +1368,21 @@ static Action Command_Store(int client, int args) static Action Command_Inventory(int client, int args) { - if(args > 0) + if (args > 0) { tPrintToChat(client, "Invalid parameter."); return Plugin_Handled; } - if(!g_ClientData[client].bLoaded) + if (!g_ClientData[client].bLoaded) { tPrintToChat(client, "%T", "Inventory hasnt been fetched", client); return Plugin_Handled; } - if(g_ClientData[client].bBan) + if (g_ClientData[client].bBan) { - tPrintToChat(client,"[{red}CAT{white}] %T", "cat banned", client); + tPrintToChat(client, "[{red}CAT{white}] %T", "cat banned", client); return Plugin_Handled; } @@ -1391,28 +1394,28 @@ static Action Command_Inventory(int client, int args) static Action Command_Credits(int client, int args) { - if(args > 0) + if (args > 0) { tPrintToChat(client, "Invalid parameter."); return Plugin_Handled; } - if(!g_ClientData[client].bLoaded) + if (!g_ClientData[client].bLoaded) { tPrintToChat(client, "%T", "Inventory hasnt been fetched", client); return Plugin_Handled; } - if(g_ClientData[client].bBan) + if (g_ClientData[client].bBan) { - tPrintToChat(client,"[{red}CAT{white}] %T", "cat banned", client); + tPrintToChat(client, "[{red}CAT{white}] %T", "cat banned", client); return Plugin_Handled; } - if(g_iSpam[client]0) + if (g_Items[parent].iPrice > 0) { - if(!Store_IsItemInBoughtPackage(client, parent)) + if (!Store_IsItemInBoughtPackage(client, parent)) { - AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "sell_package", "%T", "Package Sell", client, RoundToFloor(g_Items[parent].iPrice*0.6)); + AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "sell_package", "%T", "Package Sell", client, RoundToFloor(g_Items[parent].iPrice * 0.6)); ++m_iPosition; - if(g_Items[parent].bGiftable) + if (g_Items[parent].bGiftable) { AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "gift_package", "%T", "Package Gift", client); ++m_iPosition; } - for(int i = 0; i < g_iMenuHandlers; ++i) + for (int i = 0; i < g_iMenuHandlers; ++i) { - if(g_MenuHandlers[i].hPlugin == null || !IsPluginRunning(g_MenuHandlers[i].hPlugin, g_MenuHandlers[i].szPlFile)) + if (g_MenuHandlers[i].hPlugin == null || !IsPluginRunning(g_MenuHandlers[i].hPlugin, g_MenuHandlers[i].szPlFile)) continue; Call_StartFunction(g_MenuHandlers[i].hPlugin, g_MenuHandlers[i].fnMenu); @@ -1473,40 +1476,40 @@ void DisplayStoreMenu(int client, int parent = -1, int last = -1) } } - for(int i = 0; i < g_iItems; ++i) + for (int i = 0; i < g_iItems; ++i) { - if(g_Items[i].iParent==parent) + if (g_Items[i].iParent == parent) { int m_iPrice = UTIL_GetLowestPrice(i); // This is a package - if(g_Items[i].iHandler == g_iPackageHandler) + if (g_Items[i].iHandler == g_iPackageHandler) { - if(!UTIL_PackageHasClientItem(client, i, g_bInvMode[client])) + if (!UTIL_PackageHasClientItem(client, i, g_bInvMode[client])) continue; int m_iStyle = ITEMDRAW_DEFAULT; - if(!AllowItemForAuth(client, g_Items[i].szSteam) || !AllowItemForVIP(client, g_Items[i].bVIP)) + if (!AllowItemForAuth(client, g_Items[i].szSteam) || !AllowItemForVIP(client, g_Items[i].bVIP)) m_iStyle = ITEMDRAW_DISABLED; IntToString(i, STRING(m_szId)); - if(g_Items[i].iPrice == -1 || Store_HasClientItem(client, i)) + if (g_Items[i].iPrice == -1 || Store_HasClientItem(client, i)) AddMenuItem(m_hMenu, m_szId, g_Items[i].szName, m_iStyle); - else if(!g_bInvMode[client] && g_Items[i].iPlans==0 && g_Items[i].bBuyable) - InsertMenuItemEx(m_hMenu, m_iPosition, ((m_iPrice<=g_ClientData[client].iCredits && !g_Items[i].bCompose) || g_Items[i].bCompose)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED, m_szId, "%T", "Item Available", client, g_Items[i].szName, g_Items[i].iPrice); - else if(!g_bInvMode[client]) - InsertMenuItemEx(m_hMenu, m_iPosition, ((m_iPrice<=g_ClientData[client].iCredits && !g_Items[i].bCompose) || g_Items[i].bCompose)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED, m_szId, "%T", "Item Plan Available", client, g_Items[i].szName); + else if (!g_bInvMode[client] && g_Items[i].iPlans == 0 && g_Items[i].bBuyable) + InsertMenuItemEx(m_hMenu, m_iPosition, ((m_iPrice <= g_ClientData[client].iCredits && !g_Items[i].bCompose) || g_Items[i].bCompose) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED, m_szId, "%T", "Item Available", client, g_Items[i].szName, g_Items[i].iPrice); + else if (!g_bInvMode[client]) + InsertMenuItemEx(m_hMenu, m_iPosition, ((m_iPrice <= g_ClientData[client].iCredits && !g_Items[i].bCompose) || g_Items[i].bCompose) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED, m_szId, "%T", "Item Plan Available", client, g_Items[i].szName); ++m_iPosition; } // This is a normal item else { IntToString(i, STRING(m_szId)); - if(Store_HasClientItem(client, i)) + if (Store_HasClientItem(client, i)) { InsertMenuItemEx(m_hMenu, m_iPosition, ITEMDRAW_DEFAULT, m_szId, FormatSkinTag(client, i, UTIL_IsEquipped(client, i))); } - else if(!g_bInvMode[client]) + else if (!g_bInvMode[client]) { // use display setting instead bool display = g_Items[i].bDisplay; @@ -1525,7 +1528,7 @@ void DisplayStoreMenu(int client, int parent = -1, int last = -1) continue; } - if(strcmp(g_TypeHandlers[g_Items[i].iHandler].szType, "playerskin") == 0) + if (strcmp(g_TypeHandlers[g_Items[i].iHandler].szType, "playerskin") == 0) { #if defined Global_Skin AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, m_szId, "%T", "Item Preview Available", client, g_Items[i].szName); @@ -1536,12 +1539,12 @@ void DisplayStoreMenu(int client, int parent = -1, int last = -1) } int m_iStyle = ITEMDRAW_DEFAULT; - if((g_Items[i].iPlans==0 && g_ClientData[client].iCredits=m_iPrice && !Store_HasClientItem(client, g_iSelectedItem[client])) + if (g_ClientData[client].iCredits >= m_iPrice && !Store_HasClientItem(client, g_iSelectedItem[client])) UTIL_BuyItem(client); } - else if(param2 == 1) + else if (param2 == 1) UTIL_SellItem(client, g_iSelectedItem[client]); } else @@ -1613,28 +1616,28 @@ static int MenuHandler_Store(Menu menu, MenuAction action, int client, int param char m_szId[64]; menu.GetItem(param2, STRING(m_szId)); - g_iLastSelection[client]=param2; + g_iLastSelection[client] = param2; // We are selling a package - if(strcmp(m_szId, "sell_package")==0) + if (strcmp(m_szId, "sell_package") == 0) { char m_szTitle[128]; - FormatEx(STRING(m_szTitle), "%T", "Confirm_Sell", client, g_Items[g_iSelectedItem[client]].szName, g_TypeHandlers[g_Items[g_iSelectedItem[client]].iHandler].szType, RoundToFloor(g_Items[g_iSelectedItem[client]].iPrice*0.6)); + FormatEx(STRING(m_szTitle), "%T", "Confirm_Sell", client, g_Items[g_iSelectedItem[client]].szName, g_TypeHandlers[g_Items[g_iSelectedItem[client]].iHandler].szType, RoundToFloor(g_Items[g_iSelectedItem[client]].iPrice * 0.6)); Store_DisplayConfirmMenu(client, m_szTitle, MenuHandler_Store, 1); return 0; } // We are gifting a package - else if(strcmp(m_szId, "gift_package")==0) + else if (strcmp(m_szId, "gift_package") == 0) { DisplayPlayerMenu(client); } // This is menu handler stuff - else if(!(48 <= m_szId[0] <= 57)) + else if (!(48 <= m_szId[0] <= 57)) { int ret; - for(int i = 0; i < g_iMenuHandlers; ++i) + for (int i = 0; i < g_iMenuHandlers; ++i) { - if(g_MenuHandlers[i].hPlugin == null || !IsPluginRunning(g_MenuHandlers[i].hPlugin, g_MenuHandlers[i].szPlFile)) + if (g_MenuHandlers[i].hPlugin == null || !IsPluginRunning(g_MenuHandlers[i].hPlugin, g_MenuHandlers[i].szPlFile)) continue; Call_StartFunction(g_MenuHandlers[i].hPlugin, g_MenuHandlers[i].fnHandler); @@ -1643,34 +1646,35 @@ static int MenuHandler_Store(Menu menu, MenuAction action, int client, int param Call_PushCell(g_iSelectedItem[client]); Call_Finish(ret); - if(ret) break; + if (ret) + break; } } // We are being boring else { - int m_iId = StringToInt(m_szId); - g_iMenuBack[client]=g_Items[m_iId].iParent; + int m_iId = StringToInt(m_szId); + g_iMenuBack[client] = g_Items[m_iId].iParent; g_iSelectedItem[client] = m_iId; g_iSelectedPlan[client] = -1; bool hasItem = Store_HasClientItem(client, m_iId); - if(!hasItem) + if (!hasItem) { - if(StrEqual(g_TypeHandlers[g_Items[m_iId].iHandler].szType, "playerskin")) + if (StrEqual(g_TypeHandlers[g_Items[m_iId].iHandler].szType, "playerskin")) { DisplayPreviewMenu(client, m_iId); return 0; } - if(g_Items[m_iId].bCompose) + if (g_Items[m_iId].bCompose) { - if(g_ClientData[client].iCredits >= g_inCase[1]) + if (g_ClientData[client].iCredits >= g_inCase[1]) { - g_Compose[client].item1=-1; - g_Compose[client].item2=-1; - g_Compose[client].types=-1; + g_Compose[client].item1 = -1; + g_Compose[client].item2 = -1; + g_Compose[client].types = -1; DisplayComposeMenu(client, false); } else @@ -1679,9 +1683,9 @@ static int MenuHandler_Store(Menu menu, MenuAction action, int client, int param } else { - if((g_ClientData[client].iCredits>=g_Items[m_iId].iPrice || g_Items[m_iId].iPlans>0 && g_ClientData[client].iCredits>=UTIL_GetLowestPrice(m_iId)) && g_Items[m_iId].iPrice != -1 && g_Items[m_iId].bBuyable) + if ((g_ClientData[client].iCredits >= g_Items[m_iId].iPrice || g_Items[m_iId].iPlans > 0 && g_ClientData[client].iCredits >= UTIL_GetLowestPrice(m_iId)) && g_Items[m_iId].iPrice != -1 && g_Items[m_iId].bBuyable) { - if(g_Items[m_iId].iPlans > 0) + if (g_Items[m_iId].iPlans > 0) DisplayPlanMenu(client, m_iId); else { @@ -1694,13 +1698,13 @@ static int MenuHandler_Store(Menu menu, MenuAction action, int client, int param } } - if(g_Items[m_iId].iHandler != g_iPackageHandler) + if (g_Items[m_iId].iHandler != g_iPackageHandler) { - if(hasItem) + if (hasItem) { - if(g_TypeHandlers[g_Items[m_iId].iHandler].bRaw) + if (g_TypeHandlers[g_Items[m_iId].iHandler].bRaw) { - if(IsPluginRunning(g_TypeHandlers[g_Items[m_iId].iHandler].hPlugin, g_TypeHandlers[g_Items[m_iId].iHandler].szPlFile)) + if (IsPluginRunning(g_TypeHandlers[g_Items[m_iId].iHandler].hPlugin, g_TypeHandlers[g_Items[m_iId].iHandler].szPlFile)) { Call_StartFunction(g_TypeHandlers[g_Items[m_iId].iHandler].hPlugin, g_TypeHandlers[g_Items[m_iId].iHandler].fnUse); Call_PushCell(client); @@ -1708,16 +1712,19 @@ static int MenuHandler_Store(Menu menu, MenuAction action, int client, int param Call_Finish(); } } - else DisplayItemMenu(client, m_iId); + else + DisplayItemMenu(client, m_iId); } - else DisplayStoreMenu(client, g_iMenuBack[client]); + else + DisplayStoreMenu(client, g_iMenuBack[client]); } - else DisplayStoreMenu(client, (hasItem || g_Items[m_iId].iPrice == -1) ? m_iId : g_Items[m_iId].iParent); + else + DisplayStoreMenu(client, (hasItem || g_Items[m_iId].iPrice == -1) ? m_iId : g_Items[m_iId].iParent); } } } - else if(action==MenuAction_Cancel) - if(param2 == MenuCancel_ExitBack) + else if (action == MenuAction_Cancel) + if (param2 == MenuCancel_ExitBack) Store_DisplayPreviousMenu(client); return 0; @@ -1725,26 +1732,26 @@ static int MenuHandler_Store(Menu menu, MenuAction action, int client, int param void UTIL_GetLevelType(int client, int itemid, char[] buffer, int maxLen) { - switch(g_Items[itemid].iLevels) + switch (g_Items[itemid].iLevels) { - case 2: FormatEx(buffer, maxLen, "%T", "level 2", client); - case 3: FormatEx(buffer, maxLen, "%T", "level 3", client); - case 4: FormatEx(buffer, maxLen, "%T", "level 4", client); - case 5: FormatEx(buffer, maxLen, "%T", "level 5", client); - case 6: FormatEx(buffer, maxLen, "%T", "level 6", client); + case 2: FormatEx(buffer, maxLen, "%T", "level 2", client); + case 3: FormatEx(buffer, maxLen, "%T", "level 3", client); + case 4: FormatEx(buffer, maxLen, "%T", "level 4", client); + case 5: FormatEx(buffer, maxLen, "%T", "level 5", client); + case 6: FormatEx(buffer, maxLen, "%T", "level 6", client); default: FormatEx(buffer, maxLen, "%T", "level 1", client); } } void DisplayPreviewMenu(int client, int itemid) { - if(Store_HasClientItem(client, itemid)) + if (Store_HasClientItem(client, itemid)) return; g_iMenuNum[client] = 1; g_iMenuBack[client] = g_Items[itemid].iParent; - Menu m_hMenu = new Menu(MenuHandler_Preview); + Menu m_hMenu = new Menu(MenuHandler_Preview); m_hMenu.ExitBackButton = true; m_hMenu.SetTitle("%s\n%T\n ", g_Items[itemid].szName, "Title Credits", client, g_ClientData[client].iCredits); @@ -1757,21 +1764,21 @@ void DisplayPreviewMenu(int client, int itemid) AddMenuItemEx(m_hMenu, (g_aCaseSkins[0].Length > 0 || g_pfysRect || g_pOpenCase) ? ITEMDRAW_DEFAULT : ITEMDRAW_SPACER, "3", "%T", "Open Case Available", client); - if(g_Items[itemid].bCompose) //合成 + if (g_Items[itemid].bCompose) //合成 AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "0", "%T", "Preview Compose Available", client); - else if(g_Items[itemid].szSteam[0] != 0) //专个人属 + else if (g_Items[itemid].szSteam[0] != 0) //专个人属 AddMenuItemEx(m_hMenu, ITEMDRAW_DISABLED, "1", "%T", "Item not Buyable", client); - else if(g_Items[itemid].bIgnore) //组专属或活动限定 + else if (g_Items[itemid].bIgnore) //组专属或活动限定 AddMenuItemEx(m_hMenu, ITEMDRAW_DISABLED, "1", "%T", "Item not Buyable", client); else { - if(g_Items[itemid].bBuyable) + if (g_Items[itemid].bBuyable) { int m_iStyle = ITEMDRAW_DEFAULT; - if((g_Items[itemid].iPlans==0 && g_ClientData[client].iCredits= g_inCase[1]) + if (g_ClientData[client].iCredits >= g_inCase[1]) { - g_Compose[client].item1=-1; - g_Compose[client].item2=-1; - g_Compose[client].types=-1; + g_Compose[client].item1 = -1; + g_Compose[client].item2 = -1; + g_Compose[client].types = -1; DisplayComposeMenu(client, false); } else tPrintToChat(client, "%T", "Chat Not Enough Handing Fee", client, g_inCase[1]); } - else if(selected == 1) + else if (selected == 1) { - if((g_ClientData[client].iCredits>=g_Items[m_iId].iPrice || g_Items[m_iId].iPlans>0 && g_ClientData[client].iCredits>=UTIL_GetLowestPrice(m_iId)) && g_Items[m_iId].iPrice != -1 && g_Items[m_iId].bBuyable) + if ((g_ClientData[client].iCredits >= g_Items[m_iId].iPrice || g_Items[m_iId].iPlans > 0 && g_ClientData[client].iCredits >= UTIL_GetLowestPrice(m_iId)) && g_Items[m_iId].iPrice != -1 && g_Items[m_iId].bBuyable) { - if(g_Items[m_iId].iPlans > 0) + if (g_Items[m_iId].iPlans > 0) DisplayPlanMenu(client, m_iId); else { @@ -1822,7 +1829,7 @@ static int MenuHandler_Preview(Menu menu, MenuAction action, int client, int par } } } - else if(selected == 2) + else if (selected == 2) { #if defined Module_Skin Store_PreviewSkin(client, m_iId); @@ -1832,7 +1839,7 @@ static int MenuHandler_Preview(Menu menu, MenuAction action, int client, int par tPrintToChat(client, "%T", "Chat Preview Cooldown", client); #endif } - else if(selected == 3) + else if (selected == 3) { #if defined Module_Skin if (g_pfysRect || g_pOpenCase) @@ -1846,8 +1853,8 @@ static int MenuHandler_Preview(Menu menu, MenuAction action, int client, int par #endif } } - else if(action==MenuAction_Cancel) - if(param2 == MenuCancel_ExitBack) + else if (action == MenuAction_Cancel) + if (param2 == MenuCancel_ExitBack) Store_DisplayPreviousMenu(client); return 0; @@ -1855,35 +1862,35 @@ static int MenuHandler_Preview(Menu menu, MenuAction action, int client, int par static Action Command_Case(int client, int args) { - if(!IsClientInGame(client)) + if (!IsClientInGame(client)) return Plugin_Handled; - if(g_pOpenCase || g_pfysRect) + if (g_pOpenCase || g_pfysRect) { FakeClientCommandEx(client, "sm_opencase"); return Plugin_Handled; } - if(args > 0) + if (args > 0) { tPrintToChat(client, "Invalid parameter."); return Plugin_Handled; } - if(!g_ClientData[client].bLoaded) + if (!g_ClientData[client].bLoaded) { tPrintToChat(client, "%T", "Inventory hasnt been fetched", client); return Plugin_Handled; } - if(g_ClientData[client].bBan) + if (g_ClientData[client].bBan) { - tPrintToChat(client,"[{red}CAT{white}] %T", "cat banned", client); + tPrintToChat(client, "[{red}CAT{white}] %T", "cat banned", client); return Plugin_Handled; } #if defined Module_Skin - if(g_ClientData[client].iCredits >= g_inCase[1]) + if (g_ClientData[client].iCredits >= g_inCase[1]) UTIL_OpenSkinCase(client); else tPrintToChat(client, "%T", "Chat Not Enough Handing Fee", client, g_inCase[1]); @@ -1898,7 +1905,7 @@ static Action Command_Case(int client, int args) // HACK FIX SM 1.10 Build void UTIL_OpenSkinCase(int client, bool hack = false) { - if(g_pOpenCase || g_pfysRect || hack) + if (g_pOpenCase || g_pfysRect || hack) return; Menu menu = new Menu(MenuHandler_SelectCase); @@ -1916,14 +1923,14 @@ void UTIL_OpenSkinCase(int client, bool hack = false) static int MenuHandler_SelectCase(Menu menu, MenuAction action, int client, int param2) { - switch(action) + switch (action) { case MenuAction_End: delete menu; case MenuAction_Select: { - if(g_iDataProtect[client] > GetTime()) + if (g_iDataProtect[client] > GetTime()) { - tPrintToChat(client, "%T", "data protect", client, g_iDataProtect[client]-GetTime()); + tPrintToChat(client, "%T", "data protect", client, g_iDataProtect[client] - GetTime()); UTIL_OpenSkinCase(client); return 0; } @@ -1933,15 +1940,15 @@ static int MenuHandler_SelectCase(Menu menu, MenuAction action, int client, int g_iClientCase[client] = StringToInt(info); - if(g_iSelectedItem[client] > -1 && g_Items[g_iSelectedItem[client]].bIgnore) + if (g_iSelectedItem[client] > -1 && g_Items[g_iSelectedItem[client]].bIgnore) { - if(g_iClientCase[client] == 1) + if (g_iClientCase[client] == 1) tPrintToChat(client, "%T", "Item not in case", client); - else if(g_Items[g_iSelectedItem[client]].szSteam[0] != 0) + else if (g_Items[g_iSelectedItem[client]].szSteam[0] != 0) tPrintToChat(client, "%T", "Item not in case", client); } - g_iDataProtect[client] = GetTime()+300; + g_iDataProtect[client] = GetTime() + 300; char m_szQuery[255]; FormatEx(STRING(m_szQuery), "SELECT credits FROM store_players WHERE `id`=%d", g_ClientData[client].iId); @@ -1950,7 +1957,7 @@ static int MenuHandler_SelectCase(Menu menu, MenuAction action, int client, int } case MenuAction_Cancel: { - if(param2 == MenuCancel_ExitBack) + if (param2 == MenuCancel_ExitBack) DisplayItemMenu(client, g_iSelectedItem[client]); } } @@ -1961,10 +1968,10 @@ static int MenuHandler_SelectCase(Menu menu, MenuAction action, int client, int static void SQLCallback_OpenCase(Database db, DBResultSet results, const char[] error, int userid) { int client = GetClientOfUserId(userid); - if(!client) + if (!client) return; - if(results == null || error[0]) + if (results == null || error[0]) { LogStoreError("Error happened. Error: %s", error); return; @@ -1972,25 +1979,31 @@ static void SQLCallback_OpenCase(Database db, DBResultSet results, const char[] g_ClientData[client].bRefresh = false; - if(!results.FetchRow()) + if (!results.FetchRow()) return; int dbCredits = results.FetchInt(0); - if(dbCredits != g_ClientData[client].iOriginalCredits) + if (dbCredits != g_ClientData[client].iOriginalCredits) { - int diff = dbCredits - g_ClientData[client].iOriginalCredits; + int diff = dbCredits - g_ClientData[client].iOriginalCredits; g_ClientData[client].iOriginalCredits = dbCredits; g_ClientData[client].iCredits += diff; UTIL_LogMessage(client, diff, "Credits changed in database (sync credits from database)"); Store_SaveClientAll(client); } - switch(g_iClientCase[client]) + switch (g_iClientCase[client]) { - case 1 : if(g_ClientData[client].iCredits < g_inCase[1]) return; - case 2 : if(g_ClientData[client].iCredits < g_inCase[2]) return; - case 3 : if(g_ClientData[client].iCredits < g_inCase[3]) return; + case 1: + if (g_ClientData[client].iCredits < g_inCase[1]) + return; + case 2: + if (g_ClientData[client].iCredits < g_inCase[2]) + return; + case 3: + if (g_ClientData[client].iCredits < g_inCase[3]) + return; default: return; } @@ -2003,42 +2016,48 @@ static Action Timer_OpeningCase(Handle timer, int userid) { int client = GetClientOfUserId(userid); - if(!client || !IsClientInGame(client)) + if (!client || !IsClientInGame(client)) return Plugin_Stop; g_iDataProtect[client] = GetTime() + 10; - switch(g_iClientCase[client]) - { - case 1 : if(g_ClientData[client].iCredits < g_inCase[1]) return Plugin_Stop; - case 2 : if(g_ClientData[client].iCredits < g_inCase[2]) return Plugin_Stop; - case 3 : if(g_ClientData[client].iCredits < g_inCase[3]) return Plugin_Stop; + switch (g_iClientCase[client]) + { + case 1: + if (g_ClientData[client].iCredits < g_inCase[1]) + return Plugin_Stop; + case 2: + if (g_ClientData[client].iCredits < g_inCase[2]) + return Plugin_Stop; + case 3: + if (g_ClientData[client].iCredits < g_inCase[3]) + return Plugin_Stop; default: return Plugin_Stop; } - static int times[MAXPLAYERS+1]; + static int times[MAXPLAYERS + 1]; - if((g_iClientCase[client] == 1 && g_aCaseSkins[0].Length == 0) || (g_iClientCase[client] == 2 && g_aCaseSkins[1].Length == 0) || (g_iClientCase[client] == 3 && g_aCaseSkins[2].Length == 0)) + if ((g_iClientCase[client] == 1 && g_aCaseSkins[0].Length == 0) || (g_iClientCase[client] == 2 && g_aCaseSkins[1].Length == 0) || (g_iClientCase[client] == 3 && g_aCaseSkins[2].Length == 0)) return Plugin_Stop; int type = 0; int radm = UTIL_GetRandomInt(1, 999); // Ultima - if(g_iClientCase[client] == 3) + if (g_iClientCase[client] == 3) { // 3.5% SSR | 96.5% SR type = (radm >= 965) ? 2 : ((g_aCaseSkins[1].Length > 0) ? 1 : 0); } // advance - else if(g_iClientCase[client] == 2) + else if (g_iClientCase[client] == 2) { - if(radm >= 850) + if (radm >= 850) { // 15% SSR type = ((g_aCaseSkins[2].Length > 0) ? 2 : 1); } - else if(radm >= 500) + else if (radm >= 500) { // 35% SR type = 1; @@ -2050,7 +2069,7 @@ static Action Timer_OpeningCase(Handle timer, int userid) } else { - if(radm >= 800) + if (radm >= 800) { // 20% SR type = ((g_aCaseSkins[1].Length > 0) ? 1 : 0); @@ -2061,20 +2080,20 @@ static Action Timer_OpeningCase(Handle timer, int userid) } } - if(g_aCaseSkins[type].Length <= 0) + if (g_aCaseSkins[type].Length <= 0) { tPrintToChat(client, "{red}%T {silver}->{darkred} Null Array", "unknown error", client); - LogStoreError("Null Array in Case Array [%s]", g_szCase[type+1]); + LogStoreError("Null Array in Case Array [%s]", g_szCase[type + 1]); return Plugin_Stop; } - int aid = UTIL_GetRandomInt(0, g_aCaseSkins[type].Length-1); + int aid = UTIL_GetRandomInt(0, g_aCaseSkins[type].Length - 1); char modelname[32]; g_aCaseSkins[type].GetString(aid, STRING(modelname)); int itemid = UTIL_GetItemId(modelname); - if(itemid < 0) + if (itemid < 0) { LogStoreError("Item Id Error %s", modelname); tPrintToChat(client, "{red}%T {silver}->{darkred} Invalid Item", "unknown error", client); @@ -2085,37 +2104,37 @@ static Action Timer_OpeningCase(Handle timer, int userid) int rdm = UTIL_GetRandomInt(1, 1000); - if(++times[client] < 28) + if (++times[client] < 28) { - if(rdm >= 800) + if (rdm >= 800) days = 0; else days = UTIL_GetRandomInt(14, 365); - if(g_iClientCase[client] == 3) + if (g_iClientCase[client] == 3) days = 0; } else { - if(g_iClientCase[client] == 3) + if (g_iClientCase[client] == 3) { // always days = 0; } - else if(g_iClientCase[client] == 2) + else if (g_iClientCase[client] == 2) { - if(type == 2) + if (type == 2) { // ult case? days = (rdm >= 990) ? 0 : UTIL_GetRandomInt(15, 30); } else { - if(rdm >= 990) + if (rdm >= 990) days = 0; - else if(rdm >= 950) + else if (rdm >= 950) days = UTIL_GetRandomInt(91, 365); - else if(rdm >= 750) + else if (rdm >= 750) days = UTIL_GetRandomInt(31, 90); else days = UTIL_GetRandomInt((g_iClientCase[client] == 2 ? 15 : 7), 30); @@ -2123,11 +2142,11 @@ static Action Timer_OpeningCase(Handle timer, int userid) } else { - if(rdm >= 990) + if (rdm >= 990) days = 0; - else if(rdm >= 920) + else if (rdm >= 920) days = UTIL_GetRandomInt(91, 365); - else if(rdm >= 700) + else if (rdm >= 700) days = UTIL_GetRandomInt(31, 90); else days = UTIL_GetRandomInt((g_iClientCase[client] == 2 ? 15 : 7), 30); @@ -2140,13 +2159,20 @@ static Action Timer_OpeningCase(Handle timer, int userid) OpeningCaseMenu(client, days, g_Items[itemid].szName); - if(12 >= times[client]) CreateTimer(0.2, Timer_OpeningCase, userid); - else if(times[client] > 12) CreateTimer(0.3, Timer_OpeningCase, userid); - else if(times[client] > 20) CreateTimer(0.5, Timer_OpeningCase, userid); - else if(times[client] > 23) CreateTimer(0.8, Timer_OpeningCase, userid); - else if(times[client] > 25) CreateTimer(1.2, Timer_OpeningCase, userid); - else if(times[client] > 27) CreateTimer(1.8, Timer_OpeningCase, userid); - else if(times[client] > 28) CreateTimer(2.6, Timer_OpeningCase, userid); + if (12 >= times[client]) + CreateTimer(0.2, Timer_OpeningCase, userid); + else if (times[client] > 12) + CreateTimer(0.3, Timer_OpeningCase, userid); + else if (times[client] > 20) + CreateTimer(0.5, Timer_OpeningCase, userid); + else if (times[client] > 23) + CreateTimer(0.8, Timer_OpeningCase, userid); + else if (times[client] > 25) + CreateTimer(1.2, Timer_OpeningCase, userid); + else if (times[client] > 27) + CreateTimer(1.8, Timer_OpeningCase, userid); + else if (times[client] > 28) + CreateTimer(2.6, Timer_OpeningCase, userid); return Plugin_Stop; } @@ -2155,7 +2181,7 @@ void OpeningCaseMenu(int client, int days, const char[] name) { static Panel m_hCasePanel = null; - if(m_hCasePanel != null) + if (m_hCasePanel != null) delete m_hCasePanel; m_hCasePanel = new Panel(); @@ -2170,7 +2196,7 @@ void OpeningCaseMenu(int client, int days, const char[] name) m_hCasePanel.DrawText("░░░░░░░░░░░░░░░░░░"); m_hCasePanel.DrawText(" "); - if(days) + if (days) { FormatEx(STRING(fmt), " %s (%d day%s)", name, days, days > 1 ? "s" : ""); PrintCenterText(client, "%s (%d day%s)", name, days, days > 1 ? "s" : ""); @@ -2199,17 +2225,17 @@ static int MenuHandler_OpeningCase(Menu menu, MenuAction action, int client, int int UTIL_GetSkinSellPrice(int client, int itemid, int days) { - if(days == 0) + if (days == 0) return RoundToCeil(g_inCase[g_iClientCase[client]] * 0.8); - if(g_Items[itemid].iPlans > 0) + if (g_Items[itemid].iPlans > 0) { - if(days > 30) + if (days > 30) return (g_PurchasePlan[itemid][2].iPrice > 0) ? RoundToCeil(float(days) / 365.0 * g_PurchasePlan[itemid][2].iPrice * 0.85) : 100; - else if(days > 7) - return (g_PurchasePlan[itemid][1].iPrice > 0) ? RoundToCeil(float(days) / 30.0 * g_PurchasePlan[itemid][1].iPrice * 0.85) : 100; + else if (days > 7) + return (g_PurchasePlan[itemid][1].iPrice > 0) ? RoundToCeil(float(days) / 30.0 * g_PurchasePlan[itemid][1].iPrice * 0.85) : 100; - return (g_PurchasePlan[itemid][0].iPrice > 0) ? RoundToCeil(float(days) / 1.0 * g_PurchasePlan[itemid][0].iPrice * 0.85) : 100; + return (g_PurchasePlan[itemid][0].iPrice > 0) ? RoundToCeil(float(days) / 1.0 * g_PurchasePlan[itemid][0].iPrice * 0.85) : 100; } return RoundToCeil(float(g_Items[itemid].iPrice) / 180.0 * days * 0.85); @@ -2224,7 +2250,7 @@ static Action Timer_ReEndingCase(Handle timer, DataPack pack) if (!client) return Plugin_Stop; - //LogMessage("Redraw EndingCaseMenu to %L with %d and %d", client, g_Items[itemid].szUniqueId, length); + // LogMessage("Redraw EndingCaseMenu to %L with %d and %d", client, g_Items[itemid].szUniqueId, length); EndingCaseMenu(client, length, itemid, false); return Plugin_Stop; @@ -2232,25 +2258,25 @@ static Action Timer_ReEndingCase(Handle timer, DataPack pack) void EndingCaseMenu(int client, int days, int itemid, bool sound = true) { - if(g_bInterMission) + if (g_bInterMission) { LogMessage("Stop EndingCaseMenu in g_bInterMission"); return; } - if(!g_ClientData[client].bLoaded) + if (!g_ClientData[client].bLoaded) { tPrintToChat(client, "%T", "Inventory hasnt been fetched", client); return; } - if(g_ClientData[client].bBan) + if (g_ClientData[client].bBan) { - tPrintToChat(client,"[{red}CAT{white}] %T", "cat banned", client); + tPrintToChat(client, "[{red}CAT{white}] %T", "cat banned", client); return; } - g_iDataProtect[client] = GetTime()+10; + g_iDataProtect[client] = GetTime() + 10; Menu menu = new Menu(MenuHandler_OpenSuccessful); menu.SetTitle("%T\n%T\n ", "Open case successful", client, g_szCase[g_iClientCase[client]], client); @@ -2262,7 +2288,7 @@ void EndingCaseMenu(int client, int days, int itemid, bool sound = true) char leveltype[32]; UTIL_GetLevelType(client, itemid, STRING(leveltype)); AddMenuItemEx(menu, ITEMDRAW_DISABLED, "", "%T: %s - %s", "playerskin", client, name, leveltype); - if(days) + if (days) { AddMenuItemEx(menu, ITEMDRAW_DISABLED, "", "%T: %d day%s", "time limit", client, days, days > 1 ? "s" : ""); PrintCenterText(client, "%s (%d day%s)", name, days, days > 1 ? "s" : ""); @@ -2276,7 +2302,7 @@ void EndingCaseMenu(int client, int days, int itemid, bool sound = true) AddMenuItemEx(menu, ITEMDRAW_SPACER, "", ""); AddMenuItemEx(menu, ITEMDRAW_SPACER, "", ""); - int crd = UTIL_GetSkinSellPrice(client, itemid, days); + int crd = UTIL_GetSkinSellPrice(client, itemid, days); char fmt[32]; FormatEx(STRING(fmt), "sell_%d_%d", itemid, days); AddMenuItemEx(menu, ITEMDRAW_DEFAULT, fmt, "%T(%d)", "quickly sell", client, crd); @@ -2286,35 +2312,35 @@ void EndingCaseMenu(int client, int days, int itemid, bool sound = true) menu.Display(client, 0); if (sound) - ClientCommand(client, "playgamesound ui/item_drop3_rare.wav"); + ClientCommand(client, "playgamesound ui/item_drop3_rare.wav"); } static int MenuHandler_OpenSuccessful(Menu menu, MenuAction action, int client, int param2) { - switch(action) + switch (action) { case MenuAction_End: delete menu; case MenuAction_Select: { - if(g_bInterMission) + if (g_bInterMission) { LogMessage("Stop MenuHandler_OpenSuccessful in g_bInterMission"); return 0; } - if(!g_ClientData[client].bLoaded) + if (!g_ClientData[client].bLoaded) { tPrintToChat(client, "%T", "Inventory hasnt been fetched", client); return 0; } - if(g_ClientData[client].bBan) + if (g_ClientData[client].bBan) { - tPrintToChat(client,"[{red}CAT{white}] %T", "cat banned", client); + tPrintToChat(client, "[{red}CAT{white}] %T", "cat banned", client); return 0; } - if(g_ClientData[client].iCredits < g_inCase[g_iClientCase[client]] || g_iClientCase[client] < 0 || g_iClientCase[client] > 3) + if (g_ClientData[client].iCredits < g_inCase[g_iClientCase[client]] || g_iClientCase[client] < 0 || g_iClientCase[client] > 3) return 0; char info[32]; @@ -2324,12 +2350,12 @@ static int MenuHandler_OpenSuccessful(Menu menu, MenuAction action, int client, ExplodeString(info, "_", data, 3, 16); int itemid = StringToInt(data[1]); - int days = StringToInt(data[2]); + int days = StringToInt(data[2]); char name[128]; strcopy(STRING(name), g_Items[itemid].szName); - if(days) + if (days) { tPrintToChatAll("%t", "opencase earned day", client, g_szCase[g_iClientCase[client]], name, days); } @@ -2338,41 +2364,46 @@ static int MenuHandler_OpenSuccessful(Menu menu, MenuAction action, int client, tPrintToChatAll("%t", "opencase earned perm", client, g_szCase[g_iClientCase[client]], name); } - if(StrEqual(data[0], "sell")) + if (StrEqual(data[0], "sell")) { - int crd = UTIL_GetSkinSellPrice(client, itemid, days); + int crd = UTIL_GetSkinSellPrice(client, itemid, days); char reason[128]; FormatEx(STRING(reason), "open %s and quickly sell [%s] c[%d] e[%d]", g_szCase[g_iClientCase[client]], name, g_inCase[g_iClientCase[client]], crd); - Store_SetClientCredits(client, Store_GetClientCredits(client)+crd-g_inCase[g_iClientCase[client]], reason); - if(days) tPrintToChat(client, "%t", "open and sell day chat", name, days, crd); - else tPrintToChat(client, "%t", "open and sell permanent chat", name, crd); + Store_SetClientCredits(client, Store_GetClientCredits(client) + crd - g_inCase[g_iClientCase[client]], reason); + if (days) + tPrintToChat(client, "%t", "open and sell day chat", name, days, crd); + else + tPrintToChat(client, "%t", "open and sell permanent chat", name, crd); UTIL_LogOpencase(client, itemid, days, "sell", g_iClientCase[client]); UTIL_OpenSkinCase(client); - if(g_iClientCase[client] > 1) + if (g_iClientCase[client] > 1) { - g_iDataProtect[client] = GetTime()+15; + g_iDataProtect[client] = GetTime() + 15; Store_SaveClientAll(client); } } - else if(StrEqual(data[0], "add")) + else if (StrEqual(data[0], "add")) { char reason[128]; FormatEx(STRING(reason), "open %s and add [%s] d[%d] c[%d]", g_szCase[g_iClientCase[client]], name, days, g_inCase[g_iClientCase[client]]); - Store_SetClientCredits(client, Store_GetClientCredits(client)-g_inCase[g_iClientCase[client]], reason); - Store_GiveItem(client, itemid, GetTime(), (days == 0) ? 0 : GetTime()+days*86400, -11); - if(days) tPrintToChat(client, "%t", "open and add day chat", g_szCase[g_iClientCase[client]], name, days); - else tPrintToChat(client, "%t", "open and add permanent chat", g_szCase[g_iClientCase[client]], name); + Store_SetClientCredits(client, Store_GetClientCredits(client) - g_inCase[g_iClientCase[client]], reason); + Store_GiveItem(client, itemid, GetTime(), (days == 0) ? 0 : GetTime() + days * 86400, -11); + if (days) + tPrintToChat(client, "%t", "open and add day chat", g_szCase[g_iClientCase[client]], name, days); + else + tPrintToChat(client, "%t", "open and add permanent chat", g_szCase[g_iClientCase[client]], name); Store_SaveClientAll(client); UTIL_LogOpencase(client, itemid, days, "add", g_iClientCase[client]); - g_iDataProtect[client] = GetTime()+15; + g_iDataProtect[client] = GetTime() + 15; g_iSelectedItem[client] = itemid; DisplayItemMenu(client, itemid); } - else LogStoreError("\"%L\" Open case error: %s", client, info); + else + LogStoreError("\"%L\" Open case error: %s", client, info); } case MenuAction_Cancel: { - if(IsClientInGame(client) && param2 == MenuCancel_Interrupted) + if (IsClientInGame(client) && param2 == MenuCancel_Interrupted) { char info[32]; menu.GetItem(5, STRING(info)); @@ -2381,7 +2412,7 @@ static int MenuHandler_OpenSuccessful(Menu menu, MenuAction action, int client, ExplodeString(info, "_", data, 3, 16); int itemid = StringToInt(data[1]); - int days = StringToInt(data[2]); + int days = StringToInt(data[2]); DataPack pack = new DataPack(); pack.WriteCell(GetClientUserId(client)); @@ -2405,46 +2436,46 @@ static int MenuHandler_OpenSuccessful(Menu menu, MenuAction action, int client, void DisplayItemMenu(int client, int itemid) { - if(!Store_HasClientItem(client, itemid)) + if (!Store_HasClientItem(client, itemid)) { - if(StrEqual(g_TypeHandlers[g_Items[itemid].iHandler].szType, "playerskin")) + if (StrEqual(g_TypeHandlers[g_Items[itemid].iHandler].szType, "playerskin")) DisplayPreviewMenu(client, itemid); return; } - g_iMenuNum[client] = 1; + g_iMenuNum[client] = 1; g_iMenuBack[client] = g_Items[itemid].iParent; - Menu m_hMenu = new Menu(MenuHandler_Item); + Menu m_hMenu = new Menu(MenuHandler_Item); m_hMenu.ExitBackButton = true; bool m_bEquipped = UTIL_IsEquipped(client, itemid); char m_szTitle[256]; - int idx = 0; - if(m_bEquipped) + int idx = 0; + if (m_bEquipped) idx = FormatEx(STRING(m_szTitle), "%T\n%T ", "Item Equipped", client, g_Items[itemid].szName, "Title Credits", client, g_ClientData[client].iCredits); else idx = FormatEx(STRING(m_szTitle), "%s\n%T ", g_Items[itemid].szName, "Title Credits", client, g_ClientData[client].iCredits); int m_iExpiration = UTIL_GetExpiration(client, itemid); - if(m_iExpiration > 0) + if (m_iExpiration > 0) { - m_iExpiration = m_iExpiration-GetTime(); - int m_iDays = m_iExpiration/(24*60*60); - int m_iHours = (m_iExpiration-m_iDays*24*60*60)/(60*60); - FormatEx(m_szTitle[idx-1], sizeof(m_szTitle)-idx-1, "\n%T", "Title Expiration", client, m_iDays, m_iHours); + m_iExpiration = m_iExpiration - GetTime(); + int m_iDays = m_iExpiration / (24 * 60 * 60); + int m_iHours = (m_iExpiration - m_iDays * 24 * 60 * 60) / (60 * 60); + FormatEx(m_szTitle[idx - 1], sizeof(m_szTitle) - idx - 1, "\n%T", "Title Expiration", client, m_iDays, m_iHours); } - else if(m_iExpiration == 0) + else if (m_iExpiration == 0) { // PM item - FormatEx(m_szTitle[idx-1], sizeof(m_szTitle)-idx-1, "\n%T", "Title Expiration PM", client); + FormatEx(m_szTitle[idx - 1], sizeof(m_szTitle) - idx - 1, "\n%T", "Title Expiration PM", client); } m_hMenu.SetTitle("%s\n ", m_szTitle); - if(g_TypeHandlers[g_Items[itemid].iHandler].bEquipable) + if (g_TypeHandlers[g_Items[itemid].iHandler].bEquipable) { - if(StrEqual(g_TypeHandlers[g_Items[itemid].iHandler].szType, "playerskin")) + if (StrEqual(g_TypeHandlers[g_Items[itemid].iHandler].szType, "playerskin")) { AddMenuItemEx(m_hMenu, (g_Items[itemid].szDesc[0] == '\0') ? ITEMDRAW_SPACER : ITEMDRAW_DISABLED, "3", "%s", g_Items[itemid].szDesc); @@ -2454,12 +2485,12 @@ void DisplayItemMenu(int client, int itemid) AddMenuItemEx(m_hMenu, (g_aCaseSkins[0].Length > 0 || g_pfysRect || g_pOpenCase) ? ITEMDRAW_DEFAULT : ITEMDRAW_SPACER, "4", "%T", "Open Case Available", client); } - if(!m_bEquipped) + if (!m_bEquipped) AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "0", "%T", "Item Equip", client); else AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "3", "%T", "Item Unequip", client); - if(StrEqual(g_TypeHandlers[g_Items[itemid].iHandler].szType, "playerskin") && g_pRandomSkin) + if (StrEqual(g_TypeHandlers[g_Items[itemid].iHandler].szType, "playerskin") && g_pRandomSkin) { AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "5", "%T", "random skin", client); } @@ -2469,30 +2500,30 @@ void DisplayItemMenu(int client, int itemid) AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "0", "%T", "Item Use", client); } - if(!Store_IsItemInBoughtPackage(client, itemid)) + if (!Store_IsItemInBoughtPackage(client, itemid)) { - int m_iCredits = RoundToFloor(UTIL_GetClientItemPrice(client, itemid)*0.6); - if(m_iCredits!=0) + int m_iCredits = RoundToFloor(UTIL_GetClientItemPrice(client, itemid) * 0.6); + if (m_iCredits != 0) { int uid = UTIL_GetClientItemId(client, itemid); - if(g_ClientItem[client][uid].iDateOfExpiration != 0) + if (g_ClientItem[client][uid].iDateOfExpiration != 0) { - int m_iLength = g_ClientItem[client][uid].iDateOfExpiration-g_ClientItem[client][uid].iDateOfPurchase; - int m_iLeft = g_ClientItem[client][uid].iDateOfExpiration-GetTime(); - if(m_iLeft < 0) + int m_iLength = g_ClientItem[client][uid].iDateOfExpiration - g_ClientItem[client][uid].iDateOfPurchase; + int m_iLeft = g_ClientItem[client][uid].iDateOfExpiration - GetTime(); + if (m_iLeft < 0) m_iLeft = 0; - m_iCredits = RoundToCeil(m_iCredits*float(m_iLeft)/float(m_iLength)); + m_iCredits = RoundToCeil(m_iCredits * float(m_iLeft) / float(m_iLength)); } AddMenuItemEx(m_hMenu, m_iCredits > 0 ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED, "1", "%T", "Item Sell", client, m_iCredits); - if(g_Items[itemid].bGiftable) + if (g_Items[itemid].bGiftable) AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "2", "%T", "Item Gift", client); } } - for(int i = 0; i < g_iMenuHandlers; ++i) + for (int i = 0; i < g_iMenuHandlers; ++i) { - if(g_MenuHandlers[i].hPlugin == null || !IsPluginRunning(g_MenuHandlers[i].hPlugin, g_MenuHandlers[i].szPlFile)) + if (g_MenuHandlers[i].hPlugin == null || !IsPluginRunning(g_MenuHandlers[i].hPlugin, g_MenuHandlers[i].szPlFile)) continue; Call_StartFunction(g_MenuHandlers[i].hPlugin, g_MenuHandlers[i].fnMenu); Call_PushCellRef(m_hMenu); @@ -2508,14 +2539,14 @@ void DisplayPlanMenu(int client, int itemid) { g_iMenuNum[client] = 1; - Menu m_hMenu = new Menu(MenuHandler_Plan); + Menu m_hMenu = new Menu(MenuHandler_Plan); m_hMenu.ExitBackButton = true; m_hMenu.SetTitle("%s\n%T\n ", g_Items[itemid].szName, "Title Credits", client, g_ClientData[client].iCredits); - for(int i = 0; i < g_Items[itemid].iPlans; ++i) + for (int i = 0; i < g_Items[itemid].iPlans; ++i) { - AddMenuItemEx(m_hMenu, (g_ClientData[client].iCredits>=g_PurchasePlan[itemid][i].iPrice?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED), "", "%T", "Item Available", client, g_PurchasePlan[itemid][i].szName, g_PurchasePlan[itemid][i].iPrice); + AddMenuItemEx(m_hMenu, (g_ClientData[client].iCredits >= g_PurchasePlan[itemid][i].iPrice ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED), "", "%T", "Item Available", client, g_PurchasePlan[itemid][i].szName, g_PurchasePlan[itemid][i].iPrice); } m_hMenu.Display(client, 0); @@ -2525,28 +2556,28 @@ void DisplayPlanMenu(int client, int itemid) void DisplayComposeMenu(int client, bool last) { // data protection - if(g_iDataProtect[client] > GetTime()) + if (g_iDataProtect[client] > GetTime()) { - tPrintToChat(client, "%T", "data protect", client, g_iDataProtect[client]-GetTime()); + tPrintToChat(client, "%T", "data protect", client, g_iDataProtect[client] - GetTime()); DisplayPreviewMenu(client, g_iSelectedItem[client]); return; } // 当前菜单层级 - g_iMenuNum[client] = 1; - Menu m_hMenu = new Menu(MenuHandler_Compose); + g_iMenuNum[client] = 1; + Menu m_hMenu = new Menu(MenuHandler_Compose); m_hMenu.ExitBackButton = true; // 合成道具1 char sitem1[64]; - if(g_Compose[client].item1 >= 0) + if (g_Compose[client].item1 >= 0) strcopy(STRING(sitem1), g_Items[g_Compose[client].item1].szName); else FormatEx(STRING(sitem1), "%T", "unselect", client); // 合成道具2 char sitem2[64]; - if(g_Compose[client].item2 >= 0) + if (g_Compose[client].item2 >= 0) strcopy(STRING(sitem2), g_Items[g_Compose[client].item2].szName); else FormatEx(STRING(sitem2), "%T", "unselect", client); @@ -2557,21 +2588,21 @@ void DisplayComposeMenu(int client, bool last) int level = g_Items[g_iSelectedItem[client]].iLevels - 1; // 已选择全部道具 - if(!last) + if (!last) { char m_szId[8]; - for(int i = 0; i < g_iItems; ++i) + for (int i = 0; i < g_iItems; ++i) { - if(g_Items[i].iHandler == g_iPackageHandler) + if (g_Items[i].iHandler == g_iPackageHandler) continue; - if(!Store_HasClientItem(client, i)) + if (!Store_HasClientItem(client, i)) continue; - if(i == g_Compose[client].item1 || i == g_Compose[client].item2) + if (i == g_Compose[client].item1 || i == g_Compose[client].item2) continue; - if(!StrEqual(g_TypeHandlers[g_Items[i].iHandler].szType, "playerskin")) + if (!StrEqual(g_TypeHandlers[g_Items[i].iHandler].szType, "playerskin")) continue; // if level not match or is personal item. @@ -2580,7 +2611,7 @@ void DisplayComposeMenu(int client, bool last) int uid = UTIL_GetClientItemId(client, i); - if(uid < 0 || g_ClientItem[client][uid].iDateOfExpiration != 0) + if (uid < 0 || g_ClientItem[client][uid].iDateOfExpiration != 0) continue; IntToString(i, STRING(m_szId)); @@ -2590,15 +2621,15 @@ void DisplayComposeMenu(int client, bool last) // 选择合成器 else { - AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "0", "[30%%] Iron furnace (%s%t)", g_szComposeFee[0], "credits"); - AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "1", "[40%%] Bronze furnace (%s%t)", g_szComposeFee[1], "credits"); - AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "2", "[50%%] Silver furnace (%s%t)", g_szComposeFee[2], "credits"); - AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "3", "[60%%] Gold furnace (%s%t)", g_szComposeFee[3], "credits"); + AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "0", "[30%%] Iron furnace (%s%t)", g_szComposeFee[0], "credits"); + AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "1", "[40%%] Bronze furnace (%s%t)", g_szComposeFee[1], "credits"); + AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "2", "[50%%] Silver furnace (%s%t)", g_szComposeFee[2], "credits"); + AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "3", "[60%%] Gold furnace (%s%t)", g_szComposeFee[3], "credits"); AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "4", "[70%%] Platinum furnace (%s%t)", g_szComposeFee[4], "credits"); - AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "5", "[80%%] Diamond furnace (%s%t)", g_szComposeFee[5], "credits"); + AddMenuItemEx(m_hMenu, ITEMDRAW_DEFAULT, "5", "[80%%] Diamond furnace (%s%t)", g_szComposeFee[5], "credits"); } - if(m_hMenu.ItemCount > 0) + if (m_hMenu.ItemCount > 0) { m_hMenu.Display(client, 0); return; @@ -2611,14 +2642,14 @@ void DisplayComposeMenu(int client, bool last) static int MenuHandler_Compose(Menu menu, MenuAction action, int client, int param2) { - if(action == MenuAction_End) + if (action == MenuAction_End) delete menu; - else if(action == MenuAction_Select) + else if (action == MenuAction_Select) { // Confirmation was sent - if(menu == null) + if (menu == null) { - if(param2 == 0) + if (param2 == 0) { UTIL_ComposeItem(client); } @@ -2627,29 +2658,29 @@ static int MenuHandler_Compose(Menu menu, MenuAction action, int client, int par { char m_szId[64]; menu.GetItem(param2, STRING(m_szId)); - int itemid = StringToInt(m_szId); + int itemid = StringToInt(m_szId); g_iMenuNum[client] = 1; - if(g_Compose[client].item1==-1) + if (g_Compose[client].item1 == -1) { - g_Compose[client].item1=itemid; + g_Compose[client].item1 = itemid; DisplayComposeMenu(client, false); } - else if(g_Compose[client].item2==-1) + else if (g_Compose[client].item2 == -1) { - g_Compose[client].item2=itemid; + g_Compose[client].item2 = itemid; DisplayComposeMenu(client, true); } - else if(0 <= itemid <= 5 && g_Compose[client].item1 >= 0 && g_Compose[client].item2 >= 0 && Store_HasClientItem(client, g_Compose[client].item1) && Store_HasClientItem(client, g_Compose[client].item2)) + else if (0 <= itemid <= 5 && g_Compose[client].item1 >= 0 && g_Compose[client].item2 >= 0 && Store_HasClientItem(client, g_Compose[client].item1) && Store_HasClientItem(client, g_Compose[client].item2)) { - g_Compose[client].types=itemid; + g_Compose[client].types = itemid; char m_szTitle[256]; FormatEx(STRING(m_szTitle), "%T", "Confirm_Compose", client, g_Items[g_iSelectedItem[client]].szName, g_Items[g_Compose[client].item1].szName, g_Items[g_Compose[client].item2].szName, g_szComposeFee[itemid]); Store_DisplayConfirmMenu(client, m_szTitle, MenuHandler_Compose, 0); } } } - else if(action==MenuAction_Cancel) - if(param2 == MenuCancel_ExitBack) + else if (action == MenuAction_Cancel) + if (param2 == MenuCancel_ExitBack) { g_Compose[client].item1 = -1; g_Compose[client].item2 = -1; @@ -2662,14 +2693,14 @@ static int MenuHandler_Compose(Menu menu, MenuAction action, int client, int par static int MenuHandler_Plan(Menu menu, MenuAction action, int client, int param2) { - if(action == MenuAction_End) + if (action == MenuAction_End) delete menu; - else if(action == MenuAction_Select) + else if (action == MenuAction_Select) { if (g_Items[g_iSelectedItem[client]].bBuyable) { - g_iSelectedPlan[client]=param2; - g_iMenuNum[client]=4; + g_iSelectedPlan[client] = param2; + g_iMenuNum[client] = 4; char m_szTitle[128]; FormatEx(STRING(m_szTitle), "%T", "Confirm_Buy", client, g_Items[g_iSelectedItem[client]].szName, g_TypeHandlers[g_Items[g_iSelectedItem[client]].iHandler].szType); @@ -2680,8 +2711,8 @@ static int MenuHandler_Plan(Menu menu, MenuAction action, int client, int param2 Store_DisplayPreviousMenu(client); } } - else if(action==MenuAction_Cancel) - if(param2 == MenuCancel_ExitBack) + else if (action == MenuAction_Cancel) + if (param2 == MenuCancel_ExitBack) Store_DisplayPreviousMenu(client); return 0; @@ -2689,14 +2720,14 @@ static int MenuHandler_Plan(Menu menu, MenuAction action, int client, int param2 static int MenuHandler_Item(Menu menu, MenuAction action, int client, int param2) { - if(action == MenuAction_End) + if (action == MenuAction_End) delete menu; - else if(action == MenuAction_Select) + else if (action == MenuAction_Select) { // Confirmation was sent - if(menu == null) + if (menu == null) { - if(param2 == 0) + if (param2 == 0) { g_iMenuNum[client] = 1; UTIL_SellItem(client, g_iSelectedItem[client]); @@ -2710,12 +2741,12 @@ static int MenuHandler_Item(Menu menu, MenuAction action, int client, int param2 int m_iId = StringToInt(m_szId); // Menu handlers - if(!(48 <= m_szId[0] <= 57)) //ASCII 0~9 + if (!(48 <= m_szId[0] <= 57)) // ASCII 0~9 { int ret; - for(int i=0;i 0) + int m_iFees = UTIL_GetClientHandleFees(client, g_iSelectedItem[client]); + if (m_iFees > 0) { FormatEx(STRING(m_szTitle), "%T\n%T", "Confirm_Gift", client, g_Items[g_iSelectedItem[client]].szName, g_TypeHandlers[g_Items[g_iSelectedItem[client]].iHandler].szType, m_iReceiver, "Gift_Handing", client, m_iFees); Store_DisplayConfirmMenu(client, m_szTitle, MenuHandler_Gift, m_iId); @@ -2876,8 +2907,8 @@ static int MenuHandler_Gift(Menu menu, MenuAction action, int client, int param2 tPrintToChat(client, " {darkred}UNKNOWN ERROR{white} : {red}%d", UTIL_GetRandomInt(100000, 999999)); } } - else if(action==MenuAction_Cancel) - if(param2 == MenuCancel_ExitBack) + else if (action == MenuAction_Cancel) + if (param2 == MenuCancel_ExitBack) DisplayItemMenu(client, g_iSelectedItem[client]); return 0; @@ -2885,23 +2916,23 @@ static int MenuHandler_Gift(Menu menu, MenuAction action, int client, int param2 static int MenuHandler_Confirm(Menu menu, MenuAction action, int client, int param2) { - if(action == MenuAction_End) + if (action == MenuAction_End) delete menu; - else if(action == MenuAction_Select) + else if (action == MenuAction_Select) { - if(param2 == 0) + if (param2 == 0) { char m_szCallback[32]; char m_szData[11]; char m_szFile[64]; menu.GetItem(0, STRING(m_szCallback)); menu.GetItem(1, STRING(m_szData)); - DataPack pack = view_as(StringToInt(m_szCallback)); - Handle m_hPlugin = pack.ReadCell(); + DataPack pack = view_as(StringToInt(m_szCallback)); + Handle m_hPlugin = pack.ReadCell(); Function fnMenuCallback = pack.ReadFunction(); pack.ReadString(STRING(m_szFile)); delete pack; - if(m_hPlugin != null && fnMenuCallback != INVALID_FUNCTION && IsPluginRunning(m_hPlugin, m_szFile)) + if (m_hPlugin != null && fnMenuCallback != INVALID_FUNCTION && IsPluginRunning(m_hPlugin, m_szFile)) { Call_StartFunction(m_hPlugin, fnMenuCallback); Call_PushCell(INVALID_HANDLE); @@ -2910,9 +2941,11 @@ static int MenuHandler_Confirm(Menu menu, MenuAction action, int client, int par Call_PushCell(StringToInt(m_szData)); Call_Finish(); } - else Store_DisplayPreviousMenu(client); + else + Store_DisplayPreviousMenu(client); } - else Store_DisplayPreviousMenu(client); + else + Store_DisplayPreviousMenu(client); } return 0; @@ -2924,10 +2957,10 @@ static int MenuHandler_Confirm(Menu menu, MenuAction action, int client, int par static Action Timer_DababaseRetry(Handle timer, int retry) { // Database is connected successfully - if(g_hDatabase != null) + if (g_hDatabase != null) return Plugin_Stop; - if(retry >= 100) + if (retry >= 100) { SetFailState("Database connection failed to initialize after 100 retrie"); return Plugin_Stop; @@ -2945,7 +2978,7 @@ static void SQLCallback_Connection(Database db, const char[] error, int retry) { retry++; - if(db == null || error[0]) + if (db == null || error[0]) { LogStoreError("Failed to connect to SQL database. [%03d] Error: %s", retry, error); CreateTimer(5.0, Timer_DababaseRetry, retry); @@ -2953,7 +2986,7 @@ static void SQLCallback_Connection(Database db, const char[] error, int retry) } // If it's already connected we are good to go - if(g_hDatabase != null) + if (g_hDatabase != null) { delete db; return; @@ -2962,7 +2995,7 @@ static void SQLCallback_Connection(Database db, const char[] error, int retry) g_hDatabase = db; // Do some housekeeping - if(!g_hDatabase.SetCharset("utf8mb4")) + if (!g_hDatabase.SetCharset("utf8mb4")) { // if failure g_hDatabase.SetCharset("utf8"); @@ -2976,16 +3009,16 @@ static void SQLCallback_Connection(Database db, const char[] error, int retry) UTIL_ReloadConfig(); // if Loaded late. - if(g_bLateLoad) + if (g_bLateLoad) { - for(int client = 1; client <= MaxClients; ++client) + for (int client = 1; client <= MaxClients; ++client) { - if(!IsClientConnected(client)) + if (!IsClientConnected(client)) continue; OnClientConnected(client); - if(!IsClientInGame(client) || !IsClientAuthorized(client)) + if (!IsClientInGame(client) || !IsClientAuthorized(client)) continue; OnClientPostAdminCheck(client); @@ -2995,14 +3028,14 @@ static void SQLCallback_Connection(Database db, const char[] error, int retry) static void SQLCallback_LoadClientInventory_Credits(Database db, DBResultSet results, const char[] error, int userid) { - if(results == null || error[0]) + if (results == null || error[0]) { LogStoreError("Error happened. Error: %s", error); return; } int client = GetClientOfUserId(userid); - if(!client || g_bInterMission) + if (!client || g_bInterMission) return; char m_szSteamID[32]; @@ -3010,21 +3043,21 @@ static void SQLCallback_LoadClientInventory_Credits(Database db, DBResultSet res return; char m_szQuery[512]; - int m_iTime = GetTime(); + int m_iTime = GetTime(); g_ClientData[client].iUserId = userid; - g_ClientData[client].iItems = 0; + g_ClientData[client].iItems = 0; strcopy(g_ClientData[client].szAuthId, sizeof(Client_Data::szAuthId), m_szSteamID[8]); - if(results.FetchRow() && results.RowCount > 0) + if (results.FetchRow() && results.RowCount > 0) { - g_ClientData[client].iId = results.FetchInt(0); - g_ClientData[client].iCredits = results.FetchInt(3); + g_ClientData[client].iId = results.FetchInt(0); + g_ClientData[client].iCredits = results.FetchInt(3); g_ClientData[client].iOriginalCredits = results.FetchInt(3); - g_ClientData[client].iDateOfJoin = results.FetchInt(4); - g_ClientData[client].iDateOfLastJoin = m_iTime; - g_ClientData[client].bBan = (results.FetchInt(6) == 1 || g_ClientData[client].iCredits < 0) ? true : false; + g_ClientData[client].iDateOfJoin = results.FetchInt(4); + g_ClientData[client].iDateOfLastJoin = m_iTime; + g_ClientData[client].bBan = (results.FetchInt(6) == 1 || g_ClientData[client].iCredits < 0) ? true : false; - if(g_ClientData[client].bBan) + if (g_ClientData[client].bBan) { g_ClientData[client].iItems = 0; Call_OnClientLoaded(client); @@ -3036,7 +3069,7 @@ static void SQLCallback_LoadClientInventory_Credits(Database db, DBResultSet res } UTIL_LogMessage(client, 0, "Joined"); - g_iDataProtect[client] = GetTime()+90; + g_iDataProtect[client] = GetTime() + 90; } else { @@ -3050,21 +3083,21 @@ static void SQLCallback_LoadClientInventory_Credits(Database db, DBResultSet res static void SQLCallback_LoadClientInventory_Items(Database db, DBResultSet results, const char[] error, int userid) { - if(results == null || error[0]) + if (results == null || error[0]) { LogStoreError("Error happened. Error: %s", error); return; } int client = GetClientOfUserId(userid); - if(!client || g_bInterMission) + if (!client || g_bInterMission) return; char m_szQuery[512]; - if(results.RowCount <= 0) + if (results.RowCount <= 0) { - if(UTIL_GetTotalInventoryItems(client) > 0) + if (UTIL_GetTotalInventoryItems(client) > 0) { FormatEx(STRING(m_szQuery), "SELECT * FROM store_equipment WHERE `player_id`=%d", g_ClientData[client].iId); g_hDatabase.Query(SQLCallback_LoadClientInventory_Equipment, m_szQuery, userid, DBPrio_High); @@ -3072,58 +3105,58 @@ static void SQLCallback_LoadClientInventory_Items(Database db, DBResultSet resul } Call_OnClientLoaded(client); - //FormatEx(STRING(m_szQuery), "DELETE FROM store_equipment WHERE `player_id`=%d", g_ClientData[client].iId); - //SQL_TVoid(g_hDatabase, m_szQuery, DBPrio_Low); + // FormatEx(STRING(m_szQuery), "DELETE FROM store_equipment WHERE `player_id`=%d", g_ClientData[client].iId); + // SQL_TVoid(g_hDatabase, m_szQuery, DBPrio_Low); return; } char m_szUniqueId[PLATFORM_MAX_PATH]; char m_szType[16]; - int m_iExpiration; - int m_iUniqueId; - int m_iTime = GetTime(); + int m_iExpiration; + int m_iUniqueId; + int m_iTime = GetTime(); int i = 0; - while(results.FetchRow()) + while (results.FetchRow()) { - m_iUniqueId = -1; + m_iUniqueId = -1; m_iExpiration = results.FetchInt(5); - if(m_iExpiration && m_iExpiration <= m_iTime) + if (m_iExpiration && m_iExpiration <= m_iTime) continue; results.FetchString(2, STRING(m_szType)); results.FetchString(3, STRING(m_szUniqueId)); - while((m_iUniqueId = UTIL_GetItemId(m_szUniqueId, m_iUniqueId)) != -1) + while ((m_iUniqueId = UTIL_GetItemId(m_szUniqueId, m_iUniqueId)) != -1) { - g_ClientItem[client][i].iId = results.FetchInt(0); - g_ClientItem[client][i].iUniqueId = m_iUniqueId; - g_ClientItem[client][i].bSynced = true; - g_ClientItem[client][i].bDeleted = false; - g_ClientItem[client][i].iDateOfPurchase = results.FetchInt(4); + g_ClientItem[client][i].iId = results.FetchInt(0); + g_ClientItem[client][i].iUniqueId = m_iUniqueId; + g_ClientItem[client][i].bSynced = true; + g_ClientItem[client][i].bDeleted = false; + g_ClientItem[client][i].iDateOfPurchase = results.FetchInt(4); g_ClientItem[client][i].iDateOfExpiration = m_iExpiration; - g_ClientItem[client][i].iPriceOfPurchase = results.FetchInt(6); + g_ClientItem[client][i].iPriceOfPurchase = results.FetchInt(6); i++; } } g_ClientData[client].iItems = i; - g_iDataProtect[client] = GetTime()+15; + g_iDataProtect[client] = GetTime() + 15; #if defined DATA_VERIFY FormatEx(STRING(m_szQuery), "SELECT * FROM `store_newlogs` WHERE `store_id` = '%d' AND (`reason` = 'Disconnect' OR `reason` = 'Add Funds') ORDER BY `timestamp` DESC LIMIT 1", g_ClientData[client].iId); g_hDatabase.Query(SQLCallback_LoadClientInventory_DATAVERIFY, m_szQuery, userid, DBPrio_Low); #endif - if(i > 0) + if (i > 0) { FormatEx(STRING(m_szQuery), "SELECT * FROM store_equipment WHERE `player_id`=%d", g_ClientData[client].iId); g_hDatabase.Query(SQLCallback_LoadClientInventory_Equipment, m_szQuery, userid, DBPrio_High); } else { - //FormatEx(STRING(m_szQuery), "DELETE FROM store_equipment WHERE `player_id`=%d", g_ClientData[client].iId); - //SQL_TVoid(g_hDatabase, m_szQuery, DBPrio_Low); + // FormatEx(STRING(m_szQuery), "DELETE FROM store_equipment WHERE `player_id`=%d", g_ClientData[client].iId); + // SQL_TVoid(g_hDatabase, m_szQuery, DBPrio_Low); Call_OnClientLoaded(client); } @@ -3132,23 +3165,23 @@ static void SQLCallback_LoadClientInventory_Items(Database db, DBResultSet resul #if defined DATA_VERIFY static void SQLCallback_LoadClientInventory_DATAVERIFY(Database db, DBResultSet results, const char[] error, int userid) { - if(results == null || error[0]) + if (results == null || error[0]) { LogStoreError("Error happened. Error: %s", error); return; } - if(results.FetchRow()) + if (results.FetchRow()) { int client = GetClientOfUserId(userid); - if(!client || g_bInterMission) + if (!client || g_bInterMission) return; int credits = results.FetchInt(0); int diff = g_ClientData[client].iCredits - credits; - if(diff > 1000) + if (diff > 1000) { char m_szQuery[256]; FormatEx(STRING(m_szQuery), "UPDATE `store_players` SET `ban` = 1, `credits` = -1 WHERE `id` = '%d';", g_ClientData[client].iId); @@ -3156,16 +3189,16 @@ static void SQLCallback_LoadClientInventory_DATAVERIFY(Database db, DBResultSet LogMessage("[CAT] Store Inject detected : \"%L\" -> credits[%d] -> loaded[%d] -> diff[%d]", client, credits, g_ClientData[client].iCredits, diff); ServerCommand("sm_ban #%d 0 \"[CAT] Store Inject detected.\"", GetClientUserId(client)); - //BanClient(client, 0, BANFLAG_IP|BANFLAG_AUTHID, "[CAT] Store Inject detected", "[CAT] Store Inject detected"); + // BanClient(client, 0, BANFLAG_IP|BANFLAG_AUTHID, "[CAT] Store Inject detected", "[CAT] Store Inject detected"); return; } - g_iDataProtect[client] = GetTime()+30; + g_iDataProtect[client] = GetTime() + 30; } else { int client = GetClientOfUserId(userid); - if(!client) + if (!client) return; LogMessage("[CAT] Store invalid data detected : \"%L\" -> no results", client); @@ -3176,42 +3209,42 @@ static void SQLCallback_LoadClientInventory_DATAVERIFY(Database db, DBResultSet static void SQLCallback_LoadClientInventory_Equipment(Database db, DBResultSet results, const char[] error, int userid) { - if(results == null || error[0]) + if (results == null || error[0]) { LogStoreError("Error happened. Error: %s", error); return; } int client = GetClientOfUserId(userid); - if(!client || g_bInterMission) + if (!client || g_bInterMission) return; char m_szUniqueId[PLATFORM_MAX_PATH]; char m_szType[16]; - int m_iUniqueId, m_iSlot; + int m_iUniqueId, m_iSlot; - while(results.FetchRow()) + while (results.FetchRow()) { results.FetchString(1, STRING(m_szType)); results.FetchString(2, STRING(m_szUniqueId)); m_iUniqueId = UTIL_GetItemId(m_szUniqueId); - if(m_iUniqueId == -1) + if (m_iUniqueId == -1) continue; m_iSlot = results.FetchInt(3); - if(StrEqual(m_szType, "playerskin")) + if (StrEqual(m_szType, "playerskin")) { #if defined Global_Skin - if(m_iSlot != 2) + if (m_iSlot != 2) continue; #else - if(m_iSlot >= 2) + if (m_iSlot >= 2) continue; #endif } - if(Store_HasClientItem(client, m_iUniqueId)) + if (Store_HasClientItem(client, m_iUniqueId)) UTIL_UseItem(client, m_iUniqueId, true, m_iSlot); else UTIL_UnequipItem(client, m_iUniqueId); @@ -3223,26 +3256,26 @@ static void SQLCallback_LoadClientInventory_Equipment(Database db, DBResultSet r static void SQLCallback_InsertClient(Database db, DBResultSet results, const char[] error, int userid) { int client = GetClientOfUserId(userid); - if(!client || g_bInterMission) + if (!client || g_bInterMission) return; - if(results == null || error[0]) + if (results == null || error[0]) { LogStoreError("Error happened. Error: %s", error); KickClient(client, "Failed to check your store account."); return; } - g_ClientData[client].iId = results.InsertId; - g_ClientData[client].iCredits = 300; + g_ClientData[client].iId = results.InsertId; + g_ClientData[client].iCredits = 300; g_ClientData[client].iOriginalCredits = 0; - g_ClientData[client].iDateOfJoin = GetTime(); - g_ClientData[client].iDateOfLastJoin = g_ClientData[client].iDateOfJoin; - g_ClientData[client].iItems = 0; + g_ClientData[client].iDateOfJoin = GetTime(); + g_ClientData[client].iDateOfLastJoin = g_ClientData[client].iDateOfJoin; + g_ClientData[client].iItems = 0; Call_OnClientLoaded(client); - g_iDataProtect[client] = GetTime()+90; + g_iDataProtect[client] = GetTime() + 90; } ////////////////////////////// @@ -3267,35 +3300,35 @@ void UTIL_LoadClientInventory(int client) void UTIL_SaveClientInventory(int client) { - if(g_hDatabase == null) + if (g_hDatabase == null) { LogStoreError("Database connection is lost or not yet initialized."); return; } // Player disconnected before his inventory was even fetched - if(!g_ClientData[client].bLoaded) + if (!g_ClientData[client].bLoaded) return; char m_szQuery[512]; char m_szType[16]; char m_szUniqueId[PLATFORM_MAX_PATH]; - for(int i = 0; i < g_ClientData[client].iItems; ++i) + for (int i = 0; i < g_ClientData[client].iItems; ++i) { strcopy(STRING(m_szType), g_TypeHandlers[g_Items[g_ClientItem[client][i].iUniqueId].iHandler].szType); strcopy(STRING(m_szUniqueId), g_Items[g_ClientItem[client][i].iUniqueId].szUniqueId); - if(!g_ClientItem[client][i].bSynced && !g_ClientItem[client][i].bDeleted) + if (!g_ClientItem[client][i].bSynced && !g_ClientItem[client][i].bDeleted) { g_ClientItem[client][i].bSynced = true; FormatEx(STRING(m_szQuery), "INSERT INTO store_items (`player_id`, `type`, `unique_id`, `date_of_purchase`, `date_of_expiration`, `price_of_purchase`) VALUES(%d, \"%s\", \"%s\", FROM_UNIXTIME(%d), %d, %d)", g_ClientData[client].iId, m_szType, m_szUniqueId, g_ClientItem[client][i].iDateOfPurchase, g_ClientItem[client][i].iDateOfExpiration, g_ClientItem[client][i].iPriceOfPurchase); SQL_TVoid(g_hDatabase, m_szQuery, DBPrio_High); } - else if(g_ClientItem[client][i].bSynced && g_ClientItem[client][i].bDeleted) + else if (g_ClientItem[client][i].bSynced && g_ClientItem[client][i].bDeleted) { // Might have been synced already but ID wasn't acquired - if(g_ClientItem[client][i].iId==-1) + if (g_ClientItem[client][i].iId == -1) FormatEx(STRING(m_szQuery), "DELETE FROM store_items WHERE `player_id`=%d AND `type`=\"%s\" AND `unique_id`=\"%s\"", g_ClientData[client].iId, m_szType, m_szUniqueId); else FormatEx(STRING(m_szQuery), "DELETE FROM store_items WHERE `id`=%d", g_ClientItem[client][i].iId); @@ -3307,38 +3340,38 @@ void UTIL_SaveClientInventory(int client) void UTIL_SaveClientEquipment(int client) { - if(g_hDatabase == null) + if (g_hDatabase == null) { LogStoreError("Database connection is lost or not yet initialized."); return; } // Player disconnected before his inventory was even fetched - if(!g_ClientData[client].bLoaded) + if (!g_ClientData[client].bLoaded) return; char m_szQuery[512]; - int m_iId; - for(int i = 0; i < STORE_MAX_HANDLERS; ++i) + int m_iId; + for (int i = 0; i < STORE_MAX_HANDLERS; ++i) { - for(int a = 0; a < STORE_MAX_SLOTS; ++a) + for (int a = 0; a < STORE_MAX_SLOTS; ++a) { - m_iId = i*STORE_MAX_SLOTS+a; - if(g_ClientData[client].aEquipmentSynced[m_iId] == g_ClientData[client].aEquipment[m_iId]) + m_iId = i * STORE_MAX_SLOTS + a; + if (g_ClientData[client].aEquipmentSynced[m_iId] == g_ClientData[client].aEquipment[m_iId]) continue; - else if(g_ClientData[client].aEquipmentSynced[m_iId] != -2) + else if (g_ClientData[client].aEquipmentSynced[m_iId] != -2) { - if(g_ClientData[client].aEquipment[m_iId]==-1) + if (g_ClientData[client].aEquipment[m_iId] == -1) FormatEx(STRING(m_szQuery), "DELETE FROM store_equipment WHERE `player_id`=%d AND `type`=\"%s\" AND `slot`=%d", g_ClientData[client].iId, g_TypeHandlers[i].szType, a); else FormatEx(STRING(m_szQuery), "INSERT INTO store_equipment (`player_id`, `type`, `unique_id`, `slot`) VALUES(%d, \"%s\", \"%s\", %d) ON DUPLICATE KEY UPDATE `unique_id` = VALUES(`unique_id`)", g_ClientData[client].iId, g_TypeHandlers[i].szType, g_Items[g_ClientData[client].aEquipment[m_iId]].szUniqueId, a); - //FormatEx(STRING(m_szQuery), "UPDATE store_equipment SET `unique_id`=\"%s\" WHERE `player_id`=%d AND `type`=\"%s\" AND `slot`=%d", g_Items[g_ClientData[client].aEquipment[m_iId]].szUniqueId, g_ClientData[client].iId, g_TypeHandlers[i].szType, a); + // FormatEx(STRING(m_szQuery), "UPDATE store_equipment SET `unique_id`=\"%s\" WHERE `player_id`=%d AND `type`=\"%s\" AND `slot`=%d", g_Items[g_ClientData[client].aEquipment[m_iId]].szUniqueId, g_ClientData[client].iId, g_TypeHandlers[i].szType, a); } else FormatEx(STRING(m_szQuery), "INSERT INTO store_equipment (`player_id`, `type`, `unique_id`, `slot`) VALUES(%d, \"%s\", \"%s\", %d) ON DUPLICATE KEY UPDATE `unique_id` = VALUES(`unique_id`)", g_ClientData[client].iId, g_TypeHandlers[i].szType, g_Items[g_ClientData[client].aEquipment[m_iId]].szUniqueId, a); - //FormatEx(STRING(m_szQuery), "INSERT INTO store_equipment (`player_id`, `type`, `unique_id`, `slot`) VALUES(%d, \"%s\", \"%s\", %d)", g_ClientData[client].iId, g_TypeHandlers[i].szType, g_Items[g_ClientData[client].aEquipment[m_iId]].szUniqueId, a); + // FormatEx(STRING(m_szQuery), "INSERT INTO store_equipment (`player_id`, `type`, `unique_id`, `slot`) VALUES(%d, \"%s\", \"%s\", %d)", g_ClientData[client].iId, g_TypeHandlers[i].szType, g_Items[g_ClientData[client].aEquipment[m_iId]].szUniqueId, a); SQL_TVoid(g_hDatabase, m_szQuery, DBPrio_Low); g_ClientData[client].aEquipmentSynced[m_iId] = g_ClientData[client].aEquipment[m_iId]; @@ -3348,24 +3381,24 @@ void UTIL_SaveClientEquipment(int client) void UTIL_SaveClientData(int client, bool disconnect) { - if(g_hDatabase == null) + if (g_hDatabase == null) { LogStoreError("Database connection is lost or not yet initialized."); return; } - if(!g_ClientData[client].bLoaded) + if (!g_ClientData[client].bLoaded) return; - if(!disconnect && g_ClientData[client].bRefresh) + if (!disconnect && g_ClientData[client].bRefresh) return; char m_szQuery[512], m_szName[64], m_szEName[128]; GetClientName(client, STRING(m_szName)); g_hDatabase.Escape(m_szName, STRING(m_szEName)); - FormatEx(STRING(m_szQuery), "UPDATE store_players SET `credits`=`credits`+%d, `date_of_last_join`=FROM_UNIXTIME(%d), `name`='%s' WHERE `id`=%d", g_ClientData[client].iCredits-g_ClientData[client].iOriginalCredits, g_ClientData[client].iDateOfLastJoin, m_szEName, g_ClientData[client].iId); + FormatEx(STRING(m_szQuery), "UPDATE store_players SET `credits`=`credits`+%d, `date_of_last_join`=FROM_UNIXTIME(%d), `name`='%s' WHERE `id`=%d", g_ClientData[client].iCredits - g_ClientData[client].iOriginalCredits, g_ClientData[client].iDateOfLastJoin, m_szEName, g_ClientData[client].iId); - if(disconnect) + if (disconnect) { g_ClientData[client].iOriginalCredits = g_ClientData[client].iCredits; SQL_TVoid(g_hDatabase, m_szQuery, DBPrio_High); @@ -3381,12 +3414,12 @@ void UTIL_SaveClientData(int client, bool disconnect) static void SQLCallback_RefreshCredits(Database db, DBResultSet results, const char[] error, int userid) { int client = GetClientOfUserId(userid); - if(!client) + if (!client) return; g_ClientData[client].bRefresh = false; - if(results == null || error[0]) + if (results == null || error[0]) { LogStoreError("Refresh \"%L\" data failed : %s", client, error); return; @@ -3399,7 +3432,7 @@ void UTIL_DisconnectClient(int client, bool pre = false) { ClearTimer(g_ClientData[client].hTimer); - if(pre) + if (pre) { g_ClientData[client].iCredits = 0; g_ClientData[client].iOriginalCredits = 0; @@ -3411,8 +3444,8 @@ void UTIL_DisconnectClient(int client, bool pre = false) int UTIL_GetItemId(const char[] uid, int start = -1) { - for(int i = start+1; i < g_iItems; ++i) - if(strcmp(g_Items[i].szUniqueId, uid)==0 && g_Items[i].iPrice >= 0) + for (int i = start + 1; i < g_iItems; ++i) + if (strcmp(g_Items[i].szUniqueId, uid) == 0 && g_Items[i].iPrice >= 0) return i; return -1; } @@ -3420,31 +3453,31 @@ int UTIL_GetItemId(const char[] uid, int start = -1) static void SQLCallback_BuyItem(Database db, DBResultSet results, const char[] error, int userid) { int client = GetClientOfUserId(userid); - if(!client) + if (!client) return; - if(results == null || error[0]) + if (results == null || error[0]) { LogStoreError("Error happened. Error: %s", error); return; } - if(!results.FetchRow()) + if (!results.FetchRow()) return; int dbCredits = results.FetchInt(0); - int itemid = g_iSelectedItem[client]; - int plan = g_iSelectedPlan[client]; + int itemid = g_iSelectedItem[client]; + int plan = g_iSelectedPlan[client]; int m_iPrice = 0; - if(plan==-1) + if (plan == -1) m_iPrice = g_Items[itemid].iPrice; else m_iPrice = g_PurchasePlan[itemid][plan].iPrice; - if(dbCredits != g_ClientData[client].iOriginalCredits) + if (dbCredits != g_ClientData[client].iOriginalCredits) { - int diff = dbCredits - g_ClientData[client].iOriginalCredits; + int diff = dbCredits - g_ClientData[client].iOriginalCredits; g_ClientData[client].iOriginalCredits = dbCredits; g_ClientData[client].iCredits += diff; UTIL_LogMessage(client, diff, "Credits changed in database (sync credits from database)"); @@ -3452,7 +3485,7 @@ static void SQLCallback_BuyItem(Database db, DBResultSet results, const char[] e g_ClientData[client].bRefresh = false; - if(g_ClientData[client].iCredits %L -> compose -> %s -> %s -> [%s:%s] -> [%s:%s] -> %d -> %d -> %d", - client, - g_Items[g_iSelectedItem[client]].szUniqueId, - g_Items[g_iSelectedItem[client]].szName, - g_Items[g_Compose[client].item1].szUniqueId, - g_Items[g_Compose[client].item2].szUniqueId, - g_Items[g_Compose[client].item1].szName, - g_Items[g_Compose[client].item2].szName, - m_iFees, - probability, - successful); + client, + g_Items[g_iSelectedItem[client]].szUniqueId, + g_Items[g_iSelectedItem[client]].szName, + g_Items[g_Compose[client].item1].szUniqueId, + g_Items[g_Compose[client].item2].szUniqueId, + g_Items[g_Compose[client].item1].szName, + g_Items[g_Compose[client].item2].szName, + m_iFees, + probability, + successful); Action res = Plugin_Continue; Call_StartForward(g_hOnClientComposing); @@ -3569,32 +3602,32 @@ void UTIL_ComposeItem(int client) } LogMessage("PostCompose -> %L -> compose -> %s -> %s -> [%s:%s] -> [%s:%s] -> %d -> %d -> %d", - client, - g_Items[g_iSelectedItem[client]].szUniqueId, - g_Items[g_iSelectedItem[client]].szName, - g_Items[g_Compose[client].item1].szUniqueId, - g_Items[g_Compose[client].item2].szUniqueId, - g_Items[g_Compose[client].item1].szName, - g_Items[g_Compose[client].item2].szName, - m_iFees, - probability, - successful); + client, + g_Items[g_iSelectedItem[client]].szUniqueId, + g_Items[g_iSelectedItem[client]].szName, + g_Items[g_Compose[client].item1].szUniqueId, + g_Items[g_Compose[client].item2].szUniqueId, + g_Items[g_Compose[client].item1].szName, + g_Items[g_Compose[client].item2].szName, + m_iFees, + probability, + successful); char reason[128]; FormatEx(STRING(reason), "Compose Fee[%s]", g_Items[g_iSelectedItem[client]].szName); - Store_SetClientCredits(client, Store_GetClientCredits(client)-m_iFees, reason); + Store_SetClientCredits(client, Store_GetClientCredits(client) - m_iFees, reason); char m_szQuery[256]; - if(successful >= probability) + if (successful >= probability) { int rd = UTIL_GetRandomInt(0, 1000000); Store_RemoveItem(client, rd > 500000 ? g_Compose[client].item2 : g_Compose[client].item1); tPrintToChat(client, "%t", "Compose Failed"); - //tPrintToChat(client, "%t {green} %s", "Compose lost", rd > 500000 ? g_Items[g_Compose[client].item2].szName : g_Items[g_Compose[client].item1].szName); + // tPrintToChat(client, "%t {green} %s", "Compose lost", rd > 500000 ? g_Items[g_Compose[client].item2].szName : g_Items[g_Compose[client].item1].szName); tPrintToChat(client, "%t {orange}%d%t", "Compose cost", m_iFees, "credits"); Store_SaveClientAll(client); - g_iDataProtect[client] = GetTime()+30; + g_iDataProtect[client] = GetTime() + 30; Call_StartForward(g_hOnClientComposed); Call_PushCell(client); Call_PushCell(false); @@ -3613,7 +3646,7 @@ void UTIL_ComposeItem(int client) Store_SaveClientAll(client); - g_iDataProtect[client] = GetTime()+30; + g_iDataProtect[client] = GetTime() + 30; tPrintToChat(client, "Compose successfully", client, g_Items[g_iSelectedItem[client]].szName); @@ -3634,25 +3667,26 @@ void UTIL_ComposeItem(int client) void UTIL_BuyItem(int client) { #if defined Module_Skin - if(g_tKillPreview[client] != null) TriggerTimer(g_tKillPreview[client], false); + if (g_tKillPreview[client] != null) + TriggerTimer(g_tKillPreview[client], false); #endif - if(g_Items[g_iSelectedItem[client]].iHandler == g_iPackageHandler) + if (g_Items[g_iSelectedItem[client]].iHandler == g_iPackageHandler) return; - if(Store_HasClientItem(client, g_iSelectedItem[client])) + if (Store_HasClientItem(client, g_iSelectedItem[client])) { DisplayItemMenu(client, g_iSelectedItem[client]); return; } - if(g_iDataProtect[client] > GetTime()) + if (g_iDataProtect[client] > GetTime()) { - tPrintToChat(client, "%T", "data protect", client, g_iDataProtect[client]-GetTime()); + tPrintToChat(client, "%T", "data protect", client, g_iDataProtect[client] - GetTime()); Store_DisplayPreviousMenu(client); return; } - g_iDataProtect[client] = GetTime()+15; + g_iDataProtect[client] = GetTime() + 15; char m_szQuery[255]; FormatEx(STRING(m_szQuery), "SELECT credits FROM store_players WHERE `id`=%d", g_ClientData[client].iId); g_hDatabase.Query(SQLCallback_BuyItem, m_szQuery, g_ClientData[client].iUserId, DBPrio_High); @@ -3661,25 +3695,25 @@ void UTIL_BuyItem(int client) void UTIL_SellItem(int client, int itemid) { - if(g_iDataProtect[client] > GetTime()) + if (g_iDataProtect[client] > GetTime()) { - tPrintToChat(client, "%T", "data protect", client, g_iDataProtect[client]-GetTime()); + tPrintToChat(client, "%T", "data protect", client, g_iDataProtect[client] - GetTime()); Store_DisplayPreviousMenu(client); return; } - g_iDataProtect[client] = GetTime()+15; - int m_iCredits = RoundToFloor(UTIL_GetClientItemPrice(client, itemid)*0.6); + g_iDataProtect[client] = GetTime() + 15; + int m_iCredits = RoundToFloor(UTIL_GetClientItemPrice(client, itemid) * 0.6); if (m_iCredits <= 0) return; int uid = UTIL_GetClientItemId(client, itemid); - if(g_ClientItem[client][uid].iDateOfExpiration != 0) + if (g_ClientItem[client][uid].iDateOfExpiration != 0) { - int m_iLength = g_ClientItem[client][uid].iDateOfExpiration-g_ClientItem[client][uid].iDateOfPurchase; - int m_iLeft = g_ClientItem[client][uid].iDateOfExpiration-GetTime(); - if(m_iLeft<0) + int m_iLength = g_ClientItem[client][uid].iDateOfExpiration - g_ClientItem[client][uid].iDateOfPurchase; + int m_iLeft = g_ClientItem[client][uid].iDateOfExpiration - GetTime(); + if (m_iLeft < 0) m_iLeft = 0; - m_iCredits = RoundToCeil(m_iCredits*float(m_iLeft)/float(m_iLength)); + m_iCredits = RoundToCeil(m_iCredits * float(m_iLeft) / float(m_iLength)); } g_ClientData[client].iCredits += m_iCredits; tPrintToChat(client, "%T", "Chat Sold Item", client, g_Items[itemid].szName, g_TypeHandlers[g_Items[itemid].iHandler].szType); @@ -3697,34 +3731,34 @@ void UTIL_GiftItem(int client, int receiver, int item) { int m_iId = g_ClientItem[client][item].iUniqueId; - if(!g_ClientData[client].bLoaded || !g_ClientData[receiver].bLoaded) + if (!g_ClientData[client].bLoaded || !g_ClientData[receiver].bLoaded) return; - if(g_iDataProtect[client] > GetTime()) + if (g_iDataProtect[client] > GetTime()) { - tPrintToChat(client, "%T", "data protect", client, g_iDataProtect[client]-GetTime()); + tPrintToChat(client, "%T", "data protect", client, g_iDataProtect[client] - GetTime()); Store_DisplayPreviousMenu(client); return; } - if(IsFakeClient(receiver) || IsClientSourceTV(receiver)) + if (IsFakeClient(receiver) || IsClientSourceTV(receiver)) { tPrintToChat(client, "%T", "receiver BOT"); return; } - g_iDataProtect[client] = GetTime()+15; - g_iDataProtect[receiver] = GetTime()+15; + g_iDataProtect[client] = GetTime() + 15; + g_iDataProtect[receiver] = GetTime() + 15; int m_iFees = UTIL_GetClientHandleFees(client, m_iId); - if(m_iFees < 0) + if (m_iFees < 0) { tPrintToChat(client, " {darkred}UNKNOWN ERROR{white} : {red}%d", UTIL_GetRandomInt(100000, 999999)); return; } - if(m_iFees > g_ClientData[client].iCredits) + if (m_iFees > g_ClientData[client].iCredits) { tPrintToChat(client, "%T", "Chat Not Enough Handing Fee", client, m_iFees); return; @@ -3732,28 +3766,28 @@ void UTIL_GiftItem(int client, int receiver, int item) char reason[128]; FormatEx(STRING(reason), "Giftd [%s] Fee", g_Items[m_iId].szName); - Store_SetClientCredits(client, Store_GetClientCredits(client)-m_iFees, reason); + Store_SetClientCredits(client, Store_GetClientCredits(client) - m_iFees, reason); g_ClientItem[client][item].bDeleted = true; UTIL_UnequipItem(client, m_iId); - if(g_ClientData[receiver].iItems == -1) + if (g_ClientData[receiver].iItems == -1) g_ClientData[receiver].iItems = 0; int id = g_ClientData[receiver].iItems++; - g_ClientItem[receiver][id].iId = -1; - g_ClientItem[receiver][id].iUniqueId = m_iId; - g_ClientItem[receiver][id].bSynced = false; - g_ClientItem[receiver][id].bDeleted = false; - g_ClientItem[receiver][id].iDateOfPurchase = g_ClientItem[client][item].iDateOfPurchase; + g_ClientItem[receiver][id].iId = -1; + g_ClientItem[receiver][id].iUniqueId = m_iId; + g_ClientItem[receiver][id].bSynced = false; + g_ClientItem[receiver][id].bDeleted = false; + g_ClientItem[receiver][id].iDateOfPurchase = g_ClientItem[client][item].iDateOfPurchase; g_ClientItem[receiver][id].iDateOfExpiration = g_ClientItem[client][item].iDateOfExpiration; - g_ClientItem[receiver][id].iPriceOfPurchase = g_ClientItem[client][item].iPriceOfPurchase; + g_ClientItem[receiver][id].iPriceOfPurchase = g_ClientItem[client][item].iPriceOfPurchase; tPrintToChat(client, "%T", "Chat Gift Item Sent", client, receiver, g_Items[m_iId].szName, g_TypeHandlers[g_Items[m_iId].iHandler].szType); tPrintToChat(receiver, "%T", "Chat Gift Item Received", receiver, client, g_Items[m_iId].szName, g_TypeHandlers[g_Items[m_iId].iHandler].szType); - UTIL_LogMessage(client , 0, "Giftd %s to %N[%s]", g_Items[m_iId].szName, receiver, g_ClientData[receiver].szAuthId); + UTIL_LogMessage(client, 0, "Giftd %s to %N[%s]", g_Items[m_iId].szName, receiver, g_ClientData[receiver].szAuthId); UTIL_LogMessage(receiver, 0, "Received %s from %N[%s]", g_Items[m_iId].szName, client, g_ClientData[client].szAuthId); Store_SaveClientAll(client); @@ -3762,17 +3796,17 @@ void UTIL_GiftItem(int client, int receiver, int item) int UTIL_GetClientItemId(int client, int itemid) { - for(int i = 0; i < g_ClientData[client].iItems; ++i) - if(g_ClientItem[client][i].iUniqueId == itemid && !g_ClientItem[client][i].bDeleted) - return i; + for (int i = 0; i < g_ClientData[client].iItems; ++i) + if (g_ClientItem[client][i].iUniqueId == itemid && !g_ClientItem[client][i].bDeleted) + return i; return -1; } void Store_ResetAll() { - for(int x = 0; x < 3; ++x) g_aCaseSkins[x].Clear(); + for (int x = 0; x < 3; ++x) g_aCaseSkins[x].Clear(); - for(int i = 0; i < g_iTypeHandlers; ++i) + for (int i = 0; i < g_iTypeHandlers; ++i) { g_TypeHandlers[i].szType[0] = '\0'; g_TypeHandlers[i].bEquipable = false; @@ -3786,7 +3820,7 @@ void Store_ResetAll() g_TypeHandlers[i].fnRemove = INVALID_FUNCTION; } - g_iItems = 0; + g_iItems = 0; g_iTypeHandlers = 0; g_iMenuHandlers = 0; @@ -3805,22 +3839,22 @@ void UTIL_ReloadConfig() // Initiaze module UTIL_CheckModules(); - for(int i = 0; i < g_iTypeHandlers; ++i) - if(g_TypeHandlers[i].fnReset != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].szPlFile)) - { - Call_StartFunction(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].fnReset); - Call_Finish(); - } + for (int i = 0; i < g_iTypeHandlers; ++i) + if (g_TypeHandlers[i].fnReset != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].szPlFile)) + { + Call_StartFunction(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].fnReset); + Call_Finish(); + } g_hDatabase.Query(SQL_LoadParents, "SELECT * FROM store_item_parent ORDER BY `parent` ASC, `order` ASC;", 0, DBPrio_High); } static void SQL_LoadParents(Database db, DBResultSet item_parent, const char[] error, any data) { - if(item_parent == null) + if (item_parent == null) SetFailState("Can not retrieve item.parent from database: %s", error); - if(item_parent.RowCount <= 0) + if (item_parent.RowCount <= 0) SetFailState("Can not retrieve item.parent from database: no result row"); g_smParentMap.Clear(); @@ -3828,11 +3862,11 @@ static void SQL_LoadParents(Database db, DBResultSet item_parent, const char[] e char parent_str[12]; int validCategories = 0; - while(item_parent.FetchRow()) + while (item_parent.FetchRow()) { // Store to Map IntToString(item_parent.FetchInt(0), STRING(parent_str)); - if(!g_smParentMap.SetValue(parent_str, g_iItems, true)) + if (!g_smParentMap.SetValue(parent_str, g_iItems, true)) { LogStoreError("Failed to bind itemId[%d] to parentId[%s]", g_iItems, parent_str); continue; @@ -3855,7 +3889,7 @@ static void SQL_LoadParents(Database db, DBResultSet item_parent, const char[] e SetFailState("Can not retrieve item.parent from database: fetched %d rows, but they are invalid.", item_parent.RowCount); // Refresh Parent's parent. - for(int parent = 0; parent < g_iItems; parent++) + for (int parent = 0; parent < g_iItems; parent++) { // Interval g_Items[parent].iParent = UTIL_GetParent(parent, g_Items[parent].iParent); @@ -3870,30 +3904,30 @@ static void SQL_LoadParents(Database db, DBResultSet item_parent, const char[] e static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] error, any data) { - if(item_child == null) + if (item_child == null) SetFailState("Can not retrieve item.child from database: %s", error); - if(item_child.RowCount <= 0) + if (item_child.RowCount <= 0) SetFailState("Can not retrieve item.child from database: no result row"); ArrayList item_array = new ArrayList(ByteCountToCells(32)); int validItems = 0; - while(item_child.FetchRow()) + while (item_child.FetchRow()) { // Field 1 -> type char m_szType[32]; item_child.FetchString(1, STRING(m_szType)); - if(strcmp(m_szType, "ITEM_ERROR") == 0) + if (strcmp(m_szType, "ITEM_ERROR") == 0) { - //LogStoreError("Failed to loaded %s -> ITEM_ERROR", g_Items[g_iItems].szName); + // LogStoreError("Failed to loaded %s -> ITEM_ERROR", g_Items[g_iItems].szName); continue; } int m_iHandler = UTIL_GetTypeHandler(m_szType); - if(m_iHandler == -1) + if (m_iHandler == -1) { - //LogStoreError("Failed to loaded %s -> Invalid m_iHandler", g_Items[g_iItems].szName); + // LogStoreError("Failed to loaded %s -> Invalid m_iHandler", g_Items[g_iItems].szName); continue; } g_Items[g_iItems].iHandler = m_iHandler; @@ -3903,9 +3937,9 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e item_child.FetchString(2, STRING(m_szUniqueId)); // Ignore bad item or dumplicate item - if(strcmp(m_szUniqueId, "ITEM_ERROR") == 0 || item_array.FindString(m_szUniqueId) != -1) + if (strcmp(m_szUniqueId, "ITEM_ERROR") == 0 || item_array.FindString(m_szUniqueId) != -1) { - //LogStoreError("Failed to loaded %s -> Ignore bad item or dumplicate item", g_Items[g_iItems].szName); + // LogStoreError("Failed to loaded %s -> Ignore bad item or dumplicate item", g_Items[g_iItems].szName); continue; } item_array.PushString(m_szUniqueId); @@ -3936,7 +3970,7 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e char m_szAuth[256]; item_child.FetchString(7, STRING(m_szAuth)); g_Items[g_iItems].szSteam[0] = '\0'; - if(strcmp(m_szAuth, "ITEM_NOT_PERSONAL") != 0) + if (strcmp(m_szAuth, "ITEM_NOT_PERSONAL") != 0) strcopy(g_Items[g_iItems].szSteam, sizeof(Store_Item::szSteam), m_szAuth); // Field 8 -> vip @@ -3956,11 +3990,11 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e char m_szDesc[128]; item_child.FetchString(11, STRING(m_szDesc)); g_Items[g_iItems].szDesc[0] = '\0'; - if(StrContains(m_szDesc, "ITEM_NO") == -1) + if (StrContains(m_szDesc, "ITEM_NO") == -1) strcopy(g_Items[g_iItems].szDesc, sizeof(Store_Item::szDesc), m_szDesc); // Field 12 -> case - int caseType = item_child.FetchInt(12); + int caseType = item_child.FetchInt(12); g_Items[g_iItems].iCaseType = caseType; // Field 13 -> Compose @@ -3980,31 +4014,31 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e // #20 team g_Items[g_iItems].iTeam = item_child.FetchInt(20); - if(price_1d != 0 || price_1m != 0) + if (price_1d != 0 || price_1m != 0) { g_Items[g_iItems].iPlans = 0; - if(price_1d > 0) + if (price_1d > 0) { strcopy(g_PurchasePlan[g_iItems][0].szName, sizeof(Item_Plan::szName), "1 day"); g_PurchasePlan[g_iItems][0].iPrice = price_1d; - g_PurchasePlan[g_iItems][0].iTime = 86400; + g_PurchasePlan[g_iItems][0].iTime = 86400; g_Items[g_iItems].iPlans++; } - if(price_1m > 0) + if (price_1m > 0) { strcopy(g_PurchasePlan[g_iItems][1].szName, sizeof(Item_Plan::szName), "1 month"); g_PurchasePlan[g_iItems][1].iPrice = price_1m; - g_PurchasePlan[g_iItems][1].iTime = 2592000; + g_PurchasePlan[g_iItems][1].iTime = 2592000; g_Items[g_iItems].iPlans++; } - if(price_pm > 0) + if (price_pm > 0) { strcopy(g_PurchasePlan[g_iItems][2].szName, sizeof(Item_Plan::szName), "Permanent"); g_PurchasePlan[g_iItems][2].iPrice = price_pm; - g_PurchasePlan[g_iItems][2].iTime = 0; + g_PurchasePlan[g_iItems][2].iTime = 0; g_Items[g_iItems].iPlans++; } } @@ -4016,19 +4050,19 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e // Field 16 ~ KeyValues kv = new KeyValues("Store", "", ""); kv.JumpToKey(g_Items[g_iItems].szName, true); - //for(int field = 16; field < item_child.FieldCount; ++field) + // for(int field = 16; field < item_child.FieldCount; ++field) int count = item_child.FieldCount - 1; - for(int field = 1; field < count; ++field) + for (int field = 1; field < count; ++field) { char key[32], values[192]; item_child.FieldNumToName(field, STRING(key)); item_child.FetchString(field, STRING(values)); - if(StrContains(values, "ITEM_NO") == -1) + if (StrContains(values, "ITEM_NO") == -1) kv.SetString(key, values); } bool m_bSuccess = true; - if(g_TypeHandlers[m_iHandler].fnConfig != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[m_iHandler].hPlugin, g_TypeHandlers[m_iHandler].szPlFile)) + if (g_TypeHandlers[m_iHandler].fnConfig != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[m_iHandler].hPlugin, g_TypeHandlers[m_iHandler].szPlFile)) { Call_StartFunction(g_TypeHandlers[m_iHandler].hPlugin, g_TypeHandlers[m_iHandler].fnConfig); Call_PushCell(kv); @@ -4038,18 +4072,18 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e delete kv; - //LogMessage("Loaded Item -> %s", g_Items[g_iItems].szName); + // LogMessage("Loaded Item -> %s", g_Items[g_iItems].szName); - if(!m_bSuccess) + if (!m_bSuccess) continue; // Field 0 -> parent g_Items[g_iItems].iParent = UTIL_GetParent(g_iItems, item_child.FetchInt(0)); - if(g_Items[g_iItems].iParent == -1) + if (g_Items[g_iItems].iParent == -1) continue; - if(!g_Items[g_iItems].bIgnore && strcmp(m_szType, "playerskin", false) == 0 && caseType >= 0 && caseType <= 2) + if (!g_Items[g_iItems].bIgnore && strcmp(m_szType, "playerskin", false) == 0 && caseType >= 0 && caseType <= 2) { g_aCaseSkins[caseType].PushString(m_szUniqueId); } @@ -4063,7 +4097,7 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e ArrayList items = new ArrayList(sizeof(Store_Item)); - for(int itemid = 0; itemid < g_iItems; ++itemid) + for (int itemid = 0; itemid < g_iItems; ++itemid) { items.PushArray(g_Items[itemid]); } @@ -4083,22 +4117,22 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e char map[128]; GetCurrentMap(STRING(map)); - if(strlen(map) > 3 && IsMapValid(map)) + if (strlen(map) > 3 && IsMapValid(map)) { - LogMessage("Force reload map to prevent server crash!"); //late precache will crash server. + LogMessage("Force reload map to prevent server crash!"); // late precache will crash server. ForceChangeLevel(map, "Reload Map to prevent server crash!"); } } int UTIL_GetParent(int itemId, int parentId) { - if(parentId > -1) + if (parentId > -1) { - int index; + int index; char parent_str[12]; IntToString(parentId, STRING(parent_str)); - if(!g_smParentMap.GetValue(parent_str, index)) + if (!g_smParentMap.GetValue(parent_str, index)) { LogStoreError("Id [%s] not found in parent_map -> %s", parent_str, g_Items[itemId].szName); return -1; @@ -4112,46 +4146,47 @@ int UTIL_GetParent(int itemId, int parentId) int UTIL_GetTypeHandler(const char[] type) { - for(int i = 0; i < g_iTypeHandlers; ++i) - if(strcmp(g_TypeHandlers[i].szType, type)==0) - return i; + for (int i = 0; i < g_iTypeHandlers; ++i) + if (strcmp(g_TypeHandlers[i].szType, type) == 0) + return i; return -1; } int UTIL_GetMenuHandler(const char[] id) { - for(int i = 0; i < g_iMenuHandlers; ++i) - if(strcmp(g_MenuHandlers[i].szIdentifier, id)==0) - return i; + for (int i = 0; i < g_iMenuHandlers; ++i) + if (strcmp(g_MenuHandlers[i].szIdentifier, id) == 0) + return i; return -1; } bool UTIL_IsEquipped(int client, int itemid) { - for(int i = 0; i < STORE_MAX_SLOTS; ++i) - if(g_ClientData[client].aEquipment[g_Items[itemid].iHandler*STORE_MAX_SLOTS+i] == itemid) - return true; + for (int i = 0; i < STORE_MAX_SLOTS; ++i) + if (g_ClientData[client].aEquipment[g_Items[itemid].iHandler * STORE_MAX_SLOTS + i] == itemid) + return true; return false; } int UTIL_GetExpiration(int client, int itemid) { - //if(g_Items[itemid].bVIP && AllowItemForVIP(client, true)) - if(g_Items[itemid].bVIP && AllowItemForVIP(client, true) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans==0) + // if(g_Items[itemid].bVIP && AllowItemForVIP(client, true)) + if (g_Items[itemid].bVIP && AllowItemForVIP(client, true) && g_Items[itemid].iPrice <= 0 && g_Items[itemid].iPlans == 0) return 0; - if(g_Items[itemid].bIgnore && strlen(g_Items[itemid].szSteam) > 3 && AllowItemForAuth(client, g_Items[itemid].szSteam)) + if (g_Items[itemid].bIgnore && strlen(g_Items[itemid].szSteam) > 3 && AllowItemForAuth(client, g_Items[itemid].szSteam)) return 0; int uid = UTIL_GetClientItemId(client, itemid); - if(uid < 0) return -1; //ThrowError("UTIL_GetExpiration -> %L -> %d -> uid -1", client, itemid); + if (uid < 0) + return -1; // ThrowError("UTIL_GetExpiration -> %L -> %d -> uid -1", client, itemid); return g_ClientItem[client][uid].iDateOfExpiration; } int UTIL_UseItem(int client, int itemid, bool synced = false, int slot = 0) { int m_iSlot = slot; - if(g_TypeHandlers[g_Items[itemid].iHandler].fnUse != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[g_Items[itemid].iHandler].hPlugin, g_TypeHandlers[g_Items[itemid].iHandler].szPlFile)) + if (g_TypeHandlers[g_Items[itemid].iHandler].fnUse != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[g_Items[itemid].iHandler].hPlugin, g_TypeHandlers[g_Items[itemid].iHandler].szPlFile)) { int m_iReturn = -1; Call_StartFunction(g_TypeHandlers[g_Items[itemid].iHandler].hPlugin, g_TypeHandlers[g_Items[itemid].iHandler].fnUse); @@ -4159,17 +4194,17 @@ int UTIL_UseItem(int client, int itemid, bool synced = false, int slot = 0) Call_PushCell(itemid); Call_Finish(m_iReturn); - if(m_iReturn != -1) + if (m_iReturn != -1) m_iSlot = m_iReturn; } - if(g_TypeHandlers[g_Items[itemid].iHandler].bEquipable) + if (g_TypeHandlers[g_Items[itemid].iHandler].bEquipable) { - g_ClientData[client].aEquipment[g_Items[itemid].iHandler*STORE_MAX_SLOTS+m_iSlot]=itemid; - if(synced) - g_ClientData[client].aEquipmentSynced[g_Items[itemid].iHandler*STORE_MAX_SLOTS+m_iSlot]=itemid; + g_ClientData[client].aEquipment[g_Items[itemid].iHandler * STORE_MAX_SLOTS + m_iSlot] = itemid; + if (synced) + g_ClientData[client].aEquipmentSynced[g_Items[itemid].iHandler * STORE_MAX_SLOTS + m_iSlot] = itemid; } - else if(m_iSlot == 0) + else if (m_iSlot == 0) { Store_RemoveItem(client, itemid); return 1; @@ -4180,7 +4215,7 @@ int UTIL_UseItem(int client, int itemid, bool synced = false, int slot = 0) void UTIL_UnequipItem(int client, int itemid, bool fn = true) { int m_iSlot = 0; - if(fn && itemid > 0 && g_TypeHandlers[g_Items[itemid].iHandler].fnRemove != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[g_Items[itemid].iHandler].hPlugin, g_TypeHandlers[g_Items[itemid].iHandler].szPlFile)) + if (fn && itemid > 0 && g_TypeHandlers[g_Items[itemid].iHandler].fnRemove != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[g_Items[itemid].iHandler].hPlugin, g_TypeHandlers[g_Items[itemid].iHandler].szPlFile)) { Call_StartFunction(g_TypeHandlers[g_Items[itemid].iHandler].hPlugin, g_TypeHandlers[g_Items[itemid].iHandler].fnRemove); Call_PushCell(client); @@ -4189,28 +4224,28 @@ void UTIL_UnequipItem(int client, int itemid, bool fn = true) } int m_iId; - if(g_Items[itemid].iHandler != g_iPackageHandler) + if (g_Items[itemid].iHandler != g_iPackageHandler) { - m_iId = g_Items[itemid].iHandler*STORE_MAX_SLOTS+m_iSlot; - if(g_ClientData[client].aEquipmentSynced[m_iId]==-2) - g_ClientData[client].aEquipment[m_iId]=-2; + m_iId = g_Items[itemid].iHandler * STORE_MAX_SLOTS + m_iSlot; + if (g_ClientData[client].aEquipmentSynced[m_iId] == -2) + g_ClientData[client].aEquipment[m_iId] = -2; else - g_ClientData[client].aEquipment[m_iId]=-1; + g_ClientData[client].aEquipment[m_iId] = -1; } else { - for(int i = 0; i < STORE_MAX_HANDLERS; ++i) + for (int i = 0; i < STORE_MAX_HANDLERS; ++i) { - for(int a = 0; i < STORE_MAX_SLOTS; ++i) + for (int a = 0; i < STORE_MAX_SLOTS; ++i) { - if(g_ClientData[client].aEquipment[i+a] < 0) + if (g_ClientData[client].aEquipment[i + a] < 0) continue; - m_iId = i*STORE_MAX_SLOTS+a; - if(Store_IsItemInBoughtPackage(client, g_ClientData[client].aEquipment[m_iId], itemid)) - if(g_ClientData[client].aEquipmentSynced[m_iId]==-2) - g_ClientData[client].aEquipment[m_iId]=-2; + m_iId = i * STORE_MAX_SLOTS + a; + if (Store_IsItemInBoughtPackage(client, g_ClientData[client].aEquipment[m_iId], itemid)) + if (g_ClientData[client].aEquipmentSynced[m_iId] == -2) + g_ClientData[client].aEquipment[m_iId] = -2; else - g_ClientData[client].aEquipment[m_iId]=-1; + g_ClientData[client].aEquipment[m_iId] = -1; } } } @@ -4218,18 +4253,18 @@ void UTIL_UnequipItem(int client, int itemid, bool fn = true) int UTIL_GetEquippedItemFromHandler(int client, int handler, int slot = 0) { - return g_ClientData[client].aEquipment[handler*STORE_MAX_SLOTS+slot]; + return g_ClientData[client].aEquipment[handler * STORE_MAX_SLOTS + slot]; } bool UTIL_PackageHasClientItem(int client, int packageid, bool invmode = false) { - if(g_Items[packageid].szSteam[0] != 0 && !AllowItemForAuth(client, g_Items[packageid].szSteam)) + if (g_Items[packageid].szSteam[0] != 0 && !AllowItemForAuth(client, g_Items[packageid].szSteam)) return false; - for(int i = 0; i < g_iItems; ++i) - if(g_Items[i].iParent == packageid && ((invmode && Store_HasClientItem(client, i)) || !invmode)) - if((g_Items[i].iHandler == g_iPackageHandler && UTIL_PackageHasClientItem(client, i, invmode)) || g_Items[i].iHandler != g_iPackageHandler) - return true; + for (int i = 0; i < g_iItems; ++i) + if (g_Items[i].iParent == packageid && ((invmode && Store_HasClientItem(client, i)) || !invmode)) + if ((g_Items[i].iHandler == g_iPackageHandler && UTIL_PackageHasClientItem(client, i, invmode)) || g_Items[i].iHandler != g_iPackageHandler) + return true; return false; } @@ -4237,9 +4272,9 @@ bool UTIL_PackageHasClientItem(int client, int packageid, bool invmode = false) // new table // field -> id storeid credits diff reason timestamp // modify in 1.91 -void UTIL_LogMessage(int client, int diff, const char[] message, any ...) +void UTIL_LogMessage(int client, int diff, const char[] message, any...) { - if(IsFakeClient(client)) + if (IsFakeClient(client)) return; char m_szReason[256]; @@ -4263,26 +4298,26 @@ void UTIL_LogOpencase(int client, int itemid, int length, const char[] handle, i int UTIL_GetLowestPrice(int itemid) { - if(g_Items[itemid].iPlans==0) + if (g_Items[itemid].iPlans == 0) return g_Items[itemid].iPrice; - int m_iLowest=g_PurchasePlan[itemid][0].iPrice; - for(int i = 1; i < g_Items[itemid].iPlans; ++i) - if(m_iLowest>g_PurchasePlan[itemid][i].iPrice) - m_iLowest = g_PurchasePlan[itemid][i].iPrice; + int m_iLowest = g_PurchasePlan[itemid][0].iPrice; + for (int i = 1; i < g_Items[itemid].iPlans; ++i) + if (m_iLowest > g_PurchasePlan[itemid][i].iPrice) + m_iLowest = g_PurchasePlan[itemid][i].iPrice; return m_iLowest; } int UTIL_GetHighestPrice(int itemid) { - if(g_Items[itemid].iPlans==0) + if (g_Items[itemid].iPlans == 0) return g_Items[itemid].iPrice; - int m_iHighest=g_PurchasePlan[itemid][0].iPrice; - for(int i = 1; i < g_Items[itemid].iPlans; ++i) - if(m_iHighest 1.0) - g_ClientData[client].hTimer = CreateTimer(g_fCreditsTimerInterval, Timer_OnlineCredit, client, TIMER_REPEAT); + g_ClientData[client].hTimer = CreateTimer(g_fCreditsTimerInterval, Timer_OnlineCredit, client, TIMER_REPEAT); } static void InterMissionLock(ConVar convar, const char[] oldValue, const char[] newValue) @@ -4528,15 +4563,15 @@ void InterMissionConVars() bool IsPluginRunning(Handle plugin, const char[] file) { - if(plugin == INVALID_HANDLE) + if (plugin == INVALID_HANDLE) return false; - if(strlen(file) < 4) + if (strlen(file) < 4) return false; Handle dummy = FindPluginByFile(file); - if(dummy == INVALID_HANDLE || dummy != plugin) + if (dummy == INVALID_HANDLE || dummy != plugin) { if (StrContains(file, "store.smx", false) != -1) { diff --git a/store/cpsupport.sp b/store/cpsupport.sp index ce924ee..ebd7a37 100644 --- a/store/cpsupport.sp +++ b/store/cpsupport.sp @@ -1,3 +1,8 @@ +// MAIN_FILE ../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #define Module_Chat #if defined GM_IS || defined GM_EF @@ -5,27 +10,27 @@ #endif #if !defined CHAT_PROCESSOR_DEFINTION - #define CHAT_PROCESSOR_DEFINTION - #define CHAT_TYPE_NAME 0 - #define CHAT_TYPE_TEXT 1 - #define CHAT_C_NONE 0 - #define CHAT_C_RAINBOW 1 - #define CHAT_C_RANDOM 2 + #define CHAT_PROCESSOR_DEFINTION + #define CHAT_TYPE_NAME 0 + #define CHAT_TYPE_TEXT 1 + #define CHAT_C_NONE 0 + #define CHAT_C_RAINBOW 1 + #define CHAT_C_RANDOM 2 #endif #define TEAM_SPEC 1 -static UserMsg g_umUMId; -static Handle g_hCPAForward; -static Handle g_hCPPForward; -static Handle g_hCPRForward; +static UserMsg g_umUMId; +static Handle g_hCPAForward; +static Handle g_hCPPForward; +static Handle g_hCPRForward; static StringMap g_tMsgFmt; static char g_szNameTags[STORE_MAX_ITEMS][128]; static char g_szNameColors[STORE_MAX_ITEMS][32]; static char g_szMessageColors[STORE_MAX_ITEMS][32]; -static int g_iNameTags = 0; -static int g_iNameColors = 0; +static int g_iNameTags = 0; +static int g_iNameColors = 0; static int g_iMessageColors = 0; public void CPSupport_OnPluginStart() @@ -34,13 +39,13 @@ public void CPSupport_OnPluginStart() g_tMsgFmt = new StringMap(); - if(!GenerateMessageFormats()) + if (!GenerateMessageFormats()) { LogError("Error loading Chat Format, CP support will be disabled."); return; } - if((g_umUMId = GetUserMessageId("SayText2")) != INVALID_MESSAGE_ID) + if ((g_umUMId = GetUserMessageId("SayText2")) != INVALID_MESSAGE_ID) { // hook UM HookUserMessage(g_umUMId, OnSayText2, true); @@ -51,9 +56,9 @@ public void CPSupport_OnPluginStart() return; } - g_hCPAForward = CreateGlobalForward("CP_OnChatMessage", ET_Hook, Param_CellByRef, Param_Cell, Param_String, Param_String, Param_String, Param_CellByRef, Param_CellByRef); + g_hCPAForward = CreateGlobalForward("CP_OnChatMessage", ET_Hook, Param_CellByRef, Param_Cell, Param_String, Param_String, Param_String, Param_CellByRef, Param_CellByRef); g_hCPPForward = CreateGlobalForward("CP_OnChatMessagePost", ET_Ignore, Param_Cell, Param_Cell, Param_String, Param_String, Param_String, Param_Cell, Param_Cell); - g_hCPRForward = CreateGlobalForward("CP_OnChatRainbow", ET_Hook, Param_String, Param_Cell, Param_Cell, Param_Cell); + g_hCPRForward = CreateGlobalForward("CP_OnChatRainbow", ET_Hook, Param_String, Param_Cell, Param_Cell, Param_Cell); Store_RegisterHandler("nametag", CPSupport_OnMappStart, CPSupport_Reset, NameTags_Config, CPSupport_Equip, CPSupport_Remove, true); Store_RegisterHandler("namecolor", CPSupport_OnMappStart, CPSupport_Reset, NameColors_Config, CPSupport_Equip, CPSupport_Remove, true); @@ -69,8 +74,8 @@ static void CPSupport_OnMappStart() static void CPSupport_Reset() { - g_iNameTags = 0; - g_iNameColors = 0; + g_iNameTags = 0; + g_iNameColors = 0; g_iMessageColors = 0; } @@ -126,29 +131,30 @@ void CPP_Forward(int client, const char flagstring[32], const char name[128], co Action CPA_Forward(int &client, char flagstring[32], char name[128], char message[256], ArrayList hRecipients, bool &removedColor, bool &processColor) { - int m_iEquippedNameTag = Store_GetEquippedItem(client, "nametag"); + int m_iEquippedNameTag = Store_GetEquippedItem(client, "nametag"); int m_iEquippedNameColor = Store_GetEquippedItem(client, "namecolor"); - int m_iEquippedMsgColor = Store_GetEquippedItem(client, "msgcolor"); + int m_iEquippedMsgColor = Store_GetEquippedItem(client, "msgcolor"); char m_szNameTag[128]; char m_szNameColor[32]; strcopy(STRING(m_szNameColor), "{teamcolor}"); - if(m_iEquippedNameTag >= 0) + if (m_iEquippedNameTag >= 0) strcopy(STRING(m_szNameTag), g_szNameTags[Store_GetDataIndex(m_iEquippedNameTag)]); int rainbowname = CHAT_C_NONE; if (m_iEquippedNameColor >= 0) { int m_iData = Store_GetDataIndex(m_iEquippedNameColor); - if(strcmp(g_szNameColors[m_iData], "rainbow") == 0) + if (strcmp(g_szNameColors[m_iData], "rainbow") == 0) rainbowname = CHAT_C_RAINBOW; - else if(strcmp(g_szNameColors[m_iData], "random") == 0) + else if (strcmp(g_szNameColors[m_iData], "random") == 0) rainbowname = CHAT_C_RANDOM; - else if(strcmp(g_szNameColors[m_iData], "shuffle") == 0) + else if (strcmp(g_szNameColors[m_iData], "shuffle") == 0) rainbowname = CHAT_C_SHUFFLE; - else strcopy(STRING(m_szNameColor), g_szNameColors[m_iData]); + else + strcopy(STRING(m_szNameColor), g_szNameColors[m_iData]); } if (rainbowname) @@ -157,17 +163,18 @@ Action CPA_Forward(int &client, char flagstring[32], char name[128], char messag String_Rainbow(name, STRING(buffer), CHAT_TYPE_NAME, rainbowname); Format(STRING(name), "%s %s", m_szNameTag, buffer); } - else Format(STRING(name), "%s%s %s", m_szNameTag, m_szNameColor, name); + else + Format(STRING(name), "%s%s %s", m_szNameTag, m_szNameColor, name); - if(m_iEquippedMsgColor >= 0) + if (m_iEquippedMsgColor >= 0) { - int m_iData = Store_GetDataIndex(m_iEquippedMsgColor); + int m_iData = Store_GetDataIndex(m_iEquippedMsgColor); int rainbowmsg = CHAT_C_NONE; - if(strcmp(g_szMessageColors[m_iData], "rainbow") == 0) + if (strcmp(g_szMessageColors[m_iData], "rainbow") == 0) rainbowmsg = CHAT_C_RAINBOW; - else if(strcmp(g_szMessageColors[m_iData], "random") == 0) + else if (strcmp(g_szMessageColors[m_iData], "random") == 0) rainbowmsg = CHAT_C_RANDOM; - else if(strcmp(g_szMessageColors[m_iData], "shuffle") == 0) + else if (strcmp(g_szMessageColors[m_iData], "shuffle") == 0) rainbowmsg = CHAT_C_SHUFFLE; if (rainbowmsg) @@ -176,27 +183,28 @@ Action CPA_Forward(int &client, char flagstring[32], char name[128], char messag String_Rainbow(message, STRING(buffer), CHAT_TYPE_TEXT, rainbowmsg); strcopy(STRING(message), buffer); } - else Format(STRING(message), "%s%s", g_szMessageColors[m_iData], message); + else + Format(STRING(message), "%s%s", g_szMessageColors[m_iData], message); } Call_StartForward(g_hCPAForward); Call_PushCellRef(client); Call_PushCell(hRecipients); - Call_PushStringEx(STRING(flagstring), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); - Call_PushStringEx(STRING(name), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); - Call_PushStringEx(STRING(message), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(STRING(flagstring), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(STRING(name), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(STRING(message), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_PushCellRef(processColor); Call_PushCellRef(removedColor); Action iResults; - int error = Call_Finish(iResults); + int error = Call_Finish(iResults); if (error != SP_ERROR_NONE) { ThrowNativeError(error, "Global Forward 'CP_OnChatMessage' has failed to fire. [Error code: %d]", error); return Plugin_Continue; } - if(iResults >= Plugin_Handled) + if (iResults >= Plugin_Handled) return Plugin_Handled; return Plugin_Changed; @@ -204,12 +212,12 @@ Action CPA_Forward(int &client, char flagstring[32], char name[128], char messag void String_Rainbow(const char[] input, char[] output, int maxLen, int type, int rainbow) { - char[] copy = new char [maxLen]; + char[] copy = new char[maxLen]; strcopy(copy, maxLen, input); Action res = Plugin_Continue; Call_StartForward(g_hCPRForward); - Call_PushStringEx(copy, maxLen, SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(copy, maxLen, SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_PushCell(maxLen); Call_PushCell(type); Call_PushCell(rainbow); @@ -238,30 +246,30 @@ void String_Rainbow(const char[] input, char[] output, int maxLen, int type, int int bytes, buffs; - for(int x = 0; x < maxLen; ++x) + for (int x = 0; x < maxLen; ++x) { - if(input[x] == '\0') + if (input[x] == '\0') break; - if(buffs == 2) + if (buffs == 2) { strcopy(copy, maxLen, input); - copy[x+1] = '\0'; + copy[x + 1] = '\0'; output[bytes] = RandomColor(); bytes++; - bytes += StrCat(output, maxLen, copy[x-buffs]); + bytes += StrCat(output, maxLen, copy[x - buffs]); buffs = 0; continue; } - if(!IsChar(input[x])) + if (!IsChar(input[x])) { buffs++; continue; } strcopy(copy, maxLen, input); - copy[x+1] = '\0'; + copy[x + 1] = '\0'; output[bytes] = RandomColor(); bytes++; bytes += StrCat(output, maxLen, copy[x]); @@ -272,9 +280,9 @@ void String_Rainbow(const char[] input, char[] output, int maxLen, int type, int } #if !defined USE_BF -bool IsChar(char c) +bool IsChar(char c) { - if(0 <= c <= 126) + if (0 <= c <= 126) return true; return false; @@ -282,17 +290,17 @@ bool IsChar(char c) int RandomColor() { - switch(UTIL_GetRandomInt(1, 16)) + switch (UTIL_GetRandomInt(1, 16)) { - case 1: return '\x01'; - case 2: return '\x02'; - case 3: return '\x03'; - case 4: return '\x03'; - case 5: return '\x04'; - case 6: return '\x05'; - case 7: return '\x06'; - case 8: return '\x07'; - case 9: return '\x08'; + case 1: return '\x01'; + case 2: return '\x02'; + case 3: return '\x03'; + case 4: return '\x03'; + case 5: return '\x04'; + case 6: return '\x05'; + case 7: return '\x06'; + case 8: return '\x07'; + case 9: return '\x08'; case 10: return '\x09'; case 11: return '\x10'; case 12: return '\x0A'; @@ -308,42 +316,42 @@ int RandomColor() bool GenerateMessageFormats() { - switch(GetEngineVersion()) + switch (GetEngineVersion()) { case Engine_CSGO: { - g_tMsgFmt.SetString("Cstrike_Chat_CT_Loc", "(CT) {1} : {2}"); - g_tMsgFmt.SetString("Cstrike_Chat_CT", "(CT) {1} : {2}"); - g_tMsgFmt.SetString("Cstrike_Chat_T_Loc", "(TE) {1} : {2}"); - g_tMsgFmt.SetString("Cstrike_Chat_T", "(TE) {1} : {2}"); + g_tMsgFmt.SetString("Cstrike_Chat_CT_Loc", "(CT) {1} : {2}"); + g_tMsgFmt.SetString("Cstrike_Chat_CT", "(CT) {1} : {2}"); + g_tMsgFmt.SetString("Cstrike_Chat_T_Loc", "(TE) {1} : {2}"); + g_tMsgFmt.SetString("Cstrike_Chat_T", "(TE) {1} : {2}"); g_tMsgFmt.SetString("Cstrike_Chat_CT_Dead", "*DEAD*(CT) {1} : {2}"); - g_tMsgFmt.SetString("Cstrike_Chat_T_Dead", "*DEAD*(TE) {1} : {2}"); - g_tMsgFmt.SetString("Cstrike_Chat_Spec", "(SPEC) {1} : {2}"); - g_tMsgFmt.SetString("Cstrike_Chat_All", " {1} : {2}"); + g_tMsgFmt.SetString("Cstrike_Chat_T_Dead", "*DEAD*(TE) {1} : {2}"); + g_tMsgFmt.SetString("Cstrike_Chat_Spec", "(SPEC) {1} : {2}"); + g_tMsgFmt.SetString("Cstrike_Chat_All", " {1} : {2}"); g_tMsgFmt.SetString("Cstrike_Chat_AllDead", "*DEAD* {1} : {2}"); g_tMsgFmt.SetString("Cstrike_Chat_AllSpec", "*SPEC* {1} : {2}"); return true; } case Engine_Left4Dead2, Engine_Left4Dead: { - g_tMsgFmt.SetString("L4D_Chat_Infected", "(Infected) {1} : {2}"); - g_tMsgFmt.SetString("L4D_Chat_Survivor", "(Survivor) {1} : {2}"); - g_tMsgFmt.SetString("L4D_Chat_Infected_Dead", "*DEAD*(Infected) {1} : {2}"); - g_tMsgFmt.SetString("L4D_Chat_Survivor_Dead", "*DEAD*(Survivor) {1} : {2}"); - g_tMsgFmt.SetString("L4D_Chat_Spec", "(Spectator) {1} : {2}"); - g_tMsgFmt.SetString("L4D_Chat_All", "{1} : {2}"); - g_tMsgFmt.SetString("L4D_Chat_AllDead", "*DEAD* {1} : {2}"); - g_tMsgFmt.SetString("L4D_Chat_AllSpec", "*SPEC* {1} : {2}"); + g_tMsgFmt.SetString("L4D_Chat_Infected", "(Infected) {1} : {2}"); + g_tMsgFmt.SetString("L4D_Chat_Survivor", "(Survivor) {1} : {2}"); + g_tMsgFmt.SetString("L4D_Chat_Infected_Dead", "*DEAD*(Infected) {1} : {2}"); + g_tMsgFmt.SetString("L4D_Chat_Survivor_Dead", "*DEAD*(Survivor) {1} : {2}"); + g_tMsgFmt.SetString("L4D_Chat_Spec", "(Spectator) {1} : {2}"); + g_tMsgFmt.SetString("L4D_Chat_All", "{1} : {2}"); + g_tMsgFmt.SetString("L4D_Chat_AllDead", "*DEAD* {1} : {2}"); + g_tMsgFmt.SetString("L4D_Chat_AllSpec", "*SPEC* {1} : {2}"); return true; } case Engine_Insurgency: { - g_tMsgFmt.SetString("INS_Chat_All", " {1} : {2}"); - g_tMsgFmt.SetString("INS_Chat_AllDead", "*DEAD* {1} : {2}"); - g_tMsgFmt.SetString("INS_Chat_AllSpec", "*SPEC* {1} : {2}"); - g_tMsgFmt.SetString("INS_Chat", " {1} : {2}"); - g_tMsgFmt.SetString("INS_Chat_Dead", "*DEAD* {1} : {2}"); - g_tMsgFmt.SetString("INS_Chat_Spec", "(TEAM) *SPEC* {1} : {2}"); + g_tMsgFmt.SetString("INS_Chat_All", " {1} : {2}"); + g_tMsgFmt.SetString("INS_Chat_AllDead", "*DEAD* {1} : {2}"); + g_tMsgFmt.SetString("INS_Chat_AllSpec", "*SPEC* {1} : {2}"); + g_tMsgFmt.SetString("INS_Chat", " {1} : {2}"); + g_tMsgFmt.SetString("INS_Chat_Dead", "*DEAD* {1} : {2}"); + g_tMsgFmt.SetString("INS_Chat_Spec", "(TEAM) *SPEC* {1} : {2}"); return true; } } @@ -352,19 +360,20 @@ bool GenerateMessageFormats() } #if defined USE_BF -public Action OnSayText2(UserMsg msg_id, BfRead msg, const int[] players, int playersNum, bool reliable, bool init) + +public Action OnSayText2(UserMsg msg_id, BfRead msg, const int[] players, int playersNum, bool reliable, bool init) #else + public Action OnSayText2(UserMsg msg_id, Protobuf msg, const int[] players, int playersNum, bool reliable, bool init) #endif { - #if defined USE_BF int m_iSender = msg.ReadByte(); #else int m_iSender = PbReadInt(msg, "ent_idx"); #endif - if(m_iSender <= 0) + if (m_iSender <= 0) return Plugin_Continue; char m_szFlag[32], m_szName[128], m_szText[256], m_szFmt[32]; @@ -388,7 +397,7 @@ public Action OnSayText2(UserMsg msg_id, Protobuf msg, const int[] players, int msg.ReadString("params", STRING(m_szText), 1); #endif - if(!g_tMsgFmt.GetString(m_szFlag, STRING(m_szFmt))) + if (!g_tMsgFmt.GetString(m_szFlag, STRING(m_szFmt))) return Plugin_Continue; RemoveAllColors(STRING(m_szName)); @@ -405,29 +414,29 @@ public Action OnSayText2(UserMsg msg_id, Protobuf msg, const int[] players, int for (int i = 0; i < playersNum; i++) hRecipients.Push(players[i]); - bool removedColor = false; - bool processColor = true; - Action iResults = CPA_Forward(m_iSender, m_szFlag, m_szName, m_szText, hRecipients, removedColor, processColor); + bool removedColor = false; + bool processColor = true; + Action iResults = CPA_Forward(m_iSender, m_szFlag, m_szName, m_szText, hRecipients, removedColor, processColor); - if(iResults != Plugin_Changed) + if (iResults != Plugin_Changed) { delete hRecipients; return iResults; } - if(strcmp(m_szFlag, m_szFlagCopy) != 0 && !g_tMsgFmt.GetString(m_szFlag, STRING(m_szFmt))) + if (strcmp(m_szFlag, m_szFlagCopy) != 0 && !g_tMsgFmt.GetString(m_szFlag, STRING(m_szFmt))) { delete hRecipients; return Plugin_Continue; } #if !defined USE_BF - if(strcmp(m_szNameCopy, m_szName) == 0) + if (strcmp(m_szNameCopy, m_szName) == 0) { - switch(g_iClientTeam[m_iSender]) + switch (g_iClientTeam[m_iSender]) { - case 3: Format(STRING(m_szName), "\x0B%s", m_szName); - case 2: Format(STRING(m_szName), "\x05%s", m_szName); + case 3: Format(STRING(m_szName), "\x0B%s", m_szName); + case 2: Format(STRING(m_szName), "\x05%s", m_szName); default: Format(STRING(m_szName), "\x01%s", m_szName); } } @@ -452,15 +461,15 @@ public Action OnSayText2(UserMsg msg_id, Protobuf msg, const int[] players, int void Frame_OnChatMessage_SayText2(DataPack data) { - int m_iSender = data.ReadCell(); - bool m_bChat = data.ReadCell(); + int m_iSender = data.ReadCell(); + bool m_bChat = data.ReadCell(); - int target_list[MAXPLAYERS+1], target_count; + int target_list[MAXPLAYERS + 1], target_count; ArrayList hRecipients = view_as(data.ReadCell()); - for(int x = 0; x < hRecipients.Length; ++x) + for (int x = 0; x < hRecipients.Length; ++x) { int client = hRecipients.Get(x); - if(IsClientInGame(client)) + if (IsClientInGame(client)) target_list[target_count++] = client; } @@ -491,23 +500,23 @@ void Frame_OnChatMessage_SayText2(DataPack data) Format(STRING(m_szBuffer), "(TEAM) %s", m_szBuffer); #endif - if(removedColor) + if (removedColor) { RemoveAllColors(STRING(m_szName)); RemoveAllColors(STRING(m_szText)); } - if(processColor) + if (processColor) { ReplaceColorsCode(STRING(m_szBuffer), g_iClientTeam[m_iSender]); } #if defined USE_BF - Handle um = StartMessage("SayText", target_list, target_count, USERMSG_RELIABLE|USERMSG_BLOCKHOOKS); + Handle um = StartMessage("SayText", target_list, target_count, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS); #else - Handle um = StartMessageEx(g_umUMId, target_list, target_count, USERMSG_RELIABLE|USERMSG_BLOCKHOOKS); + Handle um = StartMessageEx(g_umUMId, target_list, target_count, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS); #endif - if(um == null) + if (um == null) { delete hRecipients; delete data; @@ -541,12 +550,12 @@ void Frame_OnChatMessage_SayText2(DataPack data) static void CheckCPandSCP() { - if(FindPluginByFile("chat-processor.smx") != INVALID_HANDLE) + if (FindPluginByFile("chat-processor.smx") != INVALID_HANDLE) { char path[2][128]; BuildPath(Path_SM, path[0], 128, "plugins/chat-processor.smx"); BuildPath(Path_SM, path[1], 128, "plugins/disabled/chat-processor.smx"); - if(!RenameFile(path[1], path[0])) + if (!RenameFile(path[1], path[0])) { LogError("Failed to move 'chat-processor.smx' to disabled folder."); DeleteFile(path[0]); @@ -555,12 +564,12 @@ static void CheckCPandSCP() LogMessage("'chat-processor.smx' detected!"); } - if(FindPluginByFile("simple-chatprocessor.smx") != INVALID_HANDLE) + if (FindPluginByFile("simple-chatprocessor.smx") != INVALID_HANDLE) { char path[2][128]; BuildPath(Path_SM, path[0], 128, "plugins/simple-chatprocessor"); BuildPath(Path_SM, path[1], 128, "plugins/disabled/simple-chatprocessor"); - if(!RenameFile(path[1], path[0])) + if (!RenameFile(path[1], path[0])) { LogError("Failed to move 'simple-chatprocessor.smx' to disabled folder."); DeleteFile(path[0]); diff --git a/store/grenades.sp b/store/grenades.sp index d685a67..0bdbc08 100644 --- a/store/grenades.sp +++ b/store/grenades.sp @@ -1,31 +1,35 @@ +// MAIN_FILE ../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #define Module_Grenade -enum struct GrenadeSkin +abstract_struct GrenadeSkin { char szModel[PLATFORM_MAX_PATH]; char szWeapon[64]; - int iLength; - int iSlot; + int iLength; + int iSlot; } -enum struct GrenadeTrail +abstract_struct GrenadeTrail { - char szMaterial[PLATFORM_MAX_PATH]; - char szWidth[16]; - char szColor[16]; + char szMaterial[PLATFORM_MAX_PATH]; + char szWidth[16]; + char szColor[16]; float fWidth; - int iColor[4]; - int iSlot; - int iCacheID; + int iColor[4]; + int iSlot; + int iCacheID; } -static GrenadeSkin g_eGrenadeSkins[STORE_MAX_ITEMS]; +static GrenadeSkin g_eGrenadeSkins[STORE_MAX_ITEMS]; static GrenadeTrail g_eGrenadeTrails[STORE_MAX_ITEMS]; -static int g_iGrenadeSkins = 0; -static int g_iSlots = 0; -static int g_iGrenadeTrails = 0; -static char g_szSlots[6][64]; - +static int g_iGrenadeSkins = 0; +static int g_iSlots = 0; +static int g_iGrenadeTrails = 0; +static char g_szSlots[6][64]; public void Grenades_OnPluginStart() { @@ -35,7 +39,7 @@ public void Grenades_OnPluginStart() static void GrenadeSkins_OnMapStart() { - for(int i = 0; i< g_iGrenadeSkins; ++i) + for (int i = 0; i < g_iGrenadeSkins; ++i) { PrecacheModel(g_eGrenadeSkins[i].szModel, false); AddFileToDownloadsTable(g_eGrenadeSkins[i].szModel); @@ -44,7 +48,7 @@ static void GrenadeSkins_OnMapStart() static void GrenadeTrails_OnMapStart() { - for(int i = 0; i < g_iGrenadeTrails; ++i) + for (int i = 0; i < g_iGrenadeTrails; ++i) { g_eGrenadeTrails[i].iCacheID = PrecacheModel(g_eGrenadeTrails[i].szMaterial, false); AddFileToDownloadsTable(g_eGrenadeTrails[i].szMaterial); @@ -67,10 +71,10 @@ static bool GrenadeSkins_Config(KeyValues kv, int itemid) kv.GetString("model", g_eGrenadeSkins[g_iGrenadeSkins].szModel, PLATFORM_MAX_PATH); kv.GetString("grenade", g_eGrenadeSkins[g_iGrenadeSkins].szWeapon, PLATFORM_MAX_PATH); - g_eGrenadeSkins[g_iGrenadeSkins].iSlot = GrenadeSkins_GetSlot(g_eGrenadeSkins[g_iGrenadeSkins].szWeapon); + g_eGrenadeSkins[g_iGrenadeSkins].iSlot = GrenadeSkins_GetSlot(g_eGrenadeSkins[g_iGrenadeSkins].szWeapon); g_eGrenadeSkins[g_iGrenadeSkins].iLength = strlen(g_eGrenadeSkins[g_iGrenadeSkins].szWeapon); - if(!(FileExists(g_eGrenadeSkins[g_iGrenadeSkins].szModel, true))) + if (!(FileExists(g_eGrenadeSkins[g_iGrenadeSkins].szModel, true))) return false; ++g_iGrenadeSkins; @@ -87,7 +91,7 @@ static bool GrenadeTrails_Config(KeyValues kv, int itemid) KvGetColor(kv, "color", g_eGrenadeTrails[g_iGrenadeTrails].iColor[0], g_eGrenadeTrails[g_iGrenadeTrails].iColor[1], g_eGrenadeTrails[g_iGrenadeTrails].iColor[2], g_eGrenadeTrails[g_iGrenadeTrails].iColor[3]); g_eGrenadeTrails[g_iGrenadeTrails].iSlot = kv.GetNum("slot"); - if(FileExists(g_eGrenadeTrails[g_iGrenadeTrails].szMaterial, true)) + if (FileExists(g_eGrenadeTrails[g_iGrenadeTrails].szMaterial, true)) { ++g_iGrenadeTrails; return true; @@ -118,8 +122,8 @@ static int GrenadeTrails_Remove(int client, int id) static int GrenadeSkins_GetSlot(char[] weapon) { - for(int i = 0; i < g_iSlots; ++i) - if(strcmp(weapon, g_szSlots[i])==0) + for (int i = 0; i < g_iSlots; ++i) + if (strcmp(weapon, g_szSlots[i]) == 0) return i; strcopy(g_szSlots[g_iSlots], sizeof(g_szSlots[]), weapon); @@ -128,10 +132,10 @@ static int GrenadeSkins_GetSlot(char[] weapon) public void OnEntityCreated(int entity, const char[] classname) { - if(g_iGrenadeTrails == 0 && g_iGrenadeSkins == 0) + if (g_iGrenadeTrails == 0 && g_iGrenadeSkins == 0) return; - if(StrContains(classname, "_projectile") > 0) + if (StrContains(classname, "_projectile") > 0) SDKHook(entity, SDKHook_SpawnPost, Grenades_OnEntitySpawnedPost); } @@ -139,16 +143,16 @@ public void Grenades_OnEntitySpawnedPost(int entity) { int client = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity"); - if(!(0 < client <= MaxClients)) + if (!(0 < client <= MaxClients)) return; char m_szClassname[64]; GetEdictClassname(entity, STRING(m_szClassname)); - for(int i = 0; i < strlen(m_szClassname); ++i) - if(m_szClassname[i]=='_') + for (int i = 0; i < strlen(m_szClassname); ++i) + if (m_szClassname[i] == '_') { - m_szClassname[i]=0; + m_szClassname[i] = 0; break; } @@ -159,17 +163,17 @@ public void Grenades_OnEntitySpawnedPost(int entity) m_iEquipped = Store_GetEquippedItem(client, "nadeskin", m_iSlot); - if(m_iEquipped >= 0) + if (m_iEquipped >= 0) { m_iData = Store_GetDataIndex(m_iEquipped); SetEntityModel(entity, g_eGrenadeSkins[m_iData].szModel); } m_iEquipped = 0; - m_iData = 0; + m_iData = 0; m_iEquipped = Store_GetEquippedItem(client, "nadetrail", 0); - if(m_iEquipped >= 0) + if (m_iEquipped >= 0) { m_iData = Store_GetDataIndex(m_iEquipped); diff --git a/store/modules/aura.sp b/store/modules/aura.sp index 8d91956..1373c3b 100644 --- a/store/modules/aura.sp +++ b/store/modules/aura.sp @@ -1,21 +1,26 @@ +// MAIN_FILE ../../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #define Module_Aura #define MAX_AURA 128 -static int g_iAuras = 0; -static int g_iClientAura[MAXPLAYERS+1] = {INVALID_ENT_REFERENCE, ...}; +static int g_iAuras = 0; +static int g_iClientAura[MAXPLAYERS + 1] = { INVALID_ENT_REFERENCE, ... }; static char g_szAuraName[MAX_AURA][PLATFORM_MAX_PATH]; static char g_szAuraFPcf[MAX_AURA][PLATFORM_MAX_PATH]; -static char g_szAuraClient[MAXPLAYERS+1][PLATFORM_MAX_PATH]; +static char g_szAuraClient[MAXPLAYERS + 1][PLATFORM_MAX_PATH]; void Aura_OnMapStart() { - if(g_iAuras <= 0) + if (g_iAuras <= 0) return; PrecacheEffect("ParticleEffect"); - for(int index = 0; index < g_iAuras; ++index) + for (int index = 0; index < g_iAuras; ++index) { PrecacheGeneric(g_szAuraFPcf[index], true); PrecacheParticleEffect(g_szAuraName[index]); @@ -31,16 +36,16 @@ void Aura_OnClientDisconnect(int client) bool Aura_Config(KeyValues kv, int itemid) { - if(g_iAuras >= MAX_AURA) + if (g_iAuras >= MAX_AURA) return false; Store_SetDataIndex(itemid, g_iAuras); kv.GetString("effect", g_szAuraName[g_iAuras], PLATFORM_MAX_PATH); - kv.GetString("model", g_szAuraFPcf[g_iAuras], PLATFORM_MAX_PATH); + kv.GetString("model", g_szAuraFPcf[g_iAuras], PLATFORM_MAX_PATH); - if(!FileExists(g_szAuraFPcf[g_iAuras], true)) + if (!FileExists(g_szAuraFPcf[g_iAuras], true)) { - #if defined LOG_NOT_FOUND +#if defined LOG_NOT_FOUND // missing model char auth[32], name[32]; kv.GetString("auth", auth, 32); @@ -53,7 +58,7 @@ bool Aura_Config(KeyValues kv, int itemid) { LogMessage("Skipped aura <%s> -> [%s]", name, g_szAuraFPcf[g_iAuras]); } - #endif +#endif return false; } @@ -70,7 +75,7 @@ int Aura_Equip(int client, int id) { g_szAuraClient[client] = g_szAuraName[Store_GetDataIndex(id)]; - if(IsPlayerAlive(client)) + if (IsPlayerAlive(client)) Store_SetClientAura(client); return 0; @@ -86,7 +91,7 @@ int Aura_Remove(int client, int id) void Store_RemoveClientAura(int client) { - if(g_iClientAura[client] != INVALID_ENT_REFERENCE) + if (g_iClientAura[client] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iClientAura[client]); if (entity > 0 && IsValidEdict(entity)) @@ -102,11 +107,11 @@ void Store_SetClientAura(int client) Store_RemoveClientAura(client); #if defined GM_ZE - if(g_iClientTeam[client] == 2) + if (g_iClientTeam[client] == 2) return; #endif - if(strlen(g_szAuraClient[client]) > 0) + if (strlen(g_szAuraClient[client]) > 0) { float clientOrigin[3], clientAngles[3]; GetClientAbsOrigin(client, clientOrigin); @@ -117,7 +122,7 @@ void Store_SetClientAura(int client) int iEnt = CreateEntityByName("info_particle_system"); DispatchKeyValue(iEnt, "targetname", "store_item_aura"); - DispatchKeyValue(iEnt , "start_active", "1"); + DispatchKeyValue(iEnt, "start_active", "1"); DispatchKeyValue(iEnt, "effect_name", g_szAuraClient[client]); DispatchSpawn(iEnt); diff --git a/store/modules/hats.sp b/store/modules/hats.sp index d4d7156..dc21ee2 100644 --- a/store/modules/hats.sp +++ b/store/modules/hats.sp @@ -1,21 +1,26 @@ +// MAIN_FILE ../../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #define Module_Hats -enum struct Hat +abstract_struct Hat { - char szModel[PLATFORM_MAX_PATH]; - char szAttachment[64]; + char szModel[PLATFORM_MAX_PATH]; + char szAttachment[64]; float fPosition[3]; float fAngles[3]; - bool bBonemerge; - bool bHide; - int iSlot; - int iTeam; + bool bBonemerge; + bool bHide; + int iSlot; + int iTeam; } static Hat g_eHats[STORE_MAX_ITEMS]; -static int g_iClientHats[MAXPLAYERS+1][STORE_MAX_SLOTS]; +static int g_iClientHats[MAXPLAYERS + 1][STORE_MAX_SLOTS]; static int g_iHats = 0; -static int g_iSpecTarget[MAXPLAYERS+1]; +static int g_iSpecTarget[MAXPLAYERS + 1]; static int g_iHatsOwners[2048]; bool Hats_Config(KeyValues kv, int itemid) @@ -26,16 +31,16 @@ bool Hats_Config(KeyValues kv, int itemid) KvGetVector(kv, "position", m_fTemp); g_eHats[g_iHats].fPosition = m_fTemp; KvGetVector(kv, "angles", m_fTemp); - g_eHats[g_iHats].fAngles = m_fTemp; - g_eHats[g_iHats].bBonemerge = (kv.GetNum("bonemerge", 0)?true:false); - g_eHats[g_iHats].iSlot = kv.GetNum("slot"); - g_eHats[g_iHats].bHide = kv.GetNum("hide", 1) ? true : false; // hide by default - g_eHats[g_iHats].iTeam = kv.GetNum("team"); + g_eHats[g_iHats].fAngles = m_fTemp; + g_eHats[g_iHats].bBonemerge = (kv.GetNum("bonemerge", 0) ? true : false); + g_eHats[g_iHats].iSlot = kv.GetNum("slot"); + g_eHats[g_iHats].bHide = kv.GetNum("hide", 1) ? true : false; // hide by default + g_eHats[g_iHats].iTeam = kv.GetNum("team"); kv.GetString("attachment", g_eHats[g_iHats].szAttachment, sizeof(Hat::szAttachment), "facemask"); - if(!(FileExists(g_eHats[g_iHats].szModel, true))) + if (!(FileExists(g_eHats[g_iHats].szModel, true))) { - #if defined LOG_NOT_FOUND +#if defined LOG_NOT_FOUND // missing model char auth[32], name[32]; kv.GetString("auth", auth, 32); @@ -48,7 +53,7 @@ bool Hats_Config(KeyValues kv, int itemid) { LogMessage("Skipped hat <%s> -> [%s]", name, g_eHats[g_iHats].szModel); } - #endif +#endif return false; } @@ -58,25 +63,25 @@ bool Hats_Config(KeyValues kv, int itemid) void Hats_OnMapStart() { - for(int a = 1; a <= MaxClients; ++a) - for(int b = 0; b < STORE_MAX_SLOTS; ++b) + for (int a = 1; a <= MaxClients; ++a) + for (int b = 0; b < STORE_MAX_SLOTS; ++b) g_iClientHats[a][b] = INVALID_ENT_REFERENCE; - for(int i = 0; i < g_iHats; ++i) + for (int i = 0; i < g_iHats; ++i) { PrecacheModel(g_eHats[i].szModel, false); AddFileToDownloadsTable(g_eHats[i].szModel); } - CreateTimer(0.1, Timer_Hats_Adjust, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); + CreateTimer(0.1, Timer_Hats_Adjust, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE); } static Action Timer_Hats_Adjust(Handle timer) { - for(int client = 1; client <= MaxClients; ++client) - if(IsClientInGame(client) && !IsFakeClient(client)) + for (int client = 1; client <= MaxClients; ++client) + if (IsClientInGame(client) && !IsFakeClient(client)) { - if(IsClientObserver(client)) + if (IsClientObserver(client)) g_iSpecTarget[client] = (GetEntProp(client, Prop_Send, "m_iObserverMode") == 4) ? GetEntPropEnt(client, Prop_Send, "m_hObserverTarget") : -1; else g_iSpecTarget[client] = client; @@ -87,7 +92,7 @@ static Action Timer_Hats_Adjust(Handle timer) public void OnEntityDestroyed(int entity) { - if(entity > 2048 || entity < MaxClients) + if (entity > 2048 || entity < MaxClients) return; g_iHatsOwners[entity] = -1; @@ -101,7 +106,7 @@ void Hats_Reset() int Hats_Equip(int client, int id) { int m_iData = Store_GetDataIndex(id); - if(IsPlayerAlive(client)) + if (IsPlayerAlive(client)) { Store_RemoveClientHats(client, g_eHats[m_iData].iSlot); CreateHat(client, id); @@ -118,7 +123,7 @@ int Hats_Remove(int client, int id) void Store_SetClientHat(int client) { - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) { Store_RemoveClientHats(client, i); CreateHat(client, -1, i); @@ -129,12 +134,12 @@ static void CreateHat(int client, int itemid = -1, int slot = 0) { int m_iEquipped = (itemid == -1 ? Store_GetEquippedItem(client, "hat", slot) : itemid); - if(m_iEquipped >= 0) + if (m_iEquipped >= 0) { int m_iData = Store_GetDataIndex(m_iEquipped); #if defined GM_ZE - if(g_iClientTeam[client] == 2) + if (g_iClientTeam[client] == 2) return; #endif @@ -149,8 +154,8 @@ static void CreateHat(int client, int itemid = -1, int slot = 0) float m_fForward[3]; float m_fRight[3]; float m_fUp[3]; - GetClientAbsOrigin(client,m_fHatOrigin); - GetClientAbsAngles(client,m_fHatAngles); + GetClientAbsOrigin(client, m_fHatOrigin); + GetClientAbsAngles(client, m_fHatAngles); m_fHatAngles[0] += g_eHats[m_iData].fAngles[0]; m_fHatAngles[1] += g_eHats[m_iData].fAngles[1]; @@ -163,9 +168,9 @@ static void CreateHat(int client, int itemid = -1, int slot = 0) GetAngleVectors(m_fHatAngles, m_fForward, m_fRight, m_fUp); - m_fHatOrigin[0] += m_fRight[0]*m_fOffset[0]+m_fForward[0]*m_fOffset[1]+m_fUp[0]*m_fOffset[2]; - m_fHatOrigin[1] += m_fRight[1]*m_fOffset[0]+m_fForward[1]*m_fOffset[1]+m_fUp[1]*m_fOffset[2]; - m_fHatOrigin[2] += m_fRight[2]*m_fOffset[0]+m_fForward[2]*m_fOffset[1]+m_fUp[2]*m_fOffset[2]; + m_fHatOrigin[0] += m_fRight[0] * m_fOffset[0] + m_fForward[0] * m_fOffset[1] + m_fUp[0] * m_fOffset[2]; + m_fHatOrigin[1] += m_fRight[1] * m_fOffset[0] + m_fForward[1] * m_fOffset[1] + m_fUp[1] * m_fOffset[2]; + m_fHatOrigin[2] += m_fRight[2] * m_fOffset[0] + m_fForward[2] * m_fOffset[1] + m_fUp[2] * m_fOffset[2]; int m_iEnt = CreateEntityByName("prop_dynamic_override"); DispatchKeyValue(m_iEnt, "targetname", "store_item_pet"); @@ -176,7 +181,7 @@ static void CreateHat(int client, int itemid = -1, int slot = 0) g_iHatsOwners[m_iEnt] = client; - if(g_eHats[m_iData].bBonemerge) + if (g_eHats[m_iData].bBonemerge) Bonemerge(m_iEnt); DispatchSpawn(m_iEnt); @@ -204,7 +209,7 @@ static void CreateHat(int client, int itemid = -1, int slot = 0) void Store_RemoveClientHats(int client, int slot) { - if(g_iClientHats[client][slot] != INVALID_ENT_REFERENCE) + if (g_iClientHats[client][slot] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iClientHats[client][slot]); if (entity > 0 && IsValidEdict(entity)) @@ -217,14 +222,14 @@ void Store_RemoveClientHats(int client, int slot) public Action Hook_SetTransmit_Hat(int ent, int client) { - if(client == g_iHatsOwners[ent]) + if (client == g_iHatsOwners[ent]) return IsPlayerTP(client) ? Plugin_Continue : Plugin_Handled; - if(g_iSpecTarget[client] == g_iHatsOwners[ent]) + if (g_iSpecTarget[client] == g_iHatsOwners[ent]) return Plugin_Handled; // for gotv - if(IsClientSourceTV(client)) + if (IsClientSourceTV(client)) return Plugin_Handled; return Plugin_Continue; diff --git a/store/modules/neon.sp b/store/modules/neon.sp index 9ce46b8..cc00409 100644 --- a/store/modules/neon.sp +++ b/store/modules/neon.sp @@ -1,6 +1,11 @@ +// MAIN_FILE ../../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #define Module_Neon -enum struct Neon +abstract_struct Neon { int iColor[4]; int iBright; @@ -9,23 +14,22 @@ enum struct Neon } static Neon g_eNeons[STORE_MAX_ITEMS]; -static int g_iNeons = 0; -static int g_iClientNeon[MAXPLAYERS+1] = {INVALID_ENT_REFERENCE, ...}; +static int g_iNeons = 0; +static int g_iClientNeon[MAXPLAYERS + 1] = { INVALID_ENT_REFERENCE, ... }; bool Neon_Config(KeyValues kv, int itemid) { Store_SetDataIndex(itemid, g_iNeons); KvGetColor(kv, "color", g_eNeons[g_iNeons].iColor[0], g_eNeons[g_iNeons].iColor[1], g_eNeons[g_iNeons].iColor[2], g_eNeons[g_iNeons].iColor[3]); - g_eNeons[g_iNeons].iBright = kv.GetNum("brightness"); + g_eNeons[g_iNeons].iBright = kv.GetNum("brightness"); g_eNeons[g_iNeons].iDistance = kv.GetNum("distance"); - g_eNeons[g_iNeons].iFade = kv.GetNum("distancefade"); + g_eNeons[g_iNeons].iFade = kv.GetNum("distancefade"); ++g_iNeons; return true; } void Neon_OnMapStart() { - } void Neon_OnClientDisconnect(int client) @@ -47,7 +51,7 @@ int Neon_Equip(int client, int id) public void EquipNeon_Delay(int client) { - if(IsClientInGame(client) && IsPlayerAlive(client)) + if (IsClientInGame(client) && IsPlayerAlive(client)) Store_SetClientNeon(client); } @@ -59,7 +63,7 @@ int Neon_Remove(int client, int id) void Store_RemoveClientNeon(int client) { - if(g_iClientNeon[client] != INVALID_ENT_REFERENCE) + if (g_iClientNeon[client] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iClientNeon[client]); if (entity > 0 && IsValidEdict(entity)) @@ -75,17 +79,17 @@ void Store_SetClientNeon(int client) Store_RemoveClientNeon(client); #if defined GM_ZE - if(g_iClientTeam[client] == 2) + if (g_iClientTeam[client] == 2) return; #endif int m_iEquipped = Store_GetEquippedItem(client, "neon", 0); - if(m_iEquipped < 0) + if (m_iEquipped < 0) return; int m_iData = Store_GetDataIndex(m_iEquipped); - if(g_eNeons[m_iData].iColor[3] != 0) + if (g_eNeons[m_iData].iColor[3] != 0) { float clientOrigin[3]; GetClientAbsOrigin(client, clientOrigin); diff --git a/store/modules/part.sp b/store/modules/part.sp index 5c0700f..46c0bbd 100644 --- a/store/modules/part.sp +++ b/store/modules/part.sp @@ -1,12 +1,17 @@ +// MAIN_FILE ../../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #define Module_Part #define MAX_PART 128 -static int g_iParts = 0; -static int g_iClientPart[MAXPLAYERS+1] = {INVALID_ENT_REFERENCE, ...}; +static int g_iParts = 0; +static int g_iClientPart[MAXPLAYERS + 1] = { INVALID_ENT_REFERENCE, ... }; static char g_szPartName[MAX_PART][PLATFORM_MAX_PATH]; static char g_szPartFPcf[MAX_PART][PLATFORM_MAX_PATH]; -static char g_szPartClient[MAXPLAYERS+1][PLATFORM_MAX_PATH]; +static char g_szPartClient[MAXPLAYERS + 1][PLATFORM_MAX_PATH]; void Part_OnClientDisconnect(int client) { @@ -23,11 +28,11 @@ bool Part_Config(KeyValues kv, int itemid) { Store_SetDataIndex(itemid, g_iParts); kv.GetString("effect", g_szPartName[g_iParts], PLATFORM_MAX_PATH); - kv.GetString("model", g_szPartFPcf[g_iParts], PLATFORM_MAX_PATH); + kv.GetString("model", g_szPartFPcf[g_iParts], PLATFORM_MAX_PATH); - if(!FileExists(g_szPartFPcf[g_iParts], true)) + if (!FileExists(g_szPartFPcf[g_iParts], true)) { - #if defined LOG_NOT_FOUND +#if defined LOG_NOT_FOUND // missing model char auth[32], name[32]; kv.GetString("auth", auth, 32); @@ -40,7 +45,7 @@ bool Part_Config(KeyValues kv, int itemid) { LogMessage("Skipped aura <%s> -> [%s]", name, g_szPartFPcf[g_iParts]); } - #endif +#endif return false; } @@ -52,7 +57,7 @@ int Part_Equip(int client, int id) { g_szPartClient[client] = g_szPartName[Store_GetDataIndex(id)]; - if(IsPlayerAlive(client)) + if (IsPlayerAlive(client)) Store_SetClientPart(client); return 0; @@ -68,12 +73,12 @@ int Part_Remove(int client, int id) void Part_OnMapStart() { - if(g_iParts <= 0) + if (g_iParts <= 0) return; PrecacheEffect("ParticleEffect"); - for(int index = 0; index < g_iParts; ++index) + for (int index = 0; index < g_iParts; ++index) { PrecacheGeneric(g_szPartFPcf[index], true); PrecacheParticleEffect(g_szPartName[index]); @@ -83,7 +88,7 @@ void Part_OnMapStart() void Store_RemoveClientPart(int client) { - if(g_iClientPart[client] != INVALID_ENT_REFERENCE) + if (g_iClientPart[client] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iClientPart[client]); if (entity > 0 && IsValidEdict(entity)) @@ -99,11 +104,11 @@ void Store_SetClientPart(int client) Store_RemoveClientPart(client); #if defined GM_ZE - if(g_iClientTeam[client] == 2) + if (g_iClientTeam[client] == 2) return; #endif - if(!(strcmp(g_szPartClient[client], "", false) == 0)) + if (!(strcmp(g_szPartClient[client], "", false) == 0)) { float clientOrigin[3], clientAngles[3]; GetClientAbsOrigin(client, clientOrigin); @@ -113,7 +118,7 @@ void Store_SetClientPart(int client) int iEnt = CreateEntityByName("info_particle_system"); - if(!IsValidEdict(iEnt)) + if (!IsValidEdict(iEnt)) { LogError("Failed to create info_particle_system -> %N -> %s", client, g_szPartClient[client]); return; diff --git a/store/modules/skin.sp b/store/modules/skin.sp index a5373e6..1f12dca 100644 --- a/store/modules/skin.sp +++ b/store/modules/skin.sp @@ -1,39 +1,44 @@ +// MAIN_FILE ../../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #define Module_Skin -enum struct PlayerSkin +abstract_struct PlayerSkin { char szModel[PLATFORM_MAX_PATH]; char szArms[PLATFORM_MAX_PATH]; char szSound[PLATFORM_MAX_PATH]; - int iLevel; - int iTeam; - int nBody; + int iLevel; + int iTeam; + int nBody; } static PlayerSkin g_ePlayerSkins[STORE_MAX_ITEMS]; static bool g_bSoundHooked; static int g_iPlayerSkins = 0; -static int g_iSkinLevel[MAXPLAYERS+1]; -static int g_iPreviewTimes[MAXPLAYERS+1]; -static int g_iPreviewModel[MAXPLAYERS+1] = {INVALID_ENT_REFERENCE, ...}; -static int g_iCameraRef[MAXPLAYERS+1] = {INVALID_ENT_REFERENCE, ...}; -static char g_szDeathVoice[MAXPLAYERS+1][PLATFORM_MAX_PATH]; -static char g_szSkinModel[MAXPLAYERS+1][PLATFORM_MAX_PATH]; -static bool g_bShouldFireEvent[MAXPLAYERS+1]; +static int g_iSkinLevel[MAXPLAYERS + 1]; +static int g_iPreviewTimes[MAXPLAYERS + 1]; +static int g_iPreviewModel[MAXPLAYERS + 1] = { INVALID_ENT_REFERENCE, ... }; +static int g_iCameraRef[MAXPLAYERS + 1] = { INVALID_ENT_REFERENCE, ... }; +static char g_szDeathVoice[MAXPLAYERS + 1][PLATFORM_MAX_PATH]; +static char g_szSkinModel[MAXPLAYERS + 1][PLATFORM_MAX_PATH]; +static bool g_bShouldFireEvent[MAXPLAYERS + 1]; static ConVar spec_freeze_time; static ConVar mp_round_restart_delay; static ConVar sv_disablefreezecam; static ConVar spec_replay_enable; static ConVar store_firstperson_death_camera; -Handle g_tKillPreview[MAXPLAYERS+1]; +Handle g_tKillPreview[MAXPLAYERS + 1]; -Handle g_hOnPlayerSkinDefault = null; -Handle g_hOnPlayerSetModel = null; +Handle g_hOnPlayerSkinDefault = null; +Handle g_hOnPlayerSetModel = null; Handle g_hOnPlayerSetModelPost = null; -Handle g_hOnFPDeathCamera = null; -Handle g_hOnPlayerDeathVoice = null; +Handle g_hOnFPDeathCamera = null; +Handle g_hOnPlayerDeathVoice = null; void Skin_InitConVar() { @@ -42,20 +47,20 @@ void Skin_InitConVar() void Skin_OnPluginStart() { - g_hOnPlayerSkinDefault = CreateGlobalForward("Store_OnPlayerSkinDefault", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_String, Param_Cell, Param_CellByRef); - g_hOnFPDeathCamera = CreateGlobalForward("Store_OnFPDeathCamera", ET_Hook, Param_Cell); - g_hOnPlayerSetModel = CreateGlobalForward("Store_OnSetPlayerSkin", ET_Event, Param_Cell, Param_String, Param_String, Param_CellByRef); + g_hOnPlayerSkinDefault = CreateGlobalForward("Store_OnPlayerSkinDefault", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_String, Param_Cell, Param_CellByRef); + g_hOnFPDeathCamera = CreateGlobalForward("Store_OnFPDeathCamera", ET_Hook, Param_Cell); + g_hOnPlayerSetModel = CreateGlobalForward("Store_OnSetPlayerSkin", ET_Event, Param_Cell, Param_String, Param_String, Param_CellByRef); g_hOnPlayerSetModelPost = CreateGlobalForward("Store_OnSetPlayerSkinPost", ET_Ignore, Param_Cell, Param_String, Param_String, Param_Cell); - g_hOnPlayerDeathVoice = CreateGlobalForward("Store_OnPlayerDeathVoice", ET_Event, Param_Cell, Param_String); + g_hOnPlayerDeathVoice = CreateGlobalForward("Store_OnPlayerDeathVoice", ET_Event, Param_Cell, Param_String); Store_RegisterHandler("playerskin", PlayerSkins_OnMapStart, PlayerSkins_Reset, PlayerSkins_Config, PlayerSkins_Equip, PlayerSkins_Remove, true); RegAdminCmd("sm_arms", Command_Arms, ADMFLAG_ROOT, "Fixed Player Arms"); - spec_freeze_time = FindConVar("spec_freeze_time"); - sv_disablefreezecam = FindConVar("sv_disablefreezecam"); + spec_freeze_time = FindConVar("spec_freeze_time"); + sv_disablefreezecam = FindConVar("sv_disablefreezecam"); mp_round_restart_delay = FindConVar("mp_round_restart_delay"); - spec_replay_enable = FindConVar("spec_replay_enable"); + spec_replay_enable = FindConVar("spec_replay_enable"); spec_freeze_time.AddChangeHook(Skin_OnConVarChanged); sv_disablefreezecam.AddChangeHook(Skin_OnConVarChanged); @@ -67,7 +72,7 @@ void Skin_OnPluginStart() mp_round_restart_delay.SetFloat(8.0, true, true); spec_replay_enable.SetBool(false, true, true); - //DEATH CAMERA CCVAR + // DEATH CAMERA CCVAR store_firstperson_death_camera.SetBool(true, true, true); store_firstperson_death_camera.AddChangeHook(FPD_OnConVarChanged); } @@ -94,50 +99,50 @@ public void Skin_OnConVarChanged(ConVar convar, const char[] oldValue, const cha { if (store_firstperson_death_camera.BoolValue) { - if(convar == spec_freeze_time) + if (convar == spec_freeze_time) spec_freeze_time.SetFloat(-1.0, true, true); - if(convar == sv_disablefreezecam) + if (convar == sv_disablefreezecam) sv_disablefreezecam.SetBool(true, true, true); - if(convar == mp_round_restart_delay) + if (convar == mp_round_restart_delay) mp_round_restart_delay.SetFloat(8.0, true, true); - if(convar == spec_replay_enable) + if (convar == spec_replay_enable) spec_replay_enable.SetBool(false, true, true); } else { - if(convar == spec_freeze_time) + if (convar == spec_freeze_time) spec_freeze_time.RestoreDefault(true, true); - if(convar == sv_disablefreezecam) + if (convar == sv_disablefreezecam) sv_disablefreezecam.RestoreDefault(true, true); - if(convar == mp_round_restart_delay) + if (convar == mp_round_restart_delay) mp_round_restart_delay.RestoreDefault(true, true); - if(convar == spec_replay_enable) + if (convar == spec_replay_enable) spec_replay_enable.RestoreDefault(true, true); } } void Skin_OnClientDisconnect(int client) { - if(g_tKillPreview[client] != null) + if (g_tKillPreview[client] != null) TriggerTimer(g_tKillPreview[client], false); - if(g_iCameraRef[client] != INVALID_ENT_REFERENCE) + if (g_iCameraRef[client] != INVALID_ENT_REFERENCE) Timer_ClearCamera(null, client); } public Action Command_Arms(int client, int args) { - if(!client || !IsClientInGame(client) || !IsPlayerAlive(client)) + if (!client || !IsClientInGame(client) || !IsPlayerAlive(client)) return Plugin_Handled; #if defined GM_ZE - if(g_iClientTeam[client] == 2) + if (g_iClientTeam[client] == 2) return Plugin_Handled; #endif @@ -151,7 +156,7 @@ public bool PlayerSkins_Config(KeyValues kv, int itemid) Store_SetDataIndex(itemid, g_iPlayerSkins); kv.GetString("model", g_ePlayerSkins[g_iPlayerSkins].szModel, PLATFORM_MAX_PATH); - kv.GetString("arms", g_ePlayerSkins[g_iPlayerSkins].szArms, PLATFORM_MAX_PATH); + kv.GetString("arms", g_ePlayerSkins[g_iPlayerSkins].szArms, PLATFORM_MAX_PATH); kv.GetString("sound", g_ePlayerSkins[g_iPlayerSkins].szSound, PLATFORM_MAX_PATH); g_ePlayerSkins[g_iPlayerSkins].iLevel = kv.GetNum("lvls", 0); @@ -163,9 +168,9 @@ public bool PlayerSkins_Config(KeyValues kv, int itemid) g_ePlayerSkins[g_iPlayerSkins].iTeam = kv.GetNum("team"); #endif - if(!FileExists(g_ePlayerSkins[g_iPlayerSkins].szModel, true)) + if (!FileExists(g_ePlayerSkins[g_iPlayerSkins].szModel, true)) { - #if defined LOG_NOT_FOUND +#if defined LOG_NOT_FOUND // missing model char auth[32], name[32]; kv.GetString("auth", auth, 32); @@ -178,11 +183,11 @@ public bool PlayerSkins_Config(KeyValues kv, int itemid) { LogMessage("Skipped skin <%s> -> [%s]", name, g_ePlayerSkins[g_iPlayerSkins].szModel); } - #endif +#endif return false; } - if(g_ePlayerSkins[g_iPlayerSkins].szArms[0] && !FileExists(g_ePlayerSkins[g_iPlayerSkins].szArms, true)) + if (g_ePlayerSkins[g_iPlayerSkins].szArms[0] && !FileExists(g_ePlayerSkins[g_iPlayerSkins].szArms, true)) { LogError("Missing 'Arms' files for '%s'::'%s'.", g_ePlayerSkins[g_iPlayerSkins].szModel, g_ePlayerSkins[g_iPlayerSkins].szArms); } @@ -193,24 +198,24 @@ public bool PlayerSkins_Config(KeyValues kv, int itemid) public void PlayerSkins_OnMapStart() { - int deathsounds = 0; + int deathsounds = 0; char szPath[PLATFORM_MAX_PATH], szPathStar[PLATFORM_MAX_PATH]; - for(int i = 0; i < g_iPlayerSkins; ++i) + for (int i = 0; i < g_iPlayerSkins; ++i) { PrecacheModel(g_ePlayerSkins[i].szModel, false); AddFileToDownloadsTable(g_ePlayerSkins[i].szModel); // prevent double call - if(g_ePlayerSkins[i].szArms[0] != 0 && strcmp(g_ePlayerSkins[i].szArms, g_ePlayerSkins[i].szModel, false) != 0) + if (g_ePlayerSkins[i].szArms[0] != 0 && strcmp(g_ePlayerSkins[i].szArms, g_ePlayerSkins[i].szModel, false) != 0) { PrecacheModel(g_ePlayerSkins[i].szArms, false); AddFileToDownloadsTable(g_ePlayerSkins[i].szArms); } - if(g_ePlayerSkins[i].szSound[0] != 0) + if (g_ePlayerSkins[i].szSound[0] != 0) { FormatEx(STRING(szPath), "sound/%s", g_ePlayerSkins[i].szSound); - if(FileExists(szPath, true)) + if (FileExists(szPath, true)) { FormatEx(STRING(szPathStar), "*%s", g_ePlayerSkins[i].szSound); AddToStringTable(FindStringTable("soundprecache"), szPathStar); @@ -245,25 +250,25 @@ public void PlayerSkins_Reset() public int PlayerSkins_Equip(int client, int id) { - if(IsClientInGame(client) && IsPlayerAlive(client)) + if (IsClientInGame(client) && IsPlayerAlive(client)) tPrintToChat(client, "%T", "PlayerSkins Settings Changed", client); #if defined Global_Skin return 2; #else - return g_ePlayerSkins[Store_GetDataIndex(id)].iTeam-2; + return g_ePlayerSkins[Store_GetDataIndex(id)].iTeam - 2; #endif } public int PlayerSkins_Remove(int client, int id) { - if(IsClientInGame(client)) + if (IsClientInGame(client)) tPrintToChat(client, "%T", "PlayerSkins Settings Changed", client); #if defined Global_Skin return 2; #else - return g_ePlayerSkins[Store_GetDataIndex(id)].iTeam-2; + return g_ePlayerSkins[Store_GetDataIndex(id)].iTeam - 2; #endif } @@ -271,7 +276,7 @@ void Store_PreSetClientModel(int client) { int m_iEquipped = GetEquippedSkin(client); - if(m_iEquipped >= 0) + if (m_iEquipped >= 0) { CreateTimer(0.02, Timer_SetClientModel, client | (Store_GetDataIndex(m_iEquipped) << 7), TIMER_FLAG_NO_MAPCHANGE); return; @@ -296,11 +301,11 @@ static Action Timer_SetDefaultModel(Handle timer, int client) static void Store_SetClientModel(int client, int m_iData) { - if(!IsClientInGame(client) || !IsPlayerAlive(client)) + if (!IsClientInGame(client) || !IsPlayerAlive(client)) return; #if defined GM_ZE - if(g_iClientTeam[client] == 2) + if (g_iClientTeam[client] == 2) { strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), "#zombie"); return; @@ -334,7 +339,7 @@ static void Store_SetClientModel(int client, int m_iData) strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), skin_t); - if(!StrEqual(arms_t, "null")) + if (!StrEqual(arms_t, "null")) { if (Store_CallSetPlayerSkinArms(client, STRING(arms_t))) { @@ -365,24 +370,24 @@ public Action Timer_SetClientModel(Handle timer, int val) public Action Hook_NormalSound(int clients[64], int &numClients, char sample[PLATFORM_MAX_PATH], int &client, int &channel, float &volume, int &level, int &pitch, int &flags, char soundEntry[PLATFORM_MAX_PATH], int &seed) { // not death sound - if(channel != SNDCHAN_VOICE || sample[0] != '~') + if (channel != SNDCHAN_VOICE || sample[0] != '~') return Plugin_Continue; // not from local player - if(!IsValidClient(client)) + if (!IsValidClient(client)) return Plugin_Continue; #if defined GM_ZE // ignore zombie - if(g_iClientTeam[client] == 2) + if (g_iClientTeam[client] == 2) return Plugin_Continue; #endif // allow sound - if(g_szDeathVoice[client][0] != '*') + if (g_szDeathVoice[client][0] != '*') return Plugin_Continue; - //if (strcmp(soundEntry, "Player.Death") == 0 || strcmp(soundEntry, "Player.DeathFem") == 0) + // if (strcmp(soundEntry, "Player.Death") == 0 || strcmp(soundEntry, "Player.DeathFem") == 0) if (strncmp(soundEntry, "Player.Death", 12, false) == 0) { // Block @@ -395,14 +400,14 @@ public Action Hook_NormalSound(int clients[64], int &numClients, char sample[PLA void Broadcast_DeathSound(int client) { - if(!IsClientInGame(client)) + if (!IsClientInGame(client)) return; - if(g_szDeathVoice[client][0] != '*') + if (g_szDeathVoice[client][0] != '*') return; #if defined GM_ZE - if(g_iClientTeam[client] == 2) + if (g_iClientTeam[client] == 2) return; #endif @@ -413,7 +418,7 @@ void Broadcast_DeathSound(int client) Call_StartForward(g_hOnPlayerDeathVoice); Call_PushCell(client); - Call_PushStringEx(sound, PLATFORM_MAX_PATH, SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(sound, PLATFORM_MAX_PATH, SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_Finish(res); if (res >= Plugin_Handled) @@ -424,7 +429,7 @@ void Broadcast_DeathSound(int client) float fPos[3], fAgl[3]; GetClientEyePosition(client, fPos); - GetClientEyeAngles (client, fAgl); + GetClientEyeAngles(client, fAgl); fPos[2] -= 3.0; @@ -448,25 +453,27 @@ void Broadcast_DeathSound(int client) EmitSoundToClient(client, sound, SOUND_FROM_PLAYER, SNDCHAN_VOICE, _, _, 1.0); - int[] clients = new int[MAXPLAYERS+1]; int counts; float vPos[3]; - for (int i = 1; i <= MaxClients; i++) if (IsClientInGame(i) && !IsFakeClient(i) && i != client) - { - if (IsPlayerAlive(i)) + int[] clients = new int[MAXPLAYERS + 1]; + int counts; + float vPos[3]; + for (int i = 1; i <= MaxClients; i++) + if (IsClientInGame(i) && !IsFakeClient(i) && i != client) { - GetClientEyePosition(i, vPos); - if (GetVectorDistance(fPos, vPos) >= 1024.0) + if (IsPlayerAlive(i)) { - // skip if so far - continue; + GetClientEyePosition(i, vPos); + if (GetVectorDistance(fPos, vPos) >= 1024.0) + { + // skip if so far + continue; + } } - } - clients[counts++] = i; - } + clients[counts++] = i; + } if (counts > 0) EmitSound(clients, counts, sound, speaker, SNDCHAN_VOICE, _, _, 1.0, _, speaker); - } void Store_PreviewSkin(int client, int itemid) @@ -480,7 +487,7 @@ void Store_PreviewSkin(int client, int itemid) return; } - int m_iViewModel = CreateEntityByName("prop_dynamic_override"); //prop_physics_multiplayer + int m_iViewModel = CreateEntityByName("prop_dynamic_override"); // prop_physics_multiplayer DispatchKeyValue(m_iViewModel, "spawnflags", "64"); DispatchKeyValue(m_iViewModel, "model", g_ePlayerSkins[g_Items[itemid].iData].szModel); DispatchKeyValue(m_iViewModel, "rendermode", "0"); @@ -506,8 +513,8 @@ void Store_PreviewSkin(int client, int itemid) SetEntProp(m_iViewModel, Prop_Send, "m_nGlowStyle", 2); SetEntPropFloat(m_iViewModel, Prop_Send, "m_flGlowMaxDist", 2000.0); - //Miku Green - SetEntData(m_iViewModel, offset , 57, _, true); + // Miku Green + SetEntData(m_iViewModel, offset, 57, _, true); SetEntData(m_iViewModel, offset + 1, 197, _, true); SetEntData(m_iViewModel, offset + 2, 187, _, true); SetEntData(m_iViewModel, offset + 3, 255, _, true); @@ -529,7 +536,7 @@ void Store_PreviewSkin(int client, int itemid) TeleportEntity(m_iViewModel, m_fPosition, m_fAngles, NULL_VECTOR); - g_iPreviewTimes[client] = GetTime()+18; + g_iPreviewTimes[client] = GetTime() + 18; g_iPreviewModel[client] = EntIndexToEntRef(m_iViewModel); SDKHook(m_iViewModel, SDKHook_SetTransmit, Hook_SetTransmit_Preview); @@ -580,7 +587,7 @@ public Action Timer_KillPreview(Handle timer, int client) { g_tKillPreview[client] = null; - if(g_iPreviewModel[client] != INVALID_ENT_REFERENCE) + if (g_iPreviewModel[client] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iPreviewModel[client]); if (entity > 0 && IsValidEdict(entity)) @@ -595,7 +602,7 @@ public Action Timer_KillPreview(Handle timer, int client) public void FirstPersonDeathCamera(int client) { - if(!IsClientInGame(client) || g_iClientTeam[client] < 2 || IsPlayerAlive(client)) + if (!IsClientInGame(client) || g_iClientTeam[client] < 2 || IsPlayerAlive(client)) return; if (!store_firstperson_death_camera.BoolValue) @@ -607,7 +614,7 @@ public void FirstPersonDeathCamera(int client) Call_PushCell(client); Call_Finish(ret); - if(ret >= Plugin_Handled) + if (ret >= Plugin_Handled) { g_iCameraRef[client] = INVALID_ENT_REFERENCE; return; @@ -624,12 +631,12 @@ public void FirstPersonDeathCamera(int client) static bool SpawnCamAndAttach(int client, int ragdoll) { int iEntity = CreateEntityByName("prop_dynamic"); - if(iEntity == -1) + if (iEntity == -1) return false; - DispatchKeyValue(iEntity, "model", "models/blackout.mdl"); - DispatchKeyValue(iEntity, "solid", "0"); - DispatchKeyValue(iEntity, "rendermode", "10"); // dont render + DispatchKeyValue(iEntity, "model", "models/blackout.mdl"); + DispatchKeyValue(iEntity, "solid", "0"); + DispatchKeyValue(iEntity, "rendermode", "10"); // dont render DispatchKeyValue(iEntity, "disableshadows", "1"); // no shadows float m_fAngles[3]; @@ -660,7 +667,7 @@ static bool SpawnCamAndAttach(int client, int ragdoll) public Action Timer_ClearCamera(Handle timer, int client) { - if(g_iCameraRef[client] != INVALID_ENT_REFERENCE) + if (g_iCameraRef[client] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iCameraRef[client]); @@ -681,29 +688,29 @@ public Action Timer_ClearCamera(Handle timer, int client) return Plugin_Stop; } -#define FFADE_IN 0x0001 // Just here so we don't pass 0 into the function -#define FFADE_OUT 0x0002 // Fade out (not in) -#define FFADE_MODULATE 0x0004 // Modulate (don't blend) -#define FFADE_STAYOUT 0x0008 // ignores the duration, stays faded out until new ScreenFade message received -#define FFADE_PURGE 0x0010 // Purges all other fades, replacing them with this one +#define FFADE_IN 0x0001 // Just here so we don't pass 0 into the function +#define FFADE_OUT 0x0002 // Fade out (not in) +#define FFADE_MODULATE 0x0004 // Modulate (don't blend) +#define FFADE_STAYOUT 0x0008 // ignores the duration, stays faded out until new ScreenFade message received +#define FFADE_PURGE 0x0010 // Purges all other fades, replacing them with this one static void FadeScreenBlack(int client) { - Protobuf pb = view_as(StartMessageOne("Fade", client, USERMSG_RELIABLE|USERMSG_BLOCKHOOKS)); - pb.SetInt("duration", 2560); //3072 + Protobuf pb = view_as(StartMessageOne("Fade", client, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS)); + pb.SetInt("duration", 2560); // 3072 pb.SetInt("hold_time", 0); - pb.SetInt("flags", FFADE_OUT|FFADE_PURGE|FFADE_STAYOUT); - pb.SetColor("clr", {0, 0, 0, 255}); + pb.SetInt("flags", FFADE_OUT | FFADE_PURGE | FFADE_STAYOUT); + pb.SetColor("clr", { 0, 0, 0, 255 }); EndMessage(); } static void FadeScreenWhite(int client) { - Protobuf pb = view_as(StartMessageOne("Fade", client, USERMSG_RELIABLE|USERMSG_BLOCKHOOKS)); + Protobuf pb = view_as(StartMessageOne("Fade", client, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS)); pb.SetInt("duration", 1536); pb.SetInt("hold_time", 1536); - pb.SetInt("flags", FFADE_IN|FFADE_PURGE); - pb.SetColor("clr", {0, 0, 0, 0}); + pb.SetInt("flags", FFADE_IN | FFADE_PURGE); + pb.SetColor("clr", { 0, 0, 0, 0 }); EndMessage(); } @@ -724,19 +731,20 @@ static int GetEquippedSkin(int client) #if defined Global_Skin return Store_GetEquippedItem(client, "playerskin", 2); #else - return Store_GetEquippedItem(client, "playerskin", g_iClientTeam[client]-2); + return Store_GetEquippedItem(client, "playerskin", g_iClientTeam[client] - 2); #endif } #if defined GM_ZE + public void ZR_OnClientHumanPost(int client, bool respawn, bool protect) { // If client has been respawned. - if(respawn) + if (respawn) return; // Dead Player. - if(!IsPlayerAlive(client)) + if (!IsPlayerAlive(client)) return; Store_PreSetClientModel(client); @@ -745,11 +753,11 @@ public void ZR_OnClientHumanPost(int client, bool respawn, bool protect) void Store_RemoveClientGloves(int client, int m_iData = -1) { - if(m_iData == -1 && GetEquippedSkin(client) <= 0) + if (m_iData == -1 && GetEquippedSkin(client) <= 0) return; int gloves = GetEntPropEnt(client, Prop_Send, "m_hMyWearables"); - if(gloves != -1) + if (gloves != -1) AcceptEntityInput(gloves, "KillHierarchy"); } @@ -761,7 +769,7 @@ void Store_OnPlayerSpawn(int client) void Store_ResetPlayerSkin(int client) { strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), "#default"); - g_iSkinLevel[client] = 0; + g_iSkinLevel[client] = 0; g_szDeathVoice[client][0] = '\0'; } @@ -783,28 +791,29 @@ void Store_GetPlayerSkinModel(int client, char[] model, int maxLen) void Store_CallDefaultSkin(int client) { #if defined GM_ZE - if(g_iClientTeam[client] == 2) + if (g_iClientTeam[client] == 2) { strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), "#zombie"); return; } #endif - char skin_t[128], arms_t[128]; int body; + char skin_t[128], arms_t[128]; + int body; bool ret = false; Call_StartForward(g_hOnPlayerSkinDefault); Call_PushCell(client); - Call_PushCell(g_iClientTeam[client]-2); - Call_PushStringEx(STRING(skin_t), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushCell(g_iClientTeam[client] - 2); + Call_PushStringEx(STRING(skin_t), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_PushCell(128); - Call_PushStringEx(STRING(arms_t), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(STRING(arms_t), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_PushCell(128); Call_PushCellRef(body); Call_Finish(ret); - if(ret) + if (ret) { if (IsModelPrecached(skin_t)) { @@ -814,7 +823,7 @@ void Store_CallDefaultSkin(int client) if (Store_CallSetPlayerSkinArms(client, STRING(arms_t))) { - if(IsModelPrecached(arms_t)) + if (IsModelPrecached(arms_t)) { Store_SetClientArms(client, arms_t); } @@ -839,7 +848,8 @@ void EnforceDeathSound(int client, const char[] skin, const int body) Action Store_CallPreSetModel(int client, char skin[128], char arms[128], int &body) { - char s[128], a[128]; int b = body; + char s[128], a[128]; + int b = body; strcopy(STRING(s), skin); strcopy(STRING(a), arms); @@ -847,8 +857,8 @@ Action Store_CallPreSetModel(int client, char skin[128], char arms[128], int &bo Call_StartForward(g_hOnPlayerSetModel); Call_PushCell(client); - Call_PushStringEx(STRING(s), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); - Call_PushStringEx(STRING(a), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(STRING(s), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(STRING(a), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_PushCellRef(b); Call_Finish(res); @@ -876,7 +886,7 @@ bool Store_CallSetPlayerSkinArms(int client, char[] arms, int len) Action res = Plugin_Continue; Call_StartForward(gf); Call_PushCell(client); - Call_PushStringEx(STRING(buff), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(STRING(buff), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_PushCell(len); Call_Finish(res); @@ -908,11 +918,14 @@ bool GetSkinData(int itemid, char skin[128], char arms[128], int &body, int &tea int FindDataIndexByModel(const char[] skin, const int body) { - for(int i = 0; i < g_iPlayerSkins; ++i) + for (int i = 0; i < g_iPlayerSkins; ++i) { - if (strcmp(g_ePlayerSkins[i].szModel, skin) == 0) { - if (g_ePlayerSkins[i].nBody > 0) { - if (body != g_ePlayerSkins[i].nBody) { + if (strcmp(g_ePlayerSkins[i].szModel, skin) == 0) + { + if (g_ePlayerSkins[i].nBody > 0) + { + if (body != g_ePlayerSkins[i].nBody) + { continue; } } diff --git a/store/modules/trail.sp b/store/modules/trail.sp index 7682c05..14a20b4 100644 --- a/store/modules/trail.sp +++ b/store/modules/trail.sp @@ -1,15 +1,20 @@ +// MAIN_FILE ../../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #define Module_Trail -enum struct Trail +abstract_struct Trail { char szMaterial[PLATFORM_MAX_PATH]; - int iSlot; + int iSlot; } static Trail g_eTrails[STORE_MAX_ITEMS]; static int g_iTrails = 0; -static int g_iClientTrails[MAXPLAYERS+1][STORE_MAX_SLOTS]; +static int g_iClientTrails[MAXPLAYERS + 1][STORE_MAX_SLOTS]; bool Trails_Config(KeyValues kv, int itemid) { @@ -18,13 +23,13 @@ bool Trails_Config(KeyValues kv, int itemid) kv.GetString("material", g_eTrails[g_iTrails].szMaterial, PLATFORM_MAX_PATH); g_eTrails[g_iTrails].iSlot = kv.GetNum("slot"); - if(FileExists(g_eTrails[g_iTrails].szMaterial, true)) + if (FileExists(g_eTrails[g_iTrails].szMaterial, true)) { ++g_iTrails; return true; } - #if defined LOG_NOT_FOUND +#if defined LOG_NOT_FOUND // missing model char auth[32], name[32]; kv.GetString("auth", auth, 32); @@ -37,18 +42,18 @@ bool Trails_Config(KeyValues kv, int itemid) { LogMessage("Skipped trail <%s> -> [%s]", name, g_eTrails[g_iTrails].szMaterial); } - #endif +#endif return false; } void Trails_OnMapStart() { - for(int a = 0; a <= MaxClients; ++a) - for(int b = 0; b < STORE_MAX_SLOTS; ++b) + for (int a = 0; a <= MaxClients; ++a) + for (int b = 0; b < STORE_MAX_SLOTS; ++b) g_iClientTrails[a][b] = INVALID_ENT_REFERENCE; - for(int i = 0; i < g_iTrails; ++i) + for (int i = 0; i < g_iTrails; ++i) { if (PrecacheModel(g_eTrails[i].szMaterial) > 0) { @@ -64,7 +69,7 @@ void Trails_Reset() int Trails_Equip(int client, int id) { - if(IsPlayerAlive(client)) + if (IsPlayerAlive(client)) Store_SetClientTrail(client); return g_eTrails[Store_GetDataIndex(id)].iSlot; @@ -74,12 +79,12 @@ int Trails_Remove(int client, int id) { Store_SetClientTrail(client); - return g_eTrails[Store_GetDataIndex(id)].iSlot; + return g_eTrails[Store_GetDataIndex(id)].iSlot; } void Store_RemoveClientTrail(int client, int slot) { - if(g_iClientTrails[client][slot] != INVALID_ENT_REFERENCE) + if (g_iClientTrails[client][slot] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iClientTrails[client][slot]); if (entity > 0 && IsValidEdict(entity)) @@ -93,7 +98,7 @@ void Store_RemoveClientTrail(int client, int slot) void Trails_OnClientDisconnect(int client) { - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) Store_RemoveClientTrail(client, i); } @@ -104,10 +109,10 @@ void Store_SetClientTrail(int client) public void Store_PreSetTrail(int client) { - if(!IsClientInGame(client)) + if (!IsClientInGame(client)) return; - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) { Store_RemoveClientTrail(client, i); CreateTrail(client, -1, i); @@ -117,35 +122,35 @@ public void Store_PreSetTrail(int client) void CreateTrail(int client, int itemid = -1, int slot = 0) { #if defined GM_ZE - if(g_iClientTeam[client] == 2) + if (g_iClientTeam[client] == 2) return; #endif int m_iEquipped = (itemid == -1) ? Store_GetEquippedItem(client, "trail", slot) : itemid; - if(m_iEquipped < 0) + if (m_iEquipped < 0) return; int m_iData = Store_GetDataIndex(m_iEquipped); - int m_aEquipped[STORE_MAX_SLOTS] = {-1,...}; - int m_iNumEquipped = 0; + int m_aEquipped[STORE_MAX_SLOTS] = { -1, ... }; + int m_iNumEquipped = 0; int m_iCurrent; - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) { - if((m_aEquipped[m_iNumEquipped] = Store_GetEquippedItem(client, "trail", i)) >= 0) + if ((m_aEquipped[m_iNumEquipped] = Store_GetEquippedItem(client, "trail", i)) >= 0) { - if(i == g_eTrails[m_iData].iSlot) + if (i == g_eTrails[m_iData].iSlot) m_iCurrent = m_iNumEquipped; ++m_iNumEquipped; } } - int entity = g_iClientTrails[client][slot] == INVALID_ENT_REFERENCE ? -1 : EntRefToEntIndex( g_iClientTrails[client][slot]); + int entity = g_iClientTrails[client][slot] == INVALID_ENT_REFERENCE ? -1 : EntRefToEntIndex(g_iClientTrails[client][slot]); - if(IsValidEdict(entity)) + if (IsValidEdict(entity)) return; entity = CreateEntityByName("env_spritetrail"); @@ -170,14 +175,14 @@ void AttachTrail(int ent, int client, int current, int num) { float m_fOrigin[3]; float m_fAngle[3]; - float m_fTemp[3] = {0.0, 90.0, 0.0}; + float m_fTemp[3] = { 0.0, 90.0, 0.0 }; GetEntPropVector(client, Prop_Data, "m_angAbsRotation", m_fAngle); SetEntPropVector(client, Prop_Data, "m_angAbsRotation", m_fTemp); - float m_fX = (30.0*((num-1)%3))/2-(30.0*(current%3)); + float m_fX = (30.0 * ((num - 1) % 3)) / 2 - (30.0 * (current % 3)); float m_fPosition[3]; m_fPosition[0] = m_fX; m_fPosition[1] = 0.0; - m_fPosition[2]= 0.5+(current/3)*30.0; + m_fPosition[2] = 0.5 + (current / 3) * 30.0; GetClientAbsOrigin(client, m_fOrigin); AddVectors(m_fOrigin, m_fPosition, m_fOrigin); TeleportEntity(ent, m_fOrigin, m_fTemp, NULL_VECTOR); diff --git a/store/players.sp b/store/players.sp index bd54f8e..76b2699 100644 --- a/store/players.sp +++ b/store/players.sp @@ -1,3 +1,8 @@ +// MAIN_FILE ../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #define Module_Player void Players_OnPluginStart() @@ -63,7 +68,7 @@ public Action Event_PlayerSpawn_Pre(Event event, const char[] name, bool dontBro int client = GetClientOfUserId(event.GetInt("userid")); - if(IsFakeClient(client) || g_iClientTeam[client] <= 1) + if (IsFakeClient(client) || g_iClientTeam[client] <= 1) return Plugin_Continue; RequestFrame(OnClientSpawnPost, client); @@ -77,7 +82,8 @@ public Action Event_PlayerSpawn_Pre(Event event, const char[] name, bool dontBro // 64tick ~ 0.016 // 128tick ~ 0.008 CreateTimer(0.0, Timer_ClearCamera, client); - if(g_tKillPreview[client] != null) TriggerTimer(g_tKillPreview[client], false); + if (g_tKillPreview[client] != null) + TriggerTimer(g_tKillPreview[client], false); #endif return Plugin_Continue; @@ -85,7 +91,7 @@ public Action Event_PlayerSpawn_Pre(Event event, const char[] name, bool dontBro public void OnClientSpawnPost(int client) { - if(!IsClientInGame(client) || !IsPlayerAlive(client)) + if (!IsClientInGame(client) || !IsPlayerAlive(client)) return; #if defined Module_Skin @@ -108,7 +114,7 @@ public Action Timer_DelaySpawn(Handle timer, int userid) { int client = GetClientOfUserId(userid); - if(!client || !IsPlayerAlive(client)) + if (!client || !IsPlayerAlive(client)) return Plugin_Stop; #if defined Module_Aura @@ -130,7 +136,7 @@ public Action Event_PlayerDeath_Pre(Event event, const char[] name, bool dontBro { int client = GetClientOfUserId(event.GetInt("userid")); - if(IsFakeClient(client)) + if (IsFakeClient(client)) return Plugin_Continue; #if defined Module_Skin @@ -167,7 +173,7 @@ public void ZE_OnPlayerInfected(int client, int attacker, bool motherZombie, boo void DeathReset(int client) { - #pragma unused client +#pragma unused client #if defined Module_Aura Store_RemoveClientAura(client); @@ -181,7 +187,7 @@ void DeathReset(int client) Store_RemoveClientPart(client); #endif - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) { #if defined Module_Hats Store_RemoveClientHats(client, i); @@ -195,13 +201,13 @@ void DeathReset(int client) public Action Event_PlayerTeam_Pre(Event event, const char[] name, bool dontBroadcast) { - int client = GetClientOfUserId(event.GetInt("userid")); + int client = GetClientOfUserId(event.GetInt("userid")); int newteam = event.GetInt("team"); int oldteam = event.GetInt("oldteam"); g_iClientTeam[client] = newteam; - if(oldteam > 1 && newteam <= 1) + if (oldteam > 1 && newteam <= 1) { #if defined Module_Aura Store_RemoveClientAura(client); @@ -216,12 +222,12 @@ public Action Event_PlayerTeam_Pre(Event event, const char[] name, bool dontBroa #endif #if defined Module_Trail - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) Store_RemoveClientTrail(client, i); #endif #if defined Module_Hats - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) Store_RemoveClientHats(client, i); #endif } @@ -234,9 +240,9 @@ public Action Event_PlayerTeam_Pre(Event event, const char[] name, bool dontBroa } #if defined TeamArms -void OnClientTeamPost(int client) +void OnClientTeamPost(int client) { - if(!IsClientInGame(client) || !IsPlayerAlive(client) || g_iClientTeam[client] > 1) + if (!IsClientInGame(client) || !IsPlayerAlive(client) || g_iClientTeam[client] > 1) return; Store_PreSetClientModel(client); diff --git a/store/sounds.sp b/store/sounds.sp index 7a8a149..5e72b4e 100644 --- a/store/sounds.sp +++ b/store/sounds.sp @@ -1,19 +1,24 @@ +// MAIN_FILE ../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #define Module_Sound #define SOUND_COOKIE_NAME "Store.Sound.Setting" -enum struct Sound +abstract_struct Sound { - char szName[128]; - char szSound[128]; + char szName[128]; + char szSound[128]; float fVolume; - int iCooldown; + int iCooldown; } -static int g_iSounds = 0; -static int g_iSoundClient[MAXPLAYERS+1]; -static int g_iSoundSpam[MAXPLAYERS+1]; -static bool g_bClientDisable[MAXPLAYERS+1]; +static int g_iSounds = 0; +static int g_iSoundClient[MAXPLAYERS + 1]; +static int g_iSoundSpam[MAXPLAYERS + 1]; +static bool g_bClientDisable[MAXPLAYERS + 1]; static Sound g_eSounds[STORE_MAX_ITEMS]; @@ -25,7 +30,7 @@ public void Sounds_OnPluginStart() { Store_RegisterHandler("sound", Sound_OnMapStart, Sound_Reset, Sound_Config, Sound_Equip, Sound_Remove, true); - g_hOnCheerSound = CreateGlobalForward("Store_OnCheerSound", ET_Hook, Param_Cell, Param_String, Param_String, Param_FloatByRef, Param_CellByRef); + g_hOnCheerSound = CreateGlobalForward("Store_OnCheerSound", ET_Hook, Param_Cell, Param_String, Param_String, Param_FloatByRef, Param_CellByRef); g_hOnCheerCommand = CreateGlobalForward("Store_OnCheerCommand", ET_Hook, Param_Cell, Param_CellByRef); RegConsoleCmd("cheer", Command_Cheer); @@ -37,7 +42,7 @@ public void Sounds_OnPluginStart() void Sounds_OnClientprefs() { - if(g_pClientprefs) + if (g_pClientprefs) { g_hCookieSounds = RegClientCookie(SOUND_COOKIE_NAME, "", CookieAccess_Protected); } @@ -51,10 +56,10 @@ static void Sound_OnMapStart() { char szPath[256]; char szPathStar[256]; - for(int i = 0; i < g_iSounds; ++i) + for (int i = 0; i < g_iSounds; ++i) { Format(STRING(szPath), "sound/%s", g_eSounds[i].szSound); - if(FileExists(szPath, true)) + if (FileExists(szPath, true)) { Format(STRING(szPathStar), ")%s", g_eSounds[i].szSound); AddToStringTable(FindStringTable("soundprecache"), szPathStar); @@ -65,7 +70,7 @@ static void Sound_OnMapStart() void Sound_OnClientDeath(int client, int attacker) { - g_iSoundSpam[client] = -1; + g_iSoundSpam[client] = -1; g_iSoundSpam[attacker] = -1; } @@ -83,27 +88,27 @@ static bool Sound_Config(KeyValues kv, int itemid) Store_SetDataIndex(itemid, g_iSounds); kv.GetString("sound", g_eSounds[g_iSounds].szSound, sizeof(Sound::szSound)); kv.GetString("shortname", g_eSounds[g_iSounds].szName, sizeof(Sound::szName)); - g_eSounds[g_iSounds].fVolume = kv.GetFloat("volume", 0.3); + g_eSounds[g_iSounds].fVolume = kv.GetFloat("volume", 0.3); g_eSounds[g_iSounds].iCooldown = kv.GetNum("cooldown", 30); - if(g_eSounds[g_iSounds].iCooldown < 30) + if (g_eSounds[g_iSounds].iCooldown < 30) g_eSounds[g_iSounds].iCooldown = 30; - if(g_eSounds[g_iSounds].fVolume > 1.0) + if (g_eSounds[g_iSounds].fVolume > 1.0) g_eSounds[g_iSounds].fVolume = 1.0; - if(g_eSounds[g_iSounds].fVolume <= 0.0) + if (g_eSounds[g_iSounds].fVolume <= 0.0) g_eSounds[g_iSounds].fVolume = 0.05; char szPath[256]; FormatEx(STRING(szPath), "sound/%s", g_eSounds[g_iSounds].szSound); - if(FileExists(szPath, true)) + if (FileExists(szPath, true)) { ++g_iSounds; return true; } - #if defined LOG_NOT_FOUND +#if defined LOG_NOT_FOUND // missing model char auth[32], name[32]; kv.GetString("auth", auth, 32); @@ -116,14 +121,14 @@ static bool Sound_Config(KeyValues kv, int itemid) { LogMessage("Skipped sound <%s> -> [%s]", name, g_eSounds[g_iSounds].szSound); } - #endif +#endif return false; } static int Sound_Equip(int client, int id) { - int m_iData = Store_GetDataIndex(id); + int m_iData = Store_GetDataIndex(id); g_iSoundClient[client] = m_iData; return 0; } @@ -136,52 +141,47 @@ static int Sound_Remove(int client, int id) void Sound_OnClientConnected(int client) { - g_iSoundClient[client] = -1; + g_iSoundClient[client] = -1; g_bClientDisable[client] = false; } public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs) { - if(client <= 0) + if (client <= 0) return; - if(!IsClientInGame(client)) + if (!IsClientInGame(client)) return; - if(g_iSoundClient[client] < 0) + if (g_iSoundClient[client] < 0) return; - if(sArgs[0] == '!' || sArgs[0] == '/' || sArgs[0] == '@') + if (sArgs[0] == '!' || sArgs[0] == '/' || sArgs[0] == '@') return; - if(g_iSoundSpam[client] > GetTime()) - return; + if (g_iSoundSpam[client] > GetTime()) + return; - if ( - StrContains(sArgs, "cheer", false) != -1 || - StrContains(sArgs, "lol", false) != -1 || - StrContains(sArgs, "233", false) != -1 || - StrContains(sArgs, "hah", false) != -1 || - StrContains(sArgs, "hhh", false) != -1 - ) - { - g_iSoundSpam[client] = GetTime() + g_eSounds[g_iSoundClient[client]].iCooldown; - StartSoundToAll(client); - } + if ( + StrContains(sArgs, "cheer", false) != -1 || StrContains(sArgs, "lol", false) != -1 || StrContains(sArgs, "233", false) != -1 || StrContains(sArgs, "hah", false) != -1 || StrContains(sArgs, "hhh", false) != -1) + { + g_iSoundSpam[client] = GetTime() + g_eSounds[g_iSoundClient[client]].iCooldown; + StartSoundToAll(client); + } } public Action Command_Cheer(int client, int args) { - if(!IsValidClient(client)) + if (!IsValidClient(client)) return Plugin_Handled; - if(g_iSoundSpam[client] > GetTime()) + if (g_iSoundSpam[client] > GetTime()) { tPrintToChat(client, "%T", "sound cooldown", client); return Plugin_Handled; } - if(g_iSoundClient[client] < 0) + if (g_iSoundClient[client] < 0) { if (!StartNullSound(client)) tPrintToChat(client, "%T", "sound no equip", client); @@ -195,8 +195,8 @@ public Action Command_Cheer(int client, int args) bool StartNullSound(int client) { - bool res = false; - int cooldown = 30; + bool res = false; + int cooldown = 30; Call_StartForward(g_hOnCheerCommand); Call_PushCell(client); @@ -215,16 +215,16 @@ void StartSoundToAll(int client) { char sound[256], name[64]; strcopy(STRING(sound), g_eSounds[g_iSoundClient[client]].szSound); - strcopy(STRING(name), g_eSounds[g_iSoundClient[client]].szName); + strcopy(STRING(name), g_eSounds[g_iSoundClient[client]].szName); - float volume = g_eSounds[g_iSoundClient[client]].fVolume; - int cooldown = g_eSounds[g_iSoundClient[client]].iCooldown; + float volume = g_eSounds[g_iSoundClient[client]].fVolume; + int cooldown = g_eSounds[g_iSoundClient[client]].iCooldown; Action res = Plugin_Continue; Call_StartForward(g_hOnCheerSound); Call_PushCell(client); - Call_PushStringEx(STRING(sound), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); - Call_PushStringEx(STRING(name), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(STRING(sound), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(STRING(name), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_PushFloatRef(volume); Call_PushCellRef(cooldown); Call_Finish(res); @@ -239,7 +239,7 @@ void StartSoundToAll(int client) { // copy again strcopy(STRING(sound), g_eSounds[g_iSoundClient[client]].szSound); - strcopy(STRING(name), g_eSounds[g_iSoundClient[client]].szName); + strcopy(STRING(name), g_eSounds[g_iSoundClient[client]].szName); volume = g_eSounds[g_iSoundClient[client]].fVolume; } @@ -251,20 +251,22 @@ void StartSoundToAll(int client) #if defined GM_ZE int players[MAXPLAYERS], total; - for (int i=1; i <= MaxClients; i++) if (IsClientInGame(i) && !IsFakeClient(i) && i != client) - { - if (g_bClientDisable[i]) - continue; + for (int i = 1; i <= MaxClients; i++) + if (IsClientInGame(i) && !IsFakeClient(i) && i != client) + { + if (g_bClientDisable[i]) + continue; - players[total++] = i; - } + players[total++] = i; + } EmitSound(players, total, szPath, client, SNDCHAN_VOICE, _, _, volume, _, client); #else if (IsPlayerAlive(client)) { float fPos[3]; - GetClientEyePosition(client, fPos); fPos[2] -= 3.0; + GetClientEyePosition(client, fPos); + fPos[2] -= 3.0; float fAgl[3]; GetClientEyeAngles(client, fAgl); @@ -274,12 +276,13 @@ void StartSoundToAll(int client) { TransmitManager_AddEntityHooks(speaker); TransmitManager_SetEntityOwner(speaker, client); - //PrintToChatAll("transmit speaker %d :: %N", speaker, client); + // PrintToChatAll("transmit speaker %d :: %N", speaker, client); - for (int i=1; i <= MaxClients; i++) if (IsClientInGame(i) && i != client) - { - TransmitManager_SetEntityState(speaker, i, false); - } + for (int i = 1; i <= MaxClients; i++) + if (IsClientInGame(i) && i != client) + { + TransmitManager_SetEntityState(speaker, i, false); + } } SetVariantString("!activator"); @@ -287,49 +290,51 @@ void StartSoundToAll(int client) SetVariantString("facemask"); AcceptEntityInput(speaker, "SetParentAttachment"); - //PrintToChatAll("attach speaker %d :: %N", speaker, client); - - for (int i=1; i <= MaxClients; i++) if (IsClientInGame(i) && i != client && !IsFakeClient(i)) - { - // stoppable - if (g_bClientDisable[i]) - { - //PrintToChatAll("stop speaker %N -> %N", client, i); - continue; - } + // PrintToChatAll("attach speaker %d :: %N", speaker, client); - if (g_pTransmit) + for (int i = 1; i <= MaxClients; i++) + if (IsClientInGame(i) && i != client && !IsFakeClient(i)) { - if (TransmitManager_GetEntityState(client, i)) + // stoppable + if (g_bClientDisable[i]) { - // don't transmit - TransmitManager_SetEntityState(speaker, i, true); + // PrintToChatAll("stop speaker %N -> %N", client, i); + continue; } - else + + if (g_pTransmit) { - EmitSoundToClient(i, szPath, client, SNDCHAN_VOICE, _, _, volume, _, client); - //PrintToChatAll("emit self speaker %N -> %N", client, i); - continue; + if (TransmitManager_GetEntityState(client, i)) + { + // don't transmit + TransmitManager_SetEntityState(speaker, i, true); + } + else + { + EmitSoundToClient(i, szPath, client, SNDCHAN_VOICE, _, _, volume, _, client); + // PrintToChatAll("emit self speaker %N -> %N", client, i); + continue; + } } - } - //PrintToChatAll("emit global speaker %N -> %N", client, i); - EmitSoundToClient(i, szPath, speaker, SNDCHAN_VOICE, _, _, volume, _, speaker); - } + // PrintToChatAll("emit global speaker %N -> %N", client, i); + EmitSoundToClient(i, szPath, speaker, SNDCHAN_VOICE, _, _, volume, _, speaker); + } } else { - for (int i=1; i <= MaxClients; i++) if (IsClientInGame(i) && i != client && !IsFakeClient(i)) - { - // stoppable - if (g_bClientDisable[i]) + for (int i = 1; i <= MaxClients; i++) + if (IsClientInGame(i) && i != client && !IsFakeClient(i)) { - //PrintToChatAll("stop speaker %N -> %N", client, i); - continue; - } + // stoppable + if (g_bClientDisable[i]) + { + // PrintToChatAll("stop speaker %N -> %N", client, i); + continue; + } - EmitSoundToClient(i, szPath, SOUND_FROM_WORLD, SNDCHAN_VOICE, _, _, volume); - } + EmitSoundToClient(i, szPath, SOUND_FROM_WORLD, SNDCHAN_VOICE, _, _, volume); + } } #endif @@ -338,18 +343,18 @@ void StartSoundToAll(int client) public void Sounds_OnLoadOptions(int client) { - if(g_pfysOptions) + if (g_pfysOptions) { g_bClientDisable[client] = Opts_GetOptBool(client, SOUND_COOKIE_NAME, false); return; } - if(g_pClientprefs) + if (g_pClientprefs) { char buff[4]; GetClientCookie(client, g_hCookieSounds, STRING(buff)); - if(buff[0] != 0) + if (buff[0] != 0) g_bClientDisable[client] = (StringToInt(buff) == 1 ? true : false); } } @@ -368,11 +373,11 @@ public Action Command_Silence(int client, int args) static void SetSoundState(int client, bool state) { - if(g_pfysOptions) + if (g_pfysOptions) { Opts_SetOptBool(client, SOUND_COOKIE_NAME, state); } - else if(g_pClientprefs) + else if (g_pClientprefs) { SetClientCookie(client, g_hCookieSounds, state ? "1" : "0"); } diff --git a/store/sprays.sp b/store/sprays.sp index 7347afb..0396a26 100644 --- a/store/sprays.sp +++ b/store/sprays.sp @@ -1,13 +1,18 @@ +// MAIN_FILE ../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #define Module_Spray // options -static char g_szSprays[STORE_MAX_ITEMS][256]; -static char g_szSprayName[STORE_MAX_ITEMS][256]; -static int g_iSprayCooldown[STORE_MAX_ITEMS] = {30,...}; -static int g_iSprayPrecache[STORE_MAX_ITEMS] = {-1,...}; -static int g_iSprayCache[MAXPLAYERS+1] = {-1,...}; -static int g_iSprayLimit[MAXPLAYERS+1] = {0,...}; -static int g_iSprays = 0; +static char g_szSprays[STORE_MAX_ITEMS][PLATFORM_MAX_PATH]; +static char g_szSprayName[STORE_MAX_ITEMS][PLATFORM_MAX_PATH]; +static int g_iSprayCooldown[STORE_MAX_ITEMS] = { 30, ... }; +static int g_iSprayPrecache[STORE_MAX_ITEMS] = { -1, ... }; +static int g_iSprayCache[MAXPLAYERS + 1] = { -1, ... }; +static int g_iSprayLimit[MAXPLAYERS + 1] = { 0, ... }; +static int g_iSprays = 0; static Handle g_fwdOnClientSpray; static Handle g_hOnSprayCommand; static Handle g_hOnSprayModel; @@ -21,8 +26,8 @@ public void Sprays_OnPluginStart() Store_RegisterHandler("spray", Sprays_OnMapStart, Sprays_Reset, Sprays_Config, Sprays_Equip, Sprays_Remove, true); g_fwdOnClientSpray = CreateGlobalForward("Store_OnClientSpray", ET_Ignore, Param_Cell); - g_hOnSprayCommand = CreateGlobalForward("Store_OnSprayCommand", ET_Hook, Param_Cell, Param_CellByRef); - g_hOnSprayModel = CreateGlobalForward("Store_OnSprayModel", ET_Hook, Param_Cell, Param_String, Param_String, Param_CellByRef, Param_CellByRef); + g_hOnSprayCommand = CreateGlobalForward("Store_OnSprayCommand", ET_Hook, Param_Cell, Param_CellByRef); + g_hOnSprayModel = CreateGlobalForward("Store_OnSprayModel", ET_Hook, Param_Cell, Param_String, Param_String, Param_CellByRef, Param_CellByRef); RegConsoleCmd("spray", Command_Spray); RegConsoleCmd("sprays", Command_Spray); @@ -32,24 +37,24 @@ static void Sprays_OnMapStart() { g_bFallbackSprayerSound = false; - char m_szDecal[256]; + char m_szDecal[PLATFORM_MAX_PATH]; - for(int i = 0; i < g_iSprays; ++i) - if(FileExists(g_szSprays[i], true)) - { - strcopy(STRING(m_szDecal), g_szSprays[i][10]); - m_szDecal[strlen(m_szDecal)-4]=0; + for (int i = 0; i < g_iSprays; ++i) + if (FileExists(g_szSprays[i], true)) + { + strcopy(STRING(m_szDecal), g_szSprays[i][10]); + m_szDecal[strlen(m_szDecal) - 4] = 0; - g_iSprayPrecache[i] = PrecacheDecal(m_szDecal, true); - AddFileToDownloadsTable(g_szSprays[i]); - } + g_iSprayPrecache[i] = PrecacheDecal(m_szDecal, true); + AddFileToDownloadsTable(g_szSprays[i]); + } PrecacheSound("items/spraycan_spray.wav", false); if (FileExists("sound/" ... FALLBACK_SPARYER_SOUND, false)) { g_bFallbackSprayerSound = true; - AddToStringTable(FindStringTable("soundprecache"), ")"...FALLBACK_SPARYER_SOUND); + AddToStringTable(FindStringTable("soundprecache"), ")" ... FALLBACK_SPARYER_SOUND); AddFileToDownloadsTable("sound/" ... FALLBACK_SPARYER_SOUND); } } @@ -66,13 +71,13 @@ public void Spray_OnClientDeath(int client) static Action Command_Spray(int client, int args) { - if(g_iSprayLimit[client] > GetTime()) + if (g_iSprayLimit[client] > GetTime()) { tPrintToChat(client, "%T", "spray cooldown", client); return Plugin_Handled; } - if(g_iSprayCache[client] < 0) + if (g_iSprayCache[client] < 0) { if (!StartNullSpray(client)) tPrintToChat(client, "%T", "spray no equip", client); @@ -86,8 +91,8 @@ static Action Command_Spray(int client, int args) bool StartNullSpray(int client) { - bool res = false; - int cooldown = 60; + bool res = false; + int cooldown = 60; Call_StartForward(g_hOnSprayCommand); Call_PushCell(client); @@ -114,13 +119,13 @@ static bool Sprays_Config(KeyValues kv, int itemid) kv.GetString("name", g_szSprayName[g_iSprays], sizeof(g_szSprayName[])); g_iSprayCooldown[g_iSprays] = kv.GetNum("cooldown", 30); - if(FileExists(g_szSprays[g_iSprays], true)) + if (FileExists(g_szSprays[g_iSprays], true)) { ++g_iSprays; return true; } - #if defined LOG_NOT_FOUND +#if defined LOG_NOT_FOUND // missing model char auth[32], name[32]; kv.GetString("auth", auth, 32); @@ -133,27 +138,27 @@ static bool Sprays_Config(KeyValues kv, int itemid) { LogMessage("Skipped spray <%s> -> [%s]", name, g_szSprays[g_iSprays]); } - #endif +#endif return false; } static int Sprays_Equip(int client, int id) { - int m_iData = Store_GetDataIndex(id); + int m_iData = Store_GetDataIndex(id); g_iSprayCache[client] = m_iData; return 0; } static int Sprays_Remove(int client, int id) { - g_iSprayCache[client]=-1; + g_iSprayCache[client] = -1; return 0; } void Sprays_Create(int client) { - if(!IsPlayerAlive(client)) + if (!IsPlayerAlive(client)) return; float m_flEye[3]; @@ -164,7 +169,7 @@ void Sprays_Create(int client) float distance = GetVectorDistance(m_flEye, m_flView); - if(distance > 115.0) + if (distance > 115.0) { tPrintToChat(client, "%T", "spray distance", client); return; @@ -179,9 +184,9 @@ void Sprays_Create(int client) void StartSprayToAll(int client, const float vPos[3]) { - char model[256], name[64]; + char model[PLATFORM_MAX_PATH], name[64]; strcopy(STRING(model), g_szSprays[g_iSprayCache[client]]); - strcopy(STRING(name), g_szSprayName[g_iSprayCache[client]]); + strcopy(STRING(name), g_szSprayName[g_iSprayCache[client]]); int precache = g_iSprayPrecache[g_iSprayCache[client]]; int cooldown = g_iSprayCooldown[g_iSprayCache[client]]; @@ -189,8 +194,8 @@ void StartSprayToAll(int client, const float vPos[3]) Action res = Plugin_Continue; Call_StartForward(g_hOnSprayModel); Call_PushCell(client); - Call_PushStringEx(STRING(model), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); - Call_PushStringEx(STRING(name), SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(STRING(model), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushStringEx(STRING(name), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_PushCellRef(precache); Call_PushCellRef(cooldown); Call_Finish(res); @@ -215,7 +220,7 @@ void StartSprayToAll(int client, const float vPos[3]) if (g_bFallbackSprayerSound) { - EmitSoundToAll(")"...FALLBACK_SPARYER_SOUND, client); + EmitSoundToAll(")" ... FALLBACK_SPARYER_SOUND, client); } else { @@ -242,20 +247,20 @@ void GetPlayerEyeViewPoint(int client, float m_fPosition[3]) // use for TE hook World decals bool Spray_IsSpray(int index) { - for(int i = 0; i < g_iSprays; ++i) - if (g_iSprayPrecache[i] == index) - return true; + for (int i = 0; i < g_iSprays; ++i) + if (g_iSprayPrecache[i] == index) + return true; return false; } void Spray_OnRunCmd(int client, int &buttons) { - if(g_iSprayCache[client] == -1 || !IsPlayerAlive(client)) + if (g_iSprayCache[client] == -1 || !IsPlayerAlive(client)) return; - static int lastUse[MAXPLAYERS+1]; - int time = GetTime(); + static int lastUse[MAXPLAYERS + 1]; + int time = GetTime(); if (time == lastUse[client]) return; diff --git a/store/tpmode.sp b/store/tpmode.sp index bbce4b4..aac0dcf 100644 --- a/store/tpmode.sp +++ b/store/tpmode.sp @@ -1,3 +1,8 @@ +// MAIN_FILE ../store.sp + +#pragma semicolon 1 +#pragma newdecls required + #if defined GM_ZE || defined GM_KZ || defined GM_BH || defined GM_SR || defined GM_TT #define Module_TPMode #endif From 07ebd6c861073d027f1815851337f3543dbd9677 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 5 Aug 2023 15:39:51 +0800 Subject: [PATCH 02/15] init local build environment --- .github/workflows/build.yml | 26 +++++++++++++------------- store.sp | 3 +++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8ff38e5..68c0e81 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,7 @@ jobs: cp store.sp store_tt.sp for file in store_tt.sp do - sed -i "s%%GM_TT%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_TT%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core TTT..." @@ -62,7 +62,7 @@ jobs: cp store.sp store_ze.sp for file in store_ze.sp do - sed -i "s%%GM_ZE%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_ZE%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core ZE..." @@ -74,7 +74,7 @@ jobs: cp store.sp store_mg.sp for file in store_mg.sp do - sed -i "s%%GM_MG%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_MG%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core MG..." @@ -86,7 +86,7 @@ jobs: cp store.sp store_jb.sp for file in store_jb.sp do - sed -i "s%%GM_JB%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_JB%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core JB..." @@ -98,7 +98,7 @@ jobs: cp store.sp store_kz.sp for file in store_kz.sp do - sed -i "s%%GM_KZ%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_KZ%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core KZ..." @@ -110,7 +110,7 @@ jobs: cp store.sp store_pr.sp for file in store_pr.sp do - sed -i "s%%GM_PR%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_PR%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core Pure..." @@ -122,7 +122,7 @@ jobs: cp store.sp store_hg.sp for file in store_hg.sp do - sed -i "s%%GM_HG%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_HG%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core HG..." @@ -134,7 +134,7 @@ jobs: cp store.sp store_sr.sp for file in store_sr.sp do - sed -i "s%%GM_SR%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_SR%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core Surf..." @@ -146,7 +146,7 @@ jobs: cp store.sp store_hz.sp for file in store_hz.sp do - sed -i "s%%GM_HZ%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_HZ%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core Warcraft..." @@ -158,7 +158,7 @@ jobs: cp store.sp store_bh.sp for file in store_bh.sp do - sed -i "s%%GM_BH%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_BH%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core BHOP..." @@ -170,7 +170,7 @@ jobs: cp store.sp store_is.sp for file in store_is.sp do - sed -i "s%%GM_IS%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_IS%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core Insurgency" @@ -182,7 +182,7 @@ jobs: cp store.sp store_ef.sp for file in store_ef.sp do - sed -i "s%%GM_EF%g" $file > output.txt + sed -i "s%COMPILE_ENVIRONMENT%GM_EF%g" $file > output.txt rm output.txt done echo -e "\nCompiling Core Left 4 Dead(2)..." @@ -229,4 +229,4 @@ jobs: RSYNC_PASSWORD=${{secrets.RSYNC_PSWD}} rsync -avz ./build/plugins/*.smx rsync://${{secrets.RSYNC_USER}}@${{secrets.RSYNC_HOST}}:${{secrets.RSYNC_PORT}}/${{secrets.RSYNC_PATH}}/_Raw/ RSYNC_PASSWORD=${{secrets.RSYNC_PSWD}} rsync -avz ./build/plugins/modules/*.smx rsync://${{secrets.RSYNC_USER}}@${{secrets.RSYNC_HOST}}:${{secrets.RSYNC_PORT}}/${{secrets.RSYNC_PATH}}/_Raw/ RSYNC_PASSWORD=${{secrets.RSYNC_PSWD}} rsync -avz ./build/translations/store.phrases.txt rsync://${{secrets.RSYNC_USER}}@${{secrets.RSYNC_HOST}}:${{secrets.RSYNC_PORT}}/${{secrets.RSYNC_PATH}}/_Raw/translations/ - + diff --git a/store.sp b/store.sp index b83b4dc..cc61959 100644 --- a/store.sp +++ b/store.sp @@ -21,6 +21,8 @@ #define REQUIRE_EXTENSIONS #define REQUIRE_PLUGIN +// local build compile environment +#tryinclude ////////////////////////////// // PLUGIN DEFINITION // ////////////////////////////// @@ -43,6 +45,7 @@ public Plugin myinfo = // Server #define +#define COMPILE_ENVIRONMENT // GM_TT -> ttt server // GM_ZE -> zombie escape server // GM_MG -> mini games server From b2c97cf0879c8a7eec772727c1590772e8a3afaa Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 5 Aug 2023 15:51:51 +0800 Subject: [PATCH 03/15] refactor skin module --- store.sp | 65 +++++--- store/cpsupport.sp | 8 +- store/modules/aura.sp | 2 +- store/modules/hats.sp | 6 +- store/modules/neon.sp | 2 +- store/modules/part.sp | 2 +- store/modules/skin.sp | 363 +++++++++++++++++++++++++---------------- store/modules/trail.sp | 2 +- store/players.sp | 139 ++++++++++------ store/sounds.sp | 6 +- store/tpmode.sp | 4 +- 11 files changed, 369 insertions(+), 230 deletions(-) diff --git a/store.sp b/store.sp index cc61959..0635319 100644 --- a/store.sp +++ b/store.sp @@ -5,11 +5,14 @@ // INCLUDES // ////////////////////////////// #include -#include -#include + #include #include +#include +#include +#include + #undef REQUIRE_EXTENSIONS #undef AUTOLOAD_EXTENSIONS #undef REQUIRE_PLUGIN @@ -23,6 +26,7 @@ // local build compile environment #tryinclude + ////////////////////////////// // PLUGIN DEFINITION // ////////////////////////////// @@ -43,8 +47,13 @@ public Plugin myinfo = #define abstract_struct enum struct #endif +#define TEAM_CT 3 +#define TEAM_TE 2 +#define TEAM_ZM 2 +#define TEAM_OB 1 +#define TEAM_US 0 + // Server -#define #define COMPILE_ENVIRONMENT // GM_TT -> ttt server // GM_ZE -> zombie escape server @@ -122,7 +131,6 @@ int g_iSelectedPlan[MAXPLAYERS + 1]; int g_iMenuNum[MAXPLAYERS + 1]; int g_iSpam[MAXPLAYERS + 1]; int g_iDataProtect[MAXPLAYERS + 1]; -int g_iClientTeam[MAXPLAYERS + 1]; bool g_bInvMode[MAXPLAYERS + 1]; @@ -1037,7 +1045,7 @@ static any Native_ExtClientItem(Handle myself, int numParams) static any Native_GetSkinLevel(Handle myself, int numParams) { #if defined Module_Skin - return Store_GetPlayerSkinLevel(GetNativeCell(1)); + return Skin_GetPlayerSkinLevel(GetNativeCell(1)); #else return 0; #endif @@ -1062,9 +1070,9 @@ static any Native_HasPlayerSkin(Handle myself, int numParams) #if defined Module_Skin int client = GetNativeCell(1); - char model[2][192]; - Store_GetClientSkinModel(client, model[0], 192); - Store_GetPlayerSkinModel(client, model[1], 192); + char model[2][PLATFORM_MAX_PATH]; + Skin_GetClientSkinModel(client, model[0], sizeof(model[])); + Skin_GetPlayerSkinModel(client, model[1], sizeof(model[])); return (StrContains(model[1], "#default") == -1 && StrContains(model[1], "#zombie") == -1 && StrContains(model[0], "models/player/custom_player/legacy/") == -1); #else @@ -1078,8 +1086,8 @@ static any Native_GetPlayerSkin(Handle myself, int numParams) int client = GetNativeCell(1); char model[2][192]; - Store_GetClientSkinModel(client, model[0], 192); - Store_GetPlayerSkinModel(client, model[1], 192); + Skin_GetClientSkinModel(client, model[0], 192); + Skin_GetPlayerSkinModel(client, model[1], 192); if (StrContains(model[1], "#default") != -1 || StrContains(model[1], "#zombie") != -1 || StrContains(model[0], "models/player/custom_player/legacy/") != -1) return false; @@ -1108,7 +1116,7 @@ static any Native_GetClientPlayerSkins(Handle myself, int numParmas) { char m[128], a[128]; int b, t; - if (g_Items[i].iHandler == handler && Store_HasClientItem(client, i) && GetSkinData(i, m, a, b, t)) + if (g_Items[i].iHandler == handler && Store_HasClientItem(client, i) && Skin_GetSkinData(i, m, a, b, t)) { SkinData_t s; strcopy(s.m_Name, sizeof(SkinData_t::m_Name), g_Items[i].szName); @@ -1144,7 +1152,7 @@ static any Native_GetAllPlayerSkins(Handle myself, int numParams) { char m[128], a[128]; int b, t; - if (g_Items[i].iHandler == handler && GetSkinData(i, m, a, b, t)) + if (g_Items[i].iHandler == handler && Skin_GetSkinData(i, m, a, b, t)) { SkinData_t s; strcopy(s.m_Name, sizeof(SkinData_t::m_Name), g_Items[i].szName); @@ -1167,9 +1175,9 @@ static any Native_ApplyPlayerSkin(Handle myself, int numParams) { #if defined Module_Skin int client = GetNativeCell(1); - Store_RemoveClientGloves(client, -1); - Store_ResetPlayerSkin(client); - Store_PreSetClientModel(client); + Skin_RemoveClientGloves(client, -1); + Skin_ResetPlayerSkin(client); + Skin_SetClientSkin(client); return true; #else return false; @@ -1189,7 +1197,7 @@ static any Native_GetEquippedSkin(Handle myself, int numParams) char m[128], a[128]; int b, t; - if (!GetSkinData(itemId, m, a, b, t)) + if (!Skin_GetSkinData(itemId, m, a, b, t)) return false; SetNativeCellRef(7, b); @@ -1244,7 +1252,7 @@ static any Native_LogOpenCase(Handle plugin, int numParams) static any Native_InDeathCamera(Handle plugin, int numParams) { #if defined Module_Skin - return IsInDeathCamera(GetNativeCell(1)); + return Skin_IsInDeathCamera(GetNativeCell(1)); #else return false; #endif @@ -1265,7 +1273,6 @@ static any Native_IsGlobalTeam(Handle plugin, int numParams) public void OnClientConnected(int client) { g_iSpam[client] = 0; - g_iClientTeam[client] = 0; g_iClientCase[client] = 1; g_iDataProtect[client] = GetTime() + 300; @@ -1298,6 +1305,13 @@ public void OnClientConnected(int client) TPMode_OnClientConnected(client); } +public void OnClientPutInServer(int client) +{ +#if defined Module_Player + Players_OnClientPutInServer(client); +#endif +} + public void OnClientPostAdminCheck(int client) { if (IsFakeClient(client)) @@ -1835,7 +1849,7 @@ static int MenuHandler_Preview(Menu menu, MenuAction action, int client, int par else if (selected == 2) { #if defined Module_Skin - Store_PreviewSkin(client, m_iId); + Skin_PreviewSkin(client, m_iId); DisplayPreviewMenu(client, m_iId); #else DisplayPreviewMenu(client, m_iId); @@ -3021,7 +3035,12 @@ static void SQLCallback_Connection(Database db, const char[] error, int retry) OnClientConnected(client); - if (!IsClientInGame(client) || !IsClientAuthorized(client)) + if (!IsClientInGame(client)) + continue; + + OnClientPutInServer(client); + + if (!IsClientAuthorized(client)) continue; OnClientPostAdminCheck(client); @@ -4428,18 +4447,18 @@ static void OnPlayerDeath(Event event, const char[] name, bool dontBroadcast) int client = GetClientOfUserId(event.GetInt("userid")); #if defined Module_Spray || defined Module_Sound - int attacker = GetClientOfUserId(event.GetInt("attacker")); + int killer = GetClientOfUserId(event.GetInt("attacker")); #endif ToggleTp(client, false); CheckMirror(client); #if defined Module_Spray - Spray_OnClientDeath(attacker); + Spray_OnClientDeath(killer); #endif #if defined Module_Sound - Sound_OnClientDeath(client, attacker); + Sound_OnClientDeath(client, killer); #endif } diff --git a/store/cpsupport.sp b/store/cpsupport.sp index ebd7a37..418861a 100644 --- a/store/cpsupport.sp +++ b/store/cpsupport.sp @@ -433,10 +433,10 @@ public Action OnSayText2(UserMsg msg_id, Protobuf msg, const int[] players, int #if !defined USE_BF if (strcmp(m_szNameCopy, m_szName) == 0) { - switch (g_iClientTeam[m_iSender]) + switch (GetClientTeam(m_iSender)) { - case 3: Format(STRING(m_szName), "\x0B%s", m_szName); - case 2: Format(STRING(m_szName), "\x05%s", m_szName); + case TEAM_CT: Format(STRING(m_szName), "\x0B%s", m_szName); + case TEAM_TE: Format(STRING(m_szName), "\x05%s", m_szName); default: Format(STRING(m_szName), "\x01%s", m_szName); } } @@ -508,7 +508,7 @@ void Frame_OnChatMessage_SayText2(DataPack data) if (processColor) { - ReplaceColorsCode(STRING(m_szBuffer), g_iClientTeam[m_iSender]); + ReplaceColorsCode(STRING(m_szBuffer), GetClientTeam(m_iSender)); } #if defined USE_BF diff --git a/store/modules/aura.sp b/store/modules/aura.sp index 1373c3b..b9c1a40 100644 --- a/store/modules/aura.sp +++ b/store/modules/aura.sp @@ -107,7 +107,7 @@ void Store_SetClientAura(int client) Store_RemoveClientAura(client); #if defined GM_ZE - if (g_iClientTeam[client] == 2) + if (GetClientTeam(client) == TEAM_ZM) return; #endif diff --git a/store/modules/hats.sp b/store/modules/hats.sp index dc21ee2..e13fc72 100644 --- a/store/modules/hats.sp +++ b/store/modules/hats.sp @@ -121,7 +121,7 @@ int Hats_Remove(int client, int id) return g_eHats[m_iData].iSlot; } -void Store_SetClientHat(int client) +void Hat_SetClientHat(int client) { for (int i = 0; i < STORE_MAX_SLOTS; ++i) { @@ -139,13 +139,13 @@ static void CreateHat(int client, int itemid = -1, int slot = 0) int m_iData = Store_GetDataIndex(m_iEquipped); #if defined GM_ZE - if (g_iClientTeam[client] == 2) + if (GetClientTeam(client) == TEAM_ZM) return; #endif #if !defined Global_Skin // if not in global team mode, we chose team - if (g_eHats[m_iData].iTeam > 0 && g_iClientTeam[client] != g_eHats[m_iData].iTeam) + if (g_eHats[m_iData].iTeam > TEAM_US && GetClientTeam(client) != g_eHats[m_iData].iTeam) return; #endif diff --git a/store/modules/neon.sp b/store/modules/neon.sp index cc00409..1667a91 100644 --- a/store/modules/neon.sp +++ b/store/modules/neon.sp @@ -79,7 +79,7 @@ void Store_SetClientNeon(int client) Store_RemoveClientNeon(client); #if defined GM_ZE - if (g_iClientTeam[client] == 2) + if (GetClientTeam(client) == TEAM_ZM) return; #endif diff --git a/store/modules/part.sp b/store/modules/part.sp index 46c0bbd..9eaedc5 100644 --- a/store/modules/part.sp +++ b/store/modules/part.sp @@ -104,7 +104,7 @@ void Store_SetClientPart(int client) Store_RemoveClientPart(client); #if defined GM_ZE - if (g_iClientTeam[client] == 2) + if (GetClientTeam(client) == TEAM_ZM) return; #endif diff --git a/store/modules/skin.sp b/store/modules/skin.sp index 1f12dca..85eba66 100644 --- a/store/modules/skin.sp +++ b/store/modules/skin.sp @@ -15,6 +15,19 @@ abstract_struct PlayerSkin int nBody; } +enum +{ + OBS_MODE_NONE = 0, // not in spectator mode + OBS_MODE_DEATHCAM, // special mode for death cam animation + OBS_MODE_FREEZECAM, // zooms to a target, and freeze-frames on them + OBS_MODE_FIXED, // view from a fixed camera position + OBS_MODE_IN_EYE, // follow a player in first person view + OBS_MODE_CHASE, // follow a player in third person view + OBS_MODE_ROAMING, // free roaming + + NUM_OBSERVER_MODES, +}; + static PlayerSkin g_ePlayerSkins[STORE_MAX_ITEMS]; static bool g_bSoundHooked; @@ -33,6 +46,7 @@ static ConVar spec_replay_enable; static ConVar store_firstperson_death_camera; Handle g_tKillPreview[MAXPLAYERS + 1]; +Handle g_tResetCamera[MAXPLAYERS + 1]; Handle g_hOnPlayerSkinDefault = null; Handle g_hOnPlayerSetModel = null; @@ -62,22 +76,22 @@ void Skin_OnPluginStart() mp_round_restart_delay = FindConVar("mp_round_restart_delay"); spec_replay_enable = FindConVar("spec_replay_enable"); - spec_freeze_time.AddChangeHook(Skin_OnConVarChanged); - sv_disablefreezecam.AddChangeHook(Skin_OnConVarChanged); - mp_round_restart_delay.AddChangeHook(Skin_OnConVarChanged); - spec_replay_enable.AddChangeHook(Skin_OnConVarChanged); - spec_freeze_time.SetFloat(-1.0, true, true); sv_disablefreezecam.SetBool(true, true, true); mp_round_restart_delay.SetFloat(8.0, true, true); spec_replay_enable.SetBool(false, true, true); + spec_freeze_time.AddChangeHook(OnOtherConVarChanged); + sv_disablefreezecam.AddChangeHook(OnOtherConVarChanged); + mp_round_restart_delay.AddChangeHook(OnOtherConVarChanged); + spec_replay_enable.AddChangeHook(OnOtherConVarChanged); + // DEATH CAMERA CCVAR store_firstperson_death_camera.SetBool(true, true, true); - store_firstperson_death_camera.AddChangeHook(FPD_OnConVarChanged); + store_firstperson_death_camera.AddChangeHook(OnCameraConVarChanged); } -public void FPD_OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue) +static void OnCameraConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue) { if (StringToInt(newValue) == 0) { @@ -95,7 +109,7 @@ public void FPD_OnConVarChanged(ConVar convar, const char[] oldValue, const char } } -public void Skin_OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue) +static void OnOtherConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue) { if (store_firstperson_death_camera.BoolValue) { @@ -127,31 +141,65 @@ public void Skin_OnConVarChanged(ConVar convar, const char[] oldValue, const cha } } +void Skin_OnClientPutInServer(int client, DynamicHook pHook) +{ + if (pHook == null) + return; + + pHook.HookEntity(Hook_Pre, client, Hook_OnSetModel); + pHook.HookEntity(Hook_Post, client, Hook_OnSetModelPost); +} + void Skin_OnClientDisconnect(int client) { if (g_tKillPreview[client] != null) TriggerTimer(g_tKillPreview[client], false); - if (g_iCameraRef[client] != INVALID_ENT_REFERENCE) - Timer_ClearCamera(null, client); + if (g_tResetCamera[client] != null) + TriggerTimer(g_tResetCamera[client], false); +} + +static MRESReturn Hook_OnSetModel(int client, DHookParam hParams) +{ + if (IsPlayerSpawing(client)) + { + // char model[PLATFORM_MAX_PATH]; + // hParams.GetString(1, model, sizeof(model)); + // PrintToServer("Blocking %N SetModel -> %s", client, model); + return MRES_Supercede; + } + + return MRES_Ignored; +} + +static MRESReturn Hook_OnSetModelPost(int client, DHookParam hParams) +{ + char model[PLATFORM_MAX_PATH]; + hParams.GetString(1, model, sizeof(model)); + if (strcmp(model, g_szSkinModel[client]) != 0) + Skin_ResetPlayerSkin(client); + + return MRES_Ignored; } -public Action Command_Arms(int client, int args) +static Action Command_Arms(int client, int args) { if (!client || !IsClientInGame(client) || !IsPlayerAlive(client)) return Plugin_Handled; #if defined GM_ZE - if (g_iClientTeam[client] == 2) + if (GetClientTeam(client) == TEAM_ZM) return Plugin_Handled; #endif - Store_PreSetClientModel(client); + Skin_RemoveClientGloves(client, -1); + Skin_ResetPlayerSkin(client); + Skin_SetClientSkin(client); return Plugin_Handled; } -public bool PlayerSkins_Config(KeyValues kv, int itemid) +static bool PlayerSkins_Config(KeyValues kv, int itemid) { Store_SetDataIndex(itemid, g_iPlayerSkins); @@ -196,7 +244,7 @@ public bool PlayerSkins_Config(KeyValues kv, int itemid) return true; } -public void PlayerSkins_OnMapStart() +static void PlayerSkins_OnMapStart() { int deathsounds = 0; char szPath[PLATFORM_MAX_PATH], szPathStar[PLATFORM_MAX_PATH]; @@ -243,12 +291,12 @@ void PlayerSkins_OnMapEnd() } } -public void PlayerSkins_Reset() +static void PlayerSkins_Reset() { g_iPlayerSkins = 0; } -public int PlayerSkins_Equip(int client, int id) +static int PlayerSkins_Equip(int client, int id) { if (IsClientInGame(client) && IsPlayerAlive(client)) tPrintToChat(client, "%T", "PlayerSkins Settings Changed", client); @@ -260,7 +308,7 @@ public int PlayerSkins_Equip(int client, int id) #endif } -public int PlayerSkins_Remove(int client, int id) +static int PlayerSkins_Remove(int client, int id) { if (IsClientInGame(client)) tPrintToChat(client, "%T", "PlayerSkins Settings Changed", client); @@ -272,40 +320,27 @@ public int PlayerSkins_Remove(int client, int id) #endif } -void Store_PreSetClientModel(int client) +void Skin_SetClientSkin(int client) { int m_iEquipped = GetEquippedSkin(client); if (m_iEquipped >= 0) { - CreateTimer(0.02, Timer_SetClientModel, client | (Store_GetDataIndex(m_iEquipped) << 7), TIMER_FLAG_NO_MAPCHANGE); - return; + SetClientInventorySkin(client, Store_GetDataIndex(m_iEquipped)); + } + else + { + SetClientDefaultSkin(client); } - - CreateTimer(0.02, Timer_SetDefaultModel, client, TIMER_FLAG_NO_MAPCHANGE); -} - -static Action Timer_SetDefaultModel(Handle timer, int client) -{ - if (!IsClientInGame(client) || !IsPlayerAlive(client)) - return Plugin_Stop; - - Store_CallDefaultSkin(client); - -#if defined Module_Hats - Store_SetClientHat(client); -#endif - - return Plugin_Stop; } -static void Store_SetClientModel(int client, int m_iData) +static void SetClientInventorySkin(int client, int index) { if (!IsClientInGame(client) || !IsPlayerAlive(client)) return; #if defined GM_ZE - if (g_iClientTeam[client] == 2) + if (GetClientTeam(client) == TEAM_ZM) { strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), "#zombie"); return; @@ -313,23 +348,23 @@ static void Store_SetClientModel(int client, int m_iData) #endif char skin_t[128], arms_t[128]; - strcopy(STRING(skin_t), g_ePlayerSkins[m_iData].szModel); - strcopy(STRING(arms_t), g_ePlayerSkins[m_iData].szArms); - int body_t = g_ePlayerSkins[m_iData].nBody; + strcopy(STRING(skin_t), g_ePlayerSkins[index].szModel); + strcopy(STRING(arms_t), g_ePlayerSkins[index].szArms); + int body_t = g_ePlayerSkins[index].nBody; - Action res = Store_CallPreSetModel(client, skin_t, arms_t, body_t); + Action res = CallPreSetModel(client, skin_t, arms_t, body_t); if (res >= Plugin_Handled) return; else if (res == Plugin_Changed) { // verify data index; - m_iData = FindDataIndexByModel(skin_t, body_t); - if (m_iData == -1) + index = FindDataIndexByModel(skin_t, body_t); + if (index == -1) return; } - if (g_ePlayerSkins[m_iData].szSound[0] != 0) - FormatEx(g_szDeathVoice[client], sizeof(g_szDeathVoice[]), "*%s", g_ePlayerSkins[m_iData].szSound); + if (g_ePlayerSkins[index].szSound[0] != 0) + FormatEx(g_szDeathVoice[client], sizeof(g_szDeathVoice[]), "*%s", g_ePlayerSkins[index].szSound); // basic player skin SetEntityModel(client, skin_t); @@ -339,15 +374,12 @@ static void Store_SetClientModel(int client, int m_iData) strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), skin_t); - if (!StrEqual(arms_t, "null")) + if (arms_t[0] && strcmp(arms_t, "null") != 0 && CallAllowSetPlayerSkinArms(client, STRING(arms_t))) { - if (Store_CallSetPlayerSkinArms(client, STRING(arms_t))) - { - Store_SetClientArms(client, arms_t); - } + SetClientArms(client, arms_t); } - g_iSkinLevel[client] = g_ePlayerSkins[m_iData].iLevel; + g_iSkinLevel[client] = g_ePlayerSkins[index].iLevel; Call_StartForward(g_hOnPlayerSetModelPost); Call_PushCell(client); @@ -355,19 +387,9 @@ static void Store_SetClientModel(int client, int m_iData) Call_PushString(arms_t); Call_PushCell(body_t); Call_Finish(); - -#if defined Module_Hats - Store_SetClientHat(client); -#endif -} - -public Action Timer_SetClientModel(Handle timer, int val) -{ - Store_SetClientModel(val & 0x7f, val >> 7); - return Plugin_Stop; } -public Action Hook_NormalSound(int clients[64], int &numClients, char sample[PLATFORM_MAX_PATH], int &client, int &channel, float &volume, int &level, int &pitch, int &flags, char soundEntry[PLATFORM_MAX_PATH], int &seed) +static Action Hook_NormalSound(int clients[64], int &numClients, char sample[PLATFORM_MAX_PATH], int &client, int &channel, float &volume, int &level, int &pitch, int &flags, char soundEntry[PLATFORM_MAX_PATH], int &seed) { // not death sound if (channel != SNDCHAN_VOICE || sample[0] != '~') @@ -379,7 +401,7 @@ public Action Hook_NormalSound(int clients[64], int &numClients, char sample[PLA #if defined GM_ZE // ignore zombie - if (g_iClientTeam[client] == 2) + if (GetClientTeam(client) == TEAM_ZM) return Plugin_Continue; #endif @@ -398,7 +420,7 @@ public Action Hook_NormalSound(int clients[64], int &numClients, char sample[PLA return Plugin_Continue; } -void Broadcast_DeathSound(int client) +void Skin_BroadcastDeathSound(int client) { if (!IsClientInGame(client)) return; @@ -407,7 +429,7 @@ void Broadcast_DeathSound(int client) return; #if defined GM_ZE - if (g_iClientTeam[client] == 2) + if (GetClientTeam(client) == TEAM_ZM) return; #endif @@ -476,7 +498,7 @@ void Broadcast_DeathSound(int client) EmitSound(clients, counts, sound, speaker, SNDCHAN_VOICE, _, _, 1.0, _, speaker); } -void Store_PreviewSkin(int client, int itemid) +void Skin_PreviewSkin(int client, int itemid) { if (g_tKillPreview[client] != null) TriggerTimer(g_tKillPreview[client], false); @@ -583,7 +605,7 @@ static void SafeKillPreview(int client, int entity) g_iPreviewTimes[client] = GetTime() + 3; } -public Action Timer_KillPreview(Handle timer, int client) +static Action Timer_KillPreview(Handle timer, int client) { g_tKillPreview[client] = null; @@ -600,9 +622,9 @@ public Action Timer_KillPreview(Handle timer, int client) return Plugin_Stop; } -public void FirstPersonDeathCamera(int client) +void Skin_FirstPersonDeathCamera(int client) { - if (!IsClientInGame(client) || g_iClientTeam[client] < 2 || IsPlayerAlive(client)) + if (!IsClientInGame(client) || GetClientTeam(client) <= TEAM_OB || IsPlayerAlive(client)) return; if (!store_firstperson_death_camera.BoolValue) @@ -660,31 +682,30 @@ static bool SpawnCamAndAttach(int client, int ragdoll) FadeScreenBlack(client); - CreateTimer(6.0, Timer_ClearCamera, client); + g_tResetCamera[client] = CreateTimer(6.0, Timer_ClearCamera, client); return true; } -public Action Timer_ClearCamera(Handle timer, int client) +static Action Timer_ClearCamera(Handle timer, int client) { + g_tResetCamera[client] = null; + + // Fix screen + SetClientViewEntity(client, client); + FadeScreenWhite(client); + + // Remove entity if (g_iCameraRef[client] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iCameraRef[client]); - - if (entity > 0 && IsValidEdict(entity)) + if (entity > MaxClients) { RemoveEntity(entity); } - g_iCameraRef[client] = INVALID_ENT_REFERENCE; } - if (IsClientInGame(client)) - { - SetClientViewEntity(client, client); - FadeScreenWhite(client); - } - return Plugin_Stop; } @@ -718,20 +739,24 @@ void Skin_OnRunCmd(int client) { if (g_iCameraRef[client] == INVALID_ENT_REFERENCE) return; + if (IsPlayerAlive(client)) return; int m_iObserverMode = GetEntProp(client, Prop_Send, "m_iObserverMode"); - if (m_iObserverMode < 6) - SetEntProp(client, Prop_Send, "m_iObserverMode", 6); + if (m_iObserverMode < OBS_MODE_ROAMING) + SetEntProp(client, Prop_Send, "m_iObserverMode", OBS_MODE_ROAMING); } static int GetEquippedSkin(int client) { + if (IsFakeClient(client)) + return -1; + #if defined Global_Skin return Store_GetEquippedItem(client, "playerskin", 2); #else - return Store_GetEquippedItem(client, "playerskin", g_iClientTeam[client] - 2); + return Store_GetEquippedItem(client, "playerskin", GetClientTeam(client) - 2); #endif } @@ -747,51 +772,55 @@ public void ZR_OnClientHumanPost(int client, bool respawn, bool protect) if (!IsPlayerAlive(client)) return; - Store_PreSetClientModel(client); + Skin_SetClientSkin(client); } #endif -void Store_RemoveClientGloves(int client, int m_iData = -1) +void Skin_RemoveClientGloves(int client, int index = -1) { - if (m_iData == -1 && GetEquippedSkin(client) <= 0) + if (index == -1 && GetEquippedSkin(client) <= 0) return; int gloves = GetEntPropEnt(client, Prop_Send, "m_hMyWearables"); - if (gloves != -1) + if (gloves != INVALID_ENT_REFERENCE) AcceptEntityInput(gloves, "KillHierarchy"); } -void Store_OnPlayerSpawn(int client) +void Skin_OnPlayerSpawn(int client) { g_bShouldFireEvent[client] = false; -} -void Store_ResetPlayerSkin(int client) -{ - strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), "#default"); - g_iSkinLevel[client] = 0; - g_szDeathVoice[client][0] = '\0'; -} + int entity = EntRefToEntIndex(g_iCameraRef[client]); + if (entity > MaxClients) + RemoveEntity(entity); -int Store_GetPlayerSkinLevel(int client) -{ - return g_iSkinLevel[client]; -} + SetClientViewEntity(client, client); -void Store_GetClientSkinModel(int client, char[] model, int maxLen) -{ - GetEntPropString(client, Prop_Data, "m_ModelName", model, maxLen); + if (g_tKillPreview[client] != null) + TriggerTimer(g_tKillPreview[client], false); + + Skin_RemoveClientGloves(client, -1); + Skin_ResetPlayerSkin(client); + Skin_SetClientSkin(client); } -void Store_GetPlayerSkinModel(int client, char[] model, int maxLen) +void Skin_ResetPlayerSkin(int client) { - strcopy(model, maxLen, g_szSkinModel[client]); + strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), "#default"); + +#if defined GM_ZE + if (GetClientTeam(client) == TEAM_ZM) + strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), "#zombie"); +#endif + + g_iSkinLevel[client] = 0; + g_szDeathVoice[client][0] = 0; } -void Store_CallDefaultSkin(int client) +static void SetClientDefaultSkin(int client) { #if defined GM_ZE - if (g_iClientTeam[client] == 2) + if (GetClientTeam(client) == TEAM_ZM) { strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), "#zombie"); return; @@ -799,13 +828,12 @@ void Store_CallDefaultSkin(int client) #endif char skin_t[128], arms_t[128]; - int body; - - bool ret = false; + int body = 0; + bool ret = false; Call_StartForward(g_hOnPlayerSkinDefault); Call_PushCell(client); - Call_PushCell(g_iClientTeam[client] - 2); + Call_PushCell(GetClientTeam(client) - 2); Call_PushStringEx(STRING(skin_t), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_PushCell(128); Call_PushStringEx(STRING(arms_t), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); @@ -821,11 +849,11 @@ void Store_CallDefaultSkin(int client) SetEntProp(client, Prop_Send, "m_nBody", body > 0 ? body : 0); } - if (Store_CallSetPlayerSkinArms(client, STRING(arms_t))) + if (CallAllowSetPlayerSkinArms(client, STRING(arms_t))) { if (IsModelPrecached(arms_t)) { - Store_SetClientArms(client, arms_t); + SetClientArms(client, arms_t); } } @@ -833,8 +861,10 @@ void Store_CallDefaultSkin(int client) } } -void EnforceDeathSound(int client, const char[] skin, const int body) +static void EnforceDeathSound(int client, const char[] skin, const int body) { + g_szDeathVoice[client][0] = 0; + int index = FindDataIndexByModel(skin, body); if (index == -1) { @@ -846,7 +876,7 @@ void EnforceDeathSound(int client, const char[] skin, const int body) FormatEx(g_szDeathVoice[client], sizeof(g_szDeathVoice[]), "*%s", g_ePlayerSkins[index].szSound); } -Action Store_CallPreSetModel(int client, char skin[128], char arms[128], int &body) +static Action CallPreSetModel(int client, char skin[128], char arms[128], int &body) { char s[128], a[128]; int b = body; @@ -872,7 +902,7 @@ Action Store_CallPreSetModel(int client, char skin[128], char arms[128], int &bo return res; } -bool Store_CallSetPlayerSkinArms(int client, char[] arms, int len) +static bool CallAllowSetPlayerSkinArms(int client, char[] arms, int len) { static Handle gf = null; if (gf == null) @@ -903,20 +933,7 @@ bool Store_CallSetPlayerSkinArms(int client, char[] arms, int len) return false; } -bool GetSkinData(int itemid, char skin[128], char arms[128], int &body, int &team = 0) -{ - int m_iData = Store_GetDataIndex(itemid); - if (m_iData == -1) - return false; - - strcopy(skin, 128, g_ePlayerSkins[m_iData].szModel); - strcopy(arms, 128, g_ePlayerSkins[m_iData].szArms); - body = g_ePlayerSkins[m_iData].nBody; - team = g_ePlayerSkins[m_iData].iTeam; - return true; -} - -int FindDataIndexByModel(const char[] skin, const int body) +static int FindDataIndexByModel(const char[] skin, const int body) { for (int i = 0; i < g_iPlayerSkins; ++i) { @@ -935,14 +952,9 @@ int FindDataIndexByModel(const char[] skin, const int body) return -1; } -bool IsInDeathCamera(int client) -{ - return g_iCameraRef[client] != INVALID_ENT_REFERENCE; -} - -static void Store_SetClientArms(int client, const char[] arms_t) +static void SetClientArms(int client, const char[] arms_t) { - Store_RemoveClientGloves(client, 0); + Skin_RemoveClientGloves(client, 0); SetEntPropString(client, Prop_Send, "m_szArmsModel", arms_t); if (!g_bShouldFireEvent[client]) @@ -951,6 +963,9 @@ static void Store_SetClientArms(int client, const char[] arms_t) return; } + if (IsFakeClient(client)) + return; + Event event = CreateEvent("player_spawn", true); if (event == null) return; @@ -958,4 +973,76 @@ static void Store_SetClientArms(int client, const char[] arms_t) event.SetInt("userid", GetClientUserId(client)); event.FireToClient(client); event.Cancel(); +} + +// Outer + +/** + * Checks if a client is in death camera mode. + * + * @param client The client index to check. + * @return True if the client is in death camera mode, false otherwise. + */ +bool Skin_IsInDeathCamera(int client) +{ + return g_iCameraRef[client] != INVALID_ENT_REFERENCE && EntRefToEntIndex(g_iCameraRef[client]) > MaxClients; +} + +/** + * Returns the skin level of the player with the given client index. + * + * @param client The client index of the player to get the skin level of. + * @return The skin level of the player. + */ +int Skin_GetPlayerSkinLevel(int client) +{ + return g_iSkinLevel[client]; +} + + +/** + * Retrieves the current skin model for a given client. + * + * @param client The client index. + * @param model The buffer to store the skin model. + * @param maxLen The maximum length of the buffer. + */ +void Skin_GetClientSkinModel(int client, char[] model, int maxLen) +{ + GetEntPropString(client, Prop_Data, "m_ModelName", model, maxLen); +} + +/** + * Retrieves the skin model of a player that set by store. + * + * @param client The client index of the player. + * @param model The buffer to store the skin model. + * @param maxLen The maximum length of the buffer. + */ +void Skin_GetPlayerSkinModel(int client, char[] model, int maxLen) +{ + strcopy(model, maxLen, g_szSkinModel[client]); +} + +/** + * Retrieves skin data for a given item ID. + * + * @param itemid The ID of the item to retrieve skin data for. + * @param skin The name of the skin model to retrieve. + * @param arms The name of the arms model to retrieve. + * @param body The body index to retrieve. + * @param team The team index to retrieve. + * @return True if the skin data was successfully retrieved, false otherwise. + */ +bool Skin_GetSkinData(int itemid, char skin[128], char arms[128], int &body, int &team = 0) +{ + int m_iData = Store_GetDataIndex(itemid); + if (m_iData == -1) + return false; + + strcopy(skin, 128, g_ePlayerSkins[m_iData].szModel); + strcopy(arms, 128, g_ePlayerSkins[m_iData].szArms); + body = g_ePlayerSkins[m_iData].nBody; + team = g_ePlayerSkins[m_iData].iTeam; + return true; } \ No newline at end of file diff --git a/store/modules/trail.sp b/store/modules/trail.sp index 14a20b4..6e3cc9b 100644 --- a/store/modules/trail.sp +++ b/store/modules/trail.sp @@ -122,7 +122,7 @@ public void Store_PreSetTrail(int client) void CreateTrail(int client, int itemid = -1, int slot = 0) { #if defined GM_ZE - if (g_iClientTeam[client] == 2) + if (GetClientTeam(client) == TEAM_ZM) return; #endif diff --git a/store/players.sp b/store/players.sp index 76b2699..65359a4 100644 --- a/store/players.sp +++ b/store/players.sp @@ -5,11 +5,15 @@ #define Module_Player +static bool bSpawning[MAXPLAYERS + 1]; +static DynamicHook pSetModel; + void Players_OnPluginStart() { - HookEvent("player_spawn", Event_PlayerSpawn_Pre, EventHookMode_Pre); - HookEvent("player_death", Event_PlayerDeath_Pre, EventHookMode_Pre); - HookEvent("player_team", Event_PlayerTeam_Pre, EventHookMode_Pre); + HookEvent("player_death", Event_PlayerDeath, EventHookMode_Pre); + HookEvent("player_team", Event_PlayerTeam, EventHookMode_Pre); + + InitDHooks(); #if defined Module_Skin Skin_OnPluginStart(); @@ -38,6 +42,46 @@ void Players_OnPluginStart() #endif } +void InitDHooks() +{ + // Gamedata. + GameData config = new GameData("sdktools.games"); + if (config == null) + { + LogError("Could not load sdktools.games gamedata"); + return; + } + + int offset = config.GetOffset("SetEntityModel"); + if (offset == -1) + { + LogError("Failed to find SetEntityModel offset"); + return; + } + + delete config; + + // DHooks. + pSetModel = new DynamicHook(offset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity); + if (pSetModel == null) + { + LogError("Failed to DHook \"SetEntityModel\"."); + return; + } + + pSetModel.AddParam(HookParamType_CharPtr); +} + +void Players_OnClientPutInServer(int client) +{ + SDKHook(client, SDKHook_Spawn, OnClientSpawning); + SDKHook(client, SDKHook_SpawnPost, OnClientSpawned); + +#if defined Module_Skin + Skin_OnClientPutInServer(client, pSetModel); +#endif +} + void Players_OnClientDisconnect(int client) { #if defined Module_Aura @@ -61,62 +105,48 @@ void Players_OnClientDisconnect(int client) #endif } -public Action Event_PlayerSpawn_Pre(Event event, const char[] name, bool dontBroadcast) +static Action OnClientSpawning(int client) { - if (event.GetInt("teamnum", -1) == 0) - return Plugin_Continue; - - int client = GetClientOfUserId(event.GetInt("userid")); - - if (IsFakeClient(client) || g_iClientTeam[client] <= 1) - return Plugin_Continue; - - RequestFrame(OnClientSpawnPost, client); - -#if defined Module_Skin - Store_OnPlayerSpawn(client); - Store_RemoveClientGloves(client, -1); - Store_ResetPlayerSkin(client); - Store_PreSetClientModel(client); - // 32tick ~ 0.032 - // 64tick ~ 0.016 - // 128tick ~ 0.008 - CreateTimer(0.0, Timer_ClearCamera, client); - if (g_tKillPreview[client] != null) - TriggerTimer(g_tKillPreview[client], false); -#endif + bSpawning[client] = true; return Plugin_Continue; } -public void OnClientSpawnPost(int client) +static void OnClientSpawned(int client) { - if (!IsClientInGame(client) || !IsPlayerAlive(client)) + bSpawning[client] = false; + + // preventing client connected spawning + if (GetClientTeam(client) <= TEAM_OB) return; #if defined Module_Skin - Store_RemoveClientGloves(client, -1); -#endif - -#if defined Module_Trail - Store_SetClientTrail(client); + // now support default skin for FakeClient + Skin_OnPlayerSpawn(client); #endif -#if defined Module_Hats && !defined Module_Skin - Store_SetClientHat(client); -#endif + if (IsFakeClient(client)) + return; // particles should be delay. - CreateTimer(UTIL_GetRandomInt(5, 30) * 0.1, Timer_DelaySpawn, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE); + CreateTimer(0.5 + client * 0.1, Timer_DelaySpawn, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE); } -public Action Timer_DelaySpawn(Handle timer, int userid) +static Action Timer_DelaySpawn(Handle timer, int userid) { int client = GetClientOfUserId(userid); if (!client || !IsPlayerAlive(client)) return Plugin_Stop; +#if defined Module_Trail + Store_SetClientTrail(client); +#endif + +#if defined Module_Hats + Hat_SetClientHat(client); +#endif + #if defined Module_Aura Store_SetClientAura(client); #endif @@ -132,7 +162,7 @@ public Action Timer_DelaySpawn(Handle timer, int userid) return Plugin_Stop; } -public Action Event_PlayerDeath_Pre(Event event, const char[] name, bool dontBroadcast) +static Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast) { int client = GetClientOfUserId(event.GetInt("userid")); @@ -140,8 +170,8 @@ public Action Event_PlayerDeath_Pre(Event event, const char[] name, bool dontBro return Plugin_Continue; #if defined Module_Skin - RequestFrame(Broadcast_DeathSound, client); - RequestFrame(FirstPersonDeathCamera, client); + RequestFrame(Skin_BroadcastDeathSound, client); + RequestFrame(Skin_FirstPersonDeathCamera, client); #endif DeathReset(client); @@ -151,23 +181,19 @@ public Action Event_PlayerDeath_Pre(Event event, const char[] name, bool dontBro public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn) { - g_iClientTeam[client] = 2; - DeathReset(client); #if defined Module_Skin - Store_ResetPlayerSkin(client); + Skin_ResetPlayerSkin(client); #endif } public void ZE_OnPlayerInfected(int client, int attacker, bool motherZombie, bool teleportOverride, bool teleport) { - g_iClientTeam[client] = 2; - DeathReset(client); #if defined Module_Skin - Store_ResetPlayerSkin(client); + Skin_ResetPlayerSkin(client); #endif } @@ -199,15 +225,13 @@ void DeathReset(int client) } } -public Action Event_PlayerTeam_Pre(Event event, const char[] name, bool dontBroadcast) +static Action Event_PlayerTeam(Event event, const char[] name, bool dontBroadcast) { int client = GetClientOfUserId(event.GetInt("userid")); int newteam = event.GetInt("team"); int oldteam = event.GetInt("oldteam"); - g_iClientTeam[client] = newteam; - - if (oldteam > 1 && newteam <= 1) + if (oldteam > TEAM_OB && newteam <= TEAM_OB) { #if defined Module_Aura Store_RemoveClientAura(client); @@ -240,13 +264,15 @@ public Action Event_PlayerTeam_Pre(Event event, const char[] name, bool dontBroa } #if defined TeamArms -void OnClientTeamPost(int client) + +void OnClientTeamPost(int client) { - if (!IsClientInGame(client) || !IsPlayerAlive(client) || g_iClientTeam[client] > 1) + if (!IsClientInGame(client) || !IsPlayerAlive(client) || GetClientTeam(client) <= TEAM_OB) return; - Store_PreSetClientModel(client); + Skin_SetClientSkin(client); } + #endif stock void Call_OnParticlesCreated(int client, int entity) @@ -262,4 +288,9 @@ stock void Call_OnParticlesCreated(int client, int entity) Call_PushCell(client); Call_PushCell(entity); Call_Finish(); +} + +bool IsPlayerSpawing(int client) +{ + return bSpawning[client]; } \ No newline at end of file diff --git a/store/sounds.sp b/store/sounds.sp index 5e72b4e..3759120 100644 --- a/store/sounds.sp +++ b/store/sounds.sp @@ -68,10 +68,10 @@ static void Sound_OnMapStart() } } -void Sound_OnClientDeath(int client, int attacker) +void Sound_OnClientDeath(int client, int killer) { - g_iSoundSpam[client] = -1; - g_iSoundSpam[attacker] = -1; + g_iSoundSpam[client] = -1; + g_iSoundSpam[killer] = -1; } static void Sound_Reset() diff --git a/store/tpmode.sp b/store/tpmode.sp index aac0dcf..99d089c 100644 --- a/store/tpmode.sp +++ b/store/tpmode.sp @@ -60,10 +60,12 @@ static void ConVar_store_thirdperson_enabled(ConVar convar, const char[] oldValu } #if !defined GM_IS -static void ConVar_sv_allow_thirdperson(ConVar convar, const char[] oldValue, const char[] newValue) + +static void ConVar_sv_allow_thirdperson(ConVar convar, const char[] oldValue, const char[] newValue) { convar.IntValue = 1; } + #endif void TPMode_OnClientConnected(int client) From bc9a751ed02aaa552a456a26f1f73c97f1380db9 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 5 Aug 2023 16:50:06 +0800 Subject: [PATCH 04/15] Fix late load crash --- store.sp | 22 +++++++++++++++------- store/cpsupport.sp | 2 ++ store/modules/skin.sp | 3 +-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/store.sp b/store.sp index 0635319..dbc20a7 100644 --- a/store.sp +++ b/store.sp @@ -272,8 +272,7 @@ public void OnPluginStart() SetFailState("Current game is not be supported! CSGO only!"); #endif - if (g_smParentMap == null) - g_smParentMap = new StringMap(); + g_smParentMap = new StringMap(); // Setting default values for (int client = 1; client <= MaxClients; ++client) @@ -346,6 +345,7 @@ public void OnAllPluginsLoaded() } #pragma unused g_pfysRect, g_pOpenCase, g_pTransmit + // LogMessage("Rect: %s | Case: %s", g_pfysRect ? "loaded" : "fail", g_pOpenCase ? "loaded" : "fail"); } @@ -497,11 +497,13 @@ public void OnMapStart() g_bInterMission = false; for (int i = 0; i < g_iTypeHandlers; ++i) + { if (g_TypeHandlers[i].fnMapStart != INVALID_FUNCTION && IsPluginRunning(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].szPlFile)) { Call_StartFunction(g_TypeHandlers[i].hPlugin, g_TypeHandlers[i].fnMapStart); Call_Finish(); } + } } public void OnMapEnd() @@ -4131,18 +4133,24 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e delete items; delete item_array; + // rebuild download table if (FindPluginByFile("sm_downloader.smx") != INVALID_HANDLE) { LogMessage("Force reload downloader plugin."); ServerCommand("sm plugins reload sm_downloader.smx"); + ServerExecute(); } - char map[128]; - GetCurrentMap(STRING(map)); - if (strlen(map) > 3 && IsMapValid(map)) + OnMapEnd(); + OnMapStart(); + + // re-download resources + for (int i = 1; i <= MaxClients; i++) { - LogMessage("Force reload map to prevent server crash!"); // late precache will crash server. - ForceChangeLevel(map, "Reload Map to prevent server crash!"); + if (IsClientConnected(i) && !IsFakeClient(i)) + { + ClientCommand(i, "retry;"); + } } } diff --git a/store/cpsupport.sp b/store/cpsupport.sp index 418861a..6a25f65 100644 --- a/store/cpsupport.sp +++ b/store/cpsupport.sp @@ -561,6 +561,7 @@ static void CheckCPandSCP() DeleteFile(path[0]); } ServerCommand("sm plugins unload chat-processor.smx"); + ServerExecute(); LogMessage("'chat-processor.smx' detected!"); } @@ -575,6 +576,7 @@ static void CheckCPandSCP() DeleteFile(path[0]); } ServerCommand("sm plugins unload simple-chatprocessor.smx"); + ServerExecute(); LogMessage("'simple-chatprocessor.smx' detected!"); } } diff --git a/store/modules/skin.sp b/store/modules/skin.sp index 85eba66..697aa0e 100644 --- a/store/modules/skin.sp +++ b/store/modules/skin.sp @@ -975,7 +975,7 @@ static void SetClientArms(int client, const char[] arms_t) event.Cancel(); } -// Outer +// Internal Api /** * Checks if a client is in death camera mode. @@ -999,7 +999,6 @@ int Skin_GetPlayerSkinLevel(int client) return g_iSkinLevel[client]; } - /** * Retrieves the current skin model for a given client. * From 1a3a24374323e309f27af3b36f7fd993ce6d602b Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 5 Aug 2023 17:36:46 +0800 Subject: [PATCH 05/15] refactor module and apply code style --- store.sp | 13 ++++++++++ store/cpsupport.sp | 26 ++++++++++---------- store/grenades.sp | 56 +++++++++++++++++++++++++----------------- store/modules/aura.sp | 20 +++++++-------- store/modules/hats.sp | 24 ++++++++---------- store/modules/neon.sp | 20 +++++++-------- store/modules/part.sp | 20 +++++++-------- store/modules/skin.sp | 13 ---------- store/modules/trail.sp | 26 ++++++++++---------- store/players.sp | 30 +++++++++++----------- store/sounds.sp | 28 +++++++-------------- store/sprays.sp | 16 ++++++------ 12 files changed, 145 insertions(+), 147 deletions(-) diff --git a/store.sp b/store.sp index dbc20a7..c497e82 100644 --- a/store.sp +++ b/store.sp @@ -43,6 +43,19 @@ public Plugin myinfo = // DEFINITIONS // ////////////////////////////// +enum +{ + OBS_MODE_NONE = 0, // not in spectator mode + OBS_MODE_DEATHCAM, // special mode for death cam animation + OBS_MODE_FREEZECAM, // zooms to a target, and freeze-frames on them + OBS_MODE_FIXED, // view from a fixed camera position + OBS_MODE_IN_EYE, // follow a player in first person view + OBS_MODE_CHASE, // follow a player in third person view + OBS_MODE_ROAMING, // free roaming + + NUM_OBSERVER_MODES, +}; + #if !defined abstract_struct #define abstract_struct enum struct #endif diff --git a/store/cpsupport.sp b/store/cpsupport.sp index 6a25f65..1ff57b7 100644 --- a/store/cpsupport.sp +++ b/store/cpsupport.sp @@ -18,7 +18,6 @@ #define CHAT_C_RANDOM 2 #endif -#define TEAM_SPEC 1 static UserMsg g_umUMId; static Handle g_hCPAForward; static Handle g_hCPPForward; @@ -33,7 +32,7 @@ static int g_iNameTags = 0; static int g_iNameColors = 0; static int g_iMessageColors = 0; -public void CPSupport_OnPluginStart() +void CPSupport_OnPluginStart() { CheckCPandSCP(); @@ -63,8 +62,6 @@ public void CPSupport_OnPluginStart() Store_RegisterHandler("nametag", CPSupport_OnMappStart, CPSupport_Reset, NameTags_Config, CPSupport_Equip, CPSupport_Remove, true); Store_RegisterHandler("namecolor", CPSupport_OnMappStart, CPSupport_Reset, NameColors_Config, CPSupport_Equip, CPSupport_Remove, true); Store_RegisterHandler("msgcolor", CPSupport_OnMappStart, CPSupport_Reset, MsgColors_Config, CPSupport_Equip, CPSupport_Remove, true); - - LogMessage("Init CP..."); } static void CPSupport_OnMappStart() @@ -116,7 +113,7 @@ static int CPSupport_Remove(int client, int id) return 0; } -void CPP_Forward(int client, const char flagstring[32], const char name[128], const char message[256], ArrayList hRecipients, bool removedColor, bool processColor) +static void CPP_Forward(int client, const char flagstring[32], const char name[128], const char message[256], ArrayList hRecipients, bool removedColor, bool processColor) { Call_StartForward(g_hCPPForward); Call_PushCell(client); @@ -129,7 +126,7 @@ void CPP_Forward(int client, const char flagstring[32], const char name[128], co Call_Finish(); } -Action CPA_Forward(int &client, char flagstring[32], char name[128], char message[256], ArrayList hRecipients, bool &removedColor, bool &processColor) +static Action CPA_Forward(int &client, char flagstring[32], char name[128], char message[256], ArrayList hRecipients, bool &removedColor, bool &processColor) { int m_iEquippedNameTag = Store_GetEquippedItem(client, "nametag"); int m_iEquippedNameColor = Store_GetEquippedItem(client, "namecolor"); @@ -210,7 +207,7 @@ Action CPA_Forward(int &client, char flagstring[32], char name[128], char messag return Plugin_Changed; } -void String_Rainbow(const char[] input, char[] output, int maxLen, int type, int rainbow) +static void String_Rainbow(const char[] input, char[] output, int maxLen, int type, int rainbow) { char[] copy = new char[maxLen]; strcopy(copy, maxLen, input); @@ -280,7 +277,8 @@ void String_Rainbow(const char[] input, char[] output, int maxLen, int type, int } #if !defined USE_BF -bool IsChar(char c) + +static bool IsChar(char c) { if (0 <= c <= 126) return true; @@ -288,7 +286,7 @@ bool IsChar(char c) return false; } -int RandomColor() +static int RandomColor() { switch (UTIL_GetRandomInt(1, 16)) { @@ -314,7 +312,7 @@ int RandomColor() } #endif -bool GenerateMessageFormats() +static bool GenerateMessageFormats() { switch (GetEngineVersion()) { @@ -361,10 +359,12 @@ bool GenerateMessageFormats() #if defined USE_BF -public Action OnSayText2(UserMsg msg_id, BfRead msg, const int[] players, int playersNum, bool reliable, bool init) +static Action OnSayText2(UserMsg msg_id, BfRead msg, const int[] players, int playersNum, bool reliable, bool init) + #else -public Action OnSayText2(UserMsg msg_id, Protobuf msg, const int[] players, int playersNum, bool reliable, bool init) +static Action OnSayText2(UserMsg msg_id, Protobuf msg, const int[] players, int playersNum, bool reliable, bool init) + #endif { #if defined USE_BF @@ -459,7 +459,7 @@ public Action OnSayText2(UserMsg msg_id, Protobuf msg, const int[] players, int return Plugin_Handled; } -void Frame_OnChatMessage_SayText2(DataPack data) +static void Frame_OnChatMessage_SayText2(DataPack data) { int m_iSender = data.ReadCell(); bool m_bChat = data.ReadCell(); diff --git a/store/grenades.sp b/store/grenades.sp index 0bdbc08..99d4852 100644 --- a/store/grenades.sp +++ b/store/grenades.sp @@ -31,7 +31,7 @@ static int g_iSlots = 0; static int g_iGrenadeTrails = 0; static char g_szSlots[6][64]; -public void Grenades_OnPluginStart() +void Grenades_OnPluginStart() { Store_RegisterHandler("nadetrail", GrenadeTrails_OnMapStart, GrenadeTrails_Reset, GrenadeTrails_Config, GrenadeTrails_Equip, GrenadeTrails_Remove, true); Store_RegisterHandler("nadeskin", GrenadeSkins_OnMapStart, GrenadeSkins_Reset, GrenadeSkins_Config, GrenadeSkins_Equip, GrenadeSkins_Remove, true); @@ -136,46 +136,58 @@ public void OnEntityCreated(int entity, const char[] classname) return; if (StrContains(classname, "_projectile") > 0) - SDKHook(entity, SDKHook_SpawnPost, Grenades_OnEntitySpawnedPost); + SDKHook(entity, SDKHook_SpawnPost, Grenades_OnEntitySpawned); } -public void Grenades_OnEntitySpawnedPost(int entity) +static void Grenades_OnEntitySpawned(int entity) { - int client = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity"); + SDKUnhook(entity, SDKHook_SpawnPost, Grenades_OnEntitySpawned); - if (!(0 < client <= MaxClients)) + RequestFrame(Grenades_OnEntitySpawnedPost, EntIndexToEntRef(entity)); +} + +static void Grenades_OnEntitySpawnedPost(int ref) +{ + int entity = EntRefToEntIndex(ref); + if (entity < MaxClients) + return; + + int client = GetEntPropEnt(entity, Prop_Send, "m_hThrower"); + if (client == -1) return; char m_szClassname[64]; GetEdictClassname(entity, STRING(m_szClassname)); - for (int i = 0; i < strlen(m_szClassname); ++i) - if (m_szClassname[i] == '_') - { - m_szClassname[i] = 0; - break; - } + int char = FindCharInString(m_szClassname, '_'); + if (char == -1) + return; - int m_iSlot = GrenadeSkins_GetSlot(m_szClassname); + m_szClassname[char] = 0; - int m_iEquipped; - int m_iData; + OnGrenadeModel(client, entity, m_szClassname); - m_iEquipped = Store_GetEquippedItem(client, "nadeskin", m_iSlot); + OnGrenadeTrail(client, entity, m_szClassname); +} + +static void OnGrenadeModel(int client, int entity, const char[] classname) +{ + int m_iSlot = GrenadeSkins_GetSlot(classname); + int m_iEquipped = Store_GetEquippedItem(client, "nadeskin", m_iSlot); if (m_iEquipped >= 0) { - m_iData = Store_GetDataIndex(m_iEquipped); + int m_iData = Store_GetDataIndex(m_iEquipped); SetEntityModel(entity, g_eGrenadeSkins[m_iData].szModel); } +} - m_iEquipped = 0; - m_iData = 0; - m_iEquipped = Store_GetEquippedItem(client, "nadetrail", 0); - +static void OnGrenadeTrail(int client, int entity, const char[] classname) +{ + int m_iEquipped = Store_GetEquippedItem(client, "nadetrail", 0); if (m_iEquipped >= 0) { - m_iData = Store_GetDataIndex(m_iEquipped); + int m_iData = Store_GetDataIndex(m_iEquipped); // Ugh... int m_iColor[4]; @@ -186,4 +198,4 @@ public void Grenades_OnEntitySpawnedPost(int entity) TE_SetupBeamFollow(entity, g_eGrenadeTrails[m_iData].iCacheID, 0, 2.0, g_eGrenadeTrails[m_iData].fWidth, g_eGrenadeTrails[m_iData].fWidth, 10, m_iColor); TE_SendToAll(); } -} +} \ No newline at end of file diff --git a/store/modules/aura.sp b/store/modules/aura.sp index b9c1a40..ab0bec1 100644 --- a/store/modules/aura.sp +++ b/store/modules/aura.sp @@ -30,8 +30,8 @@ void Aura_OnMapStart() void Aura_OnClientDisconnect(int client) { - Store_RemoveClientAura(client); - g_szAuraClient[client][0] = '\0'; + Aura_RemoveClientAura(client); + g_szAuraClient[client][0] = 0; } bool Aura_Config(KeyValues kv, int itemid) @@ -76,25 +76,25 @@ int Aura_Equip(int client, int id) g_szAuraClient[client] = g_szAuraName[Store_GetDataIndex(id)]; if (IsPlayerAlive(client)) - Store_SetClientAura(client); + Aura_SetClientAura(client); return 0; } int Aura_Remove(int client, int id) { - Store_RemoveClientAura(client); - g_szAuraClient[client][0] = '\0'; + Aura_RemoveClientAura(client); + g_szAuraClient[client][0] = 0; return 0; } -void Store_RemoveClientAura(int client) +void Aura_RemoveClientAura(int client) { if (g_iClientAura[client] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iClientAura[client]); - if (entity > 0 && IsValidEdict(entity)) + if (entity > MaxClients) { RemoveEntity(entity); } @@ -102,16 +102,16 @@ void Store_RemoveClientAura(int client) } } -void Store_SetClientAura(int client) +void Aura_SetClientAura(int client) { - Store_RemoveClientAura(client); + Aura_RemoveClientAura(client); #if defined GM_ZE if (GetClientTeam(client) == TEAM_ZM) return; #endif - if (strlen(g_szAuraClient[client]) > 0) + if (g_szAuraClient[client][0]) { float clientOrigin[3], clientAngles[3]; GetClientAbsOrigin(client, clientOrigin); diff --git a/store/modules/hats.sp b/store/modules/hats.sp index e13fc72..35d5799 100644 --- a/store/modules/hats.sp +++ b/store/modules/hats.sp @@ -82,7 +82,7 @@ static Action Timer_Hats_Adjust(Handle timer) if (IsClientInGame(client) && !IsFakeClient(client)) { if (IsClientObserver(client)) - g_iSpecTarget[client] = (GetEntProp(client, Prop_Send, "m_iObserverMode") == 4) ? GetEntPropEnt(client, Prop_Send, "m_hObserverTarget") : -1; + g_iSpecTarget[client] = (GetEntProp(client, Prop_Send, "m_iObserverMode") == OBS_MODE_IN_EYE) ? GetEntPropEnt(client, Prop_Send, "m_hObserverTarget") : -1; else g_iSpecTarget[client] = client; } @@ -92,10 +92,10 @@ static Action Timer_Hats_Adjust(Handle timer) public void OnEntityDestroyed(int entity) { - if (entity > 2048 || entity < MaxClients) + if (entity >= 2048 || entity < MaxClients) return; - g_iHatsOwners[entity] = -1; + g_iHatsOwners[entity] = INVALID_ENT_REFERENCE; } void Hats_Reset() @@ -108,7 +108,7 @@ int Hats_Equip(int client, int id) int m_iData = Store_GetDataIndex(id); if (IsPlayerAlive(client)) { - Store_RemoveClientHats(client, g_eHats[m_iData].iSlot); + Hats_RemoveClientHats(client, g_eHats[m_iData].iSlot); CreateHat(client, id); } return g_eHats[m_iData].iSlot; @@ -117,15 +117,15 @@ int Hats_Equip(int client, int id) int Hats_Remove(int client, int id) { int m_iData = Store_GetDataIndex(id); - Store_RemoveClientHats(client, g_eHats[m_iData].iSlot); + Hats_RemoveClientHats(client, g_eHats[m_iData].iSlot); return g_eHats[m_iData].iSlot; } -void Hat_SetClientHat(int client) +void Hats_SetClientHat(int client) { for (int i = 0; i < STORE_MAX_SLOTS; ++i) { - Store_RemoveClientHats(client, i); + Hats_RemoveClientHats(client, i); CreateHat(client, -1, i); } } @@ -207,12 +207,12 @@ static void CreateHat(int client, int itemid = -1, int slot = 0) } } -void Store_RemoveClientHats(int client, int slot) +void Hats_RemoveClientHats(int client, int slot) { if (g_iClientHats[client][slot] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iClientHats[client][slot]); - if (entity > 0 && IsValidEdict(entity)) + if (entity > MaxClients) { RemoveEntity(entity); } @@ -220,7 +220,7 @@ void Store_RemoveClientHats(int client, int slot) } } -public Action Hook_SetTransmit_Hat(int ent, int client) +static Action Hook_SetTransmit_Hat(int ent, int client) { if (client == g_iHatsOwners[ent]) return IsPlayerTP(client) ? Plugin_Continue : Plugin_Handled; @@ -228,10 +228,6 @@ public Action Hook_SetTransmit_Hat(int ent, int client) if (g_iSpecTarget[client] == g_iHatsOwners[ent]) return Plugin_Handled; - // for gotv - if (IsClientSourceTV(client)) - return Plugin_Handled; - return Plugin_Continue; } diff --git a/store/modules/neon.sp b/store/modules/neon.sp index 1667a91..0e6c279 100644 --- a/store/modules/neon.sp +++ b/store/modules/neon.sp @@ -34,7 +34,7 @@ void Neon_OnMapStart() void Neon_OnClientDisconnect(int client) { - Store_RemoveClientNeon(client); + Neon_RemoveClientNeon(client); } void Neon_Reset() @@ -44,29 +44,29 @@ void Neon_Reset() int Neon_Equip(int client, int id) { - RequestFrame(EquipNeon_Delay, client); + RequestFrame(DelayEquipNeon, client); return 0; } -public void EquipNeon_Delay(int client) +static void DelayEquipNeon(int client) { if (IsClientInGame(client) && IsPlayerAlive(client)) - Store_SetClientNeon(client); + Neon_SetClientNeon(client); } int Neon_Remove(int client, int id) { - Store_RemoveClientNeon(client); + Neon_RemoveClientNeon(client); return 0; } -void Store_RemoveClientNeon(int client) +void Neon_RemoveClientNeon(int client) { if (g_iClientNeon[client] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iClientNeon[client]); - if (entity > 0 && IsValidEdict(entity)) + if (entity > MaxClients) { RemoveEntity(entity); } @@ -74,9 +74,9 @@ void Store_RemoveClientNeon(int client) } } -void Store_SetClientNeon(int client) +void Neon_SetClientNeon(int client) { - Store_RemoveClientNeon(client); + Neon_RemoveClientNeon(client); #if defined GM_ZE if (GetClientTeam(client) == TEAM_ZM) @@ -89,7 +89,7 @@ void Store_SetClientNeon(int client) int m_iData = Store_GetDataIndex(m_iEquipped); - if (g_eNeons[m_iData].iColor[3] != 0) + if (g_eNeons[m_iData].iColor[3] > 0) { float clientOrigin[3]; GetClientAbsOrigin(client, clientOrigin); diff --git a/store/modules/part.sp b/store/modules/part.sp index 9eaedc5..ec44372 100644 --- a/store/modules/part.sp +++ b/store/modules/part.sp @@ -15,8 +15,8 @@ static char g_szPartClient[MAXPLAYERS + 1][PLATFORM_MAX_PATH]; void Part_OnClientDisconnect(int client) { - Store_RemoveClientPart(client); - g_szPartClient[client][0] = '\0'; + Part_RemoveClientPart(client); + g_szPartClient[client][0] = 0; } void Part_Reset() @@ -58,15 +58,15 @@ int Part_Equip(int client, int id) g_szPartClient[client] = g_szPartName[Store_GetDataIndex(id)]; if (IsPlayerAlive(client)) - Store_SetClientPart(client); + Part_SetClientPart(client); return 0; } int Part_Remove(int client, int id) { - Store_RemoveClientPart(client); - g_szPartClient[client][0] = '\0'; + Part_RemoveClientPart(client); + g_szPartClient[client][0] = 0; return 0; } @@ -86,12 +86,12 @@ void Part_OnMapStart() } } -void Store_RemoveClientPart(int client) +void Part_RemoveClientPart(int client) { if (g_iClientPart[client] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iClientPart[client]); - if (entity > 0 && IsValidEdict(entity)) + if (entity > MaxClients) { RemoveEntity(entity); } @@ -99,16 +99,16 @@ void Store_RemoveClientPart(int client) } } -void Store_SetClientPart(int client) +void Part_SetClientPart(int client) { - Store_RemoveClientPart(client); + Part_RemoveClientPart(client); #if defined GM_ZE if (GetClientTeam(client) == TEAM_ZM) return; #endif - if (!(strcmp(g_szPartClient[client], "", false) == 0)) + if (g_szPartClient[client][0]) { float clientOrigin[3], clientAngles[3]; GetClientAbsOrigin(client, clientOrigin); diff --git a/store/modules/skin.sp b/store/modules/skin.sp index 697aa0e..b3007c1 100644 --- a/store/modules/skin.sp +++ b/store/modules/skin.sp @@ -15,19 +15,6 @@ abstract_struct PlayerSkin int nBody; } -enum -{ - OBS_MODE_NONE = 0, // not in spectator mode - OBS_MODE_DEATHCAM, // special mode for death cam animation - OBS_MODE_FREEZECAM, // zooms to a target, and freeze-frames on them - OBS_MODE_FIXED, // view from a fixed camera position - OBS_MODE_IN_EYE, // follow a player in first person view - OBS_MODE_CHASE, // follow a player in third person view - OBS_MODE_ROAMING, // free roaming - - NUM_OBSERVER_MODES, -}; - static PlayerSkin g_ePlayerSkins[STORE_MAX_ITEMS]; static bool g_bSoundHooked; diff --git a/store/modules/trail.sp b/store/modules/trail.sp index 6e3cc9b..99d498a 100644 --- a/store/modules/trail.sp +++ b/store/modules/trail.sp @@ -70,24 +70,24 @@ void Trails_Reset() int Trails_Equip(int client, int id) { if (IsPlayerAlive(client)) - Store_SetClientTrail(client); + Trails_SetClientTrail(client); return g_eTrails[Store_GetDataIndex(id)].iSlot; } int Trails_Remove(int client, int id) { - Store_SetClientTrail(client); + Trails_SetClientTrail(client); return g_eTrails[Store_GetDataIndex(id)].iSlot; } -void Store_RemoveClientTrail(int client, int slot) +void Trails_RemoveClientTrail(int client, int slot) { if (g_iClientTrails[client][slot] != INVALID_ENT_REFERENCE) { int entity = EntRefToEntIndex(g_iClientTrails[client][slot]); - if (entity > 0 && IsValidEdict(entity)) + if (entity > MaxClients) { RemoveEntity(entity); } @@ -99,27 +99,27 @@ void Store_RemoveClientTrail(int client, int slot) void Trails_OnClientDisconnect(int client) { for (int i = 0; i < STORE_MAX_SLOTS; ++i) - Store_RemoveClientTrail(client, i); + Trails_RemoveClientTrail(client, i); } -void Store_SetClientTrail(int client) +void Trails_SetClientTrail(int client) { - RequestFrame(Store_PreSetTrail, client); + RequestFrame(PreSetTrail, client); } -public void Store_PreSetTrail(int client) +static void PreSetTrail(int client) { - if (!IsClientInGame(client)) + if (!IsClientInGame(client) || !IsPlayerAlive(client)) return; for (int i = 0; i < STORE_MAX_SLOTS; ++i) { - Store_RemoveClientTrail(client, i); + Trails_RemoveClientTrail(client, i); CreateTrail(client, -1, i); } } -void CreateTrail(int client, int itemid = -1, int slot = 0) +static void CreateTrail(int client, int itemid = -1, int slot = 0) { #if defined GM_ZE if (GetClientTeam(client) == TEAM_ZM) @@ -150,7 +150,7 @@ void CreateTrail(int client, int itemid = -1, int slot = 0) int entity = g_iClientTrails[client][slot] == INVALID_ENT_REFERENCE ? -1 : EntRefToEntIndex(g_iClientTrails[client][slot]); - if (IsValidEdict(entity)) + if (entity < MaxClients) return; entity = CreateEntityByName("env_spritetrail"); @@ -171,7 +171,7 @@ void CreateTrail(int client, int itemid = -1, int slot = 0) Call_OnTrailsCreated(client, entity, slot); } -void AttachTrail(int ent, int client, int current, int num) +static void AttachTrail(int ent, int client, int current, int num) { float m_fOrigin[3]; float m_fAngle[3]; diff --git a/store/players.sp b/store/players.sp index 65359a4..5342d54 100644 --- a/store/players.sp +++ b/store/players.sp @@ -140,23 +140,23 @@ static Action Timer_DelaySpawn(Handle timer, int userid) return Plugin_Stop; #if defined Module_Trail - Store_SetClientTrail(client); + Trails_SetClientTrail(client); #endif #if defined Module_Hats - Hat_SetClientHat(client); + Hats_SetClientHat(client); #endif #if defined Module_Aura - Store_SetClientAura(client); + Aura_SetClientAura(client); #endif #if defined Module_Neon - Store_SetClientNeon(client); + Neon_SetClientNeon(client); #endif #if defined Module_Part - Store_SetClientPart(client); + Part_SetClientPart(client); #endif return Plugin_Stop; @@ -202,25 +202,25 @@ void DeathReset(int client) #pragma unused client #if defined Module_Aura - Store_RemoveClientAura(client); + Aura_RemoveClientAura(client); #endif #if defined Module_Neon - Store_RemoveClientNeon(client); + Neon_RemoveClientNeon(client); #endif #if defined Module_Part - Store_RemoveClientPart(client); + Part_RemoveClientPart(client); #endif for (int i = 0; i < STORE_MAX_SLOTS; ++i) { #if defined Module_Hats - Store_RemoveClientHats(client, i); + Hats_RemoveClientHats(client, i); #endif #if defined Module_Trail - Store_RemoveClientTrail(client, i); + Trails_RemoveClientTrail(client, i); #endif } } @@ -234,25 +234,25 @@ static Action Event_PlayerTeam(Event event, const char[] name, bool dontBroadcas if (oldteam > TEAM_OB && newteam <= TEAM_OB) { #if defined Module_Aura - Store_RemoveClientAura(client); + Aura_RemoveClientAura(client); #endif #if defined Module_Neon - Store_RemoveClientNeon(client); + Neon_RemoveClientNeon(client); #endif #if defined Module_Part - Store_RemoveClientPart(client); + Part_RemoveClientPart(client); #endif #if defined Module_Trail for (int i = 0; i < STORE_MAX_SLOTS; ++i) - Store_RemoveClientTrail(client, i); + Trails_RemoveClientTrail(client, i); #endif #if defined Module_Hats for (int i = 0; i < STORE_MAX_SLOTS; ++i) - Store_RemoveClientHats(client, i); + Hats_RemoveClientHats(client, i); #endif } diff --git a/store/sounds.sp b/store/sounds.sp index 3759120..011e7b4 100644 --- a/store/sounds.sp +++ b/store/sounds.sp @@ -26,7 +26,7 @@ static Handle g_hCookieSounds; static Handle g_hOnCheerSound; static Handle g_hOnCheerCommand; -public void Sounds_OnPluginStart() +void Sounds_OnPluginStart() { Store_RegisterHandler("sound", Sound_OnMapStart, Sound_Reset, Sound_Config, Sound_Equip, Sound_Remove, true); @@ -147,30 +147,20 @@ void Sound_OnClientConnected(int client) public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs) { - if (client <= 0) + if (!IsValidClient(client) || g_iSoundClient[client] < 0) return; - if (!IsClientInGame(client)) - return; - - if (g_iSoundClient[client] < 0) - return; - - if (sArgs[0] == '!' || sArgs[0] == '/' || sArgs[0] == '@') + if (sArgs[0] == '!' || sArgs[0] == '/' || sArgs[0] == '@' || sArgs[0] == '.' || sArgs[0] == '#' || sArgs[0] == '$') return; if (g_iSoundSpam[client] > GetTime()) return; - if ( - StrContains(sArgs, "cheer", false) != -1 || StrContains(sArgs, "lol", false) != -1 || StrContains(sArgs, "233", false) != -1 || StrContains(sArgs, "hah", false) != -1 || StrContains(sArgs, "hhh", false) != -1) - { - g_iSoundSpam[client] = GetTime() + g_eSounds[g_iSoundClient[client]].iCooldown; + if (StrContains(sArgs, "cheer", false) != -1 || StrContains(sArgs, "lol", false) != -1 || StrContains(sArgs, "233", false) != -1 || StrContains(sArgs, "hah", false) != -1 || StrContains(sArgs, "hhh", false) != -1) StartSoundToAll(client); - } } -public Action Command_Cheer(int client, int args) +static Action Command_Cheer(int client, int args) { if (!IsValidClient(client)) return Plugin_Handled; @@ -193,7 +183,7 @@ public Action Command_Cheer(int client, int args) return Plugin_Handled; } -bool StartNullSound(int client) +static bool StartNullSound(int client) { bool res = false; int cooldown = 30; @@ -211,7 +201,7 @@ bool StartNullSound(int client) return res; } -void StartSoundToAll(int client) +static void StartSoundToAll(int client) { char sound[256], name[64]; strcopy(STRING(sound), g_eSounds[g_iSoundClient[client]].szSound); @@ -341,7 +331,7 @@ void StartSoundToAll(int client) tPrintToChatAll("%t", "sound to all", client, name); } -public void Sounds_OnLoadOptions(int client) +void Sounds_OnLoadOptions(int client) { if (g_pfysOptions) { @@ -359,7 +349,7 @@ public void Sounds_OnLoadOptions(int client) } } -public Action Command_Silence(int client, int args) +static Action Command_Silence(int client, int args) { if (!client) return Plugin_Handled; diff --git a/store/sprays.sp b/store/sprays.sp index 0396a26..dc7b3d8 100644 --- a/store/sprays.sp +++ b/store/sprays.sp @@ -21,7 +21,7 @@ static bool g_bFallbackSprayerSound; #define FALLBACK_SPARYER_SOUND "maoling/sprayer.mp3" -public void Sprays_OnPluginStart() +void Sprays_OnPluginStart() { Store_RegisterHandler("spray", Sprays_OnMapStart, Sprays_Reset, Sprays_Config, Sprays_Equip, Sprays_Remove, true); @@ -59,12 +59,12 @@ static void Sprays_OnMapStart() } } -public void Sprays_OnClientConnected(int client) +void Sprays_OnClientConnected(int client) { g_iSprayCache[client] = -1; } -public void Spray_OnClientDeath(int client) +void Spray_OnClientDeath(int client) { g_iSprayLimit[client] = -1; } @@ -84,12 +84,12 @@ static Action Command_Spray(int client, int args) return Plugin_Handled; } - Sprays_Create(client); + CreateSpray(client); return Plugin_Handled; } -bool StartNullSpray(int client) +static bool StartNullSpray(int client) { bool res = false; int cooldown = 60; @@ -156,7 +156,7 @@ static int Sprays_Remove(int client, int id) return 0; } -void Sprays_Create(int client) +static void CreateSpray(int client) { if (!IsPlayerAlive(client)) return; @@ -182,7 +182,7 @@ void Sprays_Create(int client) Call_Finish(); } -void StartSprayToAll(int client, const float vPos[3]) +static void StartSprayToAll(int client, const float vPos[3]) { char model[PLATFORM_MAX_PATH], name[64]; strcopy(STRING(model), g_szSprays[g_iSprayCache[client]]); @@ -232,7 +232,7 @@ void StartSprayToAll(int client, const float vPos[3]) tPrintToChatAll("%t", "spray to all", client, name); } -void GetPlayerEyeViewPoint(int client, float m_fPosition[3]) +static void GetPlayerEyeViewPoint(int client, float m_fPosition[3]) { float m_flRotation[3]; float m_flPosition[3]; From cfaaf1b863027b045172aa84947fd819f2cdfba8 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 5 Aug 2023 17:55:34 +0800 Subject: [PATCH 06/15] Apply code style for modules --- modules/store_defaultskin.sp | 29 ++-- modules/store_givecreditscommand.sp | 27 ++-- modules/store_models.sp | 232 ++++++++++++++-------------- modules/store_musickit.sp | 4 +- modules/store_pet.sp | 170 ++++++++++---------- modules/store_randomskin.sp | 104 +++++++------ modules/store_simplehide.sp | 13 +- modules/store_weaponskin.sp | 171 ++++++++++---------- store.sp | 4 - 9 files changed, 377 insertions(+), 377 deletions(-) diff --git a/modules/store_defaultskin.sp b/modules/store_defaultskin.sp index b2dccdc..7ed261e 100644 --- a/modules/store_defaultskin.sp +++ b/modules/store_defaultskin.sp @@ -14,15 +14,13 @@ public Plugin myinfo = url = STORE_URL }; -char g_szDefaultSkin[2][192] = -{ +char g_szDefaultSkin[2][192] = { "models/player/custom_player/legacy/tm_leet_variant_classic.mdl", "models/player/custom_player/legacy/ctm_sas_variant_classic.mdl" }; bool g_bSkinLoaded[2]; -char g_szDefaultArms[2][192] = -{ +char g_szDefaultArms[2][192] = { "models/weapons/t_arms.mdl", "models/weapons/ct_arms.mdl" }; @@ -30,18 +28,27 @@ bool g_bArmsLoaded[2]; public void OnMapStart() { - for(int x = 0; x < sizeof(g_szDefaultSkin); ++x) g_bSkinLoaded[x] = (FileExists(g_szDefaultSkin[x]) && PrecacheModel(g_szDefaultSkin[x], false)); - for(int x = 0; x < sizeof(g_szDefaultArms); ++x) g_bArmsLoaded[x] = (FileExists(g_szDefaultArms[x]) && PrecacheModel(g_szDefaultArms[x], false)); - - for(int x = 0; x < sizeof(g_szDefaultSkin); ++x) if (g_bSkinLoaded[x]) AddFileToDownloadsTable(g_szDefaultSkin[x]); - for(int x = 0; x < sizeof(g_szDefaultArms); ++x) if (g_bArmsLoaded[x]) AddFileToDownloadsTable(g_szDefaultArms[x]); + for (int x = 0; x < sizeof(g_szDefaultSkin); ++x) g_bSkinLoaded[x] = (FileExists(g_szDefaultSkin[x]) && PrecacheModel(g_szDefaultSkin[x], false)); + for (int x = 0; x < sizeof(g_szDefaultArms); ++x) g_bArmsLoaded[x] = (FileExists(g_szDefaultArms[x]) && PrecacheModel(g_szDefaultArms[x], false)); + + for (int x = 0; x < sizeof(g_szDefaultSkin); ++x) + if (g_bSkinLoaded[x]) + AddFileToDownloadsTable(g_szDefaultSkin[x]); + for (int x = 0; x < sizeof(g_szDefaultArms); ++x) + if (g_bArmsLoaded[x]) + AddFileToDownloadsTable(g_szDefaultArms[x]); } // Terriorst/Zombie = 0; Counter-Terriorst/Human = 1; public bool Store_OnPlayerSkinDefault(int client, int team, char[] skin, int skinLen, char[] arms, int armsLen) { - if (g_bArmsLoaded[team]) strcopy(arms, armsLen, g_szDefaultArms[team]); - if (g_bSkinLoaded[team]) { strcopy(skin, skinLen, g_szDefaultSkin[team]); return true; } + if (g_bArmsLoaded[team]) + strcopy(arms, armsLen, g_szDefaultArms[team]); + if (g_bSkinLoaded[team]) + { + strcopy(skin, skinLen, g_szDefaultSkin[team]); + return true; + } return false; } diff --git a/modules/store_givecreditscommand.sp b/modules/store_givecreditscommand.sp index 51c7519..dead248 100644 --- a/modules/store_givecreditscommand.sp +++ b/modules/store_givecreditscommand.sp @@ -24,7 +24,7 @@ public void OnPluginStart() public Action CommandCredits(int client, int args) { - if(args < 2) + if (args < 2) { ReplyToCommand(client, "[Store] Usage: sm_givecredits "); return Plugin_Handled; @@ -34,26 +34,27 @@ public Action CommandCredits(int client, int args) GetCmdArg(2, STRING(arg)); int credits = 0; - if(StringToIntEx(arg, credits) == 0 || credits <= 0) + if (StringToIntEx(arg, credits) == 0 || credits <= 0) { ReplyToCommand(client, "[Store] %T", "Invalid Amount", client); return Plugin_Handled; } char target_name[64]; - int target_list[MAXPLAYERS], target_count; + int target_list[MAXPLAYERS], target_count; bool tn_is_ml; GetCmdArg(1, STRING(arg)); if ((target_count = ProcessTargetString( - arg, - client, - target_list, - MAXPLAYERS, - COMMAND_FILTER_NO_BOTS, - target_name, - 64, - tn_is_ml)) <= 0) + arg, + client, + target_list, + MAXPLAYERS, + COMMAND_FILTER_NO_BOTS, + target_name, + 64, + tn_is_ml)) + <= 0) { ReplyToTargetError(client, target_count); return Plugin_Handled; @@ -62,9 +63,9 @@ public Action CommandCredits(int client, int args) char reason[128]; FormatEx(STRING(reason), "Give command by \"%L\"", client); - for(int i = 0; i < target_count; i++) + for (int i = 0; i < target_count; i++) { - if(!Store_IsClientLoaded(target_list[i]) || Store_IsClientBanned(target_list[i])) + if (!Store_IsClientLoaded(target_list[i]) || Store_IsClientBanned(target_list[i])) continue; Store_SetClientCredits(target_list[i], Store_GetClientCredits(target_list[i]) + credits, reason); diff --git a/modules/store_models.sp b/modules/store_models.sp index 2eaff6e..4e10106 100644 --- a/modules/store_models.sp +++ b/modules/store_models.sp @@ -16,26 +16,26 @@ public Plugin myinfo = url = STORE_URL }; -static int g_iRefPVM[MAXPLAYERS+1]; -static int g_iOldSequence[MAXPLAYERS+1]; -static bool g_bHooked[MAXPLAYERS+1]; -static char g_szCurWpn[MAXPLAYERS+1][64]; -static float g_fOldCycle[MAXPLAYERS+1]; -static StringMap g_smClientWeapon[MAXPLAYERS+1]; - -enum struct CustomModel +static int g_iRefPVM[MAXPLAYERS + 1]; +static int g_iOldSequence[MAXPLAYERS + 1]; +static bool g_bHooked[MAXPLAYERS + 1]; +static char g_szCurWpn[MAXPLAYERS + 1][64]; +static float g_fOldCycle[MAXPLAYERS + 1]; +static StringMap g_smClientWeapon[MAXPLAYERS + 1]; + +abstract_struct CustomModel { char szModelV[PLATFORM_MAX_PATH]; char szModelW[PLATFORM_MAX_PATH]; char szModelD[PLATFORM_MAX_PATH]; char szEntity[32]; - int iSlot; - int iCacheIdV; - int iCacheIdW; + int iSlot; + int iCacheIdV; + int iCacheIdW; } static CustomModel g_eCustomModel[STORE_MAX_ITEMS]; -static int g_iCustomModels = 0; +static int g_iCustomModels = 0; public void OnPluginStart() { @@ -49,23 +49,23 @@ public void Store_OnStoreInit(Handle store_plugin) public void Models_OnMapStart() { - for(int i = 0; i < g_iCustomModels; ++i) + for (int i = 0; i < g_iCustomModels; ++i) { g_eCustomModel[i].iCacheIdV = PrecacheModel(g_eCustomModel[i].szModelV, false); AddFileToDownloadsTable(g_eCustomModel[i].szModelV); - if(!StrEqual(g_eCustomModel[i].szModelW, "none", false)) + if (!StrEqual(g_eCustomModel[i].szModelW, "none", false)) { g_eCustomModel[i].iCacheIdW = PrecacheModel(g_eCustomModel[i].szModelW, false); AddFileToDownloadsTable(g_eCustomModel[i].szModelW); - if(g_eCustomModel[i].iCacheIdW == 0) + if (g_eCustomModel[i].iCacheIdW == 0) g_eCustomModel[i].iCacheIdW = -1; } - if(!StrEqual(g_eCustomModel[i].szModelD, "none", false)) + if (!StrEqual(g_eCustomModel[i].szModelD, "none", false)) { - if(!IsModelPrecached(g_eCustomModel[i].szModelD)) + if (!IsModelPrecached(g_eCustomModel[i].szModelD)) { PrecacheModel(g_eCustomModel[i].szModelD, false); AddFileToDownloadsTable(g_eCustomModel[i].szModelD); @@ -88,7 +88,7 @@ public bool Models_Config(KeyValues kv, int itemid) kv.GetString("weapon", g_eCustomModel[g_iCustomModels].szEntity, sizeof(CustomModel::szEntity)); g_eCustomModel[g_iCustomModels].iSlot = kv.GetNum("slot"); - if(FileExists(g_eCustomModel[g_iCustomModels].szModelV, true)) + if (FileExists(g_eCustomModel[g_iCustomModels].szModelV, true)) { ++g_iCustomModels; return true; @@ -100,7 +100,7 @@ public int Models_Equip(int client, int id) { int m_iData = Store_GetDataIndex(id); - if(!Models_AddModels(client, g_eCustomModel[m_iData].szEntity, g_eCustomModel[m_iData].iCacheIdV, g_eCustomModel[m_iData].iCacheIdW, g_eCustomModel[m_iData].szModelD) && IsClientInGame(client)) + if (!Models_AddModels(client, g_eCustomModel[m_iData].szEntity, g_eCustomModel[m_iData].iCacheIdV, g_eCustomModel[m_iData].iCacheIdW, g_eCustomModel[m_iData].szModelD) && IsClientInGame(client)) tPrintToChat(client, "\x02 unknown error! please contact to admin!"); return g_eCustomModel[m_iData].iSlot; @@ -110,7 +110,7 @@ public int Models_Remove(int client, int id) { int m_iData = Store_GetDataIndex(id); - if(!Models_RemoveModels(client, g_eCustomModel[m_iData].szEntity) && IsClientInGame(client)) + if (!Models_RemoveModels(client, g_eCustomModel[m_iData].szEntity) && IsClientInGame(client)) tPrintToChat(client, "\x02 unknown error! please contact to admin!"); return g_eCustomModel[m_iData].iSlot; @@ -126,20 +126,20 @@ public void OnClientPutInServer(int client) public void OnClientDisconnect(int client) { - if(g_bHooked[client]) + if (g_bHooked[client]) { SDKUnhook(client, SDKHook_PostThinkPost, Hook_PostThinkPost_Models); g_bHooked[client] = false; } - if(g_smClientWeapon[client] != null) + if (g_smClientWeapon[client] != null) { - if(g_smClientWeapon[client].Size > 0) + if (g_smClientWeapon[client].Size > 0) { SDKUnhook(client, SDKHook_WeaponSwitchPost, Hook_WeaponSwitchPost_Models); - SDKUnhook(client, SDKHook_WeaponSwitch, Hook_WeaponSwitch_Models); - SDKUnhook(client, SDKHook_WeaponEquip, Hook_WeaponEquip_Models); - SDKUnhook(client, SDKHook_WeaponDropPost, Hook_WeaponDropPost_Models); + SDKUnhook(client, SDKHook_WeaponSwitch, Hook_WeaponSwitch_Models); + SDKUnhook(client, SDKHook_WeaponEquip, Hook_WeaponEquip_Models); + SDKUnhook(client, SDKHook_WeaponDropPost, Hook_WeaponDropPost_Models); } delete g_smClientWeapon[client]; @@ -151,7 +151,7 @@ public void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast { int client = GetClientOfUserId(event.GetInt("userid")); - if(!g_bHooked[client]) + if (!g_bHooked[client]) return; SDKUnhook(client, SDKHook_PostThinkPost, Hook_PostThinkPost_Models); @@ -160,19 +160,19 @@ public void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast public void Hook_WeaponSwitchPost_Models(int client, int weapon) { - if(!IsValidEdict(weapon)) + if (!IsValidEdict(weapon)) return; char classname[32]; - if(!GetWeaponClassname(weapon, STRING(classname))) + if (!GetWeaponClassname(weapon, STRING(classname))) return; - if(StrContains(classname, "item", false) == 0) + if (StrContains(classname, "item", false) == 0) return; char m_szGlobalName[256]; GetEntPropString(weapon, Prop_Data, "m_iGlobalname", STRING(m_szGlobalName)); - if(StrContains(m_szGlobalName, "custom", false) != 0) + if (StrContains(m_szGlobalName, "custom", false) != 0) return; ReplaceString(STRING(m_szGlobalName), "custom", ""); @@ -183,11 +183,11 @@ public void Hook_WeaponSwitchPost_Models(int client, int weapon) int model_index = StringToInt(m_szData[0]); int m_iPVM = EntRefToEntIndex(g_iRefPVM[client]); - if(m_iPVM == INVALID_ENT_REFERENCE) + if (m_iPVM == INVALID_ENT_REFERENCE) { g_iRefPVM[client] = GetViewModelReference(client, -1); - m_iPVM = EntRefToEntIndex(g_iRefPVM[client]); - if(m_iPVM == INVALID_ENT_REFERENCE) + m_iPVM = EntRefToEntIndex(g_iRefPVM[client]); + if (m_iPVM == INVALID_ENT_REFERENCE) return; } @@ -200,7 +200,7 @@ public void Hook_WeaponSwitchPost_Models(int client, int weapon) public Action Hook_WeaponSwitch_Models(int client, int weapon) { - if(g_bHooked[client]) + if (g_bHooked[client]) { SDKUnhook(client, SDKHook_PostThinkPost, Hook_PostThinkPost_Models); g_bHooked[client] = false; @@ -210,42 +210,42 @@ public Action Hook_WeaponSwitch_Models(int client, int weapon) public Action Hook_WeaponEquip_Models(int client, int weapon) { - if(!IsValidEdict(weapon)) + if (!IsValidEdict(weapon)) return Plugin_Continue; - if(GetEntProp(weapon, Prop_Send, "m_hPrevOwner") > 0) + if (GetEntProp(weapon, Prop_Send, "m_hPrevOwner") > 0) return Plugin_Continue; char classname[32]; - if(!GetWeaponClassname(weapon, STRING(classname))) + if (!GetWeaponClassname(weapon, STRING(classname))) return Plugin_Continue; char m_szGlobalName[256]; GetEntPropString(weapon, Prop_Data, "m_iGlobalname", STRING(m_szGlobalName)); - if(StrContains(m_szGlobalName, "custom", false) == 0) + if (StrContains(m_szGlobalName, "custom", false) == 0) return Plugin_Continue; char classname_world[32], classname_drop[32]; FormatEx(STRING(classname_world), "%s_world", classname); - FormatEx(STRING(classname_drop), "%s_drop", classname); + FormatEx(STRING(classname_drop), "%s_drop", classname); int model_world; - if(g_smClientWeapon[client].GetValue(classname_world, model_world) && model_world != -1) + if (g_smClientWeapon[client].GetValue(classname_world, model_world) && model_world != -1) { int iWorldModel = GetEntPropEnt(weapon, Prop_Send, "m_hWeaponWorldModel"); - if(IsValidEdict(iWorldModel)) + if (IsValidEdict(iWorldModel)) SetEntProp(iWorldModel, Prop_Send, "m_nModelIndex", model_world); } char model_drop[192]; - if(GetTrieString(g_smClientWeapon[client], classname_drop, STRING(model_drop)) && !StrEqual(model_drop, "none")) + if (GetTrieString(g_smClientWeapon[client], classname_drop, STRING(model_drop)) && !StrEqual(model_drop, "none")) { - if(!IsModelPrecached(model_drop)) + if (!IsModelPrecached(model_drop)) LogError("Hook_WeaponEquip_Models -> not precached -> %s", model_drop); } int model_index; - if(!g_smClientWeapon[client].GetValue(classname, model_index) || model_index == -1) + if (!g_smClientWeapon[client].GetValue(classname, model_index) || model_index == -1) return Plugin_Continue; FormatEx(STRING(m_szGlobalName), "custom%i;%s", model_index, model_drop); @@ -256,7 +256,7 @@ public Action Hook_WeaponEquip_Models(int client, int weapon) public void Hook_WeaponDropPost_Models(int client, int weapon) { - if(!IsValidEdict(weapon)) + if (!IsValidEdict(weapon)) return; RequestFrame(SetWorldModel, EntIndexToEntRef(weapon)); @@ -266,55 +266,55 @@ public void Hook_PostThinkPost_Models(int client) { int model = EntRefToEntIndex(g_iRefPVM[client]); - if(model == INVALID_ENT_REFERENCE) + if (model == INVALID_ENT_REFERENCE) { SDKUnhook(client, SDKHook_PostThinkPost, Hook_PostThinkPost_Models); g_bHooked[client] = false; return; } - int m_iSequence = GetEntProp(model, Prop_Send, "m_nSequence"); - float m_fCycle = GetEntPropFloat(model, Prop_Data, "m_flCycle"); + int m_iSequence = GetEntProp(model, Prop_Send, "m_nSequence"); + float m_fCycle = GetEntPropFloat(model, Prop_Data, "m_flCycle"); - if(m_fCycle < g_fOldCycle[client] && m_iSequence == g_iOldSequence[client]) + if (m_fCycle < g_fOldCycle[client] && m_iSequence == g_iOldSequence[client]) { - if(StrEqual(g_szCurWpn[client], "weapon_knife")) + if (StrEqual(g_szCurWpn[client], "weapon_knife")) { - switch(m_iSequence) + switch (m_iSequence) { - case 3: SetEntProp(model, Prop_Send, "m_nSequence", 4); - case 4: SetEntProp(model, Prop_Send, "m_nSequence", 3); - case 5: SetEntProp(model, Prop_Send, "m_nSequence", 6); - case 6: SetEntProp(model, Prop_Send, "m_nSequence", 5); - case 7: SetEntProp(model, Prop_Send, "m_nSequence", 8); - case 8: SetEntProp(model, Prop_Send, "m_nSequence", 7); - case 9: SetEntProp(model, Prop_Send, "m_nSequence", 10); + case 3: SetEntProp(model, Prop_Send, "m_nSequence", 4); + case 4: SetEntProp(model, Prop_Send, "m_nSequence", 3); + case 5: SetEntProp(model, Prop_Send, "m_nSequence", 6); + case 6: SetEntProp(model, Prop_Send, "m_nSequence", 5); + case 7: SetEntProp(model, Prop_Send, "m_nSequence", 8); + case 8: SetEntProp(model, Prop_Send, "m_nSequence", 7); + case 9: SetEntProp(model, Prop_Send, "m_nSequence", 10); case 10: SetEntProp(model, Prop_Send, "m_nSequence", 11); case 11: SetEntProp(model, Prop_Send, "m_nSequence", 10); } } - else if(StrEqual(g_szCurWpn[client], "weapon_ak47")) + else if (StrEqual(g_szCurWpn[client], "weapon_ak47")) { - switch(m_iSequence) + switch (m_iSequence) { case 3: SetEntProp(model, Prop_Send, "m_nSequence", 2); case 2: SetEntProp(model, Prop_Send, "m_nSequence", 1); case 1: SetEntProp(model, Prop_Send, "m_nSequence", 3); } } - else if(StrEqual(g_szCurWpn[client], "weapon_mp7")) + else if (StrEqual(g_szCurWpn[client], "weapon_mp7")) { - if(m_iSequence == 3) + if (m_iSequence == 3) SetEntProp(model, Prop_Send, "m_nSequence", -1); } - else if(StrEqual(g_szCurWpn[client], "weapon_awp")) + else if (StrEqual(g_szCurWpn[client], "weapon_awp")) { - if(m_iSequence == 1) + if (m_iSequence == 1) SetEntProp(model, Prop_Send, "m_nSequence", -1); } - else if(StrEqual(g_szCurWpn[client], "weapon_deagle")) + else if (StrEqual(g_szCurWpn[client], "weapon_deagle")) { - switch(m_iSequence) + switch (m_iSequence) { case 3: SetEntProp(model, Prop_Send, "m_nSequence", 2); case 2: SetEntProp(model, Prop_Send, "m_nSequence", 1); @@ -324,7 +324,7 @@ public void Hook_PostThinkPost_Models(int client) } g_iOldSequence[client] = m_iSequence; - g_fOldCycle[client] = m_fCycle; + g_fOldCycle[client] = m_fCycle; } public Action Hook_WeaponCanUse(int client, int weapon) @@ -336,13 +336,13 @@ void SetWorldModel(int iRef) { int weapon = EntRefToEntIndex(iRef); - if(!IsValidEdict(weapon)) + if (!IsValidEdict(weapon)) return; char m_szGlobalName[256]; GetEntPropString(weapon, Prop_Data, "m_iGlobalname", STRING(m_szGlobalName)); - if(StrContains(m_szGlobalName, "custom", false) != 0) + if (StrContains(m_szGlobalName, "custom", false) != 0) return; ReplaceString(STRING(m_szGlobalName), "custom", ""); @@ -350,7 +350,7 @@ void SetWorldModel(int iRef) char m_szData[2][192]; ExplodeString(m_szGlobalName, ";", m_szData, 2, 192); - if(StrEqual(m_szData[1], "none")) + if (StrEqual(m_szData[1], "none")) return; SetEntityModel(weapon, m_szData[1]); @@ -358,24 +358,24 @@ void SetWorldModel(int iRef) bool Models_AddModels(int client, const char[] classname, int model_view, int model_world, const char[] model_drop) { - if(!IsClientInGame(client) || g_smClientWeapon[client] == INVALID_HANDLE) + if (!IsClientInGame(client) || g_smClientWeapon[client] == INVALID_HANDLE) return false; - if(GetTrieSize(g_smClientWeapon[client]) == 0) + if (GetTrieSize(g_smClientWeapon[client]) == 0) { SDKHook(client, SDKHook_WeaponSwitchPost, Hook_WeaponSwitchPost_Models); - SDKHook(client, SDKHook_WeaponSwitch, Hook_WeaponSwitch_Models); - SDKHook(client, SDKHook_WeaponEquip, Hook_WeaponEquip_Models); - SDKHook(client, SDKHook_WeaponDropPost, Hook_WeaponDropPost_Models); + SDKHook(client, SDKHook_WeaponSwitch, Hook_WeaponSwitch_Models); + SDKHook(client, SDKHook_WeaponEquip, Hook_WeaponEquip_Models); + SDKHook(client, SDKHook_WeaponDropPost, Hook_WeaponDropPost_Models); } char world_name[32], drop_name[32]; FormatEx(STRING(world_name), "%s_world", classname); - FormatEx(STRING(drop_name), "%s_drop", classname); + FormatEx(STRING(drop_name), "%s_drop", classname); - SetTrieValue(g_smClientWeapon[client], classname, model_view); - SetTrieValue(g_smClientWeapon[client], world_name, model_world); - SetTrieString(g_smClientWeapon[client], drop_name, model_drop); + SetTrieValue(g_smClientWeapon[client], classname, model_view); + SetTrieValue(g_smClientWeapon[client], world_name, model_world); + SetTrieString(g_smClientWeapon[client], drop_name, model_drop); RefreshWeapon(client, classname); @@ -384,23 +384,23 @@ bool Models_AddModels(int client, const char[] classname, int model_view, int mo bool Models_RemoveModels(int client, const char[] classname) { - if(!IsClientInGame(client) || g_smClientWeapon[client] == null) + if (!IsClientInGame(client) || g_smClientWeapon[client] == null) return false; char world_name[32], drop_name[32]; FormatEx(STRING(world_name), "%s_world", classname); - FormatEx(STRING(drop_name), "%s_drop", classname); + FormatEx(STRING(drop_name), "%s_drop", classname); g_smClientWeapon[client].Remove(classname); g_smClientWeapon[client].Remove(world_name); g_smClientWeapon[client].Remove(drop_name); - if(GetTrieSize(g_smClientWeapon[client]) == 0) + if (GetTrieSize(g_smClientWeapon[client]) == 0) { SDKUnhook(client, SDKHook_WeaponSwitchPost, Hook_WeaponSwitchPost_Models); - SDKUnhook(client, SDKHook_WeaponSwitch, Hook_WeaponSwitch_Models); - SDKUnhook(client, SDKHook_WeaponEquip, Hook_WeaponEquip_Models); - SDKUnhook(client, SDKHook_WeaponDropPost, Hook_WeaponDropPost_Models); + SDKUnhook(client, SDKHook_WeaponSwitch, Hook_WeaponSwitch_Models); + SDKUnhook(client, SDKHook_WeaponEquip, Hook_WeaponEquip_Models); + SDKUnhook(client, SDKHook_WeaponDropPost, Hook_WeaponDropPost_Models); } RefreshWeapon(client, classname); @@ -410,20 +410,20 @@ bool Models_RemoveModels(int client, const char[] classname) void RefreshWeapon(int client, const char[] classname) { - if(!IsClientInGame(client) || !IsPlayerAlive(client)) + if (!IsClientInGame(client) || !IsPlayerAlive(client)) return; int weapon = GetClientWeaponIndexByClassname(client, classname); - if(weapon == -1) + if (weapon == -1) return; - int m_iPrimaryAmmoCount = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoCount"); + int m_iPrimaryAmmoCount = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoCount"); int m_iSecondaryAmmoCount = GetEntProp(weapon, Prop_Data, "m_iSecondaryAmmoCount"); - int m_iClip1 = GetEntProp(weapon, Prop_Data, "m_iClip1"); - int m_iClip2 = GetEntProp(weapon, Prop_Data, "m_iClip2"); + int m_iClip1 = GetEntProp(weapon, Prop_Data, "m_iClip1"); + int m_iClip2 = GetEntProp(weapon, Prop_Data, "m_iClip2"); - if(GetEntPropEnt(weapon, Prop_Send, "m_hOwner") != client) + if (GetEntPropEnt(weapon, Prop_Send, "m_hOwner") != client) SetEntPropEnt(weapon, Prop_Send, "m_hOwner", client); AcceptEntityInput(weapon, "Kill"); @@ -437,7 +437,7 @@ void RefreshWeapon(int client, const char[] classname) pack.Reset(); CreateTimer(0.2, Timer_GiveBackWeapon, pack); - if(GetPlayerWeaponSlot(client, 0) == -1 && GetPlayerWeaponSlot(client, 1) == -1 && GetPlayerWeaponSlot(client, 2) == -1 && GetPlayerWeaponSlot(client, 3) == -1 && GetPlayerWeaponSlot(client, 4) == -1) + if (GetPlayerWeaponSlot(client, 0) == -1 && GetPlayerWeaponSlot(client, 1) == -1 && GetPlayerWeaponSlot(client, 2) == -1 && GetPlayerWeaponSlot(client, 3) == -1 && GetPlayerWeaponSlot(client, 4) == -1) CreateTimer(0.25, Timer_RemoveDummyWeapon, GivePlayerItem(client, "weapon_decoy")); SDKHook(client, SDKHook_WeaponCanUse, Hook_WeaponCanUse); @@ -447,38 +447,42 @@ public Action Timer_GiveBackWeapon(Handle timer, DataPack pack) { char classname[32]; pack.ReadString(STRING(classname)); - int client = pack.ReadCell(); - int m_iPrimaryAmmoCount = pack.ReadCell(); + int client = pack.ReadCell(); + int m_iPrimaryAmmoCount = pack.ReadCell(); int m_iSecondaryAmmoCount = pack.ReadCell(); - int m_iClip1 = pack.ReadCell(); - int m_iClip2 = pack.ReadCell(); + int m_iClip1 = pack.ReadCell(); + int m_iClip2 = pack.ReadCell(); delete pack; - if(!IsClientInGame(client)) + if (!IsClientInGame(client)) return Plugin_Stop; SDKUnhook(client, SDKHook_WeaponCanUse, Hook_WeaponCanUse); - if(!IsPlayerAlive(client)) + if (!IsPlayerAlive(client)) return Plugin_Stop; int weapon = GivePlayerItem(client, classname); - if(StrEqual(classname, "weapon_knife")) + if (StrEqual(classname, "weapon_knife")) EquipPlayerWeapon(client, weapon); - if(m_iPrimaryAmmoCount > -1) SetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoCount", m_iPrimaryAmmoCount); - if(m_iSecondaryAmmoCount > -1) SetEntProp(weapon, Prop_Data, "m_iSecondaryAmmoCount", m_iSecondaryAmmoCount); - if(m_iClip1 > -1) SetEntProp(weapon, Prop_Data, "m_iClip1", m_iClip1); - if(m_iClip2 > -1) SetEntProp(weapon, Prop_Data, "m_iClip2", m_iClip2); + if (m_iPrimaryAmmoCount > -1) + SetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoCount", m_iPrimaryAmmoCount); + if (m_iSecondaryAmmoCount > -1) + SetEntProp(weapon, Prop_Data, "m_iSecondaryAmmoCount", m_iSecondaryAmmoCount); + if (m_iClip1 > -1) + SetEntProp(weapon, Prop_Data, "m_iClip1", m_iClip1); + if (m_iClip2 > -1) + SetEntProp(weapon, Prop_Data, "m_iClip2", m_iClip2); return Plugin_Stop; } public Action Timer_RemoveDummyWeapon(Handle timer, int weapon) { - if(IsValidEdict(weapon)) + if (IsValidEdict(weapon)) AcceptEntityInput(weapon, "Kill"); return Plugin_Stop; } @@ -491,7 +495,7 @@ int GetViewModelReference(int client, int entity) { owner = GetEntPropEnt(entity, Prop_Send, "m_hOwner"); - if(owner == client) + if (owner == client) return EntIndexToEntRef(entity); } @@ -500,7 +504,7 @@ int GetViewModelReference(int client, int entity) int FindEntityByClassname2(int start, const char[] classname) { - while(start > MaxClients && !IsValidEntity(start)) + while (start > MaxClients && !IsValidEntity(start)) start--; return FindEntityByClassname(start, classname); @@ -508,13 +512,13 @@ int FindEntityByClassname2(int start, const char[] classname) stock bool GetWeaponClassname(int weapon, char[] classname, int maxLen) { - if(!GetEdictClassname(weapon, classname, maxLen)) + if (!GetEdictClassname(weapon, classname, maxLen)) return false; - if(!HasEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex")) + if (!HasEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex")) return false; - switch(GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex")) + switch (GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex")) { case 60: strcopy(classname, maxLen, "weapon_m4a1_silencer"); case 61: strcopy(classname, maxLen, "weapon_usp_silencer"); @@ -530,18 +534,18 @@ stock int GetClientWeaponIndexByClassname(int client, const char[] classname) { int offset = FindDataMapInfo(client, "m_hMyWeapons") - 4; - int weapon = -1; + int weapon = -1; char weaponclass[32]; - for(int i = 0; i < 48; ++i) + for (int i = 0; i < 48; ++i) { offset += 4; weapon = GetEntDataEnt2(client, offset); - if(!IsValidEdict(weapon) || !GetEdictClassname(weapon, STRING(weaponclass)) || StrContains(weaponclass, "weapon_") != 0) + if (!IsValidEdict(weapon) || !GetEdictClassname(weapon, STRING(weaponclass)) || StrContains(weaponclass, "weapon_") != 0) continue; - if(strcmp(weaponclass, classname) == 0) + if (strcmp(weaponclass, classname) == 0) return weapon; } diff --git a/modules/store_musickit.sp b/modules/store_musickit.sp index 1cb6706..c705595 100644 --- a/modules/store_musickit.sp +++ b/modules/store_musickit.sp @@ -16,12 +16,11 @@ public Plugin myinfo = #define MAX_MUSIC_ID 40 -int c_unMusicID[MAXPLAYERS+1]; +int c_unMusicID[MAXPLAYERS + 1]; int g_unMusicID[MAX_MUSIC_ID]; int g_iMusicKit = -1; // data `music id` store in filed 'sound' - public void Store_OnStoreInit(Handle store_plugin) { Store_RegisterHandler("musickit", MK_OnMapStart, MK_Reset, MK_Config, MK_Equip, MK_Remove, true); @@ -29,7 +28,6 @@ public void Store_OnStoreInit(Handle store_plugin) public void MK_OnMapStart() { - } public void MK_Reset() diff --git a/modules/store_pet.sp b/modules/store_pet.sp index e75dee7..ab82f6b 100644 --- a/modules/store_pet.sp +++ b/modules/store_pet.sp @@ -20,22 +20,22 @@ public Plugin myinfo = url = STORE_URL }; -enum struct Pet +abstract_struct Pet { - char model[192]; - char idle[32]; - char idle2[32]; - char run[32]; - char spawn[32]; - char death[32]; + char model[192]; + char idle[32]; + char idle2[32]; + char run[32]; + char spawn[32]; + char death[32]; float fPosition[3]; float fAngles[3]; float fScale; - int iSlot; - int iTeam; + int iSlot; + int iTeam; } -enum struct PetInfo_t +abstract_struct PetInfo_t { int m_iEntRef; int m_iDataIndex; @@ -46,7 +46,7 @@ enum struct PetInfo_t void Reset() { - this.m_iEntRef = INVALID_ENT_REFERENCE; + this.m_iEntRef = INVALID_ENT_REFERENCE; this.m_iDataIndex = -1; } } @@ -54,16 +54,16 @@ enum struct PetInfo_t static int g_iPets = 0; static int g_iOwner[2048]; -static Handle g_hDelay[MAXPLAYERS+1]; +static Handle g_hDelay[MAXPLAYERS + 1]; -static Pet g_ePets[STORE_MAX_ITEMS]; -static PetInfo_t g_sPetRef[MAXPLAYERS+1][STORE_MAX_SLOTS]; +static Pet g_ePets[STORE_MAX_ITEMS]; +static PetInfo_t g_sPetRef[MAXPLAYERS + 1][STORE_MAX_SLOTS]; public void OnPluginStart() { HookEvent("player_spawn", Pets_PlayerSpawn, EventHookMode_Post); HookEvent("player_death", Pets_PlayerDeath, EventHookMode_Post); - HookEvent("player_team", Pets_PlayerTeam, EventHookMode_Post); + HookEvent("player_team", Pets_PlayerTeam, EventHookMode_Post); } public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) @@ -88,21 +88,21 @@ public void Store_OnStoreInit(Handle store_plugin) Store_RegisterHandler("pet", Pets_OnMapStart, Pets_Reset, Pets_Config, Pets_Equip, Pets_Remove, true); } -public void Pets_OnMapStart() +static void Pets_OnMapStart() { - for(int i = 0; i < g_iPets; ++i) + for (int i = 0; i < g_iPets; ++i) { PrecacheModel(g_ePets[i].model, false); AddFileToDownloadsTable(g_ePets[i].model); } } -public void Pets_Reset() +static void Pets_Reset() { g_iPets = 0; } -public bool Pets_Config(Handle kv, int itemid) +static bool Pets_Config(Handle kv, int itemid) { Store_SetDataIndex(itemid, g_iPets); @@ -117,11 +117,11 @@ public bool Pets_Config(Handle kv, int itemid) g_ePets[g_iPets].fPosition = m_fTemp; KvGetVector(kv, "angles", m_fTemp); g_ePets[g_iPets].fAngles = m_fTemp; - g_ePets[g_iPets].iSlot = KvGetNum(kv, "slot"); - g_ePets[g_iPets].iTeam = KvGetNum(kv, "team"); - g_ePets[g_iPets].fScale = KvGetFloat(kv, "scale", 1.0); + g_ePets[g_iPets].iSlot = KvGetNum(kv, "slot"); + g_ePets[g_iPets].iTeam = KvGetNum(kv, "team"); + g_ePets[g_iPets].fScale = KvGetFloat(kv, "scale", 1.0); - if(FileExists(g_ePets[g_iPets].model, true)) + if (FileExists(g_ePets[g_iPets].model, true)) { ++g_iPets; return true; @@ -130,28 +130,28 @@ public bool Pets_Config(Handle kv, int itemid) return false; } -public int Pets_Equip(int client, int id) +static int Pets_Equip(int client, int id) { int m_iData = Store_GetDataIndex(id); ResetPet(client, g_ePets[m_iData].iSlot); - if(IsPlayerAlive(client)) + if (IsPlayerAlive(client)) CreatePet(client, id, g_ePets[m_iData].iSlot); return g_ePets[m_iData].iSlot; } -public int Pets_Remove(int client, int id) +static int Pets_Remove(int client, int id) { int m_iData = Store_GetDataIndex(id); ResetPet(client, g_ePets[m_iData].iSlot); return g_ePets[m_iData].iSlot; } -void Store_SetClientPet(int client) +void Pet_SetClientPet(int client) { - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) { ResetPet(client, i); CreatePet(client, -1, i); @@ -160,19 +160,19 @@ void Store_SetClientPet(int client) void Store_ClientDeathPet(int client) { - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) DeathPet(client, i); } void Store_RemovePet(int client) { - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) ResetPet(client, i); } public void OnClientConnected(int client) { - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) g_sPetRef[client][i].Reset(); } @@ -183,37 +183,34 @@ public void OnClientDisconnect(int client) Store_RemovePet(client); } -public void Pets_PlayerSpawn(Handle event, const char[] name, bool dontBroadcast) +static void Pets_PlayerSpawn(Event event, const char[] name, bool dontBroadcast) { // fix first join - if (GetEventInt(event, "teamnum") == 0) + if (event.GetInt("teamnum") == 0) return; - //TODO performance problem - // I don't know why player_spwan called twice... - - int client = GetClientOfUserId(GetEventInt(event, "userid")); + int client = GetClientOfUserId(event.GetInt("userid")); if (IsFakeClient(client)) return; delete g_hDelay[client]; - g_hDelay[client] = CreateTimer(UTIL_GetRandomInt(1, 10) * 0.1, Timer_DelaySpawn, client); + g_hDelay[client] = CreateTimer(0.5 + client * 0.1, Timer_DelaySpawn, client); } -Action Timer_DelaySpawn(Handle timer, int client) +static Action Timer_DelaySpawn(Handle timer, int client) { g_hDelay[client] = null; if (IsPlayerAlive(client)) { - Store_SetClientPet(client); + Pet_SetClientPet(client); } return Plugin_Stop; } -public void Pets_PlayerDeath(Handle event, const char[] name, bool dontBroadcast) +static void Pets_PlayerDeath(Event event, const char[] name, bool dontBroadcast) { - int client = GetClientOfUserId(GetEventInt(event, "userid")); + int client = GetClientOfUserId(event.GetInt("userid")); if (IsFakeClient(client)) return; @@ -221,14 +218,14 @@ public void Pets_PlayerDeath(Handle event, const char[] name, bool dontBroadcast Store_ClientDeathPet(client); } -public void Pets_PlayerTeam(Handle event, const char[] name, bool dontBroadcast) +static void Pets_PlayerTeam(Event event, const char[] name, bool dontBroadcast) { - int client = GetClientOfUserId(GetEventInt(event, "userid")); + int client = GetClientOfUserId(event.GetInt("userid")); - if(IsFakeClient(client)) + if (IsFakeClient(client)) return; - if (GetEventInt(event, "team") <= 1) + if (event.GetInt("team") <= 1) { // spec only Store_RemovePet(client); @@ -237,25 +234,25 @@ public void Pets_PlayerTeam(Handle event, const char[] name, bool dontBroadcast) public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype, int cmdnum, int tickcount, int seed, const int mouse[2]) { - if(tickcount % 8 != 0 || !IsPlayerAlive(client) || IsFakeClient(client)) + if (tickcount % 8 != 0 || !IsPlayerAlive(client) || IsFakeClient(client)) return; float CurVec[3]; GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", CurVec); float CurDist = GetVectorLength(CurVec); - for(int i = 0; i < STORE_MAX_SLOTS; ++i) + for (int i = 0; i < STORE_MAX_SLOTS; ++i) AdjustPet(client, i, CurDist); } -void AdjustPet(int client, int slot, const float fDist) +static void AdjustPet(int client, int slot, const float fDist) { - if(g_sPetRef[client][slot].m_iEntRef == INVALID_ENT_REFERENCE) + if (g_sPetRef[client][slot].m_iEntRef == INVALID_ENT_REFERENCE) return; int entity = EntRefToEntIndex(g_sPetRef[client][slot].m_iEntRef); - if(!IsValidEdict(entity)) + if (entity < MaxClients) return; int time = GetTime(); @@ -266,13 +263,13 @@ void AdjustPet(int client, int slot, const float fDist) if (m_iData < 0) return; - if(g_sPetRef[client][slot].m_iLastAnimation != 1 && fDist > 0.0 && g_ePets[m_iData].run[0]) + if (g_sPetRef[client][slot].m_iLastAnimation != 1 && fDist > 0.0 && g_ePets[m_iData].run[0]) { SetVariantString(g_ePets[m_iData].run); AcceptEntityInput(entity, "SetAnimation"); g_sPetRef[client][slot].m_iLastAnimation = 1; } - else if(g_sPetRef[client][slot].m_iLastAnimation != 2 && fDist == 0.0 && g_ePets[m_iData].idle[0]) + else if (g_sPetRef[client][slot].m_iLastAnimation != 2 && fDist == 0.0 && g_ePets[m_iData].idle[0]) { if (g_sPetRef[client][slot].m_iNextIdleTimes < time && g_ePets[m_iData].idle2[0]) { @@ -289,9 +286,9 @@ void AdjustPet(int client, int slot, const float fDist) } } -void CreatePet(int client, int itemid = -1, int slot = 0) +static void CreatePet(int client, int itemid = -1, int slot = 0) { - if(g_sPetRef[client][slot].m_iEntRef != INVALID_ENT_REFERENCE) + if (g_sPetRef[client][slot].m_iEntRef != INVALID_ENT_REFERENCE) { LogError("Why you create entity with equipped slot?"); return; @@ -299,7 +296,7 @@ void CreatePet(int client, int itemid = -1, int slot = 0) int m_iEquipped = (itemid == -1 ? Store_GetEquippedItem(client, "pet", slot) : itemid); - if(m_iEquipped < 0) + if (m_iEquipped < 0) return; int m_iData = Store_GetDataIndex(m_iEquipped); @@ -308,7 +305,7 @@ void CreatePet(int client, int itemid = -1, int slot = 0) return; int entity = CreateEntityByName("prop_dynamic_override"); - if(entity == -1) + if (entity == INVALID_ENT_REFERENCE) return; float m_flPosition[3]; @@ -321,18 +318,18 @@ void CreatePet(int client, int itemid = -1, int slot = 0) m_flPosition[0] = g_ePets[m_iData].fPosition[0]; m_flPosition[1] = g_ePets[m_iData].fPosition[1]; m_flPosition[2] = g_ePets[m_iData].fPosition[2]; - m_flAngles[0] = g_ePets[m_iData].fAngles[0]; - m_flAngles[1] = g_ePets[m_iData].fAngles[1]; - m_flAngles[2] = g_ePets[m_iData].fAngles[2]; + m_flAngles[0] = g_ePets[m_iData].fAngles[0]; + m_flAngles[1] = g_ePets[m_iData].fAngles[1]; + m_flAngles[2] = g_ePets[m_iData].fAngles[2]; float m_fForward[3]; float m_fRight[3]; float m_fUp[3]; GetAngleVectors(m_flClientAngles, m_fForward, m_fRight, m_fUp); - m_flClientOrigin[0] += m_fRight[0]*m_flPosition[0]+m_fForward[0]*m_flPosition[1]+m_fUp[0]*m_flPosition[2]; - m_flClientOrigin[1] += m_fRight[1]*m_flPosition[0]+m_fForward[1]*m_flPosition[1]+m_fUp[1]*m_flPosition[2]; - m_flClientOrigin[2] += m_fRight[2]*m_flPosition[0]+m_fForward[2]*m_flPosition[1]+m_fUp[2]*m_flPosition[2]; + m_flClientOrigin[0] += m_fRight[0] * m_flPosition[0] + m_fForward[0] * m_flPosition[1] + m_fUp[0] * m_flPosition[2]; + m_flClientOrigin[1] += m_fRight[1] * m_flPosition[0] + m_fForward[1] * m_flPosition[1] + m_fUp[1] * m_flPosition[2]; + m_flClientOrigin[2] += m_fRight[2] * m_flPosition[0] + m_fForward[2] * m_flPosition[1] + m_fUp[2] * m_flPosition[2]; m_flAngles[1] += m_flClientAngles[1]; DispatchKeyValue(entity, "targetname", "store_item_pet"); @@ -352,8 +349,8 @@ void CreatePet(int client, int itemid = -1, int slot = 0) SetVariantString("!activator"); AcceptEntityInput(entity, "SetParent", client, entity, 0); - g_sPetRef[client][slot].m_iDataIndex = m_iData; - g_sPetRef[client][slot].m_iEntRef = EntIndexToEntRef(entity); + g_sPetRef[client][slot].m_iDataIndex = m_iData; + g_sPetRef[client][slot].m_iEntRef = EntIndexToEntRef(entity); g_sPetRef[client][slot].m_iLastAnimation = -1; g_sPetRef[client][slot].m_iLastSpawnTime = GetTime() + 2; @@ -368,70 +365,73 @@ void CreatePet(int client, int itemid = -1, int slot = 0) Call_OnPetsCreated(client, entity, slot); } -void ResetPet(int client, int slot) +static void ResetPet(int client, int slot) { - if(g_sPetRef[client][slot].m_iEntRef == INVALID_ENT_REFERENCE) + if (g_sPetRef[client][slot].m_iEntRef == INVALID_ENT_REFERENCE) return; int entity = EntRefToEntIndex(g_sPetRef[client][slot].m_iEntRef); g_sPetRef[client][slot].Reset(); - if(entity == -1 || !IsValidEdict(client)) + if (entity < MaxClients) return; - AcceptEntityInput(entity, "Kill"); + RemoveEntity(entity); - g_iOwner[entity] = -1; + g_iOwner[entity] = INVALID_ENT_REFERENCE; } -void DeathPet(int client, int slot) +static void DeathPet(int client, int slot) { - if(g_sPetRef[client][slot].m_iEntRef == INVALID_ENT_REFERENCE) + if (g_sPetRef[client][slot].m_iEntRef == INVALID_ENT_REFERENCE) return; int entity = EntRefToEntIndex(g_sPetRef[client][slot].m_iEntRef); - if(!IsValidEdict(entity)) + if (entity < MaxClients) return; int m_iData = g_sPetRef[client][slot].m_iDataIndex; if (m_iData < 0) return; - if(g_ePets[m_iData].death[0] == '\0') + if (g_ePets[m_iData].death[0] == 0) { ResetPet(client, slot); return; } - SetVariantString(g_ePets[m_iData].death); - AcceptEntityInput(entity, "SetAnimation"); - g_sPetRef[client][slot].m_iLastAnimation = 3; - HookSingleEntityOutput(entity, "OnAnimationDone", Hook_OnAnimationDone, true); - // Fix some pets deadlock SetVariantString("OnUser4 !self:Kill::3.0:1"); if (!AcceptEntityInput(entity, "AddOutput") || !AcceptEntityInput(entity, "FireUser4")) + { ResetPet(client, slot); + return; + } + + SetVariantString(g_ePets[m_iData].death); + AcceptEntityInput(entity, "SetAnimation"); + g_sPetRef[client][slot].m_iLastAnimation = 3; + HookSingleEntityOutput(entity, "OnAnimationDone", Hook_OnAnimationDone, true); } -public void Hook_OnAnimationDone(const char[] output, int caller, int activator, float delay) +static void Hook_OnAnimationDone(const char[] output, int caller, int activator, float delay) { - if(!IsValidEdict(caller)) + if (!IsValidEdict(caller)) return; int owner = GetEntPropEnt(caller, Prop_Send, "m_hOwnerEntity"); - if(1 <= owner <= MaxClients && IsClientInGame(owner)) + if (1 <= owner <= MaxClients && IsClientInGame(owner)) { int iRef = EntIndexToEntRef(caller); - for(int slot = 0; slot < STORE_MAX_SLOTS; ++slot) - if(g_sPetRef[owner][slot].m_iEntRef == iRef) + for (int slot = 0; slot < STORE_MAX_SLOTS; ++slot) + if (g_sPetRef[owner][slot].m_iEntRef == iRef) g_sPetRef[owner][slot].Reset(); } - AcceptEntityInput(caller, "Kill"); + RemoveEntity(caller); } stock void Call_OnPetsCreated(int client, int entity, int slot) diff --git a/modules/store_randomskin.sp b/modules/store_randomskin.sp index c6f8e4d..79137a4 100644 --- a/modules/store_randomskin.sp +++ b/modules/store_randomskin.sp @@ -24,9 +24,9 @@ public Plugin myinfo = url = STORE_URL }; -#define MAX_SKINS 24 -#define TYPE_NAME_STATUS "Store.RandomSkins.Status" -#define TYPE_NAME_PREVAL "Store.RandomSkins.PrevAL" +#define MAX_SKINS 24 +#define TYPE_NAME_STATUS "Store.RandomSkins.Status" +#define TYPE_NAME_PREVAL "Store.RandomSkins.PrevAL" // copy from fys.opts #define MAX_OPTS_KEY_LENGTH 32 @@ -50,11 +50,11 @@ static char g_sOptionTeamName[][] = { bool g_pOptions; bool g_pCookies; -Handle g_hCookies[5]; +Cookie g_hCookies[5]; ArrayList g_aSkins; -bool g_bLateLoad; -ConVar store_randomskin_same_model_in_round; +bool g_bLateLoad; +ConVar store_randomskin_same_model_in_round; char g_sPrevious[MAXPLAYERS][5][MAX_OPTS_KEY_LENGTH]; int g_iSelected[MAXPLAYERS]; @@ -105,12 +105,12 @@ public void OnLibraryAdded(const char[] name) { if (strcmp(name, "clientprefs") == 0) { - g_pCookies = true; - g_hCookies[TYPE_INDEX_STATUS] = RegClientCookie(TYPE_NAME_STATUS, "Random skin feature stats", CookieAccess_Protected); - g_hCookies[TYPE_INDEX_PREVAL] = RegClientCookie(TYPE_NAME_PREVAL, "Random skin allow previouse", CookieAccess_Protected); - g_hCookies[TEAM_TE] = RegClientCookie(g_sOptionTeamName[TEAM_TE], "Random skin equipments te", CookieAccess_Protected); - g_hCookies[TEAM_CT] = RegClientCookie(g_sOptionTeamName[TEAM_CT], "Random skin equipments ct", CookieAccess_Protected); - g_hCookies[TEAM_GX] = RegClientCookie(g_sOptionTeamName[TEAM_GX], "Random skin equipments gx", CookieAccess_Protected); + g_pCookies = true; + g_hCookies[TYPE_INDEX_STATUS] = new Cookie(TYPE_NAME_STATUS, "Random skin feature stats", CookieAccess_Protected); + g_hCookies[TYPE_INDEX_PREVAL] = new Cookie(TYPE_NAME_PREVAL, "Random skin allow previouse", CookieAccess_Protected); + g_hCookies[TEAM_TE] = new Cookie(g_sOptionTeamName[TEAM_TE], "Random skin equipments te", CookieAccess_Protected); + g_hCookies[TEAM_CT] = new Cookie(g_sOptionTeamName[TEAM_CT], "Random skin equipments ct", CookieAccess_Protected); + g_hCookies[TEAM_GX] = new Cookie(g_sOptionTeamName[TEAM_GX], "Random skin equipments gx", CookieAccess_Protected); } if (strcmp(name, "fys-Opts") == 0) @@ -151,6 +151,7 @@ public void Pupd_OnCheckAllPlugins() public void Store_OnStoreAvailable(ArrayList items) { + g_aSkins.Clear(); Store_GetAllPlayerSkins(g_aSkins); for (int i = 0; i < MAXPLAYERS; i++) OnClientConnected(i); @@ -166,10 +167,10 @@ static Action Command_RandomSkin(int client, int args) return Plugin_Handled; } -void DisplayMainMenu(int client) +static void DisplayMainMenu(int client) { g_iSelected[client] = GetClientTeam(client); - bool global = Store_IsGlobalTeam(); + bool global = Store_IsGlobalTeam(); if (!global && g_iSelected[client] <= 1) { @@ -179,13 +180,15 @@ void DisplayMainMenu(int client) bool changed = false; - char options[MAX_OPTS_VAL_LENGTH], skin[MAX_SKINS][MAX_OPTS_KEY_LENGTH]; + char options[MAX_OPTS_VAL_LENGTH]; + char skin[MAX_SKINS][MAX_OPTS_KEY_LENGTH]; GetPlayerEquips(client, options); - int equipments = 0, count = ExplodeString(options, ";", skin, MAX_SKINS, sizeof(skin[]), false); + int equipments = 0; + int count = ExplodeString(options, ";", skin, MAX_SKINS, sizeof(skin[]), false); for (int i = 0; i < count; i++) { - if (strlen(skin[i]) > 0) + if (skin[i][0]) { int itemid = Store_GetItemId(skin[i]); if (itemid > -1) @@ -204,8 +207,8 @@ void DisplayMainMenu(int client) int skinTeam = GetSkinTeamById(skin[i]); if (skinTeam != g_iSelected[client]) { - if (skinTeam == TEAM_GX) - PrintToServer("[RS] <%s> mismatch team at %d", skin[i], skinTeam); + // if (skinTeam == TEAM_GX) + // PrintToServer("[RS] <%s> mismatch team at %d", skin[i], skinTeam); // skip if not match team char item[MAX_OPTS_KEY_LENGTH]; @@ -226,7 +229,8 @@ void DisplayMainMenu(int client) SetPlayerEquips(client, options); } - char buffer[64]; char key[16]; + char buffer[64]; + char key[16]; IntToString(g_iSelected[client], STRING(key)); Menu menu = new Menu(MenuHandler_Main); @@ -234,16 +238,16 @@ void DisplayMainMenu(int client) menu.SetTitle("[Store] %T\nE: %d ", "random skin", client, equipments); FormatEx(STRING(buffer), "%T: %T", "feature status", client, GetPlayerStatus(client) ? "On" : "Off", client); - menu.AddItem(key, buffer); + menu.AddItem(key, buffer); FormatEx(STRING(buffer), "%T: %T", "allow previous", client, GetPlayerPrevious(client) ? "On" : "Off", client); - menu.AddItem(key, buffer); + menu.AddItem(key, buffer); FormatEx(STRING(buffer), "%T", "select skin", client); - menu.AddItem(key, buffer, !global && g_iSelected[client] <= TEAM_OB ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT); + menu.AddItem(key, buffer, !global && g_iSelected[client] <= TEAM_OB ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT); FormatEx(STRING(buffer), "%T", "clear all", client); - menu.AddItem(key, buffer); + menu.AddItem(key, buffer); menu.ExitBackButton = false; menu.Display(client, 15); @@ -263,7 +267,7 @@ static int MenuHandler_Main(Menu menu, MenuAction action, int client, int slot) if (StringToInt(key) != GetClientTeam(client)) { - //PrintToServer("[RS] %N changed team since menu opened!", client); + // PrintToServer("[RS] %N changed team since menu opened!", client); DisplayMainMenu(client); return 0; } @@ -296,10 +300,10 @@ static int MenuHandler_Main(Menu menu, MenuAction action, int client, int slot) return 0; } -void DisplaySkinMenu(int client, int position = -1) +static void DisplaySkinMenu(int client, int position = -1) { g_iSelected[client] = GetClientTeam(client); - bool global = Store_IsGlobalTeam(); + bool global = Store_IsGlobalTeam(); ArrayList array = new ArrayList(sizeof(SkinData_t)); Store_GetClientPlayerSkins(client, array); @@ -325,7 +329,7 @@ void DisplaySkinMenu(int client, int position = -1) } // HACK xkey should include current team - char xkey[MAX_OPTS_KEY_LENGTH+1+16], options[MAX_OPTS_VAL_LENGTH]; + char xkey[MAX_OPTS_KEY_LENGTH + 1 + 16], options[MAX_OPTS_VAL_LENGTH]; GetPlayerEquips(client, options); Menu menu = new Menu(MenuHandler_Skin); @@ -352,12 +356,12 @@ void DisplaySkinMenu(int client, int position = -1) } menu.ExitBackButton = true; - menu.ExitButton = true; + menu.ExitButton = true; if (position == -1) menu.Display(client, 60); else - menu.DisplayAt(client, (position/menu.Pagination)*menu.Pagination, 60); + menu.DisplayAt(client, (position / menu.Pagination) * menu.Pagination, 60); delete array; } @@ -373,7 +377,7 @@ static int MenuHandler_Skin(Menu menu, MenuAction action, int client, int slot) char explode[2][MAX_OPTS_KEY_LENGTH]; if (FindCharInString(data, '^', false) != 1) { - //PrintToServer("[RS] invalid key from MenuHandler_Skin -> [%s]", data); + // PrintToServer("[RS] invalid key from MenuHandler_Skin -> [%s]", data); DisplayMainMenu(client); return 0; } @@ -381,7 +385,7 @@ static int MenuHandler_Skin(Menu menu, MenuAction action, int client, int slot) if (!Store_IsGlobalTeam() && StringToInt(explode[0]) != GetClientTeam(client)) { - //PrintToServer("[RS] %N changed team since menu opened!", client); + // PrintToServer("[RS] %N changed team since menu opened!", client); DisplayMainMenu(client); return 0; } @@ -393,16 +397,16 @@ static int MenuHandler_Skin(Menu menu, MenuAction action, int client, int slot) if (StrContains(options, xkey) > -1) { ReplaceString(STRING(options), xkey, ""); - //PrintToChat(client, "REPLACE %s", xkey); + // PrintToChat(client, "REPLACE %s", xkey); } else { StrCat(STRING(options), xkey); - //PrintToChat(client, "Cat %s", xkey); + // PrintToChat(client, "Cat %s", xkey); } SetPlayerEquips(client, options); - //PrintToChat(client, "options -=> [%s]", options); + // PrintToChat(client, "options -=> [%s]", options); DisplaySkinMenu(client, slot); } else if (action == MenuAction_Cancel && slot == MenuCancel_ExitBack) @@ -450,7 +454,7 @@ public Action Store_OnSetPlayerSkin(int client, char _skin[128], char _arms[128] } } - int origin = g_iSelected[client]; + int origin = g_iSelected[client]; g_iSelected[client] = teamEx; char options[MAX_OPTS_VAL_LENGTH], skin[MAX_SKINS][MAX_OPTS_KEY_LENGTH]; @@ -460,7 +464,7 @@ public Action Store_OnSetPlayerSkin(int client, char _skin[128], char _arms[128] bool prev = GetPlayerPrevious(client), changed; ArrayList list = new ArrayList(ByteCountToCells(MAX_OPTS_KEY_LENGTH)); - for(int i = 0; i < skip; i++) + for (int i = 0; i < skip; i++) { if (strlen(skin[i]) > 0) { @@ -503,7 +507,7 @@ public Action Store_OnSetPlayerSkin(int client, char _skin[128], char _arms[128] { delete list; g_sPrevious[client][teamEx][0] = 0; - //PrintToServer("[RS] %N has not found any usable skin.", client); + // PrintToServer("[RS] %N has not found any usable skin.", client); return Plugin_Continue; } @@ -534,11 +538,11 @@ public Action Store_OnSetPlayerSkin(int client, char _skin[128], char _arms[128] } g_sPrevious[client][teamEx][0] = 0; - //PrintToServer("[RS] %N has not found any usable skin in %d skins", client, skins); + // PrintToServer("[RS] %N has not found any usable skin in %d skins", client, skins); return Plugin_Continue; } -int GetTeamIndex(int client) +static int GetTeamIndex(int client) { if (Store_IsGlobalTeam()) return TEAM_GX; @@ -546,7 +550,7 @@ int GetTeamIndex(int client) return g_iSelected[client]; } -int GetSkinTeamById(const char[] uid) +static int GetSkinTeamById(const char[] uid) { for (int i = 0; i < g_aSkins.Length; i++) { @@ -561,7 +565,7 @@ int GetSkinTeamById(const char[] uid) /////////////////// /// COOKIES /// /////////////////// -bool GetPlayerStatus(int client) +static bool GetPlayerStatus(int client) { if (g_pOptions) { @@ -578,7 +582,7 @@ bool GetPlayerStatus(int client) return false; } -void SetPlayerStatus(int client, bool status) +static void SetPlayerStatus(int client, bool status) { if (g_pOptions) { @@ -586,11 +590,11 @@ void SetPlayerStatus(int client, bool status) } else if (g_pCookies) { - SetClientCookie(client, g_hCookies[TYPE_INDEX_STATUS], status ? "true" : "false"); + g_hCookies[TYPE_INDEX_STATUS].Set(client, status ? "true" : "false"); } } -bool GetPlayerPrevious(int client) +static bool GetPlayerPrevious(int client) { if (g_pOptions) { @@ -599,7 +603,7 @@ bool GetPlayerPrevious(int client) else if (g_pCookies) { char buffer[8]; - GetClientCookie(client, g_hCookies[TYPE_INDEX_PREVAL], STRING(buffer)); + g_hCookies[TYPE_INDEX_PREVAL].Get(client, STRING(buffer)); return strcmp(buffer, "true") == 0; } @@ -607,7 +611,7 @@ bool GetPlayerPrevious(int client) return false; } -void SetPlayerPrevious(int client, bool allowPrevious) +static void SetPlayerPrevious(int client, bool allowPrevious) { if (g_pOptions) { @@ -615,7 +619,7 @@ void SetPlayerPrevious(int client, bool allowPrevious) } else if (g_pCookies) { - SetClientCookie(client, g_hCookies[TYPE_INDEX_PREVAL], allowPrevious ? "true" : "false"); + g_hCookies[TYPE_INDEX_PREVAL].Set(client, allowPrevious ? "true" : "false"); } } @@ -631,7 +635,7 @@ void GetPlayerEquips(int client, char options[MAX_OPTS_VAL_LENGTH]) } else if (g_pCookies) { - GetClientCookie(client, g_hCookies[team], options, MAX_OPTS_VAL_LENGTH); + g_hCookies[team].Get(client, options, MAX_OPTS_VAL_LENGTH); } } @@ -647,6 +651,6 @@ void SetPlayerEquips(int client, const char[] options) } else if (g_pCookies) { - SetClientCookie(client, g_hCookies[team], options); + g_hCookies[team].Set(client, options); } } \ No newline at end of file diff --git a/modules/store_simplehide.sp b/modules/store_simplehide.sp index bee258b..22d447c 100644 --- a/modules/store_simplehide.sp +++ b/modules/store_simplehide.sp @@ -17,7 +17,7 @@ public Plugin myinfo = }; int g_Edict[2048]; -bool g_bHide[MAXPLAYERS+1]; +bool g_bHide[MAXPLAYERS + 1]; public void OnPluginStart() { @@ -32,9 +32,9 @@ public Action Command_Hide(int client, int args) g_bHide[client] = !g_bHide[client]; tPrintToChat(client, "[\x04Store\x01] %T", "hide setting", client, g_bHide[client] ? "on" : "off"); - for (int i = MaxClients+1; i < 2048; i++) - if (g_Edict[i] > 0 && IsValidEdict(i)) - TransmitManager_SetEntityState(i, client, !g_bHide[client]); + for (int i = MaxClients + 1; i < 2048; i++) + if (g_Edict[i] > 0 && IsValidEdict(i)) + TransmitManager_SetEntityState(i, client, !g_bHide[client]); return Plugin_Handled; } @@ -92,6 +92,7 @@ public void Store_OnPetsCreated(int client, int entity) void UpdateTransmitState(int entity) { - for (int i = 1; i <= MaxClients; i++) if (IsClientInGame(i)) - TransmitManager_SetEntityState(entity, i, !g_bHide[i]); + for (int i = 1; i <= MaxClients; i++) + if (IsClientInGame(i)) + TransmitManager_SetEntityState(entity, i, !g_bHide[i]); } \ No newline at end of file diff --git a/modules/store_weaponskin.sp b/modules/store_weaponskin.sp index b717646..cd8ff4a 100644 --- a/modules/store_weaponskin.sp +++ b/modules/store_weaponskin.sp @@ -16,21 +16,21 @@ public Plugin myinfo = url = STORE_URL }; -enum struct WeaponSkin +abstract_struct WeaponSkin { - char szUnique[32]; - char szWeapon[32]; - int iSlot; - int iSeed; - int iWearT; - int iPaint; + char szUnique[32]; + char szWeapon[32]; + int iSlot; + int iSeed; + int iWearT; + int iPaint; float fWearF; } static WeaponSkin g_eWeaponSkin[STORE_MAX_ITEMS]; -static int g_iWeaponSkin = 0; -static int g_iOffsetName = -1; -static int g_iOffsetMyWP = -1; +static int g_iWeaponSkin = 0; +static int g_iOffsetName = -1; +static int g_iOffsetMyWP = -1; static Handle g_hCookieNamed; @@ -44,18 +44,18 @@ static Handle g_hCookieNamed; public void OnPluginStart() { char ptah[32]; - if(PTaH_Version(ptah, 32) < 110) + if (PTaH_Version(ptah, 32) < 110) SetFailState("This plugin requires PTaH 1.1.0."); g_iOffsetName = FindSendPropInfo("CBaseAttributableItem", "m_szCustomName"); - if(g_iOffsetName == -1) + if (g_iOffsetName == -1) SetFailState("Offset 'CBaseAttributableItem' -> 'm_szCustomName' was not found."); g_iOffsetMyWP = FindSendPropInfo("CBasePlayer", "m_hMyWeapons"); - if(g_iOffsetMyWP == -1) + if (g_iOffsetMyWP == -1) SetFailState("Offset 'CBasePlayer' -> 'm_hMyWeapons' was not found."); - PTaH(PTaH_GiveNamedItemPre, Hook, Event_GiveNamedItemPre); + PTaH(PTaH_GiveNamedItemPre, Hook, Event_GiveNamedItemPre); PTaH(PTaH_GiveNamedItemPost, Hook, Event_GiveNamedItemPost); g_hCookieNamed = RegClientCookie("store_ws_name", "", CookieAccess_Protected); @@ -70,16 +70,16 @@ public void Store_OnStoreInit(Handle store_plugin) public Action Command_Named(int client, int args) { - if(!client) + if (!client) return Plugin_Handled; - if(!(GetUserFlagBits(client) & ADMFLAG_CUSTOM1)) + if (!(GetUserFlagBits(client) & ADMFLAG_CUSTOM1)) { PrintToChat(client, "[\x04Store\x01] \x05You do not have permission to use this function."); return Plugin_Handled; } - if(args != 1) + if (args != 1) { PrintToChat(client, "[\x04Store\x01] \x05Usage: ws_name "); return Plugin_Handled; @@ -88,7 +88,7 @@ public Action Command_Named(int client, int args) char name[32]; GetCmdArg(1, name, sizeof(name)); - if(strlen(name) < 4) + if (strlen(name) < 4) { PrintToChat(client, "[\x04Store\x01] strlen(name) must be >= 4"); return Plugin_Handled; @@ -109,7 +109,7 @@ public bool WeaponSkin_Config(Handle kv, int itemid) { Store_SetDataIndex(itemid, g_iWeaponSkin); - KvGetString(kv, "uid" , g_eWeaponSkin[g_iWeaponSkin].szUnique, sizeof(WeaponSkin::szUnique)); + KvGetString(kv, "uid", g_eWeaponSkin[g_iWeaponSkin].szUnique, sizeof(WeaponSkin::szUnique)); KvGetString(kv, "weapon", g_eWeaponSkin[g_iWeaponSkin].szWeapon, sizeof(WeaponSkin::szWeapon)); g_eWeaponSkin[g_iWeaponSkin].iSlot = KvGetNum(kv, "slot", SLOT_1); @@ -118,7 +118,7 @@ public bool WeaponSkin_Config(Handle kv, int itemid) g_eWeaponSkin[g_iWeaponSkin].iWearT = KvGetNum(kv, "weart", -1); g_eWeaponSkin[g_iWeaponSkin].fWearF = KvGetFloat(kv, "wearf", 0.0416); - //LogMessage("Weapon Skin -> %s -> Paint[%d] Seed[%d] Slot[%d] WearT[%d] WearF[%f]", g_eWeaponSkin[g_iWeaponSkin].szUnique, g_eWeaponSkin[g_iWeaponSkin].iPaint, g_eWeaponSkin[g_iWeaponSkin].iSeed, g_eWeaponSkin[g_iWeaponSkin].iSlot, g_eWeaponSkin[g_iWeaponSkin].iWearT, g_eWeaponSkin[g_iWeaponSkin].fWearF); + // LogMessage("Weapon Skin -> %s -> Paint[%d] Seed[%d] Slot[%d] WearT[%d] WearF[%f]", g_eWeaponSkin[g_iWeaponSkin].szUnique, g_eWeaponSkin[g_iWeaponSkin].iPaint, g_eWeaponSkin[g_iWeaponSkin].iSeed, g_eWeaponSkin[g_iWeaponSkin].iSlot, g_eWeaponSkin[g_iWeaponSkin].iWearT, g_eWeaponSkin[g_iWeaponSkin].fWearF); g_iWeaponSkin++; return true; @@ -154,14 +154,14 @@ public int WeaponSkin_Remove(int client, int id) public Action Event_GiveNamedItemPre(int client, char classname[64], CEconItemView &item, bool &ignoredCEconItemView, bool &OriginIsNULL, float Origin[3]) { - if(IsFakeClient(client) || !IsPlayerAlive(client)) + if (IsFakeClient(client) || !IsPlayerAlive(client)) return Plugin_Continue; - if(!IsWeaponKnife(classname)) + if (!IsWeaponKnife(classname)) return Plugin_Continue; int itemid = Store_GetEquippedItem(client, "weaponskin", SLOT_3); - if(itemid < 0) + if (itemid < 0) return Plugin_Continue; int m_iData = Store_GetDataIndex(itemid); @@ -174,19 +174,19 @@ public Action Event_GiveNamedItemPre(int client, char classname[64], CEconItemVi public void Event_GiveNamedItemPost(int client, const char[] classname, const CEconItemView item, int entity, bool OriginIsNULL, const float Origin[3]) { - if(IsFakeClient(client) || !IsPlayerAlive(client) || !IsValidEdict(entity)) + if (IsFakeClient(client) || !IsPlayerAlive(client) || !IsValidEdict(entity)) return; - if(StrContains(classname, "weapon_") != 0) + if (StrContains(classname, "weapon_") != 0) return; - for(int slot = 0; slot < STORE_MAX_SLOTS; ++slot) + for (int slot = 0; slot < STORE_MAX_SLOTS; ++slot) { int itemid = Store_GetEquippedItem(client, "weaponskin", slot); - if(itemid >= 0) + if (itemid >= 0) { int m_iData = Store_GetDataIndex(itemid); - if(strcmp(classname, g_eWeaponSkin[m_iData].szWeapon, false) == 0) + if (strcmp(classname, g_eWeaponSkin[m_iData].szWeapon, false) == 0) SetWeaponEconmoney(client, m_iData, entity); } } @@ -194,13 +194,13 @@ public void Event_GiveNamedItemPost(int client, const char[] classname, const CE void SetWeaponEconmoney(int client, int data, int weapon) { - //https://www.unknowncheats.me/wiki/Counter_Strike_Global_Offensive:Skin_Changer + // https://www.unknowncheats.me/wiki/Counter_Strike_Global_Offensive:Skin_Changer static int IDHigh = 16384; SetEntProp(weapon, Prop_Send, "m_iItemIDLow", -1); SetEntProp(weapon, Prop_Send, "m_iItemIDHigh", IDHigh++); - if(g_eWeaponSkin[data].iSlot == SLOT_3) + if (g_eWeaponSkin[data].iSlot == SLOT_3) { EquipPlayerWeapon(client, weapon); } @@ -209,21 +209,21 @@ void SetWeaponEconmoney(int client, int data, int weapon) SetEntProp(weapon, Prop_Send, "m_nFallbackSeed", (g_eWeaponSkin[data].iSeed == -1) ? GetRandomInt(0, 1024) : g_eWeaponSkin[data].iSeed); SetEntProp(weapon, Prop_Send, "m_iEntityQuality", (g_eWeaponSkin[data].iSlot == SLOT_3) ? 3 : 8); - switch(g_eWeaponSkin[data].iWearT) + switch (g_eWeaponSkin[data].iWearT) { - case 0 : SetEntPropFloat(weapon, Prop_Send, "m_flFallbackWear", (GetURandomFloat() * (0.006999 - 0.001234)) + 0.001234); - case 1 : SetEntPropFloat(weapon, Prop_Send, "m_flFallbackWear", (GetURandomFloat() * (0.149999 - 0.070000)) + 0.070000); - case 2 : SetEntPropFloat(weapon, Prop_Send, "m_flFallbackWear", (GetURandomFloat() * (0.369999 - 0.150000)) + 0.150000); - case 3 : SetEntPropFloat(weapon, Prop_Send, "m_flFallbackWear", (GetURandomFloat() * (0.439999 - 0.370000)) + 0.370000); - case 4 : SetEntPropFloat(weapon, Prop_Send, "m_flFallbackWear", (GetURandomFloat() * (0.999999 - 0.440000)) + 0.440000); + case 0: SetEntPropFloat(weapon, Prop_Send, "m_flFallbackWear", (GetURandomFloat() * (0.006999 - 0.001234)) + 0.001234); + case 1: SetEntPropFloat(weapon, Prop_Send, "m_flFallbackWear", (GetURandomFloat() * (0.149999 - 0.070000)) + 0.070000); + case 2: SetEntPropFloat(weapon, Prop_Send, "m_flFallbackWear", (GetURandomFloat() * (0.369999 - 0.150000)) + 0.150000); + case 3: SetEntPropFloat(weapon, Prop_Send, "m_flFallbackWear", (GetURandomFloat() * (0.439999 - 0.370000)) + 0.370000); + case 4: SetEntPropFloat(weapon, Prop_Send, "m_flFallbackWear", (GetURandomFloat() * (0.999999 - 0.440000)) + 0.440000); default: SetEntPropFloat(weapon, Prop_Send, "m_flFallbackWear", g_eWeaponSkin[data].fWearF); } - if(GetUserFlagBits(client) & ADMFLAG_CUSTOM1) + if (GetUserFlagBits(client) & ADMFLAG_CUSTOM1) { char name[32]; GetClientCookie(client, g_hCookieNamed, name, sizeof(name)); - if(strlen(name) >= 4) + if (strlen(name) >= 4) { SetEntDataString(weapon, g_iOffsetName, name, sizeof(name)); PrintToChat(client, "[\x04Store\x01] Set your skin named \x04%s", name); @@ -243,20 +243,21 @@ void CheckClientWeapon(DataPack dp) int unique = dp.ReadCell(); delete dp; - if(!IsPlayerAlive(client)) + if (!IsPlayerAlive(client)) return; int weapon = -1; - if(g_eWeaponSkin[data].iSlot == SLOT_3) + if (g_eWeaponSkin[data].iSlot == SLOT_3) { weapon = GetPlayerWeaponSlot(client, SLOT_2); - if(weapon == -1) return; + if (weapon == -1) + return; char classname[32]; GetEdictClassname(weapon, classname, sizeof(classname)); - if(strcmp(classname, "weapon_taser") == 0) + if (strcmp(classname, "weapon_taser") == 0) { - int taser = weapon; - DataPack pack = new DataPack(); + int taser = weapon; + DataPack pack = new DataPack(); pack.WriteCell(client); pack.WriteCell(weapon); pack.Reset(); @@ -265,13 +266,14 @@ void CheckClientWeapon(DataPack dp) CreateTimer(0.1, Timer_GiveTaser, pack, TIMER_FLAG_NO_MAPCHANGE); } } - else weapon = GetPlayerWeaponEntity(client, g_eWeaponSkin[data].szWeapon); + else + weapon = GetPlayerWeaponEntity(client, g_eWeaponSkin[data].szWeapon); - if(weapon == -1) + if (weapon == -1) return; int prevOwner = GetEntPropEnt(weapon, Prop_Send, "m_hPrevOwner"); - if(prevOwner != -1) + if (prevOwner != -1) return; int PAmmo = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoCount"); @@ -279,13 +281,13 @@ void CheckClientWeapon(DataPack dp) int Clip1 = GetEntProp(weapon, Prop_Data, "m_iClip1"); int Clip2 = GetEntProp(weapon, Prop_Data, "m_iClip2"); - if(!RemovePlayerItem(client, weapon)) + if (!RemovePlayerItem(client, weapon)) LogError("RemovePlayerItem -> %N -> %d.%s", client, weapon, g_eWeaponSkin[data].szWeapon); - if(!AcceptEntityInput(weapon, "KillHierarchy")) + if (!AcceptEntityInput(weapon, "KillHierarchy")) LogError("AcceptEntityInput -> %N -> %d.%s", client, weapon, g_eWeaponSkin[data].szWeapon); - if(unique && g_eWeaponSkin[data].iSlot == SLOT_3) + if (unique && g_eWeaponSkin[data].iSlot == SLOT_3) { GivePlayerItem(client, "weapon_knife"); return; @@ -293,8 +295,7 @@ void CheckClientWeapon(DataPack dp) weapon = GivePlayerItem(client, g_eWeaponSkin[data].szWeapon); - - if(!IsValidEdict(weapon)) + if (!IsValidEdict(weapon)) return; DataPack pack = new DataPack(); @@ -314,7 +315,7 @@ public Action Timer_GiveTaser(Handle timer, DataPack pack) int weapon = pack.ReadCell(); delete pack; - if(IsClientInGame(client) && IsPlayerAlive(client)) + if (IsClientInGame(client) && IsPlayerAlive(client)) EquipPlayerWeapon(client, weapon); else AcceptEntityInput(weapon, "Kill"); @@ -324,7 +325,7 @@ public Action Timer_GiveTaser(Handle timer, DataPack pack) public Action Timer_RevertAmmo(Handle timer, DataPack pack) { - int iref = pack.ReadCell(); + int iref = pack.ReadCell(); int PAmmo = pack.ReadCell(); int SAmmo = pack.ReadCell(); int Clip1 = pack.ReadCell(); @@ -333,26 +334,30 @@ public Action Timer_RevertAmmo(Handle timer, DataPack pack) int weapon = EntRefToEntIndex(iref); - if(!IsValidEdict(weapon)) + if (!IsValidEdict(weapon)) return Plugin_Stop; - if(PAmmo > -1) SetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoCount", PAmmo); - if(SAmmo > -1) SetEntProp(weapon, Prop_Data, "m_iSecondaryAmmoCount", SAmmo); - if(Clip1 > -1) SetEntProp(weapon, Prop_Data, "m_iClip1", Clip1); - if(Clip2 > -1) SetEntProp(weapon, Prop_Data, "m_iClip2", Clip2); + if (PAmmo > -1) + SetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoCount", PAmmo); + if (SAmmo > -1) + SetEntProp(weapon, Prop_Data, "m_iSecondaryAmmoCount", SAmmo); + if (Clip1 > -1) + SetEntProp(weapon, Prop_Data, "m_iClip1", Clip1); + if (Clip2 > -1) + SetEntProp(weapon, Prop_Data, "m_iClip2", Clip2); return Plugin_Stop; } int GetPlayerWeaponEntity(int client, const char[] weapons) { - int weapon = -1; + int weapon = -1; char classname[32]; - for(int offset = 0; offset < 128; offset += 4) - if(IsValidEdict((weapon = GetEntDataEnt2(client, g_iOffsetMyWP+offset)))) - if(GetWeaponClassname(weapon, -1, classname, sizeof(classname))) - if(strcmp(weapons, classname, false) == 0) + for (int offset = 0; offset < 128; offset += 4) + if (IsValidEdict((weapon = GetEntDataEnt2(client, g_iOffsetMyWP + offset)))) + if (GetWeaponClassname(weapon, -1, classname, sizeof(classname))) + if (strcmp(weapons, classname, false) == 0) return weapon; return -1; @@ -362,17 +367,17 @@ int GetWeaponClassname(int weapon, int index = -1, char[] classname, int maxLen) { GetEdictClassname(weapon, classname, maxLen); - if(index == -1) + if (index == -1) index = GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex"); - switch(index) + switch (index) { - case 42 : return strcopy(classname, maxLen, "weapon_knife"); - case 59 : return strcopy(classname, maxLen, "weapon_knife_t"); - case 60 : return strcopy(classname, maxLen, "weapon_m4a1_silencer"); - case 61 : return strcopy(classname, maxLen, "weapon_usp_silencer"); - case 63 : return strcopy(classname, maxLen, "weapon_cz75a"); - case 64 : return strcopy(classname, maxLen, "weapon_revolver"); + case 42: return strcopy(classname, maxLen, "weapon_knife"); + case 59: return strcopy(classname, maxLen, "weapon_knife_t"); + case 60: return strcopy(classname, maxLen, "weapon_m4a1_silencer"); + case 61: return strcopy(classname, maxLen, "weapon_usp_silencer"); + case 63: return strcopy(classname, maxLen, "weapon_cz75a"); + case 64: return strcopy(classname, maxLen, "weapon_revolver"); case 500: return strcopy(classname, maxLen, "weapon_bayonet"); case 506: return strcopy(classname, maxLen, "weapon_knife_gut"); case 505: return strcopy(classname, maxLen, "weapon_knife_flip"); @@ -394,25 +399,9 @@ int GetWeaponClassname(int weapon, int index = -1, char[] classname, int maxLen) bool IsWeaponKnife(const char[] classname) { - if( - strcmp(classname, "weapon_knife") == 0 || - strcmp(classname, "weapon_knife_t") == 0 || - strcmp(classname, "weapon_bayonet") == 0 || - strcmp(classname, "weapon_knife_gut") == 0 || - strcmp(classname, "weapon_knife_flip") == 0 || - strcmp(classname, "weapon_knife_m9_bayonet") == 0 || - strcmp(classname, "weapon_knife_karambit") == 0 || - strcmp(classname, "weapon_knife_tactical") == 0 || - strcmp(classname, "weapon_knife_butterfly") == 0 || - strcmp(classname, "weapon_knife_falchion") == 0 || - strcmp(classname, "weapon_knife_push") == 0 || - strcmp(classname, "weapon_knife_survival_bowie") == 0 || - strcmp(classname, "weapon_knife_ursus") == 0 || - strcmp(classname, "weapon_knife_windowmaker") == 0 || - strcmp(classname, "weapon_knife_stiletto") == 0 || - strcmp(classname, "weapon_knife_jackknife") == 0 - ) - return true; + if ( + strcmp(classname, "weapon_knife") == 0 || strcmp(classname, "weapon_knife_t") == 0 || strcmp(classname, "weapon_bayonet") == 0 || strcmp(classname, "weapon_knife_gut") == 0 || strcmp(classname, "weapon_knife_flip") == 0 || strcmp(classname, "weapon_knife_m9_bayonet") == 0 || strcmp(classname, "weapon_knife_karambit") == 0 || strcmp(classname, "weapon_knife_tactical") == 0 || strcmp(classname, "weapon_knife_butterfly") == 0 || strcmp(classname, "weapon_knife_falchion") == 0 || strcmp(classname, "weapon_knife_push") == 0 || strcmp(classname, "weapon_knife_survival_bowie") == 0 || strcmp(classname, "weapon_knife_ursus") == 0 || strcmp(classname, "weapon_knife_windowmaker") == 0 || strcmp(classname, "weapon_knife_stiletto") == 0 || strcmp(classname, "weapon_knife_jackknife") == 0) + return true; return false; } \ No newline at end of file diff --git a/store.sp b/store.sp index c497e82..102e993 100644 --- a/store.sp +++ b/store.sp @@ -56,10 +56,6 @@ enum NUM_OBSERVER_MODES, }; -#if !defined abstract_struct - #define abstract_struct enum struct -#endif - #define TEAM_CT 3 #define TEAM_TE 2 #define TEAM_ZM 2 From bb49392cd2bad3cc40e2a87d360277a32fbb4e52 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 5 Aug 2023 18:29:02 +0800 Subject: [PATCH 07/15] bump version --- include/store.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/store.inc b/include/store.inc index 65bcbd4..5255236 100644 --- a/include/store.inc +++ b/include/store.inc @@ -11,7 +11,7 @@ #endif #define STORE_AUTHOR "Kyle" -#define STORE_VERSION "2.6.1" ... "." ... STORE_AUTO_VERSION +#define STORE_VERSION "2.7.0" ... "." ... STORE_AUTO_VERSION #define STORE_URL "https://www.kxnrl.com" public SharedPlugin __pl_store = From 91bd829a190a6c0f6c57434c07bae1b9a669137d Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 5 Aug 2023 18:51:21 +0800 Subject: [PATCH 08/15] style: use methodmap --- include/store_stock.inc | 222 ++++++++++++++++++------------------ modules/store_pet.sp | 28 ++--- modules/store_weaponskin.sp | 24 ++-- store/cpsupport.sp | 16 +-- store/grenades.sp | 2 +- store/modules/hats.sp | 8 +- store/modules/neon.sp | 6 +- store/modules/skin.sp | 24 ++-- store/modules/trail.sp | 4 +- store/players.sp | 4 +- store/sounds.sp | 25 ++-- store/sprays.sp | 26 ++--- 12 files changed, 197 insertions(+), 192 deletions(-) diff --git a/include/store_stock.inc b/include/store_stock.inc index 074719c..09ad9fc 100644 --- a/include/store_stock.inc +++ b/include/store_stock.inc @@ -4,25 +4,29 @@ #define __STORE_STOCK__ +#if !defined abstract_struct + #define abstract_struct enum struct +#endif + #include #define STRING(%1) %1, sizeof(%1) -enum struct Item_Plan +abstract_struct Item_Plan { char szName[ITEM_NAME_LENGTH]; - int iPrice; - int iTime; + int iPrice; + int iTime; } -enum struct Type_Handler +abstract_struct Type_Handler { - char szType[64]; - char szPlFile[64]; - bool bEquipable; - bool bRaw; - bool bDisposable; - Handle hPlugin; + char szType[64]; + char szPlFile[64]; + bool bEquipable; + bool bRaw; + bool bDisposable; + Handle hPlugin; Function fnMapStart; Function fnReset; Function fnConfig; @@ -30,62 +34,62 @@ enum struct Type_Handler Function fnRemove; } -enum struct Client_Item +abstract_struct Client_Item { - int iId; - int iUniqueId; + int iId; + int iUniqueId; bool bSynced; bool bDeleted; - int iDateOfPurchase; - int iDateOfExpiration; - int iPriceOfPurchase; + int iDateOfPurchase; + int iDateOfExpiration; + int iPriceOfPurchase; } -enum struct Client_Data +abstract_struct Client_Data { - int iId; - int iUserId; - char szAuthId[32]; - int iCredits; - int iOriginalCredits; - int iDateOfJoin; - int iDateOfLastJoin; - int iItems; - int aEquipment[STORE_MAX_HANDLERS*STORE_MAX_SLOTS]; - int aEquipmentSynced[STORE_MAX_HANDLERS*STORE_MAX_SLOTS]; - bool bBan; - bool bLoaded; - bool bRefresh; + int iId; + int iUserId; + char szAuthId[32]; + int iCredits; + int iOriginalCredits; + int iDateOfJoin; + int iDateOfLastJoin; + int iItems; + int aEquipment[STORE_MAX_HANDLERS * STORE_MAX_SLOTS]; + int aEquipmentSynced[STORE_MAX_HANDLERS * STORE_MAX_SLOTS]; + bool bBan; + bool bLoaded; + bool bRefresh; Handle hTimer; } -enum struct Menu_Handler +abstract_struct Menu_Handler { - char szIdentifier[64]; - char szPlFile[64]; - Handle hPlugin; + char szIdentifier[64]; + char szPlFile[64]; + Handle hPlugin; Function fnMenu; Function fnHandler; } -enum struct Compose_Data +abstract_struct Compose_Data { int item1; int item2; int types; } -stock bool InsertMenuItemEx(Handle menu, int position, int style, char[] info, char[] display, any ...) +stock bool InsertMenuItemEx(Menu menu, int position, int style, char[] info, char[] display, any...) { char m_display[256]; VFormat(STRING(m_display), display, 6); - return (GetMenuItemCount(menu)==position) ? AddMenuItem(menu, info, m_display, style) : InsertMenuItem(menu, position, info, m_display, style); + return (menu.ItemCount == position) ? menu.AddItem(info, m_display, style) : menu.InsertItem(position, info, m_display, style); } -stock void LogStoreError(const char[] buffer, any ...) +stock void LogStoreError(const char[] buffer, any...) { static char path[128]; - if(!path[0]) + if (!path[0]) BuildPath(Path_SM, STRING(path), "logs/store.error.log"); char error[1024]; @@ -96,10 +100,12 @@ stock void LogStoreError(const char[] buffer, any ...) static void SQLCallback_Void_PrintQuery(Database db, DBResultSet results, const char[] error, DataPack pack) { float time = GetEngineTime() - pack.ReadFloat(); - char query[1024]; + char query[1024]; pack.ReadString(STRING(query)); - if(time > 20.0) LogMessage("Store SQL slow query: %f -> %s", time, query); - if(results == null || error[0]) LogStoreError("SQL error happened.\nQuery: %s\nError: %s", query, error); + if (time > 20.0) + LogMessage("Store SQL slow query: %f -> %s", time, query); + if (results == null || error[0]) + LogStoreError("SQL error happened.\nQuery: %s\nError: %s", query, error); delete pack; } @@ -115,14 +121,14 @@ stock void SQL_TVoid(Database db, char[] query, DBPriority dbp = DBPrio_Normal) stock bool AllowItemForAuth(int client, const char[] authid) { - if(authid[0] == 0) + if (authid[0] == 0) return true; char m_szAuthId[32]; - if(!GetClientAuthId(client, AuthId_Steam2, STRING(m_szAuthId))) + if (!GetClientAuthId(client, AuthId_Steam2, STRING(m_szAuthId))) return false; - if(StrContains(authid, m_szAuthId) == -1) + if (StrContains(authid, m_szAuthId) == -1) return false; return true; @@ -130,21 +136,21 @@ stock bool AllowItemForAuth(int client, const char[] authid) stock bool AllowItemForVIP(int client, bool vip) { - if(!vip) + if (!vip) return true; int flags = GetUserFlagBits(client); - if(flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION) + if (flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION) return true; return false; } stock bool IsValidClient(int client) { - if(client > MaxClients || client < 1) + if (client > MaxClients || client < 1) return false; - if(!IsClientInGame(client)) + if (!IsClientInGame(client)) return false; return true; @@ -152,21 +158,21 @@ stock bool IsValidClient(int client) stock void ClearTimer(Handle &timer) { - if(timer != INVALID_HANDLE) + if (timer != INVALID_HANDLE) { KillTimer(timer); timer = INVALID_HANDLE; } } -stock bool AddMenuItemEx(Handle menu, int style, char[] info, char[] display, any ...) +stock bool AddMenuItemEx(Menu menu, int style, char[] info, char[] display, any...) { char m_display[256]; VFormat(STRING(m_display), display, 5); - return AddMenuItem(menu, info, m_display, style); + return menu.AddItem(info, m_display, style); } -stock void tPrintToChat(int client, const char[] szMessage, any ...) +stock void tPrintToChat(int client, const char[] szMessage, any...) { char szBuffer[256]; VFormat(STRING(szBuffer), szMessage, 3); @@ -175,13 +181,13 @@ stock void tPrintToChat(int client, const char[] szMessage, any ...) SayText2(client, szBuffer); } -stock void tPrintToChatAll(const char[] szMessage, any ...) +stock void tPrintToChatAll(const char[] szMessage, any...) { char szBuffer[256]; - for(int client = 1; client <= MaxClients; client++) + for (int client = 1; client <= MaxClients; client++) { - if(IsClientInGame(client) && !IsFakeClient(client)) + if (IsClientInGame(client) && !IsFakeClient(client)) { SetGlobalTransTarget(client); VFormat(STRING(szBuffer), szMessage, 2); @@ -196,9 +202,9 @@ stock void SayText2(int client, const char[] text, int sender = 0, bool sound = { static EngineVersion engine = Engine_Unknown; if (engine == Engine_Unknown) - engine = GetEngineVersion(); + engine = GetEngineVersion(); - Handle um = StartMessageOne(engine == Engine_CSGO ? "SayText2" : "SayText", client, USERMSG_RELIABLE|USERMSG_BLOCKHOOKS); + Handle um = StartMessageOne(engine == Engine_CSGO ? "SayText2" : "SayText", client, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS); if (um == null) { LogError("StartMessageOne -> SayText2 is null"); @@ -231,59 +237,59 @@ stock void ReplaceColorsCode(char[] message, int maxLen, int team = 0) { static EngineVersion engine = Engine_Unknown; if (engine == Engine_Unknown) - engine = GetEngineVersion(); + engine = GetEngineVersion(); if (engine == Engine_CSGO) { - ReplaceString(message, maxLen, "{normal}", "\x01", false); - ReplaceString(message, maxLen, "{default}", "\x01", false); - ReplaceString(message, maxLen, "{white}", "\x01", false); - ReplaceString(message, maxLen, "{team}", "\x03", false); - - ReplaceString(message, maxLen, "{darkred}", "\x02", false); - ReplaceString(message, maxLen, "{pink}", "\x03", false); - ReplaceString(message, maxLen, "{green}", "\x04", false); - ReplaceString(message, maxLen, "{lightgreen}", "\x05", false); - ReplaceString(message, maxLen, "{lime}", "\x06", false); - ReplaceString(message, maxLen, "{red}", "\x07", false); - ReplaceString(message, maxLen, "{grey}", "\x08", false); - ReplaceString(message, maxLen, "{yellow}", "\x09", false); - ReplaceString(message, maxLen, "{gold}", "\x10", false); - ReplaceString(message, maxLen, "{silver}", "\x0A", false); - ReplaceString(message, maxLen, "{blue}", "\x0B", false); - ReplaceString(message, maxLen, "{darkblue}", "\x0C", false); - ReplaceString(message, maxLen, "{purple}", "\x0E", false); - ReplaceString(message, maxLen, "{lightred}", "\x0F", false); - - switch(team) + ReplaceString(message, maxLen, "{normal}", "\x01", false); + ReplaceString(message, maxLen, "{default}", "\x01", false); + ReplaceString(message, maxLen, "{white}", "\x01", false); + ReplaceString(message, maxLen, "{team}", "\x03", false); + + ReplaceString(message, maxLen, "{darkred}", "\x02", false); + ReplaceString(message, maxLen, "{pink}", "\x03", false); + ReplaceString(message, maxLen, "{green}", "\x04", false); + ReplaceString(message, maxLen, "{lightgreen}", "\x05", false); + ReplaceString(message, maxLen, "{lime}", "\x06", false); + ReplaceString(message, maxLen, "{red}", "\x07", false); + ReplaceString(message, maxLen, "{grey}", "\x08", false); + ReplaceString(message, maxLen, "{yellow}", "\x09", false); + ReplaceString(message, maxLen, "{gold}", "\x10", false); + ReplaceString(message, maxLen, "{silver}", "\x0A", false); + ReplaceString(message, maxLen, "{blue}", "\x0B", false); + ReplaceString(message, maxLen, "{darkblue}", "\x0C", false); + ReplaceString(message, maxLen, "{purple}", "\x0E", false); + ReplaceString(message, maxLen, "{lightred}", "\x0F", false); + + switch (team) { - case 3 : ReplaceString(message, maxLen, "{teamcolor}", "\x0B", false); - case 2 : ReplaceString(message, maxLen, "{teamcolor}", "\x05", false); + case 3: ReplaceString(message, maxLen, "{teamcolor}", "\x0B", false); + case 2: ReplaceString(message, maxLen, "{teamcolor}", "\x05", false); default: ReplaceString(message, maxLen, "{teamcolor}", "\x01", false); } } else { - ReplaceString(message, maxLen, "{normal}", "\x07FFFFFF", false); - ReplaceString(message, maxLen, "{default}", "\x07FFFFFF", false); - ReplaceString(message, maxLen, "{white}", "\x07FFFFFF", false); - ReplaceString(message, maxLen, "{darkred}", "\x07FF0000", false); - ReplaceString(message, maxLen, "{pink}", "\x07D32CE6", false); - ReplaceString(message, maxLen, "{green}", "\x077FFF00", false); - ReplaceString(message, maxLen, "{lime}", "\x07BFFF00", false); - ReplaceString(message, maxLen, "{yellow}", "\x07FFD700", false); - ReplaceString(message, maxLen, "{lightgreen}", "\x0798FB98", false); - ReplaceString(message, maxLen, "{lightred}", "\x07EB4B4B", false); - ReplaceString(message, maxLen, "{red}", "\x07DC143C", false); - ReplaceString(message, maxLen, "{gray}", "\x07DCDCDC", false); - ReplaceString(message, maxLen, "{grey}", "\x07DCDCDC", false); - ReplaceString(message, maxLen, "{olive}", "\x07808000", false); - ReplaceString(message, maxLen, "{gold}", "\x07E4AE39", false); - ReplaceString(message, maxLen, "{silver}", "\x07B0C3D9", false); - ReplaceString(message, maxLen, "{lightblue}", "\x075E98D9", false); - ReplaceString(message, maxLen, "{blue}", "\x074B69FF", false); - ReplaceString(message, maxLen, "{purple}", "\x078847FF", false); - ReplaceString(message, maxLen, "{darkorange}", "\x07CF6A32", false); + ReplaceString(message, maxLen, "{normal}", "\x07FFFFFF", false); + ReplaceString(message, maxLen, "{default}", "\x07FFFFFF", false); + ReplaceString(message, maxLen, "{white}", "\x07FFFFFF", false); + ReplaceString(message, maxLen, "{darkred}", "\x07FF0000", false); + ReplaceString(message, maxLen, "{pink}", "\x07D32CE6", false); + ReplaceString(message, maxLen, "{green}", "\x077FFF00", false); + ReplaceString(message, maxLen, "{lime}", "\x07BFFF00", false); + ReplaceString(message, maxLen, "{yellow}", "\x07FFD700", false); + ReplaceString(message, maxLen, "{lightgreen}", "\x0798FB98", false); + ReplaceString(message, maxLen, "{lightred}", "\x07EB4B4B", false); + ReplaceString(message, maxLen, "{red}", "\x07DC143C", false); + ReplaceString(message, maxLen, "{gray}", "\x07DCDCDC", false); + ReplaceString(message, maxLen, "{grey}", "\x07DCDCDC", false); + ReplaceString(message, maxLen, "{olive}", "\x07808000", false); + ReplaceString(message, maxLen, "{gold}", "\x07E4AE39", false); + ReplaceString(message, maxLen, "{silver}", "\x07B0C3D9", false); + ReplaceString(message, maxLen, "{lightblue}", "\x075E98D9", false); + ReplaceString(message, maxLen, "{blue}", "\x074B69FF", false); + ReplaceString(message, maxLen, "{purple}", "\x078847FF", false); + ReplaceString(message, maxLen, "{darkorange}", "\x07CF6A32", false); } } @@ -334,8 +340,8 @@ stock int SpawnSpeakerEntity(float fPos[3], float fAgl[3], float removeDelay = 0 { int speaker = CreateEntityByName("info_target"); - if(speaker == -1) - return -1; + if (speaker == INVALID_ENT_REFERENCE) + return INVALID_ENT_REFERENCE; DispatchKeyValue(speaker, "spawnflags", "2"); @@ -344,7 +350,7 @@ stock int SpawnSpeakerEntity(float fPos[3], float fAgl[3], float removeDelay = 0 DispatchSpawn(speaker); ActivateEntity(speaker); - if(removeDelay > 0.0) + if (removeDelay > 0.0) { /* char input[128]; @@ -368,7 +374,7 @@ static Action Timer_RemoveSpeaker(Handle timer, int ref) return Plugin_Stop; } -//https://forums.alliedmods.net/showpost.php?p=2471747&postcount=4 +// https://forums.alliedmods.net/showpost.php?p=2471747&postcount=4 stock void PrecacheParticleEffect(const char[] effect) { static int table = INVALID_STRING_TABLE; @@ -385,7 +391,7 @@ stock void PrecacheEffect(const char[] name) { static int table = INVALID_STRING_TABLE; - if(table == INVALID_STRING_TABLE) + if (table == INVALID_STRING_TABLE) table = FindStringTable("EffectDispatch"); bool save = LockStringTables(false); @@ -398,7 +404,7 @@ stock int UTIL_GetRandomInt(int min, int max) { int random = GetURandomInt(); - if(random == 0) + if (random == 0) random++; return RoundToCeil(float(random) / (float(SIZE_OF_INT) / float(max - min + 1))) + min - 1; diff --git a/modules/store_pet.sp b/modules/store_pet.sp index ab82f6b..91b0537 100644 --- a/modules/store_pet.sp +++ b/modules/store_pet.sp @@ -102,24 +102,24 @@ static void Pets_Reset() g_iPets = 0; } -static bool Pets_Config(Handle kv, int itemid) +static bool Pets_Config(KeyValues kv, int itemid) { Store_SetDataIndex(itemid, g_iPets); float m_fTemp[3]; - KvGetString(kv, "model", g_ePets[g_iPets].model, sizeof(Pet::model)); - KvGetString(kv, "idle", g_ePets[g_iPets].idle, sizeof(Pet::idle)); - KvGetString(kv, "idle2", g_ePets[g_iPets].idle2, sizeof(Pet::idle2)); - KvGetString(kv, "run", g_ePets[g_iPets].run, sizeof(Pet::run)); - KvGetString(kv, "spawn", g_ePets[g_iPets].spawn, sizeof(Pet::spawn)); - KvGetString(kv, "death", g_ePets[g_iPets].death, sizeof(Pet::death)); - KvGetVector(kv, "position", m_fTemp); + kv.GetString("model", g_ePets[g_iPets].model, sizeof(Pet::model)); + kv.GetString("idle", g_ePets[g_iPets].idle, sizeof(Pet::idle)); + kv.GetString("idle2", g_ePets[g_iPets].idle2, sizeof(Pet::idle2)); + kv.GetString("run", g_ePets[g_iPets].run, sizeof(Pet::run)); + kv.GetString("spawn", g_ePets[g_iPets].spawn, sizeof(Pet::spawn)); + kv.GetString("death", g_ePets[g_iPets].death, sizeof(Pet::death)); + kv.GetVector("position", m_fTemp); g_ePets[g_iPets].fPosition = m_fTemp; - KvGetVector(kv, "angles", m_fTemp); + kv.GetVector("angles", m_fTemp); g_ePets[g_iPets].fAngles = m_fTemp; - g_ePets[g_iPets].iSlot = KvGetNum(kv, "slot"); - g_ePets[g_iPets].iTeam = KvGetNum(kv, "team"); - g_ePets[g_iPets].fScale = KvGetFloat(kv, "scale", 1.0); + g_ePets[g_iPets].iSlot = kv.GetNum("slot"); + g_ePets[g_iPets].iTeam = kv.GetNum("team"); + g_ePets[g_iPets].fScale = kv.GetFloat("scale", 1.0); if (FileExists(g_ePets[g_iPets].model, true)) { @@ -436,11 +436,11 @@ static void Hook_OnAnimationDone(const char[] output, int caller, int activator, stock void Call_OnPetsCreated(int client, int entity, int slot) { - static Handle gf = null; + static GlobalForward gf = null; if (gf == null) { // create - gf = CreateGlobalForward("Store_OnPetsCreated", ET_Ignore, Param_Cell, Param_Cell, Param_Cell); + gf = new GlobalForward("Store_OnPetsCreated", ET_Ignore, Param_Cell, Param_Cell, Param_Cell); } Call_StartForward(gf); diff --git a/modules/store_weaponskin.sp b/modules/store_weaponskin.sp index cd8ff4a..14ad3b3 100644 --- a/modules/store_weaponskin.sp +++ b/modules/store_weaponskin.sp @@ -32,7 +32,7 @@ static int g_iWeaponSkin = 0; static int g_iOffsetName = -1; static int g_iOffsetMyWP = -1; -static Handle g_hCookieNamed; +static Cookie g_hCookieNamed; #define SLOT_0 "!!!!WE START AT 1!!!!" #define SLOT_1 1 @@ -58,7 +58,7 @@ public void OnPluginStart() PTaH(PTaH_GiveNamedItemPre, Hook, Event_GiveNamedItemPre); PTaH(PTaH_GiveNamedItemPost, Hook, Event_GiveNamedItemPost); - g_hCookieNamed = RegClientCookie("store_ws_name", "", CookieAccess_Protected); + g_hCookieNamed = new Cookie("store_ws_name", "", CookieAccess_Protected); RegConsoleCmd("ws_name", Command_Named); } @@ -94,7 +94,7 @@ public Action Command_Named(int client, int args) return Plugin_Handled; } - SetClientCookie(client, g_hCookieNamed, name); + g_hCookieNamed.Set(client, name); PrintToChat(client, "[\x04Store\x01] Set your skin named \x04%s", name); return Plugin_Handled; @@ -105,18 +105,18 @@ public void WeaponSkin_Reset() g_iWeaponSkin = 0; } -public bool WeaponSkin_Config(Handle kv, int itemid) +public bool WeaponSkin_Config(KeyValues kv, int itemid) { Store_SetDataIndex(itemid, g_iWeaponSkin); - KvGetString(kv, "uid", g_eWeaponSkin[g_iWeaponSkin].szUnique, sizeof(WeaponSkin::szUnique)); - KvGetString(kv, "weapon", g_eWeaponSkin[g_iWeaponSkin].szWeapon, sizeof(WeaponSkin::szWeapon)); + kv.GetString("uid", g_eWeaponSkin[g_iWeaponSkin].szUnique, sizeof(WeaponSkin::szUnique)); + kv.GetString("weapon", g_eWeaponSkin[g_iWeaponSkin].szWeapon, sizeof(WeaponSkin::szWeapon)); - g_eWeaponSkin[g_iWeaponSkin].iSlot = KvGetNum(kv, "slot", SLOT_1); - g_eWeaponSkin[g_iWeaponSkin].iSeed = KvGetNum(kv, "seed"); - g_eWeaponSkin[g_iWeaponSkin].iPaint = KvGetNum(kv, "paint"); - g_eWeaponSkin[g_iWeaponSkin].iWearT = KvGetNum(kv, "weart", -1); - g_eWeaponSkin[g_iWeaponSkin].fWearF = KvGetFloat(kv, "wearf", 0.0416); + g_eWeaponSkin[g_iWeaponSkin].iSlot = kv.GetNum("slot", SLOT_1); + g_eWeaponSkin[g_iWeaponSkin].iSeed = kv.GetNum("seed"); + g_eWeaponSkin[g_iWeaponSkin].iPaint = kv.GetNum("paint"); + g_eWeaponSkin[g_iWeaponSkin].iWearT = kv.GetNum("weart", -1); + g_eWeaponSkin[g_iWeaponSkin].fWearF = kv.GetFloat("wearf", 0.0416); // LogMessage("Weapon Skin -> %s -> Paint[%d] Seed[%d] Slot[%d] WearT[%d] WearF[%f]", g_eWeaponSkin[g_iWeaponSkin].szUnique, g_eWeaponSkin[g_iWeaponSkin].iPaint, g_eWeaponSkin[g_iWeaponSkin].iSeed, g_eWeaponSkin[g_iWeaponSkin].iSlot, g_eWeaponSkin[g_iWeaponSkin].iWearT, g_eWeaponSkin[g_iWeaponSkin].fWearF); @@ -222,7 +222,7 @@ void SetWeaponEconmoney(int client, int data, int weapon) if (GetUserFlagBits(client) & ADMFLAG_CUSTOM1) { char name[32]; - GetClientCookie(client, g_hCookieNamed, name, sizeof(name)); + g_hCookieNamed.Get(client, name, sizeof(name)); if (strlen(name) >= 4) { SetEntDataString(weapon, g_iOffsetName, name, sizeof(name)); diff --git a/store/cpsupport.sp b/store/cpsupport.sp index 1ff57b7..b60f4c7 100644 --- a/store/cpsupport.sp +++ b/store/cpsupport.sp @@ -18,11 +18,11 @@ #define CHAT_C_RANDOM 2 #endif -static UserMsg g_umUMId; -static Handle g_hCPAForward; -static Handle g_hCPPForward; -static Handle g_hCPRForward; -static StringMap g_tMsgFmt; +static UserMsg g_umUMId; +static GlobalForward g_hCPAForward; +static GlobalForward g_hCPPForward; +static GlobalForward g_hCPRForward; +static StringMap g_tMsgFmt; static char g_szNameTags[STORE_MAX_ITEMS][128]; static char g_szNameColors[STORE_MAX_ITEMS][32]; @@ -55,9 +55,9 @@ void CPSupport_OnPluginStart() return; } - g_hCPAForward = CreateGlobalForward("CP_OnChatMessage", ET_Hook, Param_CellByRef, Param_Cell, Param_String, Param_String, Param_String, Param_CellByRef, Param_CellByRef); - g_hCPPForward = CreateGlobalForward("CP_OnChatMessagePost", ET_Ignore, Param_Cell, Param_Cell, Param_String, Param_String, Param_String, Param_Cell, Param_Cell); - g_hCPRForward = CreateGlobalForward("CP_OnChatRainbow", ET_Hook, Param_String, Param_Cell, Param_Cell, Param_Cell); + g_hCPAForward = new GlobalForward("CP_OnChatMessage", ET_Hook, Param_CellByRef, Param_Cell, Param_String, Param_String, Param_String, Param_CellByRef, Param_CellByRef); + g_hCPPForward = new GlobalForward("CP_OnChatMessagePost", ET_Ignore, Param_Cell, Param_Cell, Param_String, Param_String, Param_String, Param_Cell, Param_Cell); + g_hCPRForward = new GlobalForward("CP_OnChatRainbow", ET_Hook, Param_String, Param_Cell, Param_Cell, Param_Cell); Store_RegisterHandler("nametag", CPSupport_OnMappStart, CPSupport_Reset, NameTags_Config, CPSupport_Equip, CPSupport_Remove, true); Store_RegisterHandler("namecolor", CPSupport_OnMappStart, CPSupport_Reset, NameColors_Config, CPSupport_Equip, CPSupport_Remove, true); diff --git a/store/grenades.sp b/store/grenades.sp index 99d4852..f384365 100644 --- a/store/grenades.sp +++ b/store/grenades.sp @@ -88,7 +88,7 @@ static bool GrenadeTrails_Config(KeyValues kv, int itemid) kv.GetString("width", g_eGrenadeTrails[g_iGrenadeTrails].szWidth, sizeof(GrenadeTrail::szWidth), "10.0"); g_eGrenadeTrails[g_iGrenadeTrails].fWidth = kv.GetFloat("width", 10.0); kv.GetString("color", g_eGrenadeTrails[g_iGrenadeTrails].szColor, sizeof(GrenadeTrail::szColor), "255 255 255 255"); - KvGetColor(kv, "color", g_eGrenadeTrails[g_iGrenadeTrails].iColor[0], g_eGrenadeTrails[g_iGrenadeTrails].iColor[1], g_eGrenadeTrails[g_iGrenadeTrails].iColor[2], g_eGrenadeTrails[g_iGrenadeTrails].iColor[3]); + kv.GetColor("color", g_eGrenadeTrails[g_iGrenadeTrails].iColor[0], g_eGrenadeTrails[g_iGrenadeTrails].iColor[1], g_eGrenadeTrails[g_iGrenadeTrails].iColor[2], g_eGrenadeTrails[g_iGrenadeTrails].iColor[3]); g_eGrenadeTrails[g_iGrenadeTrails].iSlot = kv.GetNum("slot"); if (FileExists(g_eGrenadeTrails[g_iGrenadeTrails].szMaterial, true)) diff --git a/store/modules/hats.sp b/store/modules/hats.sp index 35d5799..e9b5831 100644 --- a/store/modules/hats.sp +++ b/store/modules/hats.sp @@ -28,9 +28,9 @@ bool Hats_Config(KeyValues kv, int itemid) Store_SetDataIndex(itemid, g_iHats); float m_fTemp[3]; kv.GetString("model", g_eHats[g_iHats].szModel, PLATFORM_MAX_PATH); - KvGetVector(kv, "position", m_fTemp); + kv.GetVector("position", m_fTemp); g_eHats[g_iHats].fPosition = m_fTemp; - KvGetVector(kv, "angles", m_fTemp); + kv.GetVector("angles", m_fTemp); g_eHats[g_iHats].fAngles = m_fTemp; g_eHats[g_iHats].bBonemerge = (kv.GetNum("bonemerge", 0) ? true : false); g_eHats[g_iHats].iSlot = kv.GetNum("slot"); @@ -242,11 +242,11 @@ static void Bonemerge(int ent) stock void Call_OnHatsCreated(int client, int entity, int slot) { - static Handle gf = null; + static GlobalForward gf = null; if (gf == null) { // create - gf = CreateGlobalForward("Store_OnHatsCreated", ET_Ignore, Param_Cell, Param_Cell, Param_Cell); + gf = new GlobalForward("Store_OnHatsCreated", ET_Ignore, Param_Cell, Param_Cell, Param_Cell); } Call_StartForward(gf); diff --git a/store/modules/neon.sp b/store/modules/neon.sp index 0e6c279..0c5373b 100644 --- a/store/modules/neon.sp +++ b/store/modules/neon.sp @@ -20,7 +20,7 @@ static int g_iClientNeon[MAXPLAYERS + 1] = { INVALID_ENT_REFERENCE, ... }; bool Neon_Config(KeyValues kv, int itemid) { Store_SetDataIndex(itemid, g_iNeons); - KvGetColor(kv, "color", g_eNeons[g_iNeons].iColor[0], g_eNeons[g_iNeons].iColor[1], g_eNeons[g_iNeons].iColor[2], g_eNeons[g_iNeons].iColor[3]); + kv.GetColor("color", g_eNeons[g_iNeons].iColor[0], g_eNeons[g_iNeons].iColor[1], g_eNeons[g_iNeons].iColor[2], g_eNeons[g_iNeons].iColor[3]); g_eNeons[g_iNeons].iBright = kv.GetNum("brightness"); g_eNeons[g_iNeons].iDistance = kv.GetNum("distance"); g_eNeons[g_iNeons].iFade = kv.GetNum("distancefade"); @@ -131,11 +131,11 @@ void Neon_SetClientNeon(int client) stock void Call_OnNeonCreated(int client, int entity) { - static Handle gf = null; + static GlobalForward gf = null; if (gf == null) { // create - gf = CreateGlobalForward("Store_OnNeonCreated", ET_Ignore, Param_Cell, Param_Cell); + gf = new GlobalForward("Store_OnNeonCreated", ET_Ignore, Param_Cell, Param_Cell); } Call_StartForward(gf); diff --git a/store/modules/skin.sp b/store/modules/skin.sp index b3007c1..e1f24fc 100644 --- a/store/modules/skin.sp +++ b/store/modules/skin.sp @@ -35,11 +35,11 @@ static ConVar store_firstperson_death_camera; Handle g_tKillPreview[MAXPLAYERS + 1]; Handle g_tResetCamera[MAXPLAYERS + 1]; -Handle g_hOnPlayerSkinDefault = null; -Handle g_hOnPlayerSetModel = null; -Handle g_hOnPlayerSetModelPost = null; -Handle g_hOnFPDeathCamera = null; -Handle g_hOnPlayerDeathVoice = null; +GlobalForward g_hOnPlayerSkinDefault = null; +GlobalForward g_hOnPlayerSetModel = null; +GlobalForward g_hOnPlayerSetModelPost = null; +GlobalForward g_hOnFPDeathCamera = null; +GlobalForward g_hOnPlayerDeathVoice = null; void Skin_InitConVar() { @@ -48,11 +48,11 @@ void Skin_InitConVar() void Skin_OnPluginStart() { - g_hOnPlayerSkinDefault = CreateGlobalForward("Store_OnPlayerSkinDefault", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_String, Param_Cell, Param_CellByRef); - g_hOnFPDeathCamera = CreateGlobalForward("Store_OnFPDeathCamera", ET_Hook, Param_Cell); - g_hOnPlayerSetModel = CreateGlobalForward("Store_OnSetPlayerSkin", ET_Event, Param_Cell, Param_String, Param_String, Param_CellByRef); - g_hOnPlayerSetModelPost = CreateGlobalForward("Store_OnSetPlayerSkinPost", ET_Ignore, Param_Cell, Param_String, Param_String, Param_Cell); - g_hOnPlayerDeathVoice = CreateGlobalForward("Store_OnPlayerDeathVoice", ET_Event, Param_Cell, Param_String); + g_hOnPlayerSkinDefault = new GlobalForward("Store_OnPlayerSkinDefault", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_String, Param_Cell, Param_CellByRef); + g_hOnFPDeathCamera = new GlobalForward("Store_OnFPDeathCamera", ET_Hook, Param_Cell); + g_hOnPlayerSetModel = new GlobalForward("Store_OnSetPlayerSkin", ET_Event, Param_Cell, Param_String, Param_String, Param_CellByRef); + g_hOnPlayerSetModelPost = new GlobalForward("Store_OnSetPlayerSkinPost", ET_Ignore, Param_Cell, Param_String, Param_String, Param_Cell); + g_hOnPlayerDeathVoice = new GlobalForward("Store_OnPlayerDeathVoice", ET_Event, Param_Cell, Param_String); Store_RegisterHandler("playerskin", PlayerSkins_OnMapStart, PlayerSkins_Reset, PlayerSkins_Config, PlayerSkins_Equip, PlayerSkins_Remove, true); @@ -891,10 +891,10 @@ static Action CallPreSetModel(int client, char skin[128], char arms[128], int &b static bool CallAllowSetPlayerSkinArms(int client, char[] arms, int len) { - static Handle gf = null; + static GlobalForward gf = null; if (gf == null) { - gf = CreateGlobalForward("Store_OnSetPlayerSkinArms", ET_Hook, Param_Cell, Param_String, Param_Cell); + gf = new GlobalForward("Store_OnSetPlayerSkinArms", ET_Hook, Param_Cell, Param_String, Param_Cell); } char buff[128]; diff --git a/store/modules/trail.sp b/store/modules/trail.sp index 99d498a..41ebd41 100644 --- a/store/modules/trail.sp +++ b/store/modules/trail.sp @@ -197,11 +197,11 @@ static void AttachTrail(int ent, int client, int current, int num) stock void Call_OnTrailsCreated(int client, int entity, int slot) { - static Handle gf = null; + static GlobalForward gf = null; if (gf == null) { // create - gf = CreateGlobalForward("Store_OnTrailsCreated", ET_Ignore, Param_Cell, Param_Cell, Param_Cell); + gf = new GlobalForward("Store_OnTrailsCreated", ET_Ignore, Param_Cell, Param_Cell, Param_Cell); } Call_StartForward(gf); diff --git a/store/players.sp b/store/players.sp index 5342d54..514566e 100644 --- a/store/players.sp +++ b/store/players.sp @@ -277,11 +277,11 @@ void OnClientTeamPost(int client) stock void Call_OnParticlesCreated(int client, int entity) { - static Handle gf = null; + static GlobalForward gf = null; if (gf == null) { // create - gf = CreateGlobalForward("Store_OnParticlesCreated", ET_Ignore, Param_Cell, Param_Cell); + gf = new GlobalForward("Store_OnParticlesCreated", ET_Ignore, Param_Cell, Param_Cell); } Call_StartForward(gf); diff --git a/store/sounds.sp b/store/sounds.sp index 011e7b4..41018ab 100644 --- a/store/sounds.sp +++ b/store/sounds.sp @@ -15,23 +15,22 @@ abstract_struct Sound int iCooldown; } -static int g_iSounds = 0; -static int g_iSoundClient[MAXPLAYERS + 1]; -static int g_iSoundSpam[MAXPLAYERS + 1]; -static bool g_bClientDisable[MAXPLAYERS + 1]; - +static int g_iSounds = 0; +static int g_iSoundClient[MAXPLAYERS + 1]; +static int g_iSoundSpam[MAXPLAYERS + 1]; +static bool g_bClientDisable[MAXPLAYERS + 1]; static Sound g_eSounds[STORE_MAX_ITEMS]; -static Handle g_hCookieSounds; -static Handle g_hOnCheerSound; -static Handle g_hOnCheerCommand; +static Cookie g_hCookieSounds; +static GlobalForward g_hOnCheerSound; +static GlobalForward g_hOnCheerCommand; void Sounds_OnPluginStart() { Store_RegisterHandler("sound", Sound_OnMapStart, Sound_Reset, Sound_Config, Sound_Equip, Sound_Remove, true); - g_hOnCheerSound = CreateGlobalForward("Store_OnCheerSound", ET_Hook, Param_Cell, Param_String, Param_String, Param_FloatByRef, Param_CellByRef); - g_hOnCheerCommand = CreateGlobalForward("Store_OnCheerCommand", ET_Hook, Param_Cell, Param_CellByRef); + g_hOnCheerSound = new GlobalForward("Store_OnCheerSound", ET_Hook, Param_Cell, Param_String, Param_String, Param_FloatByRef, Param_CellByRef); + g_hOnCheerCommand = new GlobalForward("Store_OnCheerCommand", ET_Hook, Param_Cell, Param_CellByRef); RegConsoleCmd("cheer", Command_Cheer); RegConsoleCmd("sm_cheer", Command_Cheer); @@ -44,7 +43,7 @@ void Sounds_OnClientprefs() { if (g_pClientprefs) { - g_hCookieSounds = RegClientCookie(SOUND_COOKIE_NAME, "", CookieAccess_Protected); + g_hCookieSounds = new Cookie(SOUND_COOKIE_NAME, "", CookieAccess_Protected); } else { @@ -342,7 +341,7 @@ void Sounds_OnLoadOptions(int client) if (g_pClientprefs) { char buff[4]; - GetClientCookie(client, g_hCookieSounds, STRING(buff)); + g_hCookieSounds.Get(client, STRING(buff)); if (buff[0] != 0) g_bClientDisable[client] = (StringToInt(buff) == 1 ? true : false); @@ -369,6 +368,6 @@ static void SetSoundState(int client, bool state) } else if (g_pClientprefs) { - SetClientCookie(client, g_hCookieSounds, state ? "1" : "0"); + g_hCookieSounds.Set(client, state ? "1" : "0"); } } \ No newline at end of file diff --git a/store/sprays.sp b/store/sprays.sp index dc7b3d8..d64cbc2 100644 --- a/store/sprays.sp +++ b/store/sprays.sp @@ -6,16 +6,16 @@ #define Module_Spray // options -static char g_szSprays[STORE_MAX_ITEMS][PLATFORM_MAX_PATH]; -static char g_szSprayName[STORE_MAX_ITEMS][PLATFORM_MAX_PATH]; -static int g_iSprayCooldown[STORE_MAX_ITEMS] = { 30, ... }; -static int g_iSprayPrecache[STORE_MAX_ITEMS] = { -1, ... }; -static int g_iSprayCache[MAXPLAYERS + 1] = { -1, ... }; -static int g_iSprayLimit[MAXPLAYERS + 1] = { 0, ... }; -static int g_iSprays = 0; -static Handle g_fwdOnClientSpray; -static Handle g_hOnSprayCommand; -static Handle g_hOnSprayModel; +static char g_szSprays[STORE_MAX_ITEMS][PLATFORM_MAX_PATH]; +static char g_szSprayName[STORE_MAX_ITEMS][PLATFORM_MAX_PATH]; +static int g_iSprayCooldown[STORE_MAX_ITEMS] = { 30, ... }; +static int g_iSprayPrecache[STORE_MAX_ITEMS] = { -1, ... }; +static int g_iSprayCache[MAXPLAYERS + 1] = { -1, ... }; +static int g_iSprayLimit[MAXPLAYERS + 1] = { 0, ... }; +static int g_iSprays = 0; +static GlobalForward g_fwdOnClientSpray; +static GlobalForward g_hOnSprayCommand; +static GlobalForward g_hOnSprayModel; static bool g_bFallbackSprayerSound; @@ -25,9 +25,9 @@ void Sprays_OnPluginStart() { Store_RegisterHandler("spray", Sprays_OnMapStart, Sprays_Reset, Sprays_Config, Sprays_Equip, Sprays_Remove, true); - g_fwdOnClientSpray = CreateGlobalForward("Store_OnClientSpray", ET_Ignore, Param_Cell); - g_hOnSprayCommand = CreateGlobalForward("Store_OnSprayCommand", ET_Hook, Param_Cell, Param_CellByRef); - g_hOnSprayModel = CreateGlobalForward("Store_OnSprayModel", ET_Hook, Param_Cell, Param_String, Param_String, Param_CellByRef, Param_CellByRef); + g_fwdOnClientSpray = new GlobalForward("Store_OnClientSpray", ET_Ignore, Param_Cell); + g_hOnSprayCommand = new GlobalForward("Store_OnSprayCommand", ET_Hook, Param_Cell, Param_CellByRef); + g_hOnSprayModel = new GlobalForward("Store_OnSprayModel", ET_Hook, Param_Cell, Param_String, Param_String, Param_CellByRef, Param_CellByRef); RegConsoleCmd("spray", Command_Spray); RegConsoleCmd("sprays", Command_Spray); From 462c252d804205923674604e88917bb091515ef5 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 5 Aug 2023 18:57:14 +0800 Subject: [PATCH 09/15] fix(core): TVoid query with timeout --- include/store_stock.inc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/store_stock.inc b/include/store_stock.inc index 09ad9fc..e97c1e5 100644 --- a/include/store_stock.inc +++ b/include/store_stock.inc @@ -102,12 +102,12 @@ static void SQLCallback_Void_PrintQuery(Database db, DBResultSet results, const float time = GetEngineTime() - pack.ReadFloat(); char query[1024]; pack.ReadString(STRING(query)); - if (time > 20.0) - LogMessage("Store SQL slow query: %f -> %s", time, query); - if (results == null || error[0]) - LogStoreError("SQL error happened.\nQuery: %s\nError: %s", query, error); - delete pack; + + if (results == null || error[0]) + LogStoreError("SQL error happened.\nError: %s\nQuery: %s", error, query); + else if (time >= 15.0) + LogMessage("Store SQL slow query.\nTime : %fs\nQuery: %s", time, query); } stock void SQL_TVoid(Database db, char[] query, DBPriority dbp = DBPrio_Normal) From e6ad53f916d41e38af18cae4efa2165a28e6e381 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 5 Aug 2023 21:00:50 +0800 Subject: [PATCH 10/15] :pig: --- store.sp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/store.sp b/store.sp index 102e993..d8a8a41 100644 --- a/store.sp +++ b/store.sp @@ -1096,9 +1096,9 @@ static any Native_GetPlayerSkin(Handle myself, int numParams) #if defined Module_Skin int client = GetNativeCell(1); - char model[2][192]; - Skin_GetClientSkinModel(client, model[0], 192); - Skin_GetPlayerSkinModel(client, model[1], 192); + char model[2][PLATFORM_MAX_PATH]; + Skin_GetClientSkinModel(client, model[0], sizeof(model[])); + Skin_GetPlayerSkinModel(client, model[1], sizeof(model[])); if (StrContains(model[1], "#default") != -1 || StrContains(model[1], "#zombie") != -1 || StrContains(model[0], "models/player/custom_player/legacy/") != -1) return false; From fc91790d5e56fc3df227319c7971603b865e38b1 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 5 Aug 2023 22:02:42 +0800 Subject: [PATCH 11/15] fix(core): connected retry cause missing map --- store.sp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/store.sp b/store.sp index d8a8a41..0727037 100644 --- a/store.sp +++ b/store.sp @@ -118,6 +118,7 @@ GlobalForward g_hShouldDrawItem = null; ArrayList g_aCaseSkins[3]; StringMap g_smParentMap = null; +ArrayList g_aLateQueue; Store_Item g_Items[STORE_MAX_ITEMS]; Client_Data g_ClientData[MAXPLAYERS + 1]; @@ -282,6 +283,7 @@ public void OnPluginStart() #endif g_smParentMap = new StringMap(); + g_aLateQueue = new ArrayList(); // Setting default values for (int client = 1; client <= MaxClients; ++client) @@ -1323,6 +1325,18 @@ public void OnClientPutInServer(int client) #endif } +public Action OnClientPreAdminCheck(int client) +{ + int index = g_aLateQueue.FindValue(client); + if (index > -1) + { + g_aLateQueue.Erase(index); + ClientCommand(client, "retry;"); + return Plugin_Handled; + } + return Plugin_Continue; +} + public void OnClientPostAdminCheck(int client) { if (IsFakeClient(client)) @@ -1335,6 +1349,10 @@ public void OnClientPostAdminCheck(int client) public void OnClientDisconnect(int client) { + int index = g_aLateQueue.FindValue(client); + if (index > -1) + g_aLateQueue.Erase(index); + if (IsFakeClient(client)) return; @@ -4158,7 +4176,10 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e { if (IsClientConnected(i) && !IsFakeClient(i)) { - ClientCommand(i, "retry;"); + if (IsClientInGame(i)) + ClientCommand(i, "retry;"); + else + g_aLateQueue.Push(i); } } } From e272846a710084f95e5581cd062332546a6d1e04 Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 15 Aug 2023 19:54:49 +0800 Subject: [PATCH 12/15] Fix empty model crash server --- store.sp | 3 +- store/modules/skin.sp | 103 ++++++++++++++++++++++++++++-------------- 2 files changed, 71 insertions(+), 35 deletions(-) diff --git a/store.sp b/store.sp index 0727037..c80ffb3 100644 --- a/store.sp +++ b/store.sp @@ -3718,8 +3718,7 @@ void UTIL_ComposeItem(int client) void UTIL_BuyItem(int client) { #if defined Module_Skin - if (g_tKillPreview[client] != null) - TriggerTimer(g_tKillPreview[client], false); + Skin_KillPreview(client); #endif if (g_Items[g_iSelectedItem[client]].iHandler == g_iPackageHandler) diff --git a/store/modules/skin.sp b/store/modules/skin.sp index e1f24fc..f397411 100644 --- a/store/modules/skin.sp +++ b/store/modules/skin.sp @@ -19,6 +19,7 @@ static PlayerSkin g_ePlayerSkins[STORE_MAX_ITEMS]; static bool g_bSoundHooked; static int g_iPlayerSkins = 0; +static bool g_bSpawnModelHook; static int g_iSkinLevel[MAXPLAYERS + 1]; static int g_iPreviewTimes[MAXPLAYERS + 1]; static int g_iPreviewModel[MAXPLAYERS + 1] = { INVALID_ENT_REFERENCE, ... }; @@ -32,14 +33,14 @@ static ConVar sv_disablefreezecam; static ConVar spec_replay_enable; static ConVar store_firstperson_death_camera; -Handle g_tKillPreview[MAXPLAYERS + 1]; -Handle g_tResetCamera[MAXPLAYERS + 1]; +static Handle g_tKillPreview[MAXPLAYERS + 1]; +static Handle g_tResetCamera[MAXPLAYERS + 1]; -GlobalForward g_hOnPlayerSkinDefault = null; -GlobalForward g_hOnPlayerSetModel = null; -GlobalForward g_hOnPlayerSetModelPost = null; -GlobalForward g_hOnFPDeathCamera = null; -GlobalForward g_hOnPlayerDeathVoice = null; +static GlobalForward g_hOnPlayerSkinDefault = null; +static GlobalForward g_hOnPlayerSetModel = null; +static GlobalForward g_hOnPlayerSetModelPost = null; +static GlobalForward g_hOnFPDeathCamera = null; +static GlobalForward g_hOnPlayerDeathVoice = null; void Skin_InitConVar() { @@ -144,16 +145,42 @@ void Skin_OnClientDisconnect(int client) if (g_tResetCamera[client] != null) TriggerTimer(g_tResetCamera[client], false); + + // fallback + g_bSpawnModelHook = false; } static MRESReturn Hook_OnSetModel(int client, DHookParam hParams) { + if (g_bSpawnModelHook) + return MRES_Ignored; + if (IsPlayerSpawing(client)) { - // char model[PLATFORM_MAX_PATH]; - // hParams.GetString(1, model, sizeof(model)); - // PrintToServer("Blocking %N SetModel -> %s", client, model); - return MRES_Supercede; + // due to connected spawning should be ignore + int team = GetClientTeam(client); + if (team < TEAM_OB) + { + // LogStackTrace("Failed to spawning setmodel: %N", client); + return MRES_Ignored; + } + +#if defined GM_ZE + // if we are in zombie mode, fallback to default model + if (team == TEAM_ZM) + { + return MRES_Ignored; + } +#endif + + g_bShouldFireEvent[client] = false; + + g_bSpawnModelHook = true; + Skin_ResetPlayerSkin(client); + bool supercede = Skin_SetClientSkin(client); + g_bSpawnModelHook = false; + + return supercede ? MRES_Supercede : MRES_Ignored; } return MRES_Ignored; @@ -161,8 +188,13 @@ static MRESReturn Hook_OnSetModel(int client, DHookParam hParams) static MRESReturn Hook_OnSetModelPost(int client, DHookParam hParams) { + if (g_bSpawnModelHook) + return MRES_Ignored; + char model[PLATFORM_MAX_PATH]; - hParams.GetString(1, model, sizeof(model)); + // supercede!!! + // hParams.GetString(1, model, sizeof(model)); + GetClientModel(client, model, sizeof(model)); if (strcmp(model, g_szSkinModel[client]) != 0) Skin_ResetPlayerSkin(client); @@ -307,30 +339,20 @@ static int PlayerSkins_Remove(int client, int id) #endif } -void Skin_SetClientSkin(int client) +bool Skin_SetClientSkin(int client) { int m_iEquipped = GetEquippedSkin(client); - if (m_iEquipped >= 0) - { - SetClientInventorySkin(client, Store_GetDataIndex(m_iEquipped)); - } - else - { - SetClientDefaultSkin(client); - } + return m_iEquipped >= 0 ? SetClientInventorySkin(client, Store_GetDataIndex(m_iEquipped)) : SetClientDefaultSkin(client); } -static void SetClientInventorySkin(int client, int index) +static bool SetClientInventorySkin(int client, int index) { - if (!IsClientInGame(client) || !IsPlayerAlive(client)) - return; - #if defined GM_ZE if (GetClientTeam(client) == TEAM_ZM) { strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), "#zombie"); - return; + return false; } #endif @@ -341,13 +363,13 @@ static void SetClientInventorySkin(int client, int index) Action res = CallPreSetModel(client, skin_t, arms_t, body_t); if (res >= Plugin_Handled) - return; + return false; else if (res == Plugin_Changed) { // verify data index; index = FindDataIndexByModel(skin_t, body_t); if (index == -1) - return; + return false; } if (g_ePlayerSkins[index].szSound[0] != 0) @@ -374,9 +396,11 @@ static void SetClientInventorySkin(int client, int index) Call_PushString(arms_t); Call_PushCell(body_t); Call_Finish(); + + return true; } -static Action Hook_NormalSound(int clients[64], int &numClients, char sample[PLATFORM_MAX_PATH], int &client, int &channel, float &volume, int &level, int &pitch, int &flags, char soundEntry[PLATFORM_MAX_PATH], int &seed) +static Action Hook_NormalSound(int clients[MAXPLAYERS], int &numClients, char sample[PLATFORM_MAX_PATH], int &client, int &channel, float &volume, int &level, int &pitch, int &flags, char soundEntry[PLATFORM_MAX_PATH], int &seed) { // not death sound if (channel != SNDCHAN_VOICE || sample[0] != '~') @@ -787,8 +811,6 @@ void Skin_OnPlayerSpawn(int client) TriggerTimer(g_tKillPreview[client], false); Skin_RemoveClientGloves(client, -1); - Skin_ResetPlayerSkin(client); - Skin_SetClientSkin(client); } void Skin_ResetPlayerSkin(int client) @@ -804,19 +826,20 @@ void Skin_ResetPlayerSkin(int client) g_szDeathVoice[client][0] = 0; } -static void SetClientDefaultSkin(int client) +static bool SetClientDefaultSkin(int client) { #if defined GM_ZE if (GetClientTeam(client) == TEAM_ZM) { strcopy(g_szSkinModel[client], sizeof(g_szSkinModel[]), "#zombie"); - return; + return false; } #endif char skin_t[128], arms_t[128]; int body = 0; bool ret = false; + bool set = false; Call_StartForward(g_hOnPlayerSkinDefault); Call_PushCell(client); @@ -834,6 +857,7 @@ static void SetClientDefaultSkin(int client) { SetEntityModel(client, skin_t); SetEntProp(client, Prop_Send, "m_nBody", body > 0 ? body : 0); + set = true; } if (CallAllowSetPlayerSkinArms(client, STRING(arms_t))) @@ -846,6 +870,8 @@ static void SetClientDefaultSkin(int client) EnforceDeathSound(client, skin_t, body); } + + return set; } static void EnforceDeathSound(int client, const char[] skin, const int body) @@ -1031,4 +1057,15 @@ bool Skin_GetSkinData(int itemid, char skin[128], char arms[128], int &body, int body = g_ePlayerSkins[m_iData].nBody; team = g_ePlayerSkins[m_iData].iTeam; return true; +} + +/** + * Kills the skin preview for the specified client. + * + * @param client The client index to kill the skin preview for. + */ +void Skin_KillPreview(int client) +{ + if (g_tKillPreview[client] != null) + TriggerTimer(g_tKillPreview[client], false); } \ No newline at end of file From 221f960f461334d56d22dc8c3eda85a89775e6a7 Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 15 Aug 2023 20:02:32 +0800 Subject: [PATCH 13/15] optimize spawn timer performance --- modules/store_pet.sp | 2 +- store/players.sp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/store_pet.sp b/modules/store_pet.sp index 91b0537..a021c78 100644 --- a/modules/store_pet.sp +++ b/modules/store_pet.sp @@ -194,7 +194,7 @@ static void Pets_PlayerSpawn(Event event, const char[] name, bool dontBroadcast) return; delete g_hDelay[client]; - g_hDelay[client] = CreateTimer(0.5 + client * 0.1, Timer_DelaySpawn, client); + g_hDelay[client] = CreateTimer(0.5 + (client / 8) * 0.1, Timer_DelaySpawn, client); } static Action Timer_DelaySpawn(Handle timer, int client) diff --git a/store/players.sp b/store/players.sp index 514566e..29f7228 100644 --- a/store/players.sp +++ b/store/players.sp @@ -129,12 +129,12 @@ static void OnClientSpawned(int client) return; // particles should be delay. - CreateTimer(0.5 + client * 0.1, Timer_DelaySpawn, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE); + CreateTimer(0.5 + (client / 8) * 0.1, Timer_DelaySpawn, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE); } -static Action Timer_DelaySpawn(Handle timer, int userid) +static Action Timer_DelaySpawn(Handle timer, int serial) { - int client = GetClientOfUserId(userid); + int client = GetClientFromSerial(serial); if (!client || !IsPlayerAlive(client)) return Plugin_Stop; From 7c4a5906012bb18c929e5eb4bcf90a9a22235f79 Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 15 Aug 2023 20:06:35 +0800 Subject: [PATCH 14/15] use serial instead of userid for delay credits update --- store.sp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/store.sp b/store.sp index c80ffb3..aa09759 100644 --- a/store.sp +++ b/store.sp @@ -741,7 +741,7 @@ static any Native_SetClientCredits(Handle myself, int numParams) if (g_ClientData[client].bRefresh) { DataPack pack = new DataPack(); - pack.WriteCell(client); + pack.WriteCell(GetClientSerial(client)); pack.WriteCell(difference); pack.WriteCell(g_ClientData[client].iId); pack.WriteCell(GetTime()); @@ -762,14 +762,15 @@ static any Native_SetClientCredits(Handle myself, int numParams) static Action Timer_SetCreditsDelay(Handle timer, DataPack pack) { pack.Reset(); - int client = pack.ReadCell(); + int serial = pack.ReadCell(); + int client = GetClientFromSerial(serial); int difference = pack.ReadCell(); int m_iStoreId = pack.ReadCell(); int iTimeStamp = pack.ReadCell(); char logMsg[256]; pack.ReadString(STRING(logMsg)); - if (!IsClientInGame(client)) + if (!client || !IsClientInGame(client)) { delete pack; char m_szQuery[512], eReason[256]; @@ -4583,7 +4584,7 @@ void Call_OnClientLoaded(int client) tPrintToChat(client, "%T", "Inventory has been loaded", client); - if (g_fCreditsTimerInterval > 1.0) + if (g_fCreditsTimerInterval >= 1.0) g_ClientData[client].hTimer = CreateTimer(g_fCreditsTimerInterval, Timer_OnlineCredit, client, TIMER_REPEAT); } From a9ec2b774ecde09913b80b9fe1ef0304ed8138b8 Mon Sep 17 00:00:00 2001 From: Kyle Date: Wed, 16 Aug 2023 18:54:13 +0800 Subject: [PATCH 15/15] fix(core): fix stringtables on late load --- store.sp | 52 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/store.sp b/store.sp index aa09759..8736fba 100644 --- a/store.sp +++ b/store.sp @@ -144,8 +144,8 @@ int g_iDataProtect[MAXPLAYERS + 1]; bool g_bInvMode[MAXPLAYERS + 1]; -bool g_bLateLoad; - +bool g_bLateLoad; // check if we need actual reload map or fake reload +bool g_bStoreLoaded; bool g_bInterMission; // library @@ -492,7 +492,9 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max MarkNativeAsOptional("TransmitManager_GetEntityState"); MarkNativeAsOptional("TransmitManager_IsEntityHooked"); - g_bLateLoad = late; + // g_bLateLoad = late; + // engine was loaded and after 10 seconds + g_bLateLoad = GetEngineTime() >= 10.0; // RegLibrary RegPluginLibrary("store"); @@ -3341,6 +3343,9 @@ void UTIL_LoadClientInventory(int client) return; } + if (!g_bStoreLoaded) + return; + char m_szQuery[512]; char m_szAuthId[32]; if (!GetClientAuthId(client, AuthId_Steam2, STRING(m_szAuthId), true) || m_szAuthId[0] == 0 || g_bInterMission) @@ -4160,6 +4165,9 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e delete items; delete item_array; + // we are loaded. + g_bStoreLoaded = true; + // rebuild download table if (FindPluginByFile("sm_downloader.smx") != INVALID_HANDLE) { @@ -4168,19 +4176,28 @@ static void SQL_LoadChildren(Database db, DBResultSet item_child, const char[] e ServerExecute(); } - OnMapEnd(); - OnMapStart(); - - // re-download resources - for (int i = 1; i <= MaxClients; i++) + if (g_bLateLoad) { - if (IsClientConnected(i) && !IsFakeClient(i)) + OnMapEnd(); + OnMapStart(); + + // re-download resources + for (int i = 1; i <= MaxClients; i++) { - if (IsClientInGame(i)) - ClientCommand(i, "retry;"); - else - g_aLateQueue.Push(i); + if (IsClientConnected(i) && !IsFakeClient(i)) + { + if (IsClientInGame(i)) + ClientCommand(i, "retry;"); + else + g_aLateQueue.Push(i); + } } + + LogMessage("Due to late load, we do fake map change and retry all clients."); + } + else + { + CreateTimer(1.0, ReloadMap, _, TIMER_FLAG_NO_MAPCHANGE); } } @@ -4655,4 +4672,13 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 #endif return Plugin_Continue; +} + +static Action ReloadMap(Handle timer) +{ + char map[PLATFORM_MAX_PATH]; + GetCurrentMap(STRING(map)); + LogMessage("Force reload map to ensure string tables is correct!"); + ForceChangeLevel(map, "Force reload map to ensure string tables is correct!"); + return Plugin_Stop; } \ No newline at end of file