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

View of /easy_speech_plugin.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (download) (annotate)
Tue Oct 30 09:08:11 2007 UTC (16 years, 5 months ago) by ian
File size: 12453 byte(s)
/***********************************************************************
 * amx_ejl_easyspeech.sma     version 1.4c      November 28/2002
 *  By:  Eric Lidman	Alias: Ludwig van      ejlmozart@hotmail.com
 *  Upgrade: http://lidmanmusic.com/cs/plugins.html  
 *
 * This plugin makes using half-life speech much easier and more fun. 
 *  Speech commands can now be done through the chat without using the
 *  console. The commands themselves have been shortened too for the
 *  console. For example, in the chat, or console simply preceed you
 *  your speech words with yy. Also shortcuts have been added to make it
 *  easier to use the speech vocabulary from directories other than the 
 *  default (/vox).
 *
 *  UPDATED: CAN BE DONE AS THROUGH SERVER CONSOLE TOO
 *
 * Commands (console or chat):
 *
 *   yy_help <search target>
 *   uu_help <search target>
 *   tt_help <search target>
 *   ii_help <search target>
 *   rr_help <search target> 
 *   yy <speech words from the /vox directory>
 *   uu <speech words from the /fvox directory>
 *   tt <speech words from the /hgrunt directory>
 *   ii <speech words from the /scientist directory>
 *   rr <speech words from the /barney directory>
 *   amx_speak <part of nick>       --- speak words to one
 *   amx_speakteam <Team>           --- speak words to all on a team
 *   ams_speakall                   --- speak words to all
 *   amx_stopallsounds   --- in case you need to stop looping sounds
 *
 * Example (try this out):
 *
 *   say: yy the administration will control you
 *
 * Additionally, I have included a search engine, also useable from
 *  the chat. This way you can find the vocabulary words you are looking
 *  for from right within the game. For example, say yy_help ad
 *  and the search will return up to 20 words containing "ad" that you 
 *  can say with half-life speech, such as "administration".
 *
 * SETUP
 *  Same as all other AMX plugins, but in order for the search
 *  engine to work you need to have the five text files in your 
 *  ../addons/amx  folder
 *  Those files are yy_search.txt, tt_search.txt, uu_search.txt
 *  ii_search.txt, and rr_search.txt Please go to the thread for this
 *  plugin on the amx forums to get the files which are attached there.
 *  Or you may go to:  http://lidmanmusic.com/cs/plugins.html
 *  and grab them off my site. 
 *
 *********************************************************************/ 

#include <amxmod>
#include <amxmisc>

new numword
new numword_yy
new numword_uu
new numword_tt
new numword_rr
new numword_ii
new T_TrigWords_yy[650][25]
new T_TrigWords_uu[150][25]
new T_TrigWords_tt[350][25]
new T_TrigWords_rr[200][25]
new T_TrigWords_ii[400][25]

public sp_shrtcut(id,level,cid) {
	if (!cmd_access(id,level,cid,2))
		return PLUGIN_HANDLED

	new name[32]
	new Speech[192]
	new voicedir[32]
	new arg[20]
	read_argv(0,arg,19)

	if(equal(arg,"uu"))
		copy(voicedir,32,"fvox/")
	else if(equal(arg,"tt"))
		copy(voicedir,32,"hgrunt/")
	else if(equal(arg,"rr"))
		copy(voicedir,32,"barney/")
	else if(equal(arg,"ii"))
		copy(voicedir,32,"scientist/")

	read_args(Speech,191)
	get_user_name(id,name,31)

	if(safety_check(Speech)){
		console_print(id,"[AMX] Illegal input.  Speech command aborted.")
		return PLUGIN_HANDLED
	}

	if(equal(arg,"amx_speak")){
		new arg1[32]
		read_argv(1,arg1,31)
		new player = cmd_target(id,arg1,1)
		if (!player) return PLUGIN_HANDLED
		new name2[32]
		get_user_name(player,name2,31)
		client_cmd(player,"spk ^"%s^"",Speech[strlen(arg1) + 1])
		console_print(id,"To %s  YOU SPOKE:  %s",name2,Speech[strlen(arg1) + 1])
		console_print(player,"%s  SPOKE TO YOU:  %s",name,Speech[strlen(arg1) + 1])
		return PLUGIN_HANDLED			
	}

	if(equal(arg,"amx_speakteam")){
		new players[32], inum, teamname[32] 
		read_argv(1,teamname,31) 
		get_players(players,inum,"e",teamname) 
		for(new i = 0 ;i < inum ;i++) {
			client_cmd(players[i],"spk ^"%s^"",Speech[strlen(teamname) +1])    
		}
		if (inum){ 
			console_print(id,"[AMX] All clients from ^"%s^" team have been spoken to",teamname) 
		}else{ 
			console_print(id,"[AMX] No clients in such team")
		} 
		return PLUGIN_HANDLED
	}

	if(strlen(voicedir) > 0){
		client_cmd(0,"spk ^"%s%s^"",voicedir,Speech)
	}else{
		client_cmd(0,"spk ^"%s^"",Speech)
	}		
	client_print(0,print_console,"%s  SPOKE  %s",name,Speech)
	server_print("%s  SPOKE  %s",name,Speech)
	return PLUGIN_HANDLED
}

public handle_say(id) {
	
	if ((get_user_flags(id)&ADMIN_VOTE)){
		new name[32]
		new Speech[192]
		new voicedir[32]
		new arg[100]
		new cmd[10]
		new argx[32]
		read_argv(1,arg,99)
		parse(arg,cmd,9,argx,31)

		if(equal(arg,"yy_help",7)){
			search_engine(id,0,argx)
			return PLUGIN_HANDLED		
		}
		else if(equal(arg,"uu_help",7)){
			search_engine(id,1,argx)
			return PLUGIN_HANDLED		
		}
		else if(equal(arg,"tt_help",7)){
			search_engine(id,2,argx)
			return PLUGIN_HANDLED		
		}
		else if(equal(arg,"rr_help",7)){
			search_engine(id,3,argx)
			return PLUGIN_HANDLED		
		}
		else if(equal(arg,"ii_help",7)){
			search_engine(id,4,argx)
			return PLUGIN_HANDLED		
		}
		else if(equal(arg,"uu",2))
			copy(voicedir,32,"fvox/")
		else if(equal(arg,"tt",2))
			copy(voicedir,32,"hgrunt/")
		else if(equal(arg,"rr",2))
			copy(voicedir,32,"barney/")
		else if(equal(arg,"ii",2))
			copy(voicedir,32,"scientist/")
		else if(equal(arg,"yy",2))
			copy(voicedir,32,"")
		else
			return PLUGIN_CONTINUE
	
		read_args(Speech,191)
		remove_quotes(Speech)
		get_user_name(id,name,31)

		if(safety_check(Speech)){
			client_print(id,print_chat,"[AMX] Illegal input.  Speech command aborted.")
			return PLUGIN_HANDLED
		}

		if(strlen(voicedir) > 0){
			client_cmd(0,"spk ^"%s%s^"",voicedir,Speech[3])
		}else{
			client_cmd(0,"spk ^"%s^"",Speech[3])
		}
		client_print(0,print_console,"%s  SPOKE  %s",name,Speech[3])
		server_print("%s  SPOKE  %s",name,Speech[3])
		return PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE
}

safety_check(Speech[]){
	new wordlen
	new ill = 0
	for(new i=0; i<strlen(Speech);i++){
		if( (Speech[i] < 'a' || Speech[i] > 'z') && (Speech[i] < '0' || Speech[i] > '9') ){
			if( (!equal(Speech[i]," ",1)) && (!equal(Speech[i],"!",1)) && (!equal(Speech[i],"/",1)) &&
			(!equal(Speech[i],"_",1)) && (!equal(Speech[i],",",1)) && (!equal(Speech[i],".",1)) )
				ill = 1
		}
 		if(equal(Speech[i]," ",1)){
			wordlen = 0
		}else{
			wordlen++
			if(wordlen > 30){
				ill = 1
			}
		}
	}
	return ill
}

public admin_ssearch(id) {
	new arg[32]
	new argx[32]
	read_argv(0,arg,31)
	read_argv(1,argx,31)
	if(equal(arg,"yy_help",7)){
		search_engine(id,0,argx)		
	}
	else if(equal(arg,"uu_help",7)){
		search_engine(id,1,argx)		
	}
	else if(equal(arg,"tt_help",7)){
		search_engine(id,2,argx)		
	}
	else if(equal(arg,"rr_help",7)){
		search_engine(id,3,argx)		
	}
	else if(equal(arg,"ii_help",7)){
		search_engine(id,4,argx)		
	}	
	return PLUGIN_HANDLED
}

search_engine(id,type,argx[]){
	new TrigWords[20][25]
	new b
	new stype[10]

	if(type == 0){
		copy(stype,10,"vox")
		numword = numword_yy
		for(new a = 0; a < numword; a++) {
			if (containi(T_TrigWords_yy[a],argx) != -1) {
				if(b < 20){
					copy(TrigWords[b], 25, T_TrigWords_yy[a])
					b++
				}
			}
		}
	}
	else if(type == 1){
		copy(stype,10,"fvox")
		numword = numword_uu
		for(new a = 0; a < numword; a++) {
			if (containi(T_TrigWords_uu[a],argx) != -1) {
				if(b < 20){
					copy(TrigWords[b], 25, T_TrigWords_uu[a])
					b++
				}
			}
		}
	}
	else if(type == 2){
		copy(stype,10,"hgrunt")
		numword = numword_tt
		for(new a = 0; a < numword; a++) {
			if (containi(T_TrigWords_tt[a],argx) != -1) {
				if(b < 20){
					copy(TrigWords[b], 25, T_TrigWords_tt[a])
					b++
				}
			}
		}
	}
	else if(type == 3){
		copy(stype,10,"barney")
		numword = numword_rr
		for(new a = 0; a < numword; a++) {
			if (containi(T_TrigWords_rr[a],argx) != -1) {
				if(b < 20){
					copy(TrigWords[b], 25, T_TrigWords_rr[a])
					b++
				}
			}
		}
	}
	else if(type == 4){
		copy(stype,10,"scientist")
		numword = numword_ii
		for(new a = 0; a < numword; a++) {
			if (containi(T_TrigWords_ii[a],argx) != -1) {
				if(b < 20){
					copy(TrigWords[b], 25, T_TrigWords_ii[a])
					b++
				}
			}
		}
	}
	new msg[800]
	if(b > 0){
		format(msg,800,"%d %s sounds.^nHere are search results,^nonly 1st 20 shown:^n^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n   %s^n",numword, stype, TrigWords[0],TrigWords[1],TrigWords[2],TrigWords[3],
		TrigWords[4],TrigWords[5],TrigWords[6],TrigWords[7],TrigWords[8],TrigWords[9],TrigWords[10],TrigWords[11],TrigWords[12],TrigWords[13],TrigWords[14],TrigWords[15],
		TrigWords[16],TrigWords[17],TrigWords[18],TrigWords[19])
		set_hudmessage(10,100,150, 0.75, 0.10, 2, 0.02, 14.0, 0.01, 0.1, 4)
		show_hudmessage(id,"%s",msg)
		client_print(id,print_chat,"[AMX]  Sound search results: See right side of screen.") 
	}else{
		set_hudmessage(10,100,150, 0.75, 0.10, 2, 0.02, 9.0, 0.01, 0.1, 4)
		show_hudmessage(id,"No match to your search,^n%d %s sounds.",numword,stype)
		client_print(id,print_chat,"[AMX]  Sound search results: See right side of screen.") 
	}
	return PLUGIN_CONTINUE
}

public admin_stopallsounds(id,level,cid) {
	if (!cmd_access(id,level,cid,1))
		return PLUGIN_HANDLED
	client_cmd(0,"stopsound")
	client_print(0,print_console,"[AMX] 'stopsound' executed on all clients")
	server_print("[AMX] 'stopsound' executed on all clients")
	return PLUGIN_HANDLED
}

public plugin_init() {
	register_plugin("Easy Speech Plugin","1.4c","EJL")
	register_concmd("yy","sp_shrtcut",ADMIN_VOTE,"<msg>: Speak words on system of everyone. <vox>")
	register_concmd("uu","sp_shrtcut",ADMIN_VOTE,"<msg>: Speak words on system of everyone. <fvox>")
	register_concmd("ii","sp_shrtcut",ADMIN_VOTE,"<msg>: Speak words on system of everyone. <scientist>")
	register_concmd("rr","sp_shrtcut",ADMIN_VOTE,"<msg>: Speak words on system of everyone. <barney>")
	register_concmd("tt","sp_shrtcut",ADMIN_VOTE,"<msg>: Speak words on system of everyone. <hgrunt>")
	register_concmd("amx_speakall","sp_shrtcut",ADMIN_VOTE,"<msg>: Speak words on system of everyone.")
	register_concmd("amx_speakteam","sp_shrtcut",ADMIN_VOTE,"<team> <msg>: Speak words on a whole team.")
	register_concmd("amx_speak","sp_shrtcut",ADMIN_VOTE,"<part of nick> <msg>: Speak words on a player.")
	register_concmd("amx_stopallsounds","admin_stopallsounds",ADMIN_VOTE,"executes stopsound on all clients -- useful for ending looped sounds.")
	register_clcmd("yy_help","admin_ssearch",ADMIN_VOTE,"yy_help <search target>: Find words to speak from <vox>")
	register_clcmd("uu_help","admin_ssearch",ADMIN_VOTE,"uu_help <search target>: Find words to speak from <fvox>")
	register_clcmd("tt_help","admin_ssearch",ADMIN_VOTE,"tt_help <search target>: Find words to speak from <hgrunt>")
	register_clcmd("rr_help","admin_ssearch",ADMIN_VOTE,"rr_help <search target>: Find words to speak from <barney>")
	register_clcmd("ii_help","admin_ssearch",ADMIN_VOTE,"ii_help <search target>: Find words to speak from <scientist>")
	register_clcmd("say","handle_say")

	new path[48],yysearch[65],uusearch[65],ttsearch[65],rrsearch[65],iisearch[65]
	build_path(path,47,"$basedir")
	format(yysearch,64,"%s/yy_search.txt",path)
	format(uusearch,64,"%s/uu_search.txt",path)
	format(ttsearch,64,"%s/tt_search.txt",path)
	format(rrsearch,64,"%s/rr_search.txt",path)
	format(iisearch,64,"%s/ii_search.txt",path)

	for(new a = 0; a < 650; a++) {
		new data[25]
		new stextsize = 0
		read_file(yysearch,a,data,25,stextsize)
		if(strlen(data) > 0){
			copy(T_TrigWords_yy[numword_yy], 25, data)
			numword_yy++
		}
	}
	for(new a = 0; a < 150; a++) {
		new data[25]
		new stextsize = 0
		read_file(uusearch,a,data,25,stextsize)
		if(strlen(data) > 0){
			copy(T_TrigWords_uu[numword_uu], 25, data)
			numword_uu++
		}
	}
	for(new a = 0; a < 350; a++) {
		new data[25]
		new stextsize = 0
		read_file(ttsearch,a,data,25,stextsize)
		if(strlen(data) > 0){
			copy(T_TrigWords_tt[numword_tt], 25, data)
			numword_tt++
		}
	}
	for(new a = 0; a < 200; a++) {
		new data[25]
		new stextsize = 0
		read_file(rrsearch,a,data,25,stextsize)
		if(strlen(data) > 0){
			copy(T_TrigWords_rr[numword_rr], 25, data)
			numword_rr++
		}
	}
	for(new a = 0; a < 400; a++) {
		new data[25]
		new stextsize = 0
		read_file(iisearch,a,data,25,stextsize)
		if(strlen(data) > 0){
			copy(T_TrigWords_ii[numword_ii], 25, data)
			numword_ii++
		}
	}
	return PLUGIN_CONTINUE	
}


Contact
ViewVC Help
Powered by ViewVC 1.0.4