HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <sdkhooks>
  4. #undef REQUIRE_PLUGIN
  5. #include <ToggleEffects>
  6. #define VERSION "1.2"
  7.  
  8. new g_Hat[MAXPLAYERS+1];
  9. new bool:g_bToggleEffects = false;
  10. new Handle:g_hLookupAttachment = INVALID_HANDLE;
  11. new Handle:CvarEnable;
  12.  
  13. public Plugin:myinfo =
  14. {
  15. name = "Christmas Hat",
  16. author = "Xilver266 Steam: donchopo",
  17. description = "Karacsonyi sapkat ad a jatekosokra",
  18. version = VERSION,
  19. url = "servers-cfg.foroactivo.com"
  20. };
  21.  
  22. public OnPluginStart()
  23. {
  24. AutoExecConfig(true, "christmas_hat");
  25. HookEvent("player_spawn", PlayerSpawn);
  26. HookEvent("player_death", PlayerDeath);
  27. CreateConVar("sm_christmas_hat_version", VERSION, "Christmas Hat", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  28. new Handle:hGameConf = LoadGameConfigFile("hats.gamedata");
  29. g_bToggleEffects = LibraryExists("ToggleEffects");
  30. StartPrepSDKCall(SDKCall_Entity);
  31. PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "LookupAttachment");
  32. PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
  33. PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
  34. g_hLookupAttachment = EndPrepSDKCall();
  35. CvarEnable = CreateConVar("sm_christmas_hat_enable", "1", "Karacsonyi sapka engedelyezese. 0 - Nem engedelyezve | 1 -Engedelyezve", _, true, 0.0, true, 1.0);
  36. }
  37.  
  38. public OnMapStart()
  39. {
  40. AddFileToDownloadsTable("materials/models/santahat/furballs.vmt");
  41. AddFileToDownloadsTable("materials/models/santahat/santahat.vmt");
  42. AddFileToDownloadsTable("materials/models/santahat/santahat.vtf");
  43. AddFileToDownloadsTable("models/santahat/santahat.mdl");
  44. AddFileToDownloadsTable("models/santahat/santahat.phy");
  45. AddFileToDownloadsTable("models/santahat/santahat.vvd");
  46. AddFileToDownloadsTable("models/santahat/santahat.sw.vtx");
  47. AddFileToDownloadsTable("models/santahat/santahat.dx80.vtx");
  48. AddFileToDownloadsTable("models/santahat/santahat.dx90.vtx");
  49. PrecacheModel("models/santahat/santahat.mdl");
  50. }
  51.  
  52. public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
  53. {
  54. new client = GetClientOfUserId(GetEventInt(event, "userid"));
  55. if(!IsClientInGame(client) || !IsPlayerAlive(client))
  56. return Plugin_Continue;
  57.  
  58. RemoveHat(client);
  59. CreateTimer(0.0, TimerCreateHats, client);
  60.  
  61. return Plugin_Continue;
  62. }
  63.  
  64. public Action:TimerCreateHats(Handle:timer, any:client)
  65. {
  66. if (GetConVarBool(CvarEnable))
  67. CreateHat(client);
  68.  
  69. return Plugin_Stop;
  70. }
  71.  
  72. CreateHat(client)
  73. {
  74. if(!LookupAttachment(client, "forward"))
  75. return;
  76.  
  77. if(GetClientTeam(client) == 1)
  78. return;
  79.  
  80. new Float:or[3];
  81. new Float:ang[3];
  82. new Float:fForward[3];
  83. new Float:fRight[3];
  84. new Float:fUp[3];
  85. GetClientAbsOrigin(client,or);
  86. GetClientAbsAngles(client,ang);
  87.  
  88. ang[0] += 0.0;
  89. ang[1] += 0.0;
  90. ang[2] += 0.0;
  91.  
  92. new Float:fOffset[3];
  93. fOffset[0] = 0.0;
  94. fOffset[1] = -1.0;
  95. fOffset[2] = 6.0;
  96.  
  97. GetAngleVectors(ang, fForward, fRight, fUp);
  98.  
  99. or[0] += fRight[0]*fOffset[0]+fForward[0]*fOffset[1]+fUp[0]*fOffset[2];
  100. or[1] += fRight[1]*fOffset[0]+fForward[1]*fOffset[1]+fUp[1]*fOffset[2];
  101. or[2] += fRight[2]*fOffset[0]+fForward[2]*fOffset[1]+fUp[2]*fOffset[2];
  102.  
  103. new ent = CreateEntityByName("prop_dynamic_override");
  104. DispatchKeyValue(ent, "model", "models/santahat/santahat.mdl");
  105. DispatchKeyValue(ent, "spawnflags", "4");
  106. SetEntProp(ent, Prop_Data, "m_CollisionGroup", 2);
  107. SetEntPropEnt(ent, Prop_Send, "m_hOwnerEntity", client);
  108.  
  109. DispatchSpawn(ent);
  110. AcceptEntityInput(ent, "TurnOn", ent, ent, 0);
  111.  
  112. g_Hat[client] = ent;
  113.  
  114. SDKHook(ent, SDKHook_SetTransmit, ShouldHide);
  115.  
  116. TeleportEntity(ent, or, ang, NULL_VECTOR);
  117.  
  118. SetVariantString("!activator");
  119. AcceptEntityInput(ent, "SetParent", client, ent, 0);
  120.  
  121. SetVariantString("forward");
  122. AcceptEntityInput(ent, "SetParentAttachmentMaintainOffset", ent, ent, 0);
  123. }
  124.  
  125. public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
  126. {
  127. new client = GetClientOfUserId(GetEventInt(event, "userid"));
  128. RemoveHat(client);
  129. }
  130.  
  131. public OnClientDisconnect(client)
  132. {
  133. RemoveHat(client);
  134. }
  135.  
  136. public Action:ShouldHide(ent, client)
  137. {
  138. if(g_bToggleEffects)
  139. if(!ShowClientEffects(client))
  140. return Plugin_Handled;
  141.  
  142. if(ent == g_Hat[client])
  143. return Plugin_Handled;
  144.  
  145. if(IsClientInGame(client))
  146. if(GetEntProp(client, Prop_Send, "m_iObserverMode") == 4 && GetEntPropEnt(client, Prop_Send, "m_hObserverTarget")>=0)
  147. if(ent == g_Hat[GetEntPropEnt(client, Prop_Send, "m_hObserverTarget")])
  148. return Plugin_Handled;
  149.  
  150. return Plugin_Continue;
  151. }
  152.  
  153. stock LookupAttachment(client, String:point[])
  154. {
  155. if(g_hLookupAttachment==INVALID_HANDLE) return 0;
  156. if( client<=0 || !IsClientInGame(client) ) return 0;
  157. return SDKCall(g_hLookupAttachment, client, point);
  158. }
  159.  
  160. public RemoveHat(client)
  161. {
  162. if (g_Hat[client] != 0 && IsValidEdict(g_Hat[client]))
  163. {
  164. AcceptEntityInput(g_Hat[client], "Kill");
  165. SDKUnhook(g_Hat[client], SDKHook_SetTransmit, ShouldHide);
  166. g_Hat[client] = 0;
  167. }
  168. }
  169.