AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Approved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=8)
-   -   Player-Based CVARs (https://forums.alliedmods.net/showthread.php?t=170201)

nikhilgupta345 10-21-2011 19:24

Player-Based CVARs
 
8 Attachment(s)
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.

dark_style 10-22-2011 00:33

Re: Player-Based CVARs
 
Good job! :)

Korxu 10-22-2011 05:15

Re: Player-Based CVARs
 
Good job ;)

ConnorMcLeod 10-22-2011 05:48

Re: Player-Based CVARs
 
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).

nikhilgupta345 10-22-2011 09:34

Re: Player-Based CVARs
 
Quote:

Originally Posted by ConnorMcLeod (Post 1581022)
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?

DarkGod 10-22-2011 10:35

Re: Player-Based CVARs
 
Aw, first I thought every player would have the CVars set specifically for them. :(

nikhilgupta345 10-22-2011 11:07

Re: Player-Based CVARs
 
Quote:

Originally Posted by DarkGod (Post 1581174)
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 :/

ConnorMcLeod 10-22-2011 11:37

Re: Player-Based CVARs
 
Quote:

Originally Posted by nikhilgupta345 (Post 1581130)
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.

nikhilgupta345 10-22-2011 11:47

Re: Player-Based CVARs
 
Quote:

Originally Posted by ConnorMcLeod (Post 1581200)
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.

ConnorMcLeod 10-22-2011 12:27

Re: Player-Based CVARs
 
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 ;)


All times are GMT -4. The time now is 11:38.

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