Raised This Month: $66 Target: $400
 16% 

Player-Based CVARs


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Admin Commands        Approver:   Arkshine (91)
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-21-2011 , 20:24   Player-Based CVARs
Reply With Quote #1

Player-Based CVARs

By: nikhilgupta345

Description:
This plugin allows you to execute certain commands or set certain cvars when there are a certain number of players on the server. The commands are sent to the server console as soon as a player connects.

Admin Commands:
    • amx_addautocommand <players> <command> - Adds a command to be executed when there are "players" amount of players on the server.
    • amx_addautocvar <players> <cvar_name> <cvar_value> - Adds a cvar to be changed when there are "players" amount of players on the server.

Installation:
    • Click 'Get Plugin' link below
    • Place 'player_amount_cvars.amxx' in addons/amxmodx/plugins/ folder
    • Open addons/amxmodx/configs/plugins.ini
    • Add the line 'player_amount_cvars.amxx' at the bottom
    • Either create 'player_cvars.ini' on your own in the configs folder
    • Set it up to your liking.
    • Restart server or change map


Example 'player_cvars.ini':
    • An example player_cvars.ini may look like this:
      Code:
      [1]
      mp_freezetime 2
      mp_startmoney 8000
      sv_gravity 200
      
      [3]
      mp_freezetime 1
      mp_startmoney 1000
      sv_gravity 800
    • In brackets '[]', include how many players you want in the server when the commands below it execute.


Changelog:

  • Code:
    October 21, 2011
    • -v1.0-
      • Initial Release
    October 22, 2011
    • -v1.0.1-
      • Changed way of detecting player connect/disconnect
    • -v1.1-
      • Changed way of setting up file
      • Added admin commands
    July 07, 2012
    • -v1.1.1-
      • Removed one of the connect methods and used one method for both hooks.
      • Other small optimizations

Notes:
    • Some commands/cvars, such as mp_startmoney, will not take effect on the connecting player. For those commands, you should have it set for the player before, so it will work for the player you want it to. For example, if you want startmoney to be 10000 when there are 5 people, have "mp_startmoney 10000" under '4' in the config file.

Suggestions/Comments/Feedback are welcome.
Attached Files
File Type: txt player_cvars.txt (291 Bytes, 351 views)
File Type: sma Get Plugin or Get Source (player_amount_cvars.sma - 768 views - 8.6 KB)
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 07-07-2012 at 01:28.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
dark_style
Senior Member
Join Date: Jul 2009
Location: Bulgaria
Old 10-22-2011 , 01:33   Re: Player-Based CVARs
Reply With Quote #2

Good job!
dark_style is offline
Korxu
Senior Member
Join Date: Sep 2010
Old 10-22-2011 , 06:15   Re: Player-Based CVARs
Reply With Quote #3

Good job ;)
Korxu is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-22-2011 , 06:48   Re: Player-Based CVARs
Reply With Quote #4

I'm pretty sure you gonna have false numbers with that global var and connect/disconnect.
If so, use get_playersnum and client_putinserver and client_disconnect (not that in client_disconnect, the disconnected client is still counted).
__________________
- tired and retired -
ConnorMcLeod is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-22-2011 , 10:34   Re: Player-Based CVARs
Reply With Quote #5

Quote:
Originally Posted by ConnorMcLeod View Post
I'm pretty sure you gonna have false numbers with that global var and connect/disconnect.
If so, use get_playersnum and client_putinserver and client_disconnect (not that in client_disconnect, the disconnected client is still counted).
So you suggest using get_playersnum() and then subtracting 1 in disconnect?
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
DarkGod
SourceMod DarkCrab
Join Date: Jul 2007
Location: Sweden
Old 10-22-2011 , 11:35   Re: Player-Based CVARs
Reply With Quote #6

Aw, first I thought every player would have the CVars set specifically for them.
__________________
DarkGod is offline
Send a message via AIM to DarkGod Send a message via MSN to DarkGod
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-22-2011 , 12:07   Re: Player-Based CVARs
Reply With Quote #7

Quote:
Originally Posted by DarkGod View Post
Aw, first I thought every player would have the CVars set specifically for them.
That would be pretty sweet. Idk how to do that though :/
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-22-2011 , 12:37   Re: Player-Based CVARs
Reply With Quote #8

Quote:
Originally Posted by nikhilgupta345 View Post
So you suggest using get_playersnum() and then subtracting 1 in disconnect?
Main idea is to use client_putinserver instead of client_connect, i think client_connect can be triggered 2 times if players connects and is redirected to downloadurl and then client_disconnect wouldn't be triggered.
May be it is not the situation, but i've read that client_connect could be triggered few times without client_disconnect between different calls.

And the other idea is to not trust a global var but to check each time players value, global var wouldn't be a significant improvement anyway.
__________________
- tired and retired -
ConnorMcLeod is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-22-2011 , 12:47   Re: Player-Based CVARs
Reply With Quote #9

Quote:
Originally Posted by ConnorMcLeod View Post
Main idea is to use client_putinserver instead of client_connect, i think client_connect can be triggered 2 times if players connects and is redirected to downloadurl and then client_disconnect wouldn't be triggered.
May be it is not the situation, but i've read that client_connect could be triggered few times without client_disconnect between different calls.

And the other idea is to not trust a global var but to check each time players value, global var wouldn't be a significant improvement anyway.
It might be true that using client_connect could send false results if it is called more than once. However, I think I remember seeing that when I tried it at client_putinserver at first, and had the server execute mp_startmoney 1000, it would still set my startmoney to the previous start amount, because your starting money is loaded on client_putinserver, so you aren't affected by the server command. Only the next person to join the server is affected by it. And I'm sure that server owners wouldn't want to have the plugin run sv_restart on the server in order to restart everybody's start money every time somebody joins.

With that being said, would you suggest client_connect with get_playersnum() passed with 1 as a parameter so that it counts connecting players as well? I think that may work better.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-22-2011 , 13:27   Re: Player-Based CVARs
Reply With Quote #10

Seems that you are right (tested on dedicated server) :

Code:
L 10/22/2011 - 18:22:05: ClientPutInServer(1), startmoney set to 2000
L 10/22/2011 - 18:22:05: client_putinserver(1), startmoney set to 3000
L 10/22/2011 - 18:22:05: Event_Money(1), Money : 2000
Code:
#include <amxmodx> #include <fakemeta> new mp_startmoney public plugin_init() {     register_plugin("CheckStartMoney", "TEST", "ConnorMcLeod")     register_forward(FM_ClientPutInServer, "ClientPutInServer")     mp_startmoney = get_cvar_pointer("mp_startmoney")     set_pcvar_num(mp_startmoney, 1337)     register_event("Money", "Event_Money", "b") } public Event_Money( id ) {     log_to_file("StartMoney.log", "Event_Money(%d), Money : %d", id, read_data(1)) } public ClientPutInServer(id) {     set_pcvar_num(mp_startmoney, 2000)     log_to_file("StartMoney.log", "ClientPutInServer(%d), startmoney set to 2000", id) } public client_putinserver(id) {     set_pcvar_num(mp_startmoney, 3000)     log_to_file("StartMoney.log", "client_putinserver(%d), startmoney set to 3000", id) }

May be you don't want to include fakemeta to use FM_ClientPutInServer, but if you use get_playersnum at client_connect, i don't know if the client is counted, and if that client disconnect while downloading on a fasturl without disconnect being sent i doubt that server owners would be glad with bad settings as well.
I don't have time right now to investigate more on it, and anyway it's up to you to find the right way ;)
__________________
- tired and retired -

Last edited by ConnorMcLeod; 10-22-2011 at 13:28.
ConnorMcLeod is offline
Reply


Thread Tools
Display Modes

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 23:14.


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