diff --git a/FunMode/scripting/FunMode.sp b/FunMode/scripting/FunMode.sp index ee7d4f01..4d7c812a 100644 --- a/FunMode/scripting/FunMode.sp +++ b/FunMode/scripting/FunMode.sp @@ -86,7 +86,7 @@ public void OnPluginStart() g_cvarKnifeRegenTime.AddChangeHook(ConVarChanged_Max_Regen); HookEvent("player_death", EventHook_PlayerDeath, EventHookMode_Pre); - HookEvent("round_start", EventHook_RoundStart, EventHookMode_Post); + HookEvent("player_spawn", EventHook_PlayerSpawn, EventHookMode_Post); g_hNotifyTimer = CreateTimer(0.25, Timer_UpdateKnives, _, TIMER_REPEAT); @@ -132,7 +132,7 @@ public void OnPluginEnd() } UnhookEvent("player_death", EventHook_PlayerDeath, EventHookMode_Pre); - UnhookEvent("round_start", EventHook_RoundStart, EventHookMode_Post); + UnhookEvent("player_spawn", EventHook_PlayerSpawn, EventHookMode_Post); g_cvarMaxKnives.RemoveChangeHook(ConVarChanged_Max_Regen); g_cvarKnifeRegenTime.RemoveChangeHook(ConVarChanged_Max_Regen); @@ -188,8 +188,6 @@ public void OnClientPutInServer(int client) if (g_bInWarmup) return; - SDKHook(client, SDKHook_SpawnPost, SDKHookCB_ClientSpawnPost); - MenuSource iOpenMenu = GetClientMenu(client); if (iOpenMenu != MenuSource_None && iOpenMenu == MenuSource_RawPanel) //probably failnadefriday @@ -216,41 +214,34 @@ public void OnClientPutInServer(int client) delete hNotifyPanel; } -public void SDKHookCB_ClientSpawnPost(int client) +public Action EventHook_PlayerSpawn(Event hEvent, const char[] sName, bool bDontBroadcast) { - RequestFrame(RequestFrame_ClientSpawnPost, client); + if (!g_bEnabled || g_bInWarmup) + return; + + int serial = GetClientSerial(GetClientOfUserId(GetEventInt(hEvent, "userid"))); + CreateTimer(1.0, EventHook_PlayerSpawnPost, serial); } -public void RequestFrame_ClientSpawnPost(int client) +public Action EventHook_PlayerSpawnPost(Handle hTimer, int serial) { - static int iTickCount = 0; - - if (iTickCount <= 16) - { - iTickCount++; - RequestFrame(RequestFrame_ClientSpawnPost, client); - return; - } - - iTickCount = 0; - - if (!IsClientInGame(client) || GetClientTeam(client) != CS_TEAM_CT) + int client = GetClientFromSerial(serial); + if (!client || !IsClientInGame(client) || GetClientTeam(client) != CS_TEAM_CT) return; int ent = GivePlayerItem(client, "weapon_smokegrenade"); EquipPlayerWeapon(client, ent); - //PrintToChatAll("%N spawned in and got a smoke", client); + PrintToChatAll("1. %N gets %d", client, ent); char sHumanClassName[64]; ZRT_GetClientClassSectionName(client, sHumanClassName, sizeof(sHumanClassName)); if (StrEqual(sHumanClassName, "freeze_human")) { - int ent = GivePlayerItem(client, "weapon_smokegrenade"); // needs ammo_smokegrenade_max 2 + ent = GivePlayerItem(client, "weapon_smokegrenade"); // needs ammo_smokegrenade_max 2 EquipPlayerWeapon(client, ent); - //PrintToChatAll("%N spawned in as the freeze human and got another smoke", client); + PrintToChatAll("2. %N gets %d", client, ent); } - } int MenuHandler_NotifyPanel(Menu hMenu, MenuAction iAction, int iParam1, int iParam2) @@ -269,7 +260,6 @@ public void OnClientDisconnect(int client) g_iPlayerKnives[client] = 0; g_bIgnoredFirstUpdate[client] = false; - SDKUnhook(client, SDKHook_SpawnPost, SDKHookCB_ClientSpawnPost); } public void OnEntityCreated(int entity, const char[] sClassName) @@ -410,42 +400,6 @@ public Action EventHook_PlayerDeath(Event hEvent, const char[] sName, bool bDont return Plugin_Continue; } -public Action EventHook_RoundStart(Event hEvent, const char[] sName, bool bDontBroadcast) -{ - if (g_bInWarmup || !g_bEnabled) - return Plugin_Continue; - - RequestFrame(RequestFrame_OnRoundStart, 16); - - return Plugin_Continue; -} - -public void RequestFrame_OnRoundStart(int iTicksToWait) -{ - static int iTickCount = 0; - - if (iTickCount <= iTicksToWait) - { - iTickCount++; - RequestFrame(RequestFrame_OnRoundStart, 16); - return; - } - - iTickCount = 0; - - for (int i = 1; i <= MaxClients; i++) - { - if (!IsClientInGame(i) || IsFakeClient(i)) - continue; - - if (GetClientTeam(i) != CS_TEAM_CT) - continue; - - //int ent = GivePlayerItem(i, "weapon_smokegrenade"); // is done on post-spawn now - //EquipPlayerWeapon(i, ent); - } -} - public Action Timer_OnWarmupEnd(Handle hThis) { static int iTimePassed = 0; @@ -878,4 +832,4 @@ public void ConVarChanged_Max_Regen(ConVar cvar, const char[] sOldVal, const cha stock bool IsValidClient(int client) { return (client > 0 && client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client)); -} \ No newline at end of file +}