Raised This Month: $51 Target: $400
 12% 

I need a little help here


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GrO
Veteran Member
Join Date: Jun 2010
Location: Poland
Old 01-11-2012 , 18:29   I need a little help here
Reply With Quote #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.
GrO is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 01-11-2012 , 22:10   Re: I need a little help here
Reply With Quote #2

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?
TnTSCS is offline
GrO
Veteran Member
Join Date: Jun 2010
Location: Poland
Old 01-11-2012 , 23:57   Re: I need a little help here
Reply With Quote #3

Quote:
Originally Posted by TnTSCS View Post
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.

Last edited by GrO; 01-12-2012 at 03:29.
GrO is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 01-12-2012 , 13:40   Re: I need a little help here
Reply With Quote #4

That's simple. I'll be home in an hour or so
TnTSCS is offline
GrO
Veteran Member
Join Date: Jun 2010
Location: Poland
Old 01-12-2012 , 15:03   Re: I need a little help here
Reply With Quote #5

Quote:
Originally Posted by TnTSCS View Post
That's simple. I'll be home in an hour or so
Good to hear that ;]
GrO is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 01-12-2012 , 16:59   Re: I need a little help here
Reply With Quote #6

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.
Attached Files
File Type: sp Get Plugin or Get Source (non_admin_respawn.sp - 252 views - 7.1 KB)
File Type: txt non_admin_respawn.phrases.txt (700 Bytes, 120 views)
__________________
View my Plugins | Donate

Last edited by TnTSCS; 01-12-2012 at 18:32.
TnTSCS is offline
GrO
Veteran Member
Join Date: Jun 2010
Location: Poland
Old 01-12-2012 , 17:25   Re: I need a little help here
Reply With Quote #7

Quote:
Originally Posted by TnTSCS View Post
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.
GrO is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 01-12-2012 , 18:32   Re: I need a little help here
Reply With Quote #8

Updated my post above this one to reflect what you requested - only alive players can use this plugin... I changed the translation file too
__________________
View my Plugins | Donate

Last edited by TnTSCS; 01-12-2012 at 18:33.
TnTSCS is offline
GrO
Veteran Member
Join Date: Jun 2010
Location: Poland
Old 01-12-2012 , 18:37   Re: I need a little help here
Reply With Quote #9

Now it's perfect, thanks again someone, like You exists at AlliedMods ;]
GrO is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:48.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode