Raised This Month: $ Target: $400
 0% 

FindTarget() Target not found error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Giovanifsa
Member
Join Date: Jul 2013
Location: Brazil Paraná
Old 07-19-2015 , 12:38   FindTarget() Target not found error
Reply With Quote #1

Some of the plugins i've made use FindTarget, but if target isn't found it spam errors, how can I fix this?
The plugin works on or ingame clients or clients with a unique nickname, without errors

Example:
me : !regen some1else 1(only me in server)

[SM] Plugin encountered error 4: Invalid parameter or parameter type
[SM] Native "ReplyToCommand" reported: Language phrase "No matching client" not found
[SM] Displaying call stack trace for plugin "regen.smx"
[SM] [0] Line 103, C:\"Path to include folder"\commandfilters.inc::ReplyToTargetErro r()
[SM] [1] Line 184, C:\"Path to include folder"\helpers.inc::FindTarget()
[SM] [2] Line 31, C:\"Path to include folder"\regen.sp::REGEN()

Code:
#include <sourcemod>
#include <colors>
#include <tf2>

new Handle:Tempo[MAXPLAYERS+1] = INVALID_HANDLE;
new Ligado[MAXPLAYERS+1];
new Handle:T_DEFINED = INVALID_HANDLE;

public Plugin:myinfo = {
	name = "Regeneration",
	author = "Nescau",
	description = "Regenerates the target at every defined time",
	version = "1.0",
	url = "http://www.kvkserver.com"
};

public OnPluginStart()
{
	RegConsoleCmd("sm_regen", REGEN, "", FCVAR_NOTIFY|FCVAR_DONTRECORD);
	T_DEFINED = CreateConVar("sm_regentime", "2.0", "", FCVAR_NOTIFY|FCVAR_DONTRECORD);
}

public Action:REGEN(client, args)
{
	if(args == 2)
	{
		new String:argumento[64];
		new String:argumento2[64];
		GetCmdArg(1, argumento, sizeof(argumento));
		GetCmdArg(2, argumento2, sizeof(argumento2));
		new target = FindTarget(client, argumento, true, false);
		new Float:TIME = GetConVarFloat(T_DEFINED);
		
		new valor = StringToInt(argumento2);
		if(valor == 1)
		{
			Tempo[target] = CreateTimer(TIME, H_TIMER, target, TIMER_REPEAT);
			Ligado[target] = 1;
			CPrintToChat(target, "{green}[SM]{default} You are regenerating!");
			
		}
		if(valor != 1)
		{
			if(Ligado[target] == 0)
			{
				CPrintToChat(client, "{green}[SM]{default} The player don't have regeneration!");
				return Plugin_Handled;
			}
			if(Ligado[target] == 1)
			{
				CloseHandle(Tempo[target]);
				Ligado[target] = 0;
				CPrintToChat(target, "{green}[SM]{default} Regeneration off.");
				return Plugin_Handled;
			}
		}
		
	} else {
		CPrintToChat(client, "{green}[SM]{default} Incorrect syntax! Usage: sm_regen <player>."); 
		return Plugin_Handled;
	}
	return Plugin_Handled;
}

public Action:H_TIMER(Handle:timer, any:target)
{
	TF2_RegeneratePlayer(target);
}

public OnClientDisconnect(client)
{
	if(Ligado[client] == 1)
	{
		Ligado[client]=0;
		CloseHandle(Tempo[client]);
	}
}
__________________

Last edited by Giovanifsa; 07-19-2015 at 12:53.
Giovanifsa is offline
Send a message via Skype™ to Giovanifsa
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 07-19-2015 , 12:48   Re: FindTarget() Target not found error
Reply With Quote #2

PHP Code:
new String:arg[MAX_NAME_LENGTH];
GetCmdArg(1argsizeof(arg));
new 
target FindTarget(clientargs); 
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker is offline
psychonic

BAFFLED
Join Date: May 2008
Old 07-19-2015 , 13:14   Re: FindTarget() Target not found error
Reply With Quote #3

For FindTarget's error, you need to load the common.phrases translation set in OnPluginStart.

LoadTranslations("common.phrases");
psychonic is offline
Giovanifsa
Member
Join Date: Jul 2013
Location: Brazil Paraná
Old 07-19-2015 , 14:14   Re: FindTarget() Target not found error
Reply With Quote #4

Quote:
Originally Posted by psychonic View Post
For FindTarget's error, you need to load the common.phrases translation set in OnPluginStart.

LoadTranslations("common.phrases");
Thanks! It worked, but not it's giving me

[SM] Plugin encounteres error 15: Array index is out of bounds
[SM] Displayinh call stack trade for plugin "regen.smx"
[SM] [0] Line 42, C:\"Path to scripting folder"\regen.sp::REGEN()

Code:
#include <sourcemod>
#include <colors>
#include <tf2>

new Handle:Tempo[MAXPLAYERS+1] = INVALID_HANDLE;
new Ligado[MAXPLAYERS+1];
new Handle:T_DEFINED = INVALID_HANDLE;

public Plugin:myinfo = {
	name = "Regeneration",
	author = "Nescau",
	description = "Regenerates the target at every defined time",
	version = "1.0",
	url = "http://www.kvkserver.com"
};

public OnPluginStart()
{
	LoadTranslations("common.phrases");
	RegConsoleCmd("sm_regen", REGEN, "", FCVAR_NOTIFY|FCVAR_DONTRECORD);
	T_DEFINED = CreateConVar("sm_regentime", "2.0", "", FCVAR_NOTIFY|FCVAR_DONTRECORD);
}

public Action:REGEN(client, args)
{
	if(args == 2)
	{
		new String:argumento[64];
		new String:argumento2[64];
		GetCmdArg(1, argumento, sizeof(argumento));
		GetCmdArg(2, argumento2, sizeof(argumento2));
		new target = FindTarget(client, argumento, true, false);
		new Float:TIME = GetConVarFloat(T_DEFINED);
		
		new valor = StringToInt(argumento2);
		if(valor == 1)
		{
			Tempo[target] = CreateTimer(TIME, H_TIMER, target, TIMER_REPEAT);
			Ligado[target] = 1;
			CPrintToChat(target, "{green}[SM]{default} You are regenerating!");
		}
		if(valor != 1)
		{
			if(Ligado[target] == 0)
			{
				CPrintToChat(client, "{green}[SM]{default} The player don't have regeneration!");
				return Plugin_Handled;
			}
			if(Ligado[target] == 1)
			{
				CloseHandle(Tempo[target]);
				Ligado[target] = 0;
				CPrintToChat(target, "{green}[SM]{default} Regeneration off.");
				return Plugin_Handled;
			}
		}
		
	} else {
		CPrintToChat(client, "{green}[SM]{default} Incorrect syntax! Usage: sm_regen <player>."); 
		return Plugin_Handled;
	}
	return Plugin_Handled;
}

public Action:H_TIMER(Handle:timer, any:target)
{
	TF2_RegeneratePlayer(target);
}

public OnClientDisconnect(client)
{
	if(Ligado[client] == 1)
	{
		Ligado[client]=0;
		CloseHandle(Tempo[client]);
	}
}
:v
__________________
Giovanifsa is offline
Send a message via Skype™ to Giovanifsa
psychonic

BAFFLED
Join Date: May 2008
Old 07-19-2015 , 14:32   Re: FindTarget() Target not found error
Reply With Quote #5

You still need to handle the case of target not being found, else you're using -1 as an array index.
psychonic is offline
Giovanifsa
Member
Join Date: Jul 2013
Location: Brazil Paraná
Old 07-22-2015 , 14:31   Re: FindTarget() Target not found error
Reply With Quote #6

Quote:
Originally Posted by psychonic View Post
You still need to handle the case of target not being found, else you're using -1 as an array index.
Thanks! Didn't see before that FindTarget returns -1 on error
__________________
Giovanifsa is offline
Send a message via Skype™ to Giovanifsa
Reply



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 05:41.


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