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

Loading sentences from file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 07-01-2017 , 20:26   Loading sentences from file
Reply With Quote #1

Hi, I've simple code:
PHP Code:
#include <sourcemod>
#include <scp>
#include <sourcecomms>
#include <csgocolors>

#define MAX_WORDS 1024

char words[MAX_WORDS][512];
int listlen;

public 
void OnPluginStart()
{
    
LoadList();
    
RegConsoleCmd("sm_print", print);
    
    
AddCommandListener(ChatListener"say");
    
AddCommandListener(ChatListener"say2");
    
AddCommandListener(ChatListener"say_team");
}

public 
Action print(int clientint args)
{
    for(
int i 0listleni++)
    {
        
PrintToChat(client"%s"words[i]);
    }
}

public 
Action ChatListener(int client, const char[] commandint argc)
{
    
char Message[256];
    
char out[1024];
        
    
GetCmdArgString(Messagesizeof(Message));
    
StripQuotes(Message);
    
    
    for(
int i 0listleni++)
    {
        
PrintToChat(client"-%s-%s-"Messagewords[i]);
        if(
StrContains(Messagewords[i]) != -1)
        {
            
//do something
        
}
    }
    
    return 
Plugin_Continue;
}

public 
void LoadList()
{
    
char path[PLATFORM_MAX_PATH];
    
BuildPath(PathType Path_SMpathsizeof(path), "configs/zakazaneslowa.txt");
    
    
File file OpenFile(path"r");
    if(
file == INVALID_HANDLE)
    {
        
SetFailState("Unable to read file %s"path);
    }
    
    
listlen 0;
    
char word[256];
    while(!
IsEndOfFile(file) && ReadFileLine(filewordsizeof(word)))
    {
        
        
int len strlen(word);
        for (
int ileni++)
        {
            if (
IsCharSpace(word[i]))
            {
                
word[i] = '\0';
                break;
            }
        }
        
        
        
words[listlen] = word;
        
listlen++;
    }
    
    
delete file;

It's loading bad words from file, and on player message it's checking that in sentence exsist this bad word. It's working ok, but I can't add setences to file, for example "test test2", because this:
PHP Code:
            if (IsCharSpace(word[i]))
            {
                
word[i] = '\0';
                break;
            } 
limit this string to word test. If I delete it from loading words, it will load sentences ok, but StrContains can't find properly these words, only the last from file.
__________________


Max-Play.pl - the best polish servers

Last edited by CamerDisco; 07-01-2017 at 20:36.
CamerDisco is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 07-01-2017 , 21:07   Re: Loading sentences from file
Reply With Quote #2

Your file has newlines in it since you say it's multiple lines. If you use your code with the IsCharSpace check, it removes them. Your last line probably doesn't have a newline in it.

You need to remove newlines since you don't want to check for it with StrContains.
Fyren is offline
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 07-02-2017 , 05:49   Re: Loading sentences from file
Reply With Quote #3

Thanks fyren,

PHP Code:
ReplaceString(wordsizeof(word), "\n"""true); 
__________________


Max-Play.pl - the best polish servers

Last edited by CamerDisco; 07-02-2017 at 05:54.
CamerDisco is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 07-02-2017 , 07:08   Re: Loading sentences from file
Reply With Quote #4

Quote:
Originally Posted by CamerDisco View Post
PHP Code:
AddCommandListener(ChatListener"say");
AddCommandListener(ChatListener"say2");
AddCommandListener(ChatListener"say_team"); 
Oh man... Why not use OnClientSayCommand_Post?
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 07-02-2017 , 08:05   Re: Loading sentences from file
Reply With Quote #5

Quote:
Originally Posted by KissLick View Post
Oh man... Why not use OnClientSayCommand_Post?
Lol thanks, I didn't know this forward
__________________


Max-Play.pl - the best polish servers
CamerDisco is offline
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 07-02-2017 , 11:02   Re: Loading sentences from file
Reply With Quote #6

I thought this:
PHP Code:
 ReplaceString(wordsizeof(word), "\n"""true); 
fixed my problem, but it works only on my test server at windows, on my normal server at linux it still doesn't work.
Any ideas?

@Edit
PHP Code:
 ReplaceString(wordsizeof(word), "\r"""true); 
fixed this problem on linux
__________________


Max-Play.pl - the best polish servers

Last edited by CamerDisco; 07-02-2017 at 11:09.
CamerDisco 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 20:31.


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