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

VFormat and any:... Not Working


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Spirrwell
Member
Join Date: Jul 2013
Old 11-19-2014 , 06:43   VFormat and any:... Not Working
Reply With Quote #1

Hi! What I'm trying to do is create a PrintCenterTextAll type function that omits a given client, and for the sake of getting to the point, here is that function:

Code:
PrintCenterTextOmit(omitClient, const String:format[], any:...)
{
	new String:formattedString[strlen(format) + 255];
	VFormat(formattedString, sizeof(formattedString), format, 3);
	for (new i = 0; i < MaxClients; i++)
	{
		if (IsValidClient(i) && i != omitClient)
		{
			PrintCenterText(i, formattedString);
			//PrintCenterText(i, "Blablabla");
		}
	}
}
By setting omitClient to -1, this function should behave just like PrintCenterTextAll. And it works just like it's supposed to, as you can see in the commented out line I tested it to make sure it filters the client properly.

However the issue seems to be with formatting the string using the any:... parameter. I do get a warning with VFormat: warning 224: indeterminate array size in "sizeof" expression (symbol "")

Basically, when I use: PrintCenterText(i, formattedString);

it prints nothing.

If I use formattedString[512], it works just fine. So the issue is in using strlen and as the warning specifies, the length seems to be indeterminable. However, I followed the guide here on the wiki:

https://wiki.alliedmods.net/Format_C...n_Format-Class

So why doesn't it work?
Spirrwell is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 11-19-2014 , 08:37   Re: VFormat and any:... Not Working
Reply With Quote #2

sizeof doesn't work with non-constant-sized arrays.

PHP Code:
new length strlen(format) + 255;
new 
String:formattedString[length];
VFormat(formattedStringlengthformat3); 
__________________
asherkin is offline
Spirrwell
Member
Join Date: Jul 2013
Old 11-19-2014 , 09:19   Re: VFormat and any:... Not Working
Reply With Quote #3

Oh I see, you pass the length directly, I actually did the same thing creating the string with a length that I stored in variable. But I never passed it to VFormat directly. Thanks!
Spirrwell is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-19-2014 , 11:31   Re: VFormat and any:... Not Working
Reply With Quote #4

Quote:
Originally Posted by Spirrwell View Post
---

Code:
PrintCenterTextOmit(omitClient, const String:format[], any:...)
{
	new String:formattedString[strlen(format) + 255];
	VFormat(formattedString, sizeof(formattedString), format, 3);
	for (new i = 0; i < MaxClients; i++)
	{
		if (IsValidClient(i) && i != omitClient)
		{
			PrintCenterText(i, formattedString);
			//PrintCenterText(i, "Blablabla");
		}
	}
}
---
Fix this also.
- Valid client indexs start from 1, not 0 (server/console).
- And get message work for very final client index on server (i <= MaxClients)

Code:
PrintCenterTextOmit(omitClient, const String:format[], any:...)
{
	---
	---
	for (new i = 1; i <= MaxClients; i++)
	{
		if (IsClientInGame(i) && !IsFakeClient(i) && i != omitClient)
		{
			PrintCenterText(i, formattedString);
			//PrintCenterText(i, "Blablabla");
		}
	}
}
Bacardi is offline
Spirrwell
Member
Join Date: Jul 2013
Old 11-19-2014 , 12:09   Re: VFormat and any:... Not Working
Reply With Quote #5

Oh thank you! But as for that if check, I borrowed the IsValidClient() function from the saysounds plugin.

Code:
public IsValidClient (client)
{
	if (client <= 0 || client > MaxClients || !IsClientConnected(client) || IsFakeClient(client) || IsClientReplay(client) || IsClientSourceTV(client))
		return false;

	return IsClientInGame(client);
}
Edit: Guess I should've paid attention to the <= 0 in that function, heh.

Last edited by Spirrwell; 11-19-2014 at 12:13.
Spirrwell is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-19-2014 , 12:26   Re: VFormat and any:... Not Working
Reply With Quote #6

Quote:
Originally Posted by Spirrwell View Post
Oh thank you! But as for that if check, I borrowed the IsValidClient() function from the saysounds plugin.

Code:
public IsValidClient (client)
{
	if (client <= 0 || client > MaxClients || !IsClientConnected(client) || IsFakeClient(client) || IsClientReplay(client) || IsClientSourceTV(client))
		return false;

	return IsClientInGame(client);
}
yeap, I have seen those kinds "stocks".

Some of those just unnecessary...
Like if you want that player IsClientInGame(client), you not need check IsClientConnected(client), it obviously connected if in game.
So use either of those for own purpose (client spawned in game or client connecting to server, not in game).

Another is IsFakeClient(client), SourceTV and Reply are bots also.

Anyway, that function works, when you know what it will filter out.
Bacardi 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 23:28.


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