Raised This Month: $ Target: $400
 0% 

Adding a INI file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tedaimlocks
Member
Join Date: Jan 2024
Old 04-18-2024 , 11:58   Adding a INI file
Reply With Quote #1

How can i use a INI file and make something like this?

[tedaimlocks]
SOUND = sound/spkzm/tedaimlocks.mp3
SOUND_CMD = say /ted

[andrei]
SOUND = sound/spkzm/andrei.mp3
SOUND_CMD = say /andrei

HTML Code:
#include <amxmodx>
#include <colorchat>

#define PLUGIN "Sounds VIA Chat"
#define VERSION "1.0"
#define AUTHOR "tedaimlocks"

#define SOUND_FLAG ADMIN_RCON

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR);
	register_clcmd("say /ted", "tedaimlocks")
	register_clcmd("say /andrei", "andrei")
}

public plugin_precache() {
	precache_generic("sound/spkzm/tedaimlocks.mp3")
	precache_generic("sound/spkzm/andrei.mp3")
	return PLUGIN_HANDLED;
}

public tedaimlocks(id) {
        if(!(get_user_flags(id) & SOUND_FLAG)) {
        return PLUGIN_HANDLED;
        }
	new szName[32];
	get_user_name(id, szName, charsmax(szName));
	client_cmd(0, "MP3Volume 1")
	client_cmd(0, "mp3 play sound/spkzm/tedaimlocks.mp3")
        ColorChat(0, GREEN, "^x01[^x04SPK ZM^x01]^x04 %s ^x03played the sound^x04 ted", szName);
        return PLUGIN_HANDLED;
}

public andrei(id) {
        if(!(get_user_flags(id) & SOUND_FLAG)) {
        return PLUGIN_HANDLED;
        }
	new szName[32];
	get_user_name(id, szName, charsmax(szName));
	client_cmd(0, "MP3Volume 1")
	client_cmd(0, "mp3 play sound/spkzm/andrei.mp3")
        ColorChat(0, GREEN, "^x01[^x04SPK ZM^x01]^x04 %s ^x03played the sound^x04 andrei", szName);
        return PLUGIN_HANDLED;
}
tedaimlocks is offline
abdelwahab
Member
Join Date: Aug 2019
Old 04-18-2024 , 12:08   Re: Adding a INI file
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=243202
abdelwahab is offline
Lajtowy
Member
Join Date: Jun 2012
Old 04-18-2024 , 17:37   Re: Adding a INI file
Reply With Quote #3

Code:
#include <amxmodx>
#include <colorchat>
#include <amxmisc>

#define PLUGIN_NAME "Sounds via Chat"
#define PLUGIN_VERSION "1.0"
#define PLUGIN_AUTHOR "tedaimlocks"

#define SOUND_FLAG ADMIN_RCON
#define MAX_SOUNDS 10 // Maximum number of sounds in the INI file

new g_Sounds[MAX_SOUNDS][64];
new g_SoundCmds[MAX_SOUNDS][32];
new g_NumSounds;

public plugin_init() {
    register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
    register_clcmd("say /sound", "cmd_play_sound");
    read_sound_ini(); // Read sounds from the INI file on plugin start
}

public plugin_precache() {
    for (new i = 0; i < g_NumSounds; i++) {
        precache_generic(g_Sounds[i]);
    }
    return PLUGIN_HANDLED;
}

public cmd_play_sound(id) {
    new soundIndex = find_sound_by_cmd(get_user_msg(id), g_SoundCmds);
    if (soundIndex != -1) {
        if (!(get_user_flags(id) & SOUND_FLAG)) {
            return PLUGIN_HANDLED;
        }
        new playerName[32];
        get_user_name(id, playerName, sizeof(playerName));
        client_cmd(0, "MP3Volume 1");
        client_cmd(0, "mp3 play %s", g_Sounds[soundIndex]);
        ColorChat(0, GREEN, "^x01[^x04SPK ZM^x01]^x04 %s ^x03played the sound^x04 %s", playerName, g_SoundCmds[soundIndex]);
    }
    return PLUGIN_HANDLED;
}

public find_sound_by_cmd(const cmd[], const soundCmds[][]) {
    for (new i = 0; i < g_NumSounds; i++) {
        if (equali(cmd, soundCmds[i])) {
            return i;
        }
    }
    return -1;
}

public read_sound_ini() {
    new file = fopen("sound_cmds.ini", "rt");
    if (!file) {
        server_print("Unable to open sound_cmds.ini file!");
        return PLUGIN_HANDLED;
    }

    g_NumSounds = 0;
    new line[256], sound[64], soundCmd[32];
    while (fgets(file, line, sizeof(line)) != null) {
        if (sscanf(line, "%s %s", soundCmd, sound) >= 2) {
            if (g_NumSounds < MAX_SOUNDS) {
                format(g_Sounds[g_NumSounds], sizeof(g_Sounds[g_NumSounds]), "sound/%s", sound);
                format(g_SoundCmds[g_NumSounds], sizeof(g_SoundCmds[g_NumSounds]), "say /%s", soundCmd);
                g_NumSounds++;
            } else {
                server_print("Too many sounds in sound_cmds.ini file!");
                break;
            }
        }
    }
    fclose(file);
    return PLUGIN_HANDLED;


Make sure you've created an INI file named sound_cmds.ini in the folder for example:

ted sound/spkzm/tedaimlocks.mp3
andrei sound/spkzm/andrei.mp3
Lajtowy is offline
wilian159
Member
Join Date: Dec 2013
Old 04-19-2024 , 12:28   Re: Adding a INI file
Reply With Quote #4

Use this: https://forums.alliedmods.net/showthread.php?t=346837
__________________
wilian159 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 11:17.


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