Advertisement
Guest User

HRespawn

a guest
Jan 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <cstrike>
  4. #include <hosties>
  5.  
  6. new Float:g_DeathLocation[MAXPLAYERS+1][3];
  7.  
  8. Respawn_OnPluginStart()
  9. {
  10. RegAdminCmd("sm_hrespawn", Command_Respawn, ADMFLAG_SLAY);
  11. RegAdminCmd("sm_1up", Command_Respawn, ADMFLAG_SLAY);
  12. HookEvent("player_death", Respawn_PlayerDeath);
  13. }
  14.  
  15. public Action:Command_Respawn(client, args)
  16. {
  17. if (args < 1)
  18. {
  19. ReplyToCommand(client, "[SM] Usage: sm_hrespawn <#userid|name>");
  20. return Plugin_Handled;
  21. }
  22.  
  23. decl String:arg[65];
  24. GetCmdArg(1, arg, sizeof(arg));
  25.  
  26. decl String:target_name[MAX_TARGET_LENGTH];
  27. decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
  28.  
  29. if ((target_count = ProcessTargetString(
  30. arg,
  31. client,
  32. target_list,
  33. MAXPLAYERS,
  34. COMMAND_FILTER_DEAD,
  35. target_name,
  36. sizeof(target_name),
  37. tn_is_ml)) <= 0)
  38. {
  39. ReplyToTargetError(client, target_count);
  40. return Plugin_Handled;
  41. }
  42.  
  43. for (new i = 0; i < target_count; i++)
  44. {
  45. PerformRespawn(client, target_list[i]);
  46. }
  47.  
  48. ShowActivity(client, CHAT_BANNER, "Respawned Target", target_name);
  49.  
  50. return Plugin_Handled;
  51. }
  52.  
  53. public Respawn_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
  54. {
  55. new victim = GetClientOfUserId(GetEventInt(event, "userid"));
  56. GetClientAbsOrigin(victim, g_DeathLocation[victim]);
  57. g_DeathLocation[victim][2] -= 45.0;
  58. }
  59.  
  60. Respawn_Menus(Handle:h_TopMenu, TopMenuObject:obj_Hosties)
  61. {
  62. AddToTopMenu(h_TopMenu, "sm_hrespawn", TopMenuObject_Item, AdminMenu_Respawn, obj_Hosties, "sm_hrespawn", ADMFLAG_SLAY);
  63. }
  64.  
  65. PerformRespawn(client, target)
  66. {
  67. CS_RespawnPlayer(target);
  68. if (g_DeathLocation[target][0] == 0.0 && g_DeathLocation[target][1] == 0.0 && g_DeathLocation[target][2] == 0.0)
  69. {
  70. ReplyToCommand(client, CHAT_BANNER, "Respawn Data Unavailable", target);
  71. }
  72. else
  73. {
  74. TeleportEntity(target, g_DeathLocation[target], NULL_VECTOR, NULL_VECTOR);
  75. }
  76. LogAction(client, target, "\"%L\" respawned \"%L\"", client, target);
  77. }
  78.  
  79. DisplayRespawnMenu(client)
  80. {
  81. new Handle:menu = CreateMenu(MenuHandler_Respawn);
  82.  
  83. decl String:title[100];
  84. Format(title, sizeof(title), "%T", "Respawn Player", client);
  85. SetMenuTitle(menu, title);
  86. SetMenuExitBackButton(menu, true);
  87.  
  88. new targets_added = AddTargetsToMenu2(menu, client, COMMAND_FILTER_DEAD);
  89. if (targets_added == 0)
  90. {
  91. ReplyToCommand(client, CHAT_BANNER, "Target is not in game");
  92. if (gH_TopMenu != INVALID_HANDLE)
  93. {
  94. DisplayTopMenu(gH_TopMenu, client, TopMenuPosition_LastCategory);
  95. }
  96. }
  97. else
  98. {
  99. DisplayMenu(menu, client, MENU_TIME_FOREVER);
  100. }
  101. }
  102.  
  103. public AdminMenu_Respawn(Handle:topmenu,
  104. TopMenuAction:action,
  105. TopMenuObject:object_id,
  106. param,
  107. String:buffer[],
  108. maxlength)
  109. {
  110. if (action == TopMenuAction_DisplayOption)
  111. {
  112. Format(buffer, maxlength, "%T", "Respawn Player", param);
  113. }
  114. else if (action == TopMenuAction_SelectOption)
  115. {
  116. DisplayRespawnMenu(param);
  117. }
  118. }
  119.  
  120. public MenuHandler_Respawn(Handle:menu, MenuAction:action, param1, param2)
  121. {
  122. if (action == MenuAction_End)
  123. {
  124. CloseHandle(menu);
  125. }
  126. else if (action == MenuAction_Cancel)
  127. {
  128. if (param2 == MenuCancel_ExitBack && gH_TopMenu != INVALID_HANDLE)
  129. {
  130. DisplayTopMenu(gH_TopMenu, param1, TopMenuPosition_LastCategory);
  131. }
  132. }
  133. else if (action == MenuAction_Select)
  134. {
  135. decl String:info[32];
  136. new userid, target;
  137.  
  138. GetMenuItem(menu, param2, info, sizeof(info));
  139. userid = StringToInt(info);
  140.  
  141. if ((target = GetClientOfUserId(userid)) == 0)
  142. {
  143. PrintToChat(param1, CHAT_BANNER, "Player no longer available");
  144. }
  145. else if (!CanUserTarget(param1, target))
  146. {
  147. PrintToChat(param1, CHAT_BANNER, "Unable to target");
  148. }
  149. else if (IsPlayerAlive(target))
  150. {
  151. ReplyToCommand(param1, CHAT_BANNER, "Player Alive");
  152. }
  153. else
  154. {
  155. decl String:name[32];
  156. GetClientName(target, name, sizeof(name));
  157. PerformRespawn(param1, target);
  158. ShowActivity(param1, CHAT_BANNER, "Respawned Target", name);
  159. }
  160.  
  161. DisplayRespawnMenu(param1);
  162. }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement