Raised This Month: $51 Target: $400
 12% 

[CS:S] Problem plugin: Client index 0 is invalid


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Misterpown
Senior Member
Join Date: Jan 2011
Old 06-23-2013 , 08:56   [CS:S] Problem plugin: Client index 0 is invalid
Reply With Quote #1

Hello everyone,

I have a problem with my plugin, flood the server console:

Code:
[SM] Native "IsClientConnected" reported: Client index 0 is invalid
[SM] Displaying call stack trace for plugin "tueur.smx":
[SM]   [0]  Line 236, tueur.sp::UpdateContrat()
How to fix this?
Also I would like a laser that appears to tueur_vec to cible_vec, but it does not work.

Code:
public Action:UpdateContrat(Handle:timer, any:client)
{
	if(IsClientConnected(client))
	{
		if (IsClientConnected(cible[client]))
		{
			if (IsPlayerAlive(client))
			{
				oncontrat[client] = true;
				oncontrat[cible[client]] = true;
				
				//
				new Float:tueur_vec[3], Float:cible_vec[3];
 
				GetClientAbsOrigin(client, tueur_vec);
				GetClientAbsOrigin(cible[client], cible_vec);
				tueur_vec[2] += 40.0;
				cible_vec[2] += 40.0;

				TE_SetupBeamPoints(tueur_vec, cible_vec, g_BeamSprite, g_HaloSprite, 0, 1, 1.0, 10.0, 10.0, 1, 1.0, {255, 0, 0, 255}, 1);
				TE_SendToClient(client, 0.0);
				//
				
				if (HasKillCible[client])
				{
					fincontrat(client);
							
					PrintToChat(client, "%s Vous avez réussi votre contrat sur %N.", LOGO, cible[client]);
					PrintToChat(TransactionWith[client], "%s Le tueur %N a réussi son contrat sur %N !", LOGO, client, cible[client]);
				}
			}
			else
			{
				fincontrat(client);
				
				PrintToChat(client, "%s Vous vous êtes fait tuer durant votre contrat, contrat échoué.", LOGO);
				PrintToChat(TransactionWith[client], "%s Le tueur %N a échoué son contrat sur %N !", LOGO, client, cible[client]);
			}
		}
		else
		{
			fincontrat(client);
			
			PrintToChat(client, "%s Votre cible s'est déconnectée, contrat échoué.", LOGO);
			PrintToChat(TransactionWith[client], "%s Le tueur %N a échoué son contrat sur %N !", LOGO, client, cible[client]);
		}
	}
	else
	{
		fincontrat(client);
		PrintToChat(TransactionWith[client], "%s Le tueur %N a échoué son contrat sur %N !", LOGO, client, cible[client]);
	}
	return Plugin_Handled;
}
Thx !

Last edited by Misterpown; 06-23-2013 at 08:57.
Misterpown is offline
ojmdk476oj
AlliedModders Donor
Join Date: Dec 2009
Old 06-23-2013 , 09:04   Re: [CS:S] Problem plugin: Client index 0 is invalid
Reply With Quote #2

Remember to check if the client is fake or not. (IsFakeClient) as far as I remember.
ojmdk476oj is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 06-23-2013 , 09:06   Re: [CS:S] Problem plugin: Client index 0 is invalid
Reply With Quote #3

bots would not have ClientID 0... which one of your calls is on line 236
__________________
View my Plugins | Donate
TnTSCS is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 06-23-2013 , 09:20   Re: [CS:S] Problem plugin: Client index 0 is invalid
Reply With Quote #4

cible[client] is probably = 0.
You can only pass valid client indexes to IsClientConnected, 0 is not a valid client index.

If you want to have a more accurate answer please post the full code.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Misterpown
Senior Member
Join Date: Jan 2011
Old 06-23-2013 , 09:26   Re: [CS:S] Problem plugin: Client index 0 is invalid
Reply With Quote #5

I don't understand your answer :/

Here are the main lines of the plugin :

Code:
public Action:OnClientPreAdminCheck(client)
{
	oncontrat[client] = false;
}

public Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	new killer = GetClientOfUserId(GetEventInt(event, "attacker"));
	
	if (killer > 0)
	{
		if (IsClientInGame(killer))
		{
			if (killer != client)
			{
				if (oncontrat[killer])
				{
					HasKillCible[killer] = true;
				}
			}	
		}	
	}
}

public OnClientDisconnect(client)
{
	if (IsClientInGame(client))
	{
		HasKillCible[client] = false;
		oncontrat[client] = false;
	}
}

public Action:Command_Contrat(client, Args)
{
	if (IsClientInGame(client))
	{
		if (IsPlayerAlive(client))
		{
			decl String:model[256];
			GetClientModel(client, model, sizeof(model));
	
			if (strcmp(tueurskin, model, false) ==0)
			{
				acheteur[client] = GetClientAimTarget(client, true);
				TransactionWith[acheteur[client]] = client;
				TransactionWith[client] = acheteur[client];
				
				if (acheteur[client] != -1)
				{
					if (!oncontrat[client])
					{
						if (IsPlayerAlive(acheteur[client]))
						{
							if (!oncontrat[acheteur[client]])
							{
								CheckTueur(client);
							}
							else
							{
								PrintToChat(client, "%s Le joueur %N est déjà en contrat.", LOGO, TransactionWith[client]);
							}
						}
						else
						{
							PrintToChat(client, "%s Le joueur %N est mort.", LOGO, TransactionWith[client]);
						}
					}
					else
					{
							PrintToChat(client, "%s Vous êtes déjà en contrat.", LOGO);
					}
				}
				else
				{
					PrintToChat(client, "%s Vous devez viser un joueur.", LOGO);
				}
			}
			else
			{
				PrintToChat(client, "%s Vous n'avez pas accès à cette commande.", LOGO);
			}
		}
		else
		{
			PrintToChat(client, "%s Vous devez être en vie.", LOGO);
		}
	}
}

CheckTueur(client)
{
	if(client > 0 && client <= MaxClients && !IsFakeClient(client))
	{
		decl String:sMenuText[64];
		sMenuText[0] = '\0';
        
		new Handle:menu = CreateMenu(Menu_CheckTueur);
		SetMenuTitle(menu, "Choisissez le joueur :");
		SetMenuExitButton(menu, true);
        
		AddCible(menu);
        
		DisplayMenu(menu, client, MENU_TIME_FOREVER);
	}
}

public AddCible(Handle:menu)
{
	decl String:user_id[12];
	decl String:name[MAX_NAME_LENGTH];
	decl String:display[MAX_NAME_LENGTH+15];
    
	for (new i = 1; i <= MaxClients; i++)
	{
        if (IsClientInGame(i) && IsPlayerAlive(i))
		{
			IntToString(GetClientUserId(i), user_id, sizeof(user_id));
				
			GetClientName(i, name, sizeof(name));
				
			Format(display, sizeof(display), "%s (%s)", name, user_id);
				
			AddMenuItem(menu, user_id, display);
		}
	}
}

public Menu_CheckTueur(Handle:menu, MenuAction:action, client, param2)
{
	if (action == MenuAction_Select)
	{
		new String:info[64];
        
		GetMenuItem(menu, param2, info, sizeof(info));
		
		new UserID = StringToInt(info);
		cible[client] = GetClientOfUserId(UserID);
		
		new Handle:menub = CreateMenu(Menu_CibleChoose);
		SetMenuTitle(menub, "Voulez-vous un contrat sur %N à 800€ ?", cible[client]);
		AddMenuItem(menub, "oui", "Oui, sans pitier !");
		AddMenuItem(menub, "non", "Non, merci.");
		DisplayMenu(menub, acheteur[client], MENU_TIME_FOREVER);
	}
	else if (action == MenuAction_End)
	{
		CloseHandle(menu);
	}
}

public Menu_CibleChoose(Handle:menu, MenuAction:action, client, param2)
{
	if (action == MenuAction_Select)
	{
		new String:info[64];
		GetMenuItem(menu, param2, info, sizeof(info));
		
		if (StrEqual(info, "oui"))
		{
			new Money = GetEntProp(client, Prop_Send, "m_iAccount");
			new Money2 = GetEntProp(TransactionWith[client], Prop_Send, "m_iAccount");
		
			if(Money >= 800)
			{
				if (cible[TransactionWith[client]] != TransactionWith[client])
				{
					if (cible[TransactionWith[client]] != client)
					{
						PrintToChat(TransactionWith[client], "%s Le client %N a accepté le contrat.", LOGO, client); 
						PrintToChat(client, "%s Achat réalisé avec succès.", LOGO); 
						
						SetEntProp(client, Prop_Send, "m_iAccount", Money -800);
						SetEntProp(TransactionWith[client], Prop_Send, "m_iAccount", Money2 +400);
						
						Contrat[TransactionWith[client]] = CreateTimer(1.0, UpdateContrat, client, TIMER_REPEAT);
						
						GiveItem(TransactionWith[client]);
					}
					else
					{
						PrintToChat(client, "%s Vous ne pouvez pas choisir vous même.", LOGO);
					}
				}
				else
				{
					PrintToChat(TransactionWith[client], "%s Vous ne pouvez pas choisir vous même.", LOGO);
				}
			}
			else
			{
					PrintToChat(client, "%s Vous n'avez pas assez d'argent de poche.", LOGO);
					PrintToChat(TransactionWith[client], "%s Le joueur n'a pas assez d'argent de poche.", LOGO);
			}
		}
		else if (StrEqual(info, "non")) 
		{ 
			PrintToChat(TransactionWith[client], "%s Le client %N a refusé le contrat.", LOGO, client); 
		} 
	}
	else if (action == MenuAction_End)
	{
		CloseHandle(menu);
	}
}

public Action:UpdateContrat(Handle:timer, any:client)
{
	if(IsClientConnected(client))
	{
		if (IsClientConnected(cible[client]))
		{
			if (IsPlayerAlive(client))
			{
				oncontrat[client] = true;
				oncontrat[cible[client]] = true;
				
				//
				new Float:tueur_vec[3], Float:cible_vec[3];
 
				GetClientAbsOrigin(client, tueur_vec);
				GetClientAbsOrigin(cible[client], cible_vec);
				tueur_vec[2] += 40.0;
				cible_vec[2] += 40.0;

				TE_SetupBeamPoints(tueur_vec, cible_vec, g_BeamSprite, g_HaloSprite, 0, 1, 1.0, 10.0, 10.0, 1, 1.0, {255, 0, 0, 255}, 1);
				TE_SendToClient(client, 0.0);
				//
				
				if (HasKillCible[client])
				{
					fincontrat(client);
							
					PrintToChat(client, "%s Vous avez réussi votre contrat sur %N.", LOGO, cible[client]);
					PrintToChat(TransactionWith[client], "%s Le tueur %N a réussi son contrat sur %N !", LOGO, client, cible[client]);
				}
			}
			else
			{
				fincontrat(client);
				
				PrintToChat(client, "%s Vous vous êtes fait tuer durant votre contrat, contrat échoué.", LOGO);
				PrintToChat(TransactionWith[client], "%s Le tueur %N a échoué son contrat sur %N !", LOGO, client, cible[client]);
			}
		}
		else
		{
			fincontrat(client);
			
			PrintToChat(client, "%s Votre cible s'est déconnectée, contrat échoué.", LOGO);
			PrintToChat(TransactionWith[client], "%s Le tueur %N a échoué son contrat sur %N !", LOGO, client, cible[client]);
		}
	}
	else
	{
		fincontrat(client);
		PrintToChat(TransactionWith[client], "%s Le tueur %N a échoué son contrat sur %N !", LOGO, client, cible[client]);
	}
	return Plugin_Handled;
}
Misterpown is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 06-23-2013 , 09:33   Re: [CS:S] Problem plugin: Client index 0 is invalid
Reply With Quote #6

Change

PHP Code:
if (IsClientConnected(cible[client])) 
to

PHP Code:
if (cible[client] > && IsClientConnected(cible[client])) 
Edit: Also passing client indexes to asynchronous callbacks (eg.: timers) is not good.
You should convert to a userId first.
Reason: Clients can disconnect and then another player can takeover the same index.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 06-23-2013 at 09:37.
berni is offline
Misterpown
Senior Member
Join Date: Jan 2011
Old 06-23-2013 , 09:42   Re: [CS:S] Problem plugin: Client index 0 is invalid
Reply With Quote #7

Thx I try this.

Can you give me this code change if you do not mind for this :
Code:
Edit: Also passing client indexes to asynchronous callbacks (eg.: timers) is not good.
You should convert to a userId first.
Reason: Clients can disconnect and then another player can takeover the same index.
Misterpown is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 06-23-2013 , 09:48   Re: [CS:S] Problem plugin: Client index 0 is invalid
Reply With Quote #8

Change this line:
PHP Code:
Contrat[TransactionWith[client]] = CreateTimer(1.0UpdateContratclientTIMER_REPEAT); 
to:
PHP Code:
Contrat[TransactionWith[client]] = CreateTimer(1.0UpdateContratGetClientUserId(client), TIMER_REPEAT); 
And change the beginning of the UpdateContrat callback to this:
PHP Code:
public Action:UpdateContrat(Handle:timerany:userid) {
    new 
client GetClientOfUserId(client);

    if (
client && IsClientConnected(client)) {
... 
bl4nk is offline
Misterpown
Senior Member
Join Date: Jan 2011
Old 06-23-2013 , 10:10   Re: [CS:S] Problem plugin: Client index 0 is invalid
Reply With Quote #9

Thx but now I have new flood server and the laser between the tueur_vec and cible_vec don't work

Code:
L 06/23/2013 - 16:09:16: [SM] Native "IsClientInGame" reported: Client index 0 is invalid
L 06/23/2013 - 16:09:16: [SM] Displaying call stack trace for plugin "tueur.smx":
L 06/23/2013 - 16:09:16: [SM]   [0]  Line 292, tueur.sp::fincontrat()
L 06/23/2013 - 16:09:16: [SM]   [1]  Line 284, tueur.sp::UpdateContrat()
Plugin:

Code:
public Action:OnClientPreAdminCheck(client)
{
	oncontrat[client] = false;
}

public Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	new killer = GetClientOfUserId(GetEventInt(event, "attacker"));
	
	if (killer > 0)
	{
		if (IsClientInGame(killer))
		{
			if (killer != client)
			{
				if (oncontrat[killer])
				{
					HasKillCible[killer] = true;
				}
			}	
		}	
	}
}

public OnClientDisconnect(client)
{
	if (IsClientInGame(client))
	{
		HasKillCible[client] = false;
		oncontrat[client] = false;
	}
}

public Action:Command_Contrat(client, Args)
{
	if (IsClientInGame(client))
	{
		if (IsPlayerAlive(client))
		{
			decl String:model[256];
			GetClientModel(client, model, sizeof(model));
	
			if (strcmp(tueurskin, model, false) ==0)
			{
				acheteur[client] = GetClientAimTarget(client, true);
				TransactionWith[acheteur[client]] = client;
				TransactionWith[client] = acheteur[client];
				
				if (acheteur[client] != -1)
				{
					if (!oncontrat[client])
					{
						if (IsPlayerAlive(acheteur[client]))
						{
							if (!oncontrat[acheteur[client]])
							{
								CheckTueur(client);
							}
							else
							{
								PrintToChat(client, "%s Le joueur %N est déjà en contrat.", LOGO, TransactionWith[client]);
							}
						}
						else
						{
							PrintToChat(client, "%s Le joueur %N est mort.", LOGO, TransactionWith[client]);
						}
					}
					else
					{
							PrintToChat(client, "%s Vous êtes déjà en contrat.", LOGO);
					}
				}
				else
				{
					PrintToChat(client, "%s Vous devez viser un joueur.", LOGO);
				}
			}
			else
			{
				PrintToChat(client, "%s Vous n'avez pas accès à cette commande.", LOGO);
			}
		}
		else
		{
			PrintToChat(client, "%s Vous devez être en vie.", LOGO);
		}
	}
}

CheckTueur(client)
{
	if(client > 0 && client <= MaxClients && !IsFakeClient(client))
	{
		decl String:sMenuText[64];
		sMenuText[0] = '\0';
        
		new Handle:menu = CreateMenu(Menu_CheckTueur);
		SetMenuTitle(menu, "Choisissez le joueur :");
		SetMenuExitButton(menu, true);
        
		AddCible(menu);
        
		DisplayMenu(menu, client, MENU_TIME_FOREVER);
	}
}

public AddCible(Handle:menu)
{
	decl String:user_id[12];
	decl String:name[MAX_NAME_LENGTH];
	decl String:display[MAX_NAME_LENGTH+15];
    
	for (new i = 1; i <= MaxClients; i++)
	{
        if (IsClientInGame(i) && IsPlayerAlive(i))
		{
			IntToString(GetClientUserId(i), user_id, sizeof(user_id));
				
			GetClientName(i, name, sizeof(name));
				
			Format(display, sizeof(display), "%s (%s)", name, user_id);
				
			AddMenuItem(menu, user_id, display);
		}
	}
}

public Menu_CheckTueur(Handle:menu, MenuAction:action, client, param2)
{
	if (action == MenuAction_Select)
	{
		new String:info[64];
        
		GetMenuItem(menu, param2, info, sizeof(info));
		
		new UserID = StringToInt(info);
		cible[client] = GetClientOfUserId(UserID);
		
		new Handle:menub = CreateMenu(Menu_CibleChoose);
		SetMenuTitle(menub, "Voulez-vous un contrat sur %N à 800€ ?", cible[client]);
		AddMenuItem(menub, "oui", "Oui, sans pitier !");
		AddMenuItem(menub, "non", "Non, merci.");
		DisplayMenu(menub, acheteur[client], MENU_TIME_FOREVER);
	}
	else if (action == MenuAction_End)
	{
		CloseHandle(menu);
	}
}

public Menu_CibleChoose(Handle:menu, MenuAction:action, client, param2)
{
	if (action == MenuAction_Select)
	{
		new String:info[64];
		GetMenuItem(menu, param2, info, sizeof(info));
		
		if (StrEqual(info, "oui"))
		{
			new Money = GetEntProp(client, Prop_Send, "m_iAccount");
			new Money2 = GetEntProp(TransactionWith[client], Prop_Send, "m_iAccount");
		
			if(Money >= 800)
			{
				if (cible[TransactionWith[client]] != TransactionWith[client])
				{
					if (cible[TransactionWith[client]] != client)
					{
						PrintToChat(TransactionWith[client], "%s Le client %N a accepté le contrat.", LOGO, client); 
						PrintToChat(client, "%s Achat réalisé avec succès.", LOGO); 
						
						SetEntProp(client, Prop_Send, "m_iAccount", Money -800);
						SetEntProp(TransactionWith[client], Prop_Send, "m_iAccount", Money2 +400);
						
						Contrat[TransactionWith[client]] = CreateTimer(1.0, UpdateContrat, GetClientUserId(client), TIMER_REPEAT); 
						
						GiveItem(TransactionWith[client]);
					}
					else
					{
						PrintToChat(client, "%s Vous ne pouvez pas choisir vous même.", LOGO);
					}
				}
				else
				{
					PrintToChat(TransactionWith[client], "%s Vous ne pouvez pas choisir vous même.", LOGO);
				}
			}
			else
			{
					PrintToChat(client, "%s Vous n'avez pas assez d'argent de poche.", LOGO);
					PrintToChat(TransactionWith[client], "%s Le joueur n'a pas assez d'argent de poche.", LOGO);
			}
		}
		else if (StrEqual(info, "non")) 
		{ 
			PrintToChat(TransactionWith[client], "%s Le client %N a refusé le contrat.", LOGO, client); 
		} 
	}
	else if (action == MenuAction_End)
	{
		CloseHandle(menu);
	}
}

public Action:UpdateContrat(Handle:timer, any:userid)
{
    new client = GetClientOfUserId(client);

    if (client && IsClientConnected(client)) 
	{
	
		if (cible[client] > 0 && IsClientConnected(cible[client]))
		{
			if (IsPlayerAlive(client))
			{
				oncontrat[client] = true;
				oncontrat[cible[client]] = true;
				
				//
				new Float:tueur_vec[3], Float:cible_vec[3];
 
				GetClientAbsOrigin(client, tueur_vec);
				GetClientAbsOrigin(cible[client], cible_vec);
				tueur_vec[2] += 40.0;
				cible_vec[2] += 40.0;

				TE_SetupBeamPoints(tueur_vec, cible_vec, g_BeamSprite, g_HaloSprite, 0, 1, 1.0, 10.0, 10.0, 1, 1.0, {255, 0, 0, 255}, 1);
				TE_SendToClient(client, 0.0);
				//
				
				if (HasKillCible[client])
				{
					fincontrat(client);
							
					PrintToChat(client, "%s Vous avez réussi votre contrat sur %N.", LOGO, cible[client]);
					PrintToChat(TransactionWith[client], "%s Le tueur %N a réussi son contrat sur %N !", LOGO, client, cible[client]);
				}
			}
			else
			{
				fincontrat(client);
				
				PrintToChat(client, "%s Vous vous êtes fait tuer durant votre contrat, contrat échoué.", LOGO);
				PrintToChat(TransactionWith[client], "%s Le tueur %N a échoué son contrat sur %N !", LOGO, client, cible[client]);
			}
		}
		else
		{
			fincontrat(client);
			
			PrintToChat(client, "%s Votre cible s'est déconnectée, contrat échoué.", LOGO);
			PrintToChat(TransactionWith[client], "%s Le tueur %N a échoué son contrat sur %N !", LOGO, client, cible[client]);
		}
	}
	else
	{
		fincontrat(client);
		PrintToChat(TransactionWith[client], "%s Le tueur %N a échoué son contrat sur %N !", LOGO, client, cible[client]);
	}
	return Plugin_Handled;
}

public fincontrat(client)
{
	if (IsClientInGame(client))
	{
		if (Contrat[client] != INVALID_HANDLE)
		{
			KillTimer(Contrat[client]);
			Contrat[client] = INVALID_HANDLE;
		}
		
		oncontrat[client] = false;
		oncontrat[cible[client]] = false;
		HasKillCible[client] = false;
		
		GivePlayerItem(client, "weapon_knife");
		SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", 1.0);
		SetEntityGravity(client, 1.0);
		SetEntityHealth(client, 100);
	}
}
Misterpown is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 06-23-2013 , 10:19   Re: [CS:S] Problem plugin: Client index 0 is invalid
Reply With Quote #10

Change this:
PHP Code:
    else
    {
        
fincontrat(client);
        
PrintToChat(TransactionWith[client], "%s Le tueur %N a échoué son contrat sur %N !"LOGOclientcible[client]);
    } 
To this:
PHP Code:
    else if (client)
    {
        
fincontrat(client);
        
PrintToChat(TransactionWith[client], "%s Le tueur %N a échoué son contrat sur %N !"LOGOclientcible[client]);
    } 
bl4nk is offline
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 14:43.


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