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

[L4D1] How to set 1-st person view from the plugin?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 04-26-2018 , 13:40   [L4D1] How to set 1-st person view from the plugin?
Reply With Quote #1

Hi,

please, see comments at the end of code:

Code:
#define PLUGIN_VERSION "1.0"

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>

public Plugin myinfo =
{
	name = "Block3person",
	author = "Dragokas",
	description = "Forbid players to use 3-rd person view",
	version = PLUGIN_VERSION,
	url = "https://github.com/dragokas"
}

Handle g_hCvar3PersonView;

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
	char sGameName[12];
	GetGameFolderName(sGameName, sizeof(sGameName));
	if( strcmp(sGameName, "left4dead", false) )
	{
		strcopy(error, err_max, "Plugin only supports Left 4 Dead 1.");
		return APLRes_SilentFailure;
	}
	return APLRes_Success;
}

public void OnPluginStart()
{
	g_hCvar3PersonView = CreateConVar("c_thirdpersonshoulder", "0", "3-rd person view mode", FCVAR_REPLICATED);

	CreateTimer(1.1, Timer_CheckClientViewState, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

public Action Timer_CheckClientViewState(Handle timer)
{
	for (int i = 1; i <= MaxClients; i++)
	{
		if(IsClientInGame(i) && GetClientTeam(i) == 2 && !IsFakeClient(i) && IsPlayerAlive(i))
			QueryClientConVar(i, "c_thirdpersonshoulder", QueryClientConVarCallback);
	}
	return Plugin_Continue;
}

public void QueryClientConVarCallback(QueryCookie cookie, int client, ConVarQueryResult result, const char[] sCvarName, const char[] bCvarValue)
{
	if (StringToInt(bCvarValue) != 0)
		CreateTimer(0.2, Timer_ChangePersonView, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
}

public Action Timer_ChangePersonView(Handle timer, int UserId)
{
	SetFirstPersonView(UserId);
}

void SetFirstPersonView(int UserId)
{
	int client = GetClientOfUserId(UserId);
	
	if (client == 0 || !IsClientInGame(client))
		return;
	
	PrintToChat(client, "changing the state");
	
//  L4d2 only
//	SetEntPropFloat(client, Prop_Send, "m_TimeForceExternalView", 0.0);

//  Server say: can't change because not marked as FCVAR_REPLICATED on client side
//	SendConVarValue(client, g_hCvar3PersonView, "0"); 

//  Also not working
//	FakeClientCommand(client, "thirdpersonshoulder");
}
Thanks.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 04-26-2018 , 17:01   Re: [L4D1] How to set 1-st person view from the plugin?
Reply With Quote #2

Aren't firstperson and thirdpersonshoulder client-side commands? If so, you can't force them on clients.

I don't know if AddCommandListener() would work for detecting the use of thirdpersonshoulder though.
__________________
Psyk0tik is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 04-26-2018 , 17:18   Re: [L4D1] How to set 1-st person view from the plugin?
Reply With Quote #3

About: SetEntPropFloat
In L4D2 it is working, but L4D1 has no such property.

Quote:
Originally Posted by Crasher_3637
Aren't firstperson and thirdpersonshoulder client-side commands? If so, you can't force them on clients.
Quote:
Originally Posted by client console
Unknown command: thirdpersonshoulder
It seems you are right.

Quote:
Originally Posted by Crasher_3637
I don't know if AddCommandListener() would work for detecting the use of thirdpersonshoulder though.
Code:
public void OnPluginStart()
{
	AddCommandListener(Listener_3Person, "thirdpersonshoulder");
}

public Action Listener_3Person(int client, const char[] command, int argc)
{
	PrintToChat(client, "thirdpersonshoulder is intercepted.");
	return Plugin_Stop;
}
No, callback is not called. Quite expected, considering that it's client side command.
Any another ideas to block 3-rd person view?
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 04-26-2018 at 17:33.
Dragokas is offline
Alexmy
Senior Member
Join Date: Oct 2014
Location: Russian Federation
Old 04-26-2018 , 18:19   Re: [L4D1] How to set 1-st person view from the plugin?
Reply With Quote #4

PHP Code:
public void OnPluginStart()
{
    
AddCommandListener(BlockCommand"thirdpersonshoulder"); 
}
public 
Action BlockCommand(int clientchar [] commandint args
{
    return 
Plugin_Handled


Last edited by Alexmy; 04-26-2018 at 18:20.
Alexmy is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 04-26-2018 , 19:02   Re: [L4D1] How to set 1-st person view from the plugin?
Reply With Quote #5

you mean Plugin_Handled, not Plugin_Stop ?
I read Plugin_Stop can be used in this doc.

Anyway, callback is not called, so no matter.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 04-27-2018 , 00:38   Re: [L4D1] How to set 1-st person view from the plugin?
Reply With Quote #6

Here you go guys. I tested this and it works.

NOTE: If you're hosting via a listen/local server, the ReplyToCommand() message will display on the console instead of chat because you are counted as client 0. I tried adding a check but it didn't work. I also tried using PrintToChat() but it doesn't work for client 0 either, even with my bIsValidClient() check.

PHP Code:
#include <sourcemod>
#pragma semicolon 1
#pragma newdecls required
#define TPSB_VERSION "1.0"

ConVar cvAllowAdmins;
ConVar cvEnablePlugin;

public 
Plugin myinfo =
{
    
name "Thirdpersonshoulder Blocker",
    
author "Psykotik (Crasher_3637)",
    
description "Blocks thirdpersonshoulder.",
    
version TPSB_VERSION,
    
url "https://forums.alliedmods.net/showthread.php?t=307099"
};

public 
void OnPluginStart()
{
    
cvAllowAdmins CreateConVar("tpsb_allowadmins""1""Allow admins to use thirdpersonshoulder?\n(0: OFF)\n(1: ON)");
    
cvEnablePlugin CreateConVar("tpsb_enableplugin""1""Enable the Thirdpersonshoulder Blocker?\n(0: OFF)\n(1: ON)");
    
CreateConVar("tpsb_pluginversion"TPSB_VERSION"Thirdpersonshoulder Blocker version");
    
AddCommandListener(cmdTPSB"thirdpersonshoulder");
    
AutoExecConfig(true"thirdpersonshoulder_blocker");
}

public 
Action cmdTPSB(int clientchar[] commandint args)
{
    if (
cvEnablePlugin.BoolValue && (!cvAllowAdmins.BoolValue || (cvAllowAdmins.BoolValue && !bIsAdminAllowed(client))))
    {
        
ReplyToCommand(client"[TPSB] The \"thirdpersonshoulder\" command has been blocked on this server.");
        return 
Plugin_Handled;
    }

    return 
Plugin_Changed;
}

bool bIsAdminAllowed(int client)
{
    return (
CheckCommandAccess(client"tpsb_override"false));

Attached Files
File Type: sp Get Plugin or Get Source (thirdpersonshoulder_blocker.sp - 543 views - 1.3 KB)
__________________
Psyk0tik is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 04-27-2018 , 05:37   Re: [L4D1] How to set 1-st person view from the plugin?
Reply With Quote #7

Quote:
Originally Posted by Crasher_3637 View Post
listen/local server
We don't do these unspeakable things here

Thanks for code
__________________
Silvers is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 04-30-2018 , 05:33   Re: [L4D1] How to set 1-st person view from the plugin?
Reply With Quote #8

Hi, Crasher_3637. As I said before AddCommandListener callback is not called for me.
I don't know what environment you tested it.
I have 2 coop servers with SM 1.9.0.6226. Your plugin loaded successfully but not work.

Anyway, thanks for try.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas 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 00:36.


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