Raised This Month: $32 Target: $400
 8% 

Read 2 strings from a plain text files


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 07-16-2018 , 14:13   Read 2 strings from a plain text files
Reply With Quote #1

I wanted to make a plugin that when an vip or an admin(ADMFLAG_BAN) types a word to emit a sount to all players, just if the word is the same from an .cfg file from configs/

Just like saysound but with a simpler configuration.

.cfg file format:
Code:
rekt */sank/rekt.mp3
rekt = the trigger word
*/sank/rekt.mp3 = the directory file

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <vip_core>

char Sound_File_Directory[PLATFORM_MAX_PATH],
     
Buffers[2][128];

public 
void OnPluginStart()
{
    
RegConsoleCmd("say"OnSay);
}

void _PlaySound(int Clientchar[] Sound, \
                                        
float Volume 1.0)
{
    
EmitSoundToClient(ClientSound____Volume);
}

public 
Action OnSay(int Clientint Args)
{
    
char Arg[128];
    
GetCmdArgString(Argsizeof(Arg));
    
    if(
VIP_IsClientVIP(Client) == true)
    {
        if(
strcmp(Buffers[0], Arg) == 0)
        {
            
_PlaySound(ClientBuffers[1]);
        }
    }
}


public 
void OnMapStart()
{
    
LoadSounds();
}

public 
LoadSounds()
{
    static 
char Config_File_Path[PLATFORM_MAX_PATH 4], \ 
                
Config_File_Line[64];
                
    
int Size;
                
    static 
Handle pFile INVALID_HANDLE;
    
BuildPath(Path_SMConfig_File_Pathsizeof(Config_File_Path), "configs/sank_sounds.cfg");
    
pFile OpenFile(Config_File_Path"r");
    
    while (!
IsEndOfFile(pFile) && \
                
ReadFileLine(pFileConfig_File_Linesizeof(Config_File_Line)))
                {


                    
//for comments
        
if (strlen(Buffers[1]) < || strcmp(Buffers[1], ";") == || strcmp(Buffers[1], "#") == || \
            (
strcmp(Buffers[1], "//") == 0))
        {
            continue;
        } 
            
        
TrimString(Config_File_Line);

        
        
Size ExplodeString(Config_File_Line" "Bufferssizeof(Buffers), sizeof(Buffers[]));
        
        
//
        //Buffers[0] = sank sounds aka triggered word
        //Buffers[1] = directory
        //
        
        
if(Size 2)
        {
            
ReplaceString(Buffers[0], sizeof(Buffers[]), "|"" "); // word rekt|son .. in chat rekt son
            
                
ReplaceString(Buffers[1], sizeof(Buffers[]), "|"" ");
                
                
FormatEx(Sound_File_Directorysizeof(Sound_File_Directory), Buffers[1]);
                
ReplaceString(Sound_File_Directorysizeof(Sound_File_Directory), "*""sound/");

                if (!
FileExists(Sound_File_Directory))
                {
                    
LogError("Invalid Sank Sound Entry [Sound Key (\"%s\")] [Sound File (\"%s\")] - Sound File Could Not Be Found And Pre-Cached!", \
                                
Buffers[0], Sound_File_Directory);
                }
        }

        
        
AddFileToDownloadsTable(Sound_File_Directory);    
    }

if someone would help me it would be great

Last edited by kratoss1812; 07-16-2018 at 14:15.
kratoss1812 is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 07-16-2018 , 15:30   Re: Read 2 strings from a plain text files
Reply With Quote #2

I would "multi-dimension" the string, then we can check the different arguments and their order in the cfg file.

If I were you, I would still use KeyValues.

I also highly doubt this will even work, not tested also:

PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1

public Action OnClientSayCommand(int iClient, const char[] sCommand, const char[] sArgs)
{
    if (
CheckCommandAccess(iClient""ADMFLAG_CUSTOM6))
    {
        
char sPath[PLATFORM_MAX_PATH], sLine[2][256];
        
        
BuildPath(Path_SMsPathsizeof(sPath), "configs/smth.cfg");
        
        
Handle hFile OpenFile(sPath"r");
        
        if (
StrContains(sArgs"rekt"))
        {
            while (!
IsEndOfFile(hFile) && ReadFileLine(hFilesLine[0], sizeof(sLine)))
            {
                if (
StrContains(sLine[0], "rekt"))
                {
                    
AddFileToDownloadsTable(sLine[1]);
                    
                    
PrecacheSound(sLine[1]);
                    
                    
EmitSoundToClient(iClientsLine[1]);
                }
            }
        }
    }

mug1wara is offline
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 07-16-2018 , 17:10   Re: Read 2 strings from a plain text files
Reply With Quote #3

Quote:
Originally Posted by mug1wara View Post
I would "multi-dimension" the string, then we can check the different arguments and their order in the cfg file.

If I were you, I would still use KeyValues.

I also highly doubt this will even work, not tested also:

PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1

public Action OnClientSayCommand(int iClient, const char[] sCommand, const char[] sArgs)
{
    if (
CheckCommandAccess(iClient""ADMFLAG_CUSTOM6))
    {
        
char sPath[PLATFORM_MAX_PATH], sLine[2][256];
        
        
BuildPath(Path_SMsPathsizeof(sPath), "configs/smth.cfg");
        
        
Handle hFile OpenFile(sPath"r");
        
        if (
StrContains(sArgs"rekt"))
        {
            while (!
IsEndOfFile(hFile) && ReadFileLine(hFilesLine[0], sizeof(sLine)))
            {
                if (
StrContains(sLine[0], "rekt"))
                {
                    
AddFileToDownloadsTable(sLine[1]);
                    
                    
PrecacheSound(sLine[1]);
                    
                    
EmitSoundToClient(iClientsLine[1]);
                }
            }
        }
    }

ok.. but what if I want to check if sArgs = another word that "rekt"? again using the .cfg file

or can you make an code for kv like
Code:
"1"
{
"file" "sanks/rekt.mp3"
"word" "rekt"
}
please
kratoss1812 is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 07-16-2018 , 18:39   Re: Read 2 strings from a plain text files
Reply With Quote #4

First, try the code I sent.

If it's not working, I'll make a new one with KeyValues.

Line 12: Edit the cfg's path.

Should look like this inside of your cfg.

rekt "your/sound/file.mp3"

Last edited by mug1wara; 07-16-2018 at 18:40.
mug1wara is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 07-17-2018 , 08:16   Re: Read 2 strings from a plain text files
Reply With Quote #5

its a SaySound plugin You dont need to use KeyValues.. just parse the song name from the path...
ESK0 is offline
Facksy
Senior Member
Join Date: Apr 2017
Location: +2+2
Old 07-17-2018 , 08:47   Re: Read 2 strings from a plain text files
Reply With Quote #6

This is my simple saysounds plugin:
PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma newdecls required

char KvPath[256];
char hazard_n[256][256];
char hazard_f[256][256];
char hazard_af[256][256];
int iSize;

public 
Plugin myinfo 
{
    
name "Saysounds",
    
author "Facksy",
    
description "Saysounds",
    
version "1.0",
    
url "https://steamcommunity.com/id/iamfacksy/"
}

public 
void OnPluginStart()
{

}

public 
void OnMapStart()
{
    
CheckFiles();
}
 
void CheckFiles()
{
    
char name[256], file[256];
    
BuildPath(Path_SMKvPathsizeof(KvPath), "configs/tf2_saysounds.cfg");
    
Handle DB CreateKeyValues("Saysounds");
    
FileToKeyValues(DBKvPath);

    if(
KvGotoFirstSubKey(DB))
    {
        
int i 0;
        
KvGetString(DB"name"namesizeof(name));
        
KvGetString(DB"file"filesizeof(file));
        
Format(hazard_n[i], 256"%s"name);
        
Format(hazard_f[i], 256"%s"file);
        
        while(
KvGotoNextKey(DB))
        {
            
i++;
            
KvGetString(DB"name"namesizeof(name));
            
KvGetString(DB"file"filesizeof(file));
            
Format(hazard_n[i], 256"%s"name);
            
Format(hazard_f[i], 256"%s"file);
        }
        
iSize i;
    }
    for(
int i 0<= iSizei++)
    {
        
Format(hazard_af[i], 256"sound/%s"hazard_f[i]);
        
        
AddFileToDownloadsTable(hazard_af[i]);
        
PrecacheSound(hazard_f[i]);
    }
}

public 
Action OnClientSayCommand(int client, const char[] command, const char[] sArgs)
{
    for(
int i 0<= iSizei++)
    {
        if(
StrEqual(sArgshazard_n[i], false))
        {
            
EmitSoundToAll(hazard_f[i], client);
        }
    }

And this is my cfg file:
Code:
"Phrase"
{
	"Set"
	{
		"name"		"roar"
                "file"		"facustom/lion.wav"
	}
	"Set"
	{
		"name"		"hello"
                "file"		"facustom/hello.wav"
	}
}
__________________
My Steam I take private requests if related with TF2
My Plugins
Facksy is offline
LenHard
Senior Member
Join Date: Jan 2016
Old 07-18-2018 , 04:58   Re: Read 2 strings from a plain text files
Reply With Quote #7

Quote:
Originally Posted by Facksy View Post
This is my simple saysounds plugin:
PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma newdecls required

char KvPath[256];
char hazard_n[256][256];
char hazard_f[256][256];
char hazard_af[256][256];
int iSize;

public 
Plugin myinfo 
{
    
name "Saysounds",
    
author "Facksy",
    
description "Saysounds",
    
version "1.0",
    
url "https://steamcommunity.com/id/iamfacksy/"
}

public 
void OnPluginStart()
{

}

public 
void OnMapStart()
{
    
CheckFiles();
}
 
void CheckFiles()
{
    
char name[256], file[256];
    
BuildPath(Path_SMKvPathsizeof(KvPath), "configs/tf2_saysounds.cfg");
    
Handle DB CreateKeyValues("Saysounds");
    
FileToKeyValues(DBKvPath);

    if(
KvGotoFirstSubKey(DB))
    {
        
int i 0;
        
KvGetString(DB"name"namesizeof(name));
        
KvGetString(DB"file"filesizeof(file));
        
Format(hazard_n[i], 256"%s"name);
        
Format(hazard_f[i], 256"%s"file);
        
        while(
KvGotoNextKey(DB))
        {
            
i++;
            
KvGetString(DB"name"namesizeof(name));
            
KvGetString(DB"file"filesizeof(file));
            
Format(hazard_n[i], 256"%s"name);
            
Format(hazard_f[i], 256"%s"file);
        }
        
iSize i;
    }
    for(
int i 0<= iSizei++)
    {
        
Format(hazard_af[i], 256"sound/%s"hazard_f[i]);
        
        
AddFileToDownloadsTable(hazard_af[i]);
        
PrecacheSound(hazard_f[i]);
    }
}

public 
Action OnClientSayCommand(int client, const char[] command, const char[] sArgs)
{
    for(
int i 0<= iSizei++)
    {
        if(
StrEqual(sArgshazard_n[i], false))
        {
            
EmitSoundToAll(hazard_f[i], client);
        }
    }

And this is my cfg file:
Code:
"Phrase"
{
	"Set"
	{
		"name"		"roar"
                "file"		"facustom/lion.wav"
	}
	"Set"
	{
		"name"		"hello"
                "file"		"facustom/hello.wav"
	}
}
Why not use ArrayLists? They're cleaner + more efficient than a bunch of multi-dimensional strings
__________________
LenHard is offline
Reply


Thread Tools
Display Modes

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 12:11.


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