Raised This Month: $ Target: $400
 0% 

Force a player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kriax
Senior Member
Join Date: Apr 2012
Old 05-19-2012 , 11:11   Force a player
Reply With Quote #1

Hello,

I am currently enjoying my new plugin coding.
Being only one Apprentice I still have some trouble focusing.
I am looking how I can force a player to control: cl_crossairalpha 0
I wish that when he joined, the viewfinder are off.

I am Belgian and I use a translator to write this post.

Thank you.

Kriax.
Kriax is offline
ZzZombo
Member
Join Date: May 2012
Location: Ravenholm
Old 05-19-2012 , 11:53   Re: Force a player
Reply With Quote #2

You can user
PHP Code:
ClientCommand() 
to change the variable.
ZzZombo is offline
Kriax
Senior Member
Join Date: Apr 2012
Old 05-19-2012 , 11:55   Re: Force a player
Reply With Quote #3

Code:
ClientCommand(client, "cl_crosshairalpha 0");
If I put it in ONPLAYERSPAWN her go?

Last edited by Kriax; 05-19-2012 at 11:56.
Kriax is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 05-19-2012 , 12:44   Re: Force a player
Reply With Quote #4

Quote:
Originally Posted by Kriax View Post
Hello,

I am currently enjoying my new plugin coding.
Being only one Apprentice I still have some trouble focusing.
I am looking how I can force a player to control: cl_crossairalpha 0
I wish that when he joined, the viewfinder are off.

I am Belgian and I use a translator to write this post.

Thank you.

Kriax.
Hello Kriax,

thankfully the server can't change client cvars.
What you can do is to get the value of the client's cvar with QueryClientConVar() periodically asynchronously and kick the client if he didn't change the cvar.

Quote:
Originally Posted by ZzZombo View Post
You can user
PHP Code:
ClientCommand() 
to change the variable.
Can you ? or is it just a wild guess ?
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 05-19-2012 , 12:56   Re: Force a player
Reply With Quote #5

Quote:
Originally Posted by berni View Post
Can you ? or is it just a wild guess ?
I highly doubt ClientCommand can change a client cvar.
__________________
Dr. McKay is offline
Kriax
Senior Member
Join Date: Apr 2012
Old 05-19-2012 , 15:24   Re: Force a player
Reply With Quote #6

Aye an other commande ?

Kriax.
Kriax is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 05-19-2012 , 16:13   Re: Force a player
Reply With Quote #7

try

PHP Code:
#define HIDEHUD_CROSSHAIR 256
...
new 
hud GetEntProp(clientProp_Send"m_iHideHUD");
hud |= HIDEHUD_CROSSHAIR;
SetEntProp(clientProp_Send"m_iHideHUD"hud); 
blodia is offline
Kriax
Senior Member
Join Date: Apr 2012
Old 05-19-2012 , 17:00   Re: Force a player
Reply With Quote #8

Code:
public OnPluginStart()
{
      HookEvent("player_spawn", Event_player_spawn)
}
 
public Action:Event_player_spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
 client = GetClientOfUserId(GetEventInt(event, "userid"))
QueryClientConVar(client, "cl_crossairalpha 0", ConVarQueryFinished:ClientConVar, client)
 
 return Plugin_Continue
 }
 
 public ClientConVar(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
 {
       GetClientName(client, name, 64)
       PrintToServer("%s CVar %s = %s", name, cvarName, cvarValue)
 }


Is it fair if I put this?
Kriax is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 05-19-2012 , 17:26   Re: Force a player
Reply With Quote #9

I would try what blodia said.
And it's most likey named "cl_crosshairalpha", not "cl_crossairalpha":
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 05-19-2012 at 17:27.
berni is offline
TrueSurvivor
Member
Join Date: Jun 2010
Old 05-19-2012 , 17:44   Re: Force a player
Reply With Quote #10

ClientCommand doesn't work for this, FakeClientCommand does.

PHP Code:
//Fix if user changes the value back.
new Handle:g_hCheck

public OnPluginStart()
{
    
HookEvent("player_spawn"Spawn)

    
//Link Cvar
    
g_hCheck FindConVar("cl_crosshair_alpha");

    if (
g_hCheck != INVALID_HANDLE)
    {
        
HookConVarChange(g_hCheckOnValueChange);
    }
}

public 
Action:Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    
//Get Spawned Player's Info.
    
client GetClientOfUserId(GetEventInt(event"userid"))

    
//Make the player send the command.
    
ClientCommand(client"cl_crosshair_alpha 0");
}

public 
OnValueChange(Handle:cvar, const String:oldVal[], const String:newVal[])
{
    
//If Value is higher than 0, switch it to 0.
    
if (StringToInt(newVal) > 0)
    {
        
SetConVarInt(cvar0);
    }

Keep in mind that with what you're requesting you will make everyone's crosshair dissapear, on any team.
Spectator included.

Last edited by TrueSurvivor; 05-20-2012 at 06:28.
TrueSurvivor 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 09:59.


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