Raised This Month: $ Target: $400
 0% 

Set cvar when player connects and change when disconnects


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GiOVi
Junior Member
Join Date: Feb 2013
Old 05-02-2014 , 06:28   Set cvar when player connects and change when disconnects
Reply With Quote #1

Hello.
I'm trying to do a plugin that when a user with X STEAMID joins to the server, the server set a cvar with Y value, and when this user disconnects, set Z value.

I have this but I don't know how to continue, I'm new in this.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#define PLUGIN "XXXX"
#define VERSION "XXX"
#define AUTHOR "XXXXXX"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
}

public 
client_connect(id)
{
    new 
steamid[32]
    
get_user_authididsteamidcharsmax(steamid))
    
    if(
steamid == "STEAM_x:x:xxxxxxxx")
    {
        
server_cmd("amx_cvarname Y");
        return 
PLUGIN_CONTINUE;
    }

    if(
client_disconnect[steamid])
    {
        
server_cmd("amx_cvarname Z");
        return 
PLUGIN_CONTINUE;
    }

    return 
PLUGIN_HANDLED;

Thanks!
GiOVi is offline
swapped
BANNED
Join Date: Mar 2014
Location: OrpheuRegisterHook
Old 05-02-2014 , 06:48   Re: Set cvar when player connects and change when disconnects
Reply With Quote #2

use "set_cvar_num" for cvar set
use "equal" in condition for check player steam id

you dont need this :
PHP Code:
#include <amxmisc>
#include <fakemeta> 
you dont need this ..

PHP Code:
   if(client_disconnect[steamid])
    {
        
server_cmd("amx_cvarname Z");
        return 
PLUGIN_CONTINUE;
    } 
Note: set_cvar_num is used only for set numbers [ without QUOTES ]
Note2: new steamid[33] here should be new steamid[35]


Your source should look like this : ( untested )

PHP Code:
#include <amxmodx>


#define PLUGIN "Connect/ Disconnect Checker"
#define VERSION "1.0"
#define AUTHOR "GiOVi"

#define THE_STEAM "STEAM_x:x:xxxxxxxx"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR);
}

public 
client_connect(id)
{
    new 
steamid[35]
    
get_user_authididsteamidcharsmax(steamid) - 1)
    
    if(
equal(steamidTHE_STEAM))
    {
        
// "direclty_cvar_name" are the cvar name ( without amx_cvar .. ),    10 are the Value of the Cvar you wanna set
        
set_cvar_num("directly_cvar_name"10);
    }
}  

public 
client_disconnect(id)
{
    new 
steamid[35]
    
get_user_authididsteamidcharsmax(steamid) - 1)
    
    if(
equal(steamidTHE_STEAM))
    {
        
// "direclty_cvar_name" are the cvar name ( without amx_cvar .. ),    10 are the Value of the Cvar you wanna set
        
set_cvar_num("directly_cvar_name"10);
    }


Last edited by swapped; 05-02-2014 at 06:50.
swapped is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-02-2014 , 07:50   Re: Set cvar when player connects and change when disconnects
Reply With Quote #3

Quote:
Originally Posted by swapped View Post
big stuff that doesn't need to be quoted
how would you go with changing string cvars? for example hostname
aron9forever is offline
swapped
BANNED
Join Date: Mar 2014
Location: OrpheuRegisterHook
Old 05-02-2014 , 08:23   Re: Set cvar when player connects and change when disconnects
Reply With Quote #4

Usage:
PHP Code:
set_cvar_string"amx_hostname""CS. Server Name .Ro" ); 
i dont know shourt if the cvar-name is amx_hostname, i think is hostname, anywhey i gave the example.

Last edited by swapped; 05-02-2014 at 08:23.
swapped is offline
GiOVi
Junior Member
Join Date: Feb 2013
Old 05-02-2014 , 09:08   Re: Set cvar when player connects and change when disconnects
Reply With Quote #5

Thank you so much for your help!! Works excellent!
GiOVi is offline
swapped
BANNED
Join Date: Mar 2014
Location: OrpheuRegisterHook
Old 05-02-2014 , 09:29   Re: Set cvar when player connects and change when disconnects
Reply With Quote #6

Quote:
Originally Posted by GiOVi View Post
Thank you so much for your help!! Works excellent!
You are welcome
swapped is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-02-2014 , 09:59   Re: Set cvar when player connects and change when disconnects
Reply With Quote #7

When working with string, you need to use charsmax() alone. It is defined as sizeof()-1.
__________________
fysiks is offline
Old 05-02-2014, 10:15
swapped
This message has been deleted by swapped. Reason: lol
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-02-2014 , 11:20   Re: Set cvar when player connects and change when disconnects
Reply With Quote #8

Quote:
Originally Posted by swapped View Post
Usage:
PHP Code:
set_cvar_string"amx_hostname""CS. Server Name .Ro" ); 
i dont know shourt if the cvar-name is amx_hostname, i think is hostname, anywhey i gave the example.
yeah that's hostname not amx_hostname, thanks

aren't you supposed to use cvar pointers or something? I kept hearing people talk about it but goddamn I can't understand
aron9forever is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-03-2014 , 01:19   Re: Set cvar when player connects and change when disconnects
Reply With Quote #9

Quote:
Originally Posted by aron9forever View Post
aren't you supposed to use cvar pointers or something? I kept hearing people talk about it but goddamn I can't understand
pcvar (which use cvar pointers) are more efficient but they are not required for a plugin to work. They are, however, required for any plugin that is going to be submitted as a plugin submission.
__________________
fysiks is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-03-2014 , 07:10   Re: Set cvar when player connects and change when disconnects
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
pcvar (which use cvar pointers) are more efficient but they are not required for a plugin to work. They are, however, required for any plugin that is going to be submitted as a plugin submission.
so I searched and found this

Quote:
Originally Posted by drekes View Post
pcvars work like this.

PHP Code:
#include <amxmodx>

new cvar_on // Make a global var to store your cvar

public plugin_init()
{
    
cvar_on register_cvar("amx_stuff""1"); // Register your cvar and store it in cvar_on
    // Do your other stuff
}

public 
client_connect(id)
{
    if(
get_pcvar_num(cvar_on)) // If your cvar is on
    
{
        
// do stuff
    
}


how would I use this to change the hostname for example, all I can understand from there is that this is what you need to do to create your own cvar
aron9forever 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 12:52.


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