[Half-Life AMXX] / kz_rewards.sma Repository:
ViewVC logotype

View of /kz_rewards.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (download) (annotate)
Tue Nov 20 22:36:56 2007 UTC (13 years ago) by ian
File size: 3478 byte(s)
Applied AGPLv3 license.
/*
KZ Rewards v0.2
Copyright (C) 2007 Ian (Juan) Cammarata

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------
http://ian.cammarata.us
*/

#include <amxmodx>
#include <amxmisc>
#include <engine>

#define VERSION "0.2"
#define SF_MAX 50
#define SF_STRLEN 50

new sfactions[SF_MAX][50], sfcount = 0
new p_enabled

public plugin_init( )
{
	register_plugin( "KZ Rewards", VERSION, "Ian Cammarata" )
	register_cvar( "kz_rewards_version", VERSION, FCVAR_SERVER )
	
	p_enabled = register_cvar( "kzrw_enabled", "1" )
	
	//Load Start/Finish Commands
	new ini[50]
	get_configsdir( ini, 49 )
	format( ini, 49, "%s/kz_rewards.ini", ini )
	if( file_exists( ini ) )
	{
		new line = 0, text[SF_STRLEN], len
		while( read_file( ini, line++, text, SF_STRLEN-1 , len ) )
		{
			if( !equal( text, ";", 1 ) && !equal( text, "#", 1 ) && !equal( text, "//", 2 ) )
			{
				if( sfcount < SF_MAX )
				{
					sfactions[sfcount] = text
					sfcount++
				}
			}
		}
	}
	
	server_print( "[KZ Rewards] Loaded %d rewards from file.", sfcount )
	
	return PLUGIN_CONTINUE
}

public client_PreThink( id )
{
	if( is_user_alive( id ) && get_pcvar_num( p_enabled ) )
	{
		if( get_user_button(id) & IN_USE && !( get_user_oldbutton( id ) & IN_USE ) )
		{//Detect button use. Replicated from HL SDK
			new entlist[3], count
			count = find_sphere_class( id, "func_button", 64.0, entlist, 3 )
			if( count )
			{
				new Float:orig[3]
				for( new i=0; i < count; i++ )
				{
					get_brush_entity_origin( entlist[i], orig )
					if( is_in_viewcone( id, orig ) ) button_used( id, entlist[i] )
	      }
			}
		}
	}
	
	return PLUGIN_CONTINUE
}

public button_used( id, button )
{
	new targ[32]
	entity_get_string(button,EV_SZ_target,targ,32)
	
	if( equal( targ,"counter_start" ) || equal( targ, "clockstartbutton" ) || equal( targ, "firsttimerelay" ) )
		sfexec( id, 0 )
	else if( equal( targ, "counter_off" ) || equal( targ, "clockstopbutton" ) || equal( targ, "clockstop" ) )
		sfexec( id, 1 )
}

public sfexec( id, clevent )
{
	new clstat[3]
	
	if( clevent == 0 ) clstat="st"
	else clstat="fn"
		
	for( new i=0; i < sfcount; i++ )
	{
		new cmdstat[3], cmdtype[3], cmd[60], idtype[5]
		parse( sfactions[i], cmdstat, 2, cmdtype, 2, cmd, sizeof(cmd)-1, idtype, 4 )
		if( equali( cmdstat, clstat ) )
		{
			if( equali( cmdtype, "sc" ) )
			{
				if( equali( idtype, "uid" ) ) format( cmd, sizeof( cmd )-1, cmd, get_user_userid( id ) )
				else
				{
					new name[24]
					get_user_name( id, name, sizeof( name )-1 )
					format( name, sizeof( name ), "^"%s^"", name )
					format( cmd, sizeof( cmd )-1, cmd, name )
					client_print( id, print_chat, cmd )
				}
				server_cmd( cmd )
			}
			else client_cmd( id, cmd )
		}
	}
}

Contact
ViewVC Help
Powered by ViewVC 1.0.4