AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Event on player count (https://forums.alliedmods.net/showthread.php?t=29143)

L0neW0lf 05-30-2006 16:13

Event on player count
 
Hi i made a plugin that turns alltalk on and off, reacting on how many players on the server.

I made it with a cvar put in amxx.cfg, so users of the plugin can put in the number of users they want to.

In my code it is set to 4, and it works nicely when player number 5 joins, it turns off all talk, but when player 5 disconnects alltalk dont come back on.

Here is my code:
Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "AutoAllTalk" #define VERSION "1.1" #define AUTHOR "Lone Wolf" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_logevent("roundstart", 2, "0=World triggered", "1=Round_Start") } public roundstart() {     set_task(1.0, "set_NewAlltalk") } public client_connect(id) {     set_task(1.0, "set_NewAlltalk") } public client_disconnect(id) {     set_task(1.0, "set_NewAlltalk") } public set_NewAlltalk(taskId) {     new tmpPlayer     new tmpCount     tmpPlayer = get_cvar_num("amx_nrPlayer")     tmpCount = get_playersnum(1)     if (tmpCount==tmpPlayer) {         set_cvar_num("sv_alltalk",1)     }     else if (tmpCount==(tmpPlayer+1)) {         set_cvar_num("sv_alltalk",0)     } }

I also tried using plugin_init() instead of roundstart, but that didnt seem to work either, i removed that because i wasnt sure if plugin_init is run on reload or mapchange......

Hope someone can se the error

/Lone Wolf

SweatyBanana 05-30-2006 16:18

On client disconnect, check how many players there are then if its less than the cvar, turn alltalk to 0.

L0neW0lf 05-30-2006 18:01

If the cvar is 4, it should set alltalk 1, so when a client disconnects and number of players is equal or less than 4 it should set it.....

as far as i can see it is what i have coded.....or have i overlooked something ?


Code:
public set_NewAlltalk(taskId) {     new tmpPlayer     new tmpCount     tmpPlayer = get_cvar_num("amx_nrPlayer")     tmpCount = get_playersnum(1)     if (tmpCount<=tmpPlayer) {         set_cvar_num("sv_alltalk",1)     }     else if (tmpCount>=(tmpPlayer+1)) {         set_cvar_num("sv_alltalk",0)     } }

Or something like that ?

SweatyBanana 05-30-2006 21:31

is amx_nrPlayer a default cvar?

L0neW0lf 05-30-2006 21:49

It is one i put in amxx.cfg, not a default amx cvar.
I figured i dint have to register it, when it is put in....

But maby thats the error?

/Lone Wolf

SweatyBanana 05-30-2006 22:01

Look below at the updated code.

L0neW0lf 05-30-2006 22:08

Ill try :)

But one thing i dont understand, why this:
Code:
tempPlay = register_cvar("amx_how_many", "4")

And by doing that, can a user change the number to react on ?

SweatyBanana 05-30-2006 22:17

This is used to register the cvar for how many players..


And yes, you use this line in console:

Code:

amx_cvar amx_how_many number
if amx_how_many is set to 5 and there are 5 or fewer people in the server, alltalk will be on.. if amx_how_many is set to 5 and there are 6 or more people in the server, it will turn off.

Heres some updated code.

Code:
#include <amxmodx> #include <amxmisc> new tempPlay public plugin_init() {     register_plugin("AutoAllTalk","1.1","Lone Wolf")     register_logevent("roundstart", 2, "0=World triggered", "1=Round_Start")     tempPlay = register_cvar("amx_how_many","4") } public roundstart(id) {     set_NewAlltalk(id) } public client_connect(id) {     set_NewAlltalk(id) } public client_disconnect(id) {     set_NewAlltalk(id) } public set_NewAlltalk(id) {     new tmpPlayer = get_pcvar_num(tempPlay)     new tmpCount = get_playersnum(1)     if(tmpCount <= tmpPlayer)     {         set_cvar_num("sv_alltalk",1)     }     else     {         set_cvar_num("sv_alltalk",0)     } }

SweatyBanana 05-30-2006 22:33

You get that ok?

L0neW0lf 06-25-2006 04:17

Re: Event on player count
 
Sorry for the wait, my computer crashed.....

And thanks a lot for the help it works nicely :)


All times are GMT -4. The time now is 16:18.

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