Veteran Member
Join Date: Jun 2010
Location: Poland
|
01-11-2012
, 18:29
I need a little help here
|
#1
|
I took the code from here ( KaOs and Bacardi) and I've modified it to work on alive players only.
But now I need to allow non-admin players to use it on themselfs only (!respawn), but only for i.e. 30 seconds after RoundStart/Spawn and limit it to one command per round, so they can use it only one time each round.
I also want to remove existing admin related functionality (!respawn nick), so the plugin will be for non-admins only:
Code:
#pragma semicolon 1
#include <sourcemod>
#include <cstrike>
#include <adminmenu>
public Plugin:myinfo = {
name = "Respawn",
author = "KaOs and Bacardi",
description = "Respawn alive players.",
version = "1.1",
url = "http://forums.alliedmods.net/showthread.php?t=66794"
}
new Handle:hTopMenu = INVALID_HANDLE;
public OnPluginStart() {
LoadTranslations("common.phrases"); // Fix [SM] Native "ReplyToCommand" reported: Language phrase "No matching client" not found
RegAdminCmd("sm_respawn", CmdRespawn, ADMFLAG_KICK, "sm_respawn <#userid|name>");
/* Account for late loading */
new Handle:topmenu;
if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
{
OnAdminMenuReady(topmenu);
}
}
public OnAdminMenuReady(Handle:topmenu)
{
/* Block us from being called twice */
if (topmenu == hTopMenu)
{
return;
}
/* Save the Handle */
hTopMenu = topmenu;
/* Build the "Player Commands" category */
new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
if (player_commands != INVALID_TOPMENUOBJECT)
{
AddToTopMenu(hTopMenu,
"sm_respawn",
TopMenuObject_Item,
AdminMenu_Respawn,
player_commands,
"sm_respawn",
ADMFLAG_KICK);
}
}
public AdminMenu_Respawn(Handle:topmenu,
TopMenuAction:action,
TopMenuObject:object_id,
param,
String:buffer[],
maxlength)
{
if (action == TopMenuAction_DisplayOption)
{
Format(buffer, maxlength, "Respawnuj Gracza", param);
}
else if (action == TopMenuAction_SelectOption)
{
DisplayRespawnMenu(param);
}
}
DisplayRespawnMenu(client)
{
new Handle:menu = CreateMenu(MenuHandler_Respawn);
decl String:title[100];
Format(title, sizeof(title), "Respawnuj Gracza", client);
SetMenuTitle(menu, title);
SetMenuExitBackButton(menu, true);
AddTargetsToMenu2(menu, client, COMMAND_FILTER_ALIVE);
if(GetMenuItemCount(menu) == 0)
{
AddMenuItem(menu,"refresh","Odswiez",ITEMDRAW_DEFAULT);
AddMenuItem(menu,"no_client","Wszyscy martwi",ITEMDRAW_DISABLED);
}
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
public MenuHandler_Respawn(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_End)
{
CloseHandle(menu);
}
else if (action == MenuAction_Cancel)
{
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
{
DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
}
}
else if (action == MenuAction_Select)
{
decl String:info[32];
new userid, target;
GetMenuItem(menu, param2, info, sizeof(info));
if(!StrEqual(info,"no_client",true) && !StrEqual(info,"refresh",true))
{
userid = StringToInt(info);
if ((target = GetClientOfUserId(userid)) == 0)
{
PrintToChat(param1, "[SM] %t", "Gracz niedostepny");
}
else if (!CanUserTarget(param1, target))
{
PrintToChat(param1, "[SM] %t", "Nie mozna wykonac");
}
else
{
decl String:name[MAX_NAME_LENGTH];
GetClientName(target, name, sizeof(name));
doRespawn(param1, target);
}
/* Re-draw the menu if they're still valid */
if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
{
DisplayRespawnMenu(param1);
}
}
else if(StrEqual(info,"refresh",true) && IsClientInGame(param1) && !IsClientInKickQueue(param1))
{
DisplayRespawnMenu(param1);
}
}
}
public Action:CmdRespawn(client, args) {
if (args < 1)
{
ReplyToCommand(client, "[SM] Uzyj: sm_respawn <nick>");
return Plugin_Handled;
}
decl String:arg[65];
GetCmdArg(1, arg, sizeof(arg));
decl String:target_name[MAX_TARGET_LENGTH];
decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
if ((target_count = ProcessTargetString(
arg,
client,
target_list,
MAXPLAYERS,
COMMAND_FILTER_ALIVE,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
for (new i = 0; i < target_count; i++)
{
doRespawn(client, target_list[i]);
}
//return Plugin_Continue;
return Plugin_Handled; //Fix not show "Unknown command: sm_respawn" on console after respawn dead player
}
public doRespawn(client, target) {
// Fix not respawn spectators, only players in team CT and T
if(GetClientTeam(target) >= 2) {
if(client != target) {
new String:koles[MAX_NAME_LENGTH];
GetClientName(target, koles, sizeof(koles));
ShowActivity2(client, "[SM] ", "przydzielono nowy Spawn dla %s", koles);
LogAction(client, target, "Admin %L przydzielil nowy Spawn dla %L", client, target);
}
CS_RespawnPlayer(target);
}
}
Last edited by GrO; 01-13-2012 at 06:28.
|
|