HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5.  
  6. #define PLUGIN_VERSION "1.0.2"
  7.  
  8. public Plugin:myinfo =
  9. {
  10. name = "Following C4",
  11. author = "Mitch",
  12. description = "Aki letette a C4-et azt követni fogja ahova megy..",
  13. version = PLUGIN_VERSION,
  14. url = "http://snbx.info/"
  15. };
  16.  
  17. new gLeaderOffset;
  18.  
  19. new C4Hostage;
  20. new FollowingPlayer;
  21.  
  22. public OnPluginStart()
  23. {
  24. CreateConVar("sm_followingc4_version", PLUGIN_VERSION, "C4Model Version", FCVAR_DONTRECORD|FCVAR_NOTIFY);
  25. gLeaderOffset = FindSendPropOffs("CHostage", "m_leader");
  26. HookEvent("player_death", PlayerDeathEvent);
  27. HookEvent("bomb_planted", BomPlanted_Event);
  28. }
  29. public OnPluginEnd()
  30. {
  31. if(IsHostage(C4Hostage))
  32. {
  33. AcceptEntityInput(C4Hostage, "Kill");
  34. }
  35. }
  36. public OnClientDisconnect(client)
  37. {
  38. if(client==FollowingPlayer)
  39. FindNewPlayer();
  40. }
  41. public PlayerDeathEvent(Handle:event, const String:name[], bool:dontBroadcast)
  42. {
  43. new client = (GetClientOfUserId(GetEventInt(event, "userid")));
  44. if(client==FollowingPlayer)
  45. FindNewPlayer();
  46. }
  47. FindNewPlayer()
  48. {
  49. new Float:orig[3];
  50. GetEntPropVector(C4Hostage, Prop_Send, "m_vecOrigin", orig);
  51.  
  52. decl Float:vecOrigin_edict[3];
  53. new Float:distance = 0.0;
  54. new closestEdict = INVALID_ENT_REFERENCE;
  55. new Float:edict_distance = 0.0;
  56.  
  57. for (new edict=1; edict <= MaxClients; edict++) {
  58.  
  59. if (!IsValidEdict(edict))
  60. continue;
  61.  
  62. if (edict == C4Hostage)
  63. continue;
  64.  
  65. if (GetEntSendPropOffs(edict, "m_vecOrigin") == -1)
  66. continue;
  67.  
  68. GetEntPropVector(edict, Prop_Send, "m_vecOrigin", vecOrigin_edict);
  69. edict_distance = GetVectorDistance(orig, vecOrigin_edict);
  70. if (edict_distance < distance || distance == 0.0)
  71. {
  72. distance = edict_distance;
  73. closestEdict = edict;
  74. }
  75. }
  76. FollowingPlayer = closestEdict;
  77. if(FollowingPlayer > 0 && IsClientInGame(FollowingPlayer) && IsPlayerAlive(FollowingPlayer))
  78. if(IsHostage(C4Hostage))
  79. SetEntDataEnt2(C4Hostage, gLeaderOffset, FollowingPlayer);
  80. }
  81. public OnMapStart()
  82. {
  83. CreateTimer(5.0, Timer_OwnerRepeat, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  84. }
  85. public Action:Timer_OwnerRepeat(Handle:timer)
  86. {
  87. if(FollowingPlayer > 0 && IsClientInGame(FollowingPlayer) && IsPlayerAlive(FollowingPlayer))
  88. {
  89. if(IsHostage(C4Hostage))
  90. {
  91. SetEntDataEnt2(C4Hostage, gLeaderOffset, FollowingPlayer);
  92. }
  93. }
  94. }
  95. public Action:BomPlanted_Event(Handle:event, const String:name[], bool:dontBroadcast)
  96. {
  97. FollowingPlayer = GetClientOfUserId(GetEventInt(event, "userid"));
  98. new c4 = -1;
  99. c4 = FindEntityByClassname(c4, "planted_c4");
  100. new Float:pos[3], Float:angles[3];
  101. if(c4 != -1)
  102. {
  103. GetEntPropVector(FollowingPlayer, Prop_Data, "m_vecOrigin", pos);
  104. GetEntPropVector(FollowingPlayer, Prop_Data, "m_angRotation", angles);
  105. decl String:c4Model[128];
  106. GetEntPropString(c4, Prop_Data, "m_ModelName", c4Model,sizeof(c4Model));
  107. C4Hostage = CreateEntityByName("hostage_entity");
  108. if((C4Hostage == -1) )
  109. PrintToServer("Error making hostage!");
  110.  
  111. DispatchKeyValue(C4Hostage, "model", c4Model);
  112. DispatchKeyValue(C4Hostage, "skin", "1");
  113. DispatchKeyValue(C4Hostage, "solid", "0");
  114. DispatchKeyValue(C4Hostage, "disableshadows", "1");
  115. SetEntityModel(C4Hostage, c4Model);
  116. DispatchSpawn(C4Hostage);
  117. SetEntProp(C4Hostage, Prop_Data, "m_takedamage", 0);
  118. SetEntityRenderColor(C4Hostage, 255, 255, 255, 0);
  119. SetEntityRenderMode(C4Hostage, RENDER_TRANSALPHA);
  120.  
  121. TeleportEntity(C4Hostage, pos, angles, NULL_VECTOR);
  122.  
  123. SetEntProp(C4Hostage, Prop_Data, "m_CollisionGroup", 1);
  124. SetEntData(C4Hostage, FindSendPropOffs("CHostage", "m_isRescued"), true, 4, true);
  125.  
  126. SetVariantString("!activator");
  127. AcceptEntityInput(c4, "SetParent", C4Hostage, c4, 0);
  128. }
  129. return Plugin_Continue;
  130. }
  131. bool:IsHostage(Ent)
  132. {
  133. if(Ent != -1)
  134. {
  135. if(IsValidEdict(Ent) && IsValidEntity(Ent) && IsEntNetworkable(Ent))
  136. {
  137. decl String:ClassName[255];
  138. GetEdictClassname(Ent, ClassName, 255);
  139. if(StrEqual(ClassName, "hostage_entity"))
  140. {
  141. return true;
  142. }
  143. }
  144. }
  145. return false;
  146. }