hlmod.hu
https://hlmod.hu/

Autoexec
https://hlmod.hu/viewtopic.php?f=44&t=29060
Oldal: 1 / 1

Szerző:  KillerBoy12 [ 2018.06.10. 19:18 ]
Hozzászólás témája:  Autoexec

Üdv!

hogyan lehet meg oldani hogy ne kelljen manuálisan csinálni hogy ezek a parancsok le fussanak, hanem mondjuk bizonyos idő után?

mp_freezetime 0
mp_maxrounds 999
mp_respawn_immunitytime 0
mp_restartgame 1

Szerző:  JohanCorn [ 2018.06.10. 19:44 ]
Hozzászólás témája:  Re: Autoexec

Használd a ServerCommand parancsot. Esetleg készítesz egy loopot, ami percenként lefut és ha az aktuális idő egyezik az általad megadott, akkor futtatod.

Szerző:  KillerBoy12 [ 2018.06.10. 20:24 ]
Hozzászólás témája:  Re: Autoexec

nem tudnál dobni egy példát?

Szerző:  JohanCorn [ 2018.06.10. 20:29 ]
Hozzászólás témája:  Re: Autoexec

Ez szerintem egy nagyon jó példa.

  1. #include <sourcemod>
  2.  
  3. #define PL_VERSION "1.3"
  4.  
  5. new Handle:cvarEnabled = INVALID_HANDLE;
  6. new Handle:cvarTime = INVALID_HANDLE;
  7.  
  8. public const Plugin:myinfo = {
  9.     name = "AutoRestart",
  10.     author = "MikeJS",
  11.     description = "Restarts servers once a day when they empty.",
  12.     version = PL_VERSION,
  13.     url = "http://forums.alliedmods.net/showthread.php?t=87291",
  14. }
  15.  
  16. public OnPluginStart() {
  17.     CreateConVar( "sm_autorestart_version", PL_VERSION, "AutoRestart version.", FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY );
  18.  
  19.     cvarEnabled = CreateConVar( "sm_autorestart", "1", "Enable AutoRestart.", FCVAR_PLUGIN );
  20.     cvarTime = CreateConVar( "sm_autorestart_time", "0500", "Time to restart server at.", FCVAR_PLUGIN, true, 0.0, true, 2400.0 );
  21.  
  22.     CreateTimer( 300.0, CheckRestart, 0, TIMER_REPEAT );
  23. }
  24.  
  25. public Action:CheckRestart( Handle:timer, any:ignore ) {
  26.     if( !GetConVarBool( cvarEnabled ) ) {
  27.         return;
  28.     }
  29.  
  30.     // Is the server empty?
  31.     for( new i = 1; i <= MaxClients; i++ ) {
  32.         if( IsClientConnected( i ) && !IsFakeClient( i ) ) {
  33.             return;
  34.         }
  35.     }
  36.  
  37.     decl String:path[ PLATFORM_MAX_PATH ];
  38.     BuildPath( Path_SM, path, sizeof( path ), "data/lastrestart.txt" );
  39.  
  40.     // Did we already restart today?
  41.     decl String:currentDay[ 8 ];
  42.     FormatTime( currentDay, sizeof( currentDay ), "%j" );
  43.  
  44.     new const lastRestart = GetFileTime( path, FileTime_LastChange );
  45.     new String:lastRestartDay[ 8 ] = "";
  46.  
  47.     if( lastRestart != -1 ) {
  48.         FormatTime( lastRestartDay, sizeof( lastRestartDay ), "%j", lastRestart );
  49.     }
  50.  
  51.     if( StrEqual( currentDay, lastRestartDay ) ) {
  52.         return;
  53.     }
  54.  
  55.     decl String:time[ 8 ];
  56.     FormatTime( time, sizeof( time ), "%H%M" );
  57.  
  58.     // Is it too early to restart?
  59.     if( StringToInt( time ) < GetConVarInt( cvarTime ) ) {
  60.         return;
  61.     }
  62.  
  63.     // Touch autorestart.txt
  64.     new const Handle:file = OpenFile( path, "w" );
  65.     new bool:written = false;
  66.     new bool:closed = false;
  67.  
  68.     if( file != INVALID_HANDLE ) {
  69.         written = WriteFileString( file, "Don't touch this file", true );
  70.         closed = CloseHandle( file );
  71.     }
  72.  
  73.     // Don't restart endlessly if we couldn't...
  74.     if( file == INVALID_HANDLE || !written || !closed ) {
  75.         LogError( "Couldn't write %s.", path );
  76.  
  77.         return;
  78.     }
  79.  
  80.     // All good
  81.     LogMessage( "Restarting..." );
  82.     ServerCommand( "_restart" );
  83. }

Szerző:  Anonymous1337 [ 2018.06.11. 23:49 ]
Hozzászólás témája:  Re: Autoexec

Tessék, csak neked :oops: :oops:
viewtopic.php?f=48&t=29069
Amint elfogadják, már használhatod is. :P

KillerBoy12 írta:
Üdv!

hogyan lehet meg oldani hogy ne kelljen manuálisan csinálni hogy ezek a parancsok le fussanak, hanem mondjuk bizonyos idő után?

mp_freezetime 0
mp_maxrounds 999
mp_respawn_immunitytime 0
mp_restartgame 1

Oldal: 1 / 1 Minden időpont UTC+02:00 időzóna szerinti
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/