Raised This Month: $32 Target: $400
 8% 

[CS:S HELP] thirdperson


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Branddddd
New Member
Join Date: Jan 2023
Old 01-18-2023 , 08:05   [CS:S HELP] thirdperson
Reply With Quote #1

Hi,

I've been trying to enable thirdperson mode for players in our server. I've tried scripting it:

SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", 0);
SetEntProp(client, Prop_Send, "m_iObserverMode", 1);
SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 0);
SetEntProp(client, Prop_Send, "m_iFOV", 120);

This works, but it messes up camera movements. Basically it will go to thirdperson camera view, but the mouse doesn't move the camera anymore, only the player model moves.

I've also tried to allow players to use the 'cheat' command "thirdperson" in console, but it doesn't work either. I do not want to enable sv_cheats 1.

Any help would be appreciated!

Last edited by Branddddd; 01-18-2023 at 08:08.
Branddddd is offline
Johnoclock
Member
Join Date: Oct 2014
Location: denmark
Old 01-18-2023 , 21:33   Re: [CS:S HELP] thirdperson
Reply With Quote #2

something like this. it not tested

Code:
// List of Includes
#include <sourcemod>
#include <sdktools>

// The code formatting rules we wish to follow
#pragma semicolon 1
#pragma newdecls required

// Global Handles
bool Third[MAXPLAYERS+1];

public void OnPluginStart()
{
RegAdminCmd("sm_tp", Command_TP, ADMFLAG_GENERIC);
}

public Action Command_TP(int client, int args)
{
	Toggle(client);
}

public void OnClientPutInServer(int client)
{
	Third[client] = false;
}

void Toggle(int client)
{
	if(!Third[client])
	{
		SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", 0);
		SetEntProp(client, Prop_Send, "m_iObserverMode", 1);
		SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 0);
		SetEntProp(client, Prop_Send, "m_iFOV", 120);
		Third[client] = true;
	}
	
	else
	{
		SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", client);
		SetEntProp(client, Prop_Send, "m_iObserverMode", 0);
		SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 1);
		SetEntProp(client, Prop_Send, "m_iFOV", 90);
		Third[client] = false;
	}
}
__________________
Steam: johnoclock | Discord: Johnoclock#0730
Johnoclock is offline
Branddddd
New Member
Join Date: Jan 2023
Old 01-19-2023 , 04:03   Re: [CS:S HELP] thirdperson
Reply With Quote #3

Quote:
Originally Posted by Johnoclock View Post
something like this. it not tested

Code:
// List of Includes
#include <sourcemod>
#include <sdktools>

// The code formatting rules we wish to follow
#pragma semicolon 1
#pragma newdecls required

// Global Handles
bool Third[MAXPLAYERS+1];

public void OnPluginStart()
{
RegAdminCmd("sm_tp", Command_TP, ADMFLAG_GENERIC);
}

public Action Command_TP(int client, int args)
{
	Toggle(client);
}

public void OnClientPutInServer(int client)
{
	Third[client] = false;
}

void Toggle(int client)
{
	if(!Third[client])
	{
		SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", 0);
		SetEntProp(client, Prop_Send, "m_iObserverMode", 1);
		SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 0);
		SetEntProp(client, Prop_Send, "m_iFOV", 120);
		Third[client] = true;
	}
	
	else
	{
		SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", client);
		SetEntProp(client, Prop_Send, "m_iObserverMode", 0);
		SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 1);
		SetEntProp(client, Prop_Send, "m_iFOV", 90);
		Third[client] = false;
	}
}
This is almost the same code as I posted above (except you used 'client'). I've tried your code but it's still the same problem, it gives me thirdperson but the camera doesn't move when aiming with mouse, just the player model moves.
Branddddd is offline
oqyh
Senior Member
Join Date: May 2019
Location: United Arab Emirates
Old 01-19-2023 , 19:42   Re: [CS:S HELP] thirdperson
Reply With Quote #4

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <clientprefs>

#pragma semicolon 1
#pragma newdecls required

int playerfov 90;
Handle m_tpa INVALID_HANDLE;

public 
void OnPluginStart() 
{
    
HookEvent("player_spawn"Event_PlayerSpawn);
    
RegConsoleCmd("sm_fov"FovMenu);
}

public 
Action FovMenu(int clientint args
{
    
iFovMenu(client);
    return 
Plugin_Continue;
}

void iFovMenu(int client)
{
    
Menu menu = new Menu(m_fov);
    
menu.SetTitle("Fov");
    
menu.AddItem("increase""+10");
    
menu.AddItem("decrease""-10");
    
menu.Display(clientMENU_TIME_FOREVER);
}

public 
int m_fov(Menu menuMenuAction actionint clientint option)
{
    if (
action == MenuAction_Select)
    {
        
char buffer[30];
        
menu.GetItem(optionbuffersizeof(buffer));
        if(
StrEqual(buffer"increase"))
        {
            
playerfov+=30;
            
SetClientFOV(client);
        }
        else if(
StrEqual(buffer"decrease"))
        {
            
playerfov-=30;
            
SetClientFOV(client);
        }
        
iFovMenu(client);
    }
    return 
0;
}

void SetClientFOV(int iClient)
{
    
SetEntProp(iClientProp_Send"m_iFOV"playerfov);
    
SetEntProp(iClientProp_Send"m_iDefaultFOV"playerfov);
}

public 
void Event_PlayerSpawn(Event hEvent, const char[] weaponNamebool bDontBroadcast)
{
    
int iClient GetClientOfUserId(hEvent.GetInt("userid"));
    
    if(
m_tpa == INVALID_HANDLE)
    {
        
m_tpa FindConVar("sv_allow_thirdperson");
    }
    
    if(
iClient && IsPlayerAlive(iClient))
    {
        
SetConVarInt(m_tpa1);
        
ClientCommand(iClient"thirdperson");
        
SetEntProp(iClientProp_Send"m_iFOV"120);
        
SetEntProp(iClientProp_Send"m_iDefaultFOV"120);
    }


!fov = change fov
__________________
.:[ >> My Plugins << ]:.

My discord : oqyh

Last edited by oqyh; 01-19-2023 at 20:13.
oqyh is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 01-20-2023 , 06:14   Re: [CS:S HELP] thirdperson
Reply With Quote #5

oqyh, your code leads to a memory leak: the menu handle either needs to be created once when the plugin starts, or the handle must be closed when the menu is closed.

It's better to do something like this:
PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sdktools>

Handle
    m_tpa
;
Menu
    hMenu
;
int
    iFOV
[MAXPLAYERS+1] = {90, ...};

public 
void OnPluginStart() 
{
    
m_tpa FindConVar("sv_allow_thirdperson");

    
HookEvent("player_spawn"Event_PlayerSpawn);

    
RegConsoleCmd("sm_fov"Cmd_FovMenu);

    
hMenu = new Menu(Menu_FOVMenuAction_Display);
    
hMenu.SetTitle("Set FOV (90°):");
    
hMenu.AddItem("""Current\n ");
    
hMenu.AddItem("""+30°");
    
hMenu.AddItem("""-30°\n ");
    
hMenu.AddItem("""Reset to 90°");
}

public 
void OnClientDisconnect(int client)
{
    
iFOV[client] = 90;
}

public 
void Event_PlayerSpawn(Event hEvent, const char[] weaponNamebool bDontBroadcast)
{
    
int client GetClientOfUserId(hEvent.GetInt("userid"));
    if(
client && IsClientInGame(client) && IsPlayerAlive(client))
    {
        if(
m_tpaSetConVarInt(m_tpa1);
        
ClientCommand(client"thirdperson");
        
SetClientFOV(client120);
    }
}

public 
Action Cmd_FovMenu(int clientint args)
{
    
hMenu.Display(clientMENU_TIME_FOREVER);
    return 
Plugin_Continue;
}

public 
int Menu_FOV(Menu menuMenuAction actionint clientint option)
{
    if(
action == MenuAction_Display)
        
hMenu.SetTitle("Set FOV (%i°):"iFOV[client]);
    else if(
action == MenuAction_Select)
    {
        switch(
option)
        {
            case 
1iFOV[client] += 30;
            case 
2iFOV[client] -= 30;
            case 
3iFOV[client]  = 90;
        }
        
SetClientFOV(clientiFOV[client]);

        
hMenu.Display(clientMENU_TIME_FOREVER);
    }
    return 
0;
}

void SetClientFOV(int clientint fov)
{
    
SetEntProp(clientProp_Send"m_iFOV"fov);
    
SetEntProp(clientProp_Send"m_iDefaultFOV"fov);

__________________

Last edited by Grey83; 01-20-2023 at 06:15.
Grey83 is offline
Branddddd
New Member
Join Date: Jan 2023
Old 01-22-2023 , 07:11   Re: [CS:S HELP] thirdperson
Reply With Quote #6

Quote:
Originally Posted by Grey83 View Post
oqyh, your code leads to a memory leak: the menu handle either needs to be created once when the plugin starts, or the handle must be closed when the menu is closed.

It's better to do something like this:
PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sdktools>

Handle
    m_tpa
;
Menu
    hMenu
;
int
    iFOV
[MAXPLAYERS+1] = {90, ...};

public 
void OnPluginStart() 
{
    
m_tpa FindConVar("sv_allow_thirdperson");

    
HookEvent("player_spawn"Event_PlayerSpawn);

    
RegConsoleCmd("sm_fov"Cmd_FovMenu);

    
hMenu = new Menu(Menu_FOVMenuAction_Display);
    
hMenu.SetTitle("Set FOV (90°):");
    
hMenu.AddItem("""Current\n ");
    
hMenu.AddItem("""+30°");
    
hMenu.AddItem("""-30°\n ");
    
hMenu.AddItem("""Reset to 90°");
}

public 
void OnClientDisconnect(int client)
{
    
iFOV[client] = 90;
}

public 
void Event_PlayerSpawn(Event hEvent, const char[] weaponNamebool bDontBroadcast)
{
    
int client GetClientOfUserId(hEvent.GetInt("userid"));
    if(
client && IsClientInGame(client) && IsPlayerAlive(client))
    {
        if(
m_tpaSetConVarInt(m_tpa1);
        
ClientCommand(client"thirdperson");
        
SetClientFOV(client120);
    }
}

public 
Action Cmd_FovMenu(int clientint args)
{
    
hMenu.Display(clientMENU_TIME_FOREVER);
    return 
Plugin_Continue;
}

public 
int Menu_FOV(Menu menuMenuAction actionint clientint option)
{
    if(
action == MenuAction_Display)
        
hMenu.SetTitle("Set FOV (%i°):"iFOV[client]);
    else if(
action == MenuAction_Select)
    {
        switch(
option)
        {
            case 
1iFOV[client] += 30;
            case 
2iFOV[client] -= 30;
            case 
3iFOV[client]  = 90;
        }
        
SetClientFOV(clientiFOV[client]);

        
hMenu.Display(clientMENU_TIME_FOREVER);
    }
    return 
0;
}

void SetClientFOV(int clientint fov)
{
    
SetEntProp(clientProp_Send"m_iFOV"fov);
    
SetEntProp(clientProp_Send"m_iDefaultFOV"fov);

I appreciate the replies but sv_allow_thirdperson doesn't exist in Counter-Strike:Source, otherwise I would have utililized this already..

Last edited by Branddddd; 01-22-2023 at 07:12.
Branddddd is offline
Branddddd
New Member
Join Date: Jan 2023
Old 01-28-2023 , 09:23   Re: [CS:S HELP] thirdperson
Reply With Quote #7

Any bright soul that got a solution for this? Sorry for bumping but it has been almost a week :p
Branddddd is offline
Alienmario
Senior Member
Join Date: Aug 2013
Old 01-28-2023 , 13:52   Re: [CS:S HELP] thirdperson
Reply With Quote #8

You may have to settle with enabling client-side cheats. This means players will be able to use some rendering overrides and potentially see through things, but not change anything on the server. The original thirdperson by Dr. McKay used this method.
Alienmario is offline
Knock Knock
New Member
Join Date: Feb 2022
Old 04-21-2023 , 04:44   Re: [CS:S HELP] thirdperson
Reply With Quote #9

You probably need to run the "mp_forcecamera" "0" for the server, along with “SendConVarValue(client,mp_forcecamera, "0")”.
This will allow your model to be fixed, looking fwd.
.
If you want to move the model from its default position, try playing around with "m_vecViewOffset".
.
I managed to get it going on here :-
steam://connect/109.123.108.128:20015
(say tp , to toggle )
Whilst it is a really just a 'fun' mode, as it can still be a bit quirky.
.
.
include this in your plugin :-
-------------------------------------------------------------------
new Handle:mp_forcecamera;
new Float:Ori[3];
//
public OnPluginStart()
{
mp_forcecamera = FindConVar("mp_forcecamera");
if(!mp_forcecamera){SetFailState("Failed to locate mp_forcecamera");}
ServerCommand("mp_forcecamera","0");
}


public Put_PlayerInThirdperson(client)
{
SendConVarValue(client,mp_forcecamera, "0");
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", client);
SetEntProp(client, Prop_Send, "m_iObserverMode", 1);
SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 0); // This can be 0 or 1 - I cant tell the difference TBH.
Client_SetFOV(client, 96);
GetEntPropVector(client, Prop_Data, "m_vecViewOffset", Ori); // Get View offset of player
Ori[0] += 10.0;
Ori[1] += 15.0;
SetEntPropVector(client, Prop_Data, "m_vecViewOffset", Ori); // Set View offset of player
PrintToChat(client, "Thirdperson Enabled"); // Inform Client
Third[client] = true;
return;
}

public Put_PlayerInFirstPerson(client)
{
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", client);
SetEntProp(client, Prop_Send, "m_iObserverMode", 0);
SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 1);
Client_SetFOV(client, 96);
PrintToChat(client, "Firstperson Enabled"); // Inform Client
Third[client] = false;
return;
}
.

Last edited by Knock Knock; 04-21-2023 at 04:51.
Knock Knock 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 15:23.


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