AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] if server is empty (https://forums.alliedmods.net/showthread.php?t=84034)

xlenonz 01-19-2009 10:44

[HELP] if server is empty
 
hi,

i write small plugin but im not good that :(

if server is empty , change server mp_timelimit to 0.
if any user is connect or on game mp_timelimit to 40.
after if there no player on game change mp_timelimit to 0.

i write thats but , if player connect then , disconnect dont change mp_timelimit to 0

PHP Code:

#include <amxmodx>

public plugin_init()
{
   
set_task(1.0,"MyFunction"
}

public 
MyFunction()
{
server_cmd("mp_timelimit 0")
}

public 
client_putinserver(id)
{
  
server_cmd("mp_timelimit 40")
}  

public 
oyuncuvarmi()
{
new 
playernum get_playersnum()
if (
playernum 0)
{
server_cmd("mp_timelimit 40")
}
else
{
server_cmd("mp_timelimit 0")
}
set_task(30.0,"oyuncuvarmi")
return 
PLUGIN_CONTINUE



xPaw 01-19-2009 11:46

Re: [HELP] if server is empty
 
PHP Code:

#include <amxmodx>

public plugin_init() {
    
set_task(1.0"CheckPlayers"_,_,_"b");
}

public 
CheckPlayers() {
    new 
g_iPlayers get_playersnum();
    
    if( 
g_iPlayers == )
        
server_cmd("mp_timelimit 0");
    else
        
server_cmd("mp_timelimit 40");
    
    return 
PLUGIN_CONTINUE;


but i dont reccomend to use this.

Exolent[jNr] 01-19-2009 12:27

Re: [HELP] if server is empty
 
Code:
#include <amxmodx> #include <amxmisc> new g_player_count; new mp_timelimit; public plugin_init() {     register_plugin("Plugin Name", "0.1", "Exolent");         register_event("TeamInfo", "EventPlayerLeave", "a", "2=UNASSIGNED");         mp_timelimit = get_cvar_pointer("mp_timelimit"); } public client_putinserver(client) {     if( ++g_player_count == 1 )     {         set_pcvar_num(mp_timelimit, 40);     } } public EventPlayerLeave() {     if( --g_player_count == 0 )     {         set_pcvar_num(mp_timelimit, 0);     } }

ConnorMcLeod 01-19-2009 12:32

Re: [HELP] if server is empty
 
client_disconnect can be triggered before the player has enter the server, you should use get_playersnum (<- seems to return 1 when last player has left, just check it twice ;) )

Exolent[jNr] 01-19-2009 12:34

Re: [HELP] if server is empty
 
When I wrote "Team Join Management", I found out a few things about TeamInfo event.
Such as, when the "team" parameter is "UNASSIGNED", the player has left.

xlenonz 01-19-2009 15:23

Re: [HELP] if server is empty
 
Quote:

Originally Posted by xPaw (Post 746722)
PHP Code:

#include <amxmodx>

public plugin_init() {
    
set_task(1.0"CheckPlayers"_,_,_"b");
}

public 
CheckPlayers() {
    new 
g_iPlayers get_playersnum();
    
    if( 
g_iPlayers == )
        
server_cmd("mp_timelimit 0");
    else
        
server_cmd("mp_timelimit 40");
    
    return 
PLUGIN_CONTINUE;


but i dont reccomend to use this.

thats work thanks, and Exolent[jNr]

Dores 01-19-2009 15:56

Re: [HELP] if server is empty
 
Just some little notes:

@xPaw: LoL, I like the fact that you used g_iPlayers when it's not even a global variable... :lol:

@xlenonz: I think you should use Exolent's way(no offense to xPaw), as xPaw's way is very CPU demanding.

ConnorMcLeod 01-19-2009 16:22

Re: [HELP] if server is empty
 
Quote:

Originally Posted by Exolent[jNr] (Post 746751)
When I wrote "Team Join Management", I found out a few things about TeamInfo event.
Such as, when the "team" parameter is "UNASSIGNED", the player has left.

But the message is not fired everytime, i'm sure you know the bug when a player is connecting and he already appears in scores as a T or a CT.

Dores 01-19-2009 18:30

Re: [HELP] if server is empty
 
Quote:

Originally Posted by ConnorMcLeod (Post 746855)
But the message is not fired everytime, i'm sure you know the bug when a player is connecting and he already appears in scores as a T or a CT.

But his team info is still set to UNASSIGNED. That's why when the team parameter is UNASSIGNED, the player either connected or disconnected.

xPaw 01-20-2009 07:04

Re: [HELP] if server is empty
 
Quote:

Originally Posted by Dores (Post 746842)
as xPaw's way is very CPU demanding.

i told him to dont use, i just fixed his way :crab:


All times are GMT -4. The time now is 01:41.

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