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

[HELP] Get Message sent by client to chat


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 04-21-2019 , 12:19   [HELP] Get Message sent by client to chat
Reply With Quote #1

Hey guys.

I tried to get message sent to chat by client to develop a new plugin but it is not working.

PHP Code:
public Plugin myinfo 
{
    
name "Get Message Sent To Chat By Client",
    
author PLUGIN_AUTHOR,
    
description "Get message sent to chat by client after executing the command",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_msg"Command_Message);
}

public 
Action Command_Message(int clientint args)
{
    
PrintToChat(client"Send Something to chat!");
    
char MessageFromClient[512];
    
    
GetCmdArgString(MessageFromClientsizeof(MessageFromClient));
    
char path[512];
    
BuildPath(Path_SMpathsizeof(path), "configsadd_to_server_file1.txt");
    if (
FileExists(path))
    {
        
Handle file OpenFile(path"a");
        
WriteFileLine(file"\"%N\" \"%s\""clientMessageFromClient);
        
CloseHandle(file);
        
PrintToServer("[Idea Adder] A new idea was added to '%s' by %N"pathclient);
        
PrintToChat(client"[Idea Adder] Your idea was sent to the server Owner!");
        return 
Plugin_Handled;
    }
    return 
Plugin_Handled;

It compiles without any errors or warnings but it does not create file and even does not send message to the server console and to client chat after client sending a message after executing the command.

How can I fix this?
__________________
SpirT is offline
cristian20042
AlliedModders Donor
Join Date: Jun 2016
Location: Romania
Old 04-21-2019 , 12:40   Re: [HELP] Get Message sent by client to chat
Reply With Quote #2

PHP Code:
BuildPath(Path_SMpathsizeof(path), "configsadd_to_server_file1.txt"); 
maybe you should do

PHP Code:
BuildPath(Path_SMpathsizeof(path), "configs/add_to_server_file1.txt"); 
You could also improve this:

PHP Code:
WriteFileLine(file"Player %N requested an Idea: %s"clientMessageFromClient); 
And I also can't see you creating the file before.
__________________
Steam - https://steamcommunity.com/id/sniperheroofficialu/
Discord - SniperHero#8545

Last edited by cristian20042; 04-21-2019 at 12:45.
cristian20042 is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 04-22-2019 , 07:14   Re: [HELP] Get Message sent by client to chat
Reply With Quote #3

Quote:
Originally Posted by cristian20042 View Post
PHP Code:
BuildPath(Path_SMpathsizeof(path), "configsadd_to_server_file1.txt"); 
maybe you should do

PHP Code:
BuildPath(Path_SMpathsizeof(path), "configs/add_to_server_file1.txt"); 
You could also improve this:

PHP Code:
WriteFileLine(file"Player %N requested an Idea: %s"clientMessageFromClient); 
And I also can't see you creating the file before.
Hey, thanks for your reply!
I tried that but when I just do !msg it sends this to the file:
Code:
The Player SpirT sent this idea:
Else if I do "!msg This is a test"
Code:
I tried that but when I just do !msg it sends this to the file: This is a test"
Is there any way to it like waits for the player send message after executing command??
__________________
SpirT is offline
cristian20042
AlliedModders Donor
Join Date: Jun 2016
Location: Romania
Old 04-22-2019 , 08:14   Re: [HELP] Get Message sent by client to chat
Reply With Quote #4

Good news, I made it to work and improved it a little.

Here it is:

Spoiler


The file is going to be created inside data -> ideas -> server_ideas.txt
The new command is !idea.
Now it checks if the string is empty also!
__________________
Steam - https://steamcommunity.com/id/sniperheroofficialu/
Discord - SniperHero#8545

Last edited by cristian20042; 04-22-2019 at 14:32.
cristian20042 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:48.


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