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

PrintToChat - Client index 0 is invalid


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-02-2010 , 01:18   PrintToChat - Client index 0 is invalid
Reply With Quote #1

I thought I'd try my hand at coding, so I attempted to make the simplest possible command. Type "/test", it prints "Hello world!" in chat. I was wondering if there is some idiots solution to this, because obviously I did something wrong. Any help would be greatly appreciated. When I type it, I go ingame, select create game, start off of de_dust2, and type.

Code:
public OnPluginStart()
{
    RegConsoleCmd("say", Command_Say)
}
 
public Action:Command_Say(client, args)
{
    new String:text[192]
    GetCmdArgString(text, sizeof(text))
 
    new startidx = 0
    if (text[0] == '"')
    {
        startidx = 1
        /* Strip the ending quote, if there is one */
        new len = strlen(text);
        if (text[len-1] == '"')
        {
            text[len-1] = '\0'
        }
    }
 
    if (StrEqual(text[startidx], "/test"))
    {
        PrintToChat(client, "Hello world!")
        /* Block the client's messsage from broadcasting */
        return Plugin_Handled
    }
 
    /* Let say continue normally */
    return Plugin_Continue
}
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]

Last edited by Tirant; 09-02-2010 at 01:25.
Tirant is offline
rcarm
Member
Join Date: Feb 2010
Old 09-02-2010 , 01:59   Re: PrintToChat - Client index 0 is invalid
Reply With Quote #2

You're getting that error because you're testing the plugin on a listen server.

An easier way to do it would be

PHP Code:
public OnPluginStart()
{
    
RegConsoleCmd("test"Command_Test);
}

public 
Action:Command_Test(clientargs)
{
    
PrintToChat(client"Hello World");

    return 
Plugin_Handled;

This will print "Hello World" when you type 'test' in console, '!test' or '/test' in chat.
rcarm is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-02-2010 , 02:10   Re: PrintToChat - Client index 0 is invalid
Reply With Quote #3

Is there a way to test plugins on a listen server? or i that not possible with source? What you wrote was what I originally had, I couldn't get it to work, so I found the code above and tried that with the same error. Thanks for the help.
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]
Tirant is offline
Lord Canistra
Senior Member
Join Date: Mar 2009
Location: Tallinn, Estonia
Old 09-02-2010 , 02:20   Re: PrintToChat - Client index 0 is invalid
Reply With Quote #4

Why not test them on dedicated server? It's a target destination of most plugins anyway. This way you'll get the clearest view of how your plugin will behave on a real server.
__________________
Lord Canistra is offline
retsam
Veteran Member
Join Date: Aug 2008
Location: so-cal
Old 09-02-2010 , 02:43   Re: PrintToChat - Client index 0 is invalid
Reply With Quote #5

You should never use a listen server....ever.

Plugins are usually coded to filter out client = 0 so.....its never smart to use a listen server. Use dedicated servers....
__________________
retsam is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 09-02-2010 , 03:52   Re: PrintToChat - Client index 0 is invalid
Reply With Quote #6

It's just easier, I guess I'll install a dedicated server now. Thank for you help guys (or girls).
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]
Tirant is offline
dirka_dirka
Veteran Member
Join Date: Nov 2009
Old 09-02-2010 , 10:44   Re: PrintToChat - Client index 0 is invalid
Reply With Quote #7

its easier, but.. as you just experienced, client 0 is invalid for many functions.

also, unless your running purely on a listen server (never join a another server) - having sourcemod installed locally could get you kicked.. it will on my server.

also "say" is an existing command.. dont RegConsoleCmd it. use AddCmdListener
and unless your intercepting the messages for a reason, its better to do what rcarm says
dirka_dirka is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 09-02-2010 , 18:36   Re: PrintToChat - Client index 0 is invalid
Reply With Quote #8

1.) You don't create commands with Hooking say, you are better adviced to register commands as "sm_commandname", / triggers are automatically created by sourcemod then.
2.) You use ReplyToCommand instead of PrintToChat, ReplyToCommand automatically responds in the right place (chat, console, Server Console) and also works for client 0 or the server.
__________________
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
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 09-03-2010 , 13:03   Re: PrintToChat - Client index 0 is invalid
Reply With Quote #9

Quote:
Originally Posted by retsam View Post
You should never use a listen server....ever.

Plugins are usually coded to filter out client = 0 so.....its never smart to use a listen server. Use dedicated servers....
You should always make sure your Plugins run on listen servers. Because if you don't, people will keep reporting "bugs" related to 0 client errors.
AtomicStryker is offline
retsam
Veteran Member
Join Date: Aug 2008
Location: so-cal
Old 09-03-2010 , 13:05   Re: PrintToChat - Client index 0 is invalid
Reply With Quote #10

Quote:
Originally Posted by AtomicStryker View Post
You should always make sure your Plugins run on listen servers. Because if you don't, people will keep reporting "bugs" related to 0 client errors.

Huh? No. No plugins should ever be coded to support listen servers. And there will be no errors if the plugin is coded properly.
__________________
retsam 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 05:26.


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