PDA

View Full Version : I need a little help here


GrO
01-11-2012, 18:29
I took the code from here (http://forums.alliedmods.net/showthread.php?p=1333238#post1333238) (KaOs (http://forums.alliedmods.net/member.php?u=673) and Bacardi (http://forums.alliedmods.net/member.php?u=67162)) 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:

#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);
}
}

TnTSCS
01-11-2012, 22:10
i can help you with this after i get home tomorrow... you dont want/need a menu, right

just want players to be able to type !respawn and be able to respawn themselves for a timed period, correct?

GrO
01-11-2012, 23:57
i can help you with this after i get home tomorrow... you dont want/need a menu, right

just want players to be able to type !respawn and be able to respawn themselves for a timed period, correct?

Exactly and limit it, so they can respawn only once per round, and allow for alive players only (as it is now).

It would be good to print 3 types of chat messages to respawning client:

1) after successful respawn: [SM] You have just ReSpawned Yourself.
2) when used for a second, third... time etc. before time period expires: [SM] You can ReSpawn only once per round.
3) when used after time period expires: [SM] You can ReSpawn during XX seconds after RoundStart only.

And print one chat message to all:

- after successful respawn: [SM] Player {1} ReSpawned himself.

Translation file would be also good, so I could use my language with it's special characters, if it's not a big problem for You.

TnTSCS
01-12-2012, 13:40
That's simple. I'll be home in an hour or so

GrO
01-12-2012, 15:03
That's simple. I'll be home in an hour or so

Good to hear that ;]

TnTSCS
01-12-2012, 16:59
Here you go - let me know if you want anything changed or you find a bug or something you don't want.

...:: TnT Edit ::...
Added a few comments in .sp file

Translation file (english only because that's all I know) attached.

...:: TnT Edit ::...

After a PM from GrO, I realized I misunderstood... I missed the part where this command was to be allowed only for alive players (like if they're stuck together or something).

Get new plugin and new translation file.

GrO
01-12-2012, 17:25
Here you go - let me know if you want anything changed or you find a bug or something you don't want.

...:: TnT Edit ::...
Added a few comments in .sp file

Translation file (english only because that's all I know) attached.

Big thanks for Your job, going to test it.

TnTSCS
01-12-2012, 18:32
Updated my post above this one to reflect what you requested - only alive players can use this plugin... I changed the translation file too

GrO
01-12-2012, 18:37
Now it's perfect, thanks again someone, like You exists at AlliedMods ;]