Raised This Month: $ Target: $400
 0% 

wolle_gravity


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Wolle
Member
Join Date: Jun 2005
Location: Berlin / Germany
Old 01-03-2006 , 09:55   wolle_gravity
Reply With Quote #1

Hi everyone.
I wrote this small plugin to easily control the gravity setting on my server.
It's nothing new but I hope others also have a use for it.

I also welcome constructive criticism. I'm particularly looking for performance holes. Let me know if I could have written something different to make the code execute faster.

This plugin allows admins of access level A(m) to set a server's gravity through a chat command (/grav).
This command takes 2 arguments. The amount of gravity and the time in minutes for its duration.
So if you want to set a server's gravity to let's say 200 for 5 minutes simply type "/grav 200 5" without the quotes.
To reset the gravity type "/grav normal".
Enjoy!

EDIT
I just discovered that "sv_gravity" also excepts negative values.
I wasn't aware of that and therefore updated the code to dissallow negativ e numbers.
The updated code is below.
The 2 attachments are also updated.

I'm also thinking about allowing floating point numbers for both gravity and time.
Gravity doesn't really need that but it ecepts it so what the heck but it's nice for the time because it then allows to set the time to seconds instead of just minutes.
I might add that later.

Code:
/* AMXX Mod script. * * (c) Copyright 2005, Wolle * This file is provided as is (no warranties) * * Allows admins to easily control gravity * * Usage: "command amountofgravity timeinminutes" * Example: To set the gravity to 200 for a duration of 5 minutes just say or team_say: "/grav 200 5" * To reset the gravity to normal level use: "/grav normal" * * Enjoy!! * Contact: <a href="mailto:[email protected]">[email protected]</a> */ #include <amxmodx> #include <fun> new PLUGIN[]="Gravity Control"; new AUTHOR[]="Wolle"; new VERSION[]="1.00"; new g_iDuration = 0; new bool:g_bTimesUp = false; #define MAX_ARGUMENTS 3 #define MAX_ARGUMENT_LENGTH 32 public plugin_init() {     register_plugin( PLUGIN, VERSION, AUTHOR );     register_clcmd ( "say", "GravityControl" );     register_clcmd ( "say_team", "GravityControl" ); } public Timer() {     if( g_iDuration > 0 )     {         g_iDuration--;                 if( g_iDuration == 0 )         {             g_bTimesUp = true;         }         else if( g_iDuration <= 5 )         {             set_hudmessage( 230, 130, 30, 0.03, 0.6, 2, 0.02, 0.6, 0.01, 0.3, 0 );             show_hudmessage( 0, "Normal gravity in: %d", g_iDuration );         }                 if( g_bTimesUp )         {             set_cvar_num( "sv_gravity" , 800 );             g_bTimesUp = false;                         set_hudmessage( 230, 130, 30, 0.03, 0.6, 2, 0.02, 5.0, 0.01, 0.3, 1 );             show_hudmessage( 0, "Gravity has been restored." );         }     }     else if( g_iDuration < 0 )     {         g_iDuration = 0;     } } public GravityControl( id ) {     if( !id )     {         return PLUGIN_CONTINUE;     }         if( get_user_flags( id ) & ADMIN_LEVEL_A )     {         new i, j, len, len2, arg1, arg2;         new said[192], cmd[10], arguments[MAX_ARGUMENTS][MAX_ARGUMENT_LENGTH];                 read_argv( 0, cmd, 9 );         read_args( said, 191 );         remove_quotes( said );         len = strlen( said );                 for( i = 0 ; i < len ; i++ )         {             if ( said[i] == ' ' )             {                 j++;             }             else             {                 if( containi( arguments[0], "/grav" ) != -1 )                 {                     if( j > 2 )                     {                         set_hudmessage( 230, 130, 30, 0.03, 0.6, 2, 0.02, 5.0, 0.01, 0.3, 1 );                         show_hudmessage( 0, "Too many arguments!!^nUsage: /grav <gravity> <time>" );                                                 return PLUGIN_CONTINUE;                     }                 }                                 len2 = strlen( arguments[j] );                 add( arguments[j], len2+1, said[i] );             }         }                 if( containi( arguments[0], "/grav" ) != -1 )         {             arg1 = str_to_num( arguments[1] );             arg2 = str_to_num( arguments[2] );                         if( arg1 != 0 && arg2 != 0 || containi( arguments[1], "normal" ) != -1 )             {                 new user_name[64];                 get_user_name ( id, user_name, 63 );                                 if( containi( arguments[1], "normal" ) != -1 )                 {                     set_cvar_num( "sv_gravity" , 800 );                     g_iDuration = 0;                     remove_task( 1, 0 );                                         set_hudmessage( 230, 130, 30, 0.03, 0.6, 2, 0.02, 5.0, 0.01, 0.3, 0 );                     show_hudmessage( 0, "%s set the gravity back to normal", user_name );                                         return PLUGIN_CONTINUE;                 }                 else if( arg1 < 0 || arg2 < 0 )                 {                     set_hudmessage( 230, 130, 30, 0.03, 0.6, 2, 0.02, 5.0, 0.01, 0.3, 0 );                     show_hudmessage( 0, "No negative numbers allowed!" );                                         return PLUGIN_CONTINUE;                 }                 else if( arg2 * 60 > get_timeleft())                 {                     set_hudmessage( 230, 130, 30, 0.03, 0.6, 2, 0.02, 5.0, 0.01, 0.3, 1 );                     show_hudmessage( id, "Theres not enough time left.^nSet the duration to a lower value!" );                 }                 else                 {                     g_iDuration = arg2*60;                     set_task( 1.0, "Timer", 1, "", 0, "a", g_iDuration );                     set_cvar_num( "sv_gravity" , arg1 );                                         set_hudmessage( 230, 130, 30, 0.03, 0.6, 2, 0.02, 5.0, 0.01, 0.3, 0 );                     show_hudmessage( 0, "%s set the gravity to %d for %d minutes", user_name, arg1, arg2 );                 }             }             else             {                 set_hudmessage( 230, 130, 30, 0.03, 0.6, 2, 0.02, 5.0, 0.01, 0.3, 0 );                 show_hudmessage( id, "Invalid Arguments!!^nUsage: /grav <gravity> <time>" );             }         }         engclient_cmd ( id ,cmd ,said );     }     return PLUGIN_CONTINUE; }
Attached Files
File Type: amx wolle_gravity.amx (4.6 KB, 88 views)
File Type: sma Get Plugin or Get Source (wolle_gravity.sma - 595 views - 3.9 KB)
Wolle is offline
Send a message via AIM to Wolle
 


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 16:00.


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