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

Solved Read from file.


Post New Thread Reply   
 
Thread Tools Display Modes
thEsp
BANNED
Join Date: Aug 2017
Old 04-11-2020 , 11:40   Re: Read from file.
Reply With Quote #11

I hope someone else has more nerves to tell you how.
thEsp is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 04-11-2020 , 11:43   Re: Read from file.
Reply With Quote #12

Quote:
Originally Posted by thEsp View Post
I hope someone else has more nerves to tell you how.
You could just give me an example on how it should be done? I know my code doesn't make sense, that's why i'm here.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
thEsp
BANNED
Join Date: Aug 2017
Old 04-11-2020 , 13:19   Re: Read from file.
Reply With Quote #13

Code:
#include <amxmodx> public plugin_init() {     register_clcmd("say /menu", "menu_open"); } public menu_open(id) {     new menu = menu_create("title", "menu_handler");     new rgb[] = "255 0 255"; // suppose this is the line read from the file. if there is something else (like a text), make sure you erase that     menu_additem(menu, "text #1", rgb);     menu_display(id, menu); } public menu_handler(id, menu, item) {     new rgb[4 * 3], r[4], g[4], b[4]; // rgb is 12 chars wide, two spaces + one string terminator at the end, enough for "RRR GGG BBB"     menu_item_getinfo(menu, item, _, rgb, charsmax(rgb));     parse(rgb, r, charsmax(r), g, charsmax(g), b, charsmax(b));     client_print(id, print_chat, "R: %i | G: %i | B: %i", str_to_num(r), str_to_num(g), str_to_num(b));     // whatever you do, make sure you destroy the menu at the end     menu_destroy(menu); }
You can't seem to correctly use an array of integers in this case (because the module expects a string). Since strings are terminated when a null (0) character is reached, {255, 0, 255} for example would translate to {255, 0, 0}. You could go around this by incrementing each RGB channel (cell) by 1 and then decrementing it by 1 in the handler, but a character is 1 byte or 8 bits (2^8 = 256, in this case the peak is 255 since 0 also counts) long, so {256, 1, 256} would "wrongly" translate to {0, 0, 0}.

But anyway, just go around the code above if you fancy...

Last edited by thEsp; 04-11-2020 at 14:11. Reason: typo
thEsp is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 04-11-2020 , 14:08   Re: Read from file.
Reply With Quote #14

I'll just post the whole plugin, cause i can't seem to figure it out.

PHP Code:
/* Sublime AMXX Editor v2.2 */

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define iRandom random_num(10, 255)

#pragma semicolon 1

new const szVersion[] = "1.0.0";
new 
szData[128];

new 
bool:bGlowTarget;

enum _:RgbEnum {
    
r,
    
g,
    
b
}

new const 
szCommands[][] = {
    
"/glowmenu",
    
"/gm",
    
"/glow",
    
"!glowmenu",
    
"!gm",
    
"!glow"
};

new 
iMainMenu;
new 
iColorMenu;
new 
iRemoveMenu;

new 
Trie:GlowTrie;

new 
pAdminsOnly;

public 
plugin_init() {
    
register_plugin("Advanced Glow Menu"szVersion"NapoleoN#");

    
#if AMXX_VERSION_NUM < 183
    
new szChat[100];
    
#endif

    
for(new isizeof(szCommands); i++) {
        
#if AMXX_VERSION_NUM < 183
        
formatex(szChatcharsmax(szChat), "say %s"szCommands[i]);
        
register_clcmd(szChat"CheckSettings");

        
formatex(szChatcharsmax(szChat), "say_team %s"szCommands[i]);
        
register_clcmd(szChat"CheckSettings");
        
#else
        
register_clcmd(fmt("say %s"szCommands[i]), "CheckSettings");
        
register_clcmd(fmt("say_team %s"szCommands[i]), "CheckSettings");
        
#endif
    
}

    
pAdminsOnly =         register_cvar("glow_adminsonly""1");

    
// Create global menu's
    
iMainMenu menu_create("\r[\wAdvanced Glow Menu\r]\w^nChoose an option:""MainMenuHandler");

    
menu_additem(iMainMenu"Glow Target");
    
menu_additem(iMainMenu"Glow Yourself"); // Glow by aim will be added later on.
    
menu_additem(iMainMenu"Glow All Random");
    
menu_additem(iMainMenu"Glow All");
    
menu_additem(iMainMenu"Remove Glow");

    
iRemoveMenu menu_create("\r[\wAdvanced Glow Menu\r]\w^nChoose an option:""RemoveGlowHandler");

    
menu_additem(iRemoveMenu"Remove Your Glow");
    
menu_additem(iRemoveMenu"Remove Glow From Player");
    
menu_additem(iRemoveMenu"Remove Glow All Players");

    
GlowTrie TrieCreate();
    
ReadFile(); // This also contains a global menu.
}

public 
CheckSettings(id) {
    if(
get_user_flags(id) & ADMIN_KICK && get_pcvar_num(pAdminsOnly)) {
        
menu_display(idiMainMenu);
    }

    else if(!
get_pcvar_num(pAdminsOnly)) {
        
menu_display(idiMainMenu);
    }
}

public 
MainMenuHandler(idiMainMenuitem) {
    switch(
item) {
        case 
0GlowTarget(id);
        case 
1GlowYourSelf(id);
        case 
2GlowAllRandom(id);
        case 
3GlowAll(id);
        case 
4menu_display(idiRemoveMenu);
        
// case 5: GlowAimTarget(id);
    
}
}

public 
ColorMenuHandler(idiColorMenuitem) {
    new 
GlowColors[RgbEnum];

    new 
szItemName[32];
    
menu_item_getinfo(iColorMenuitem, .name=szItemName, .namelen charsmax(szItemName));

    
TrieGetArray(GlowTrieszItemNameGlowColorsRgbEnum);

    if(
bGlowTarget) {
        new 
szPlayer[20];
        new 
iPlayer cmd_target(idszPlayerCMDTARGET_ONLY_ALIVE);

        if(
iPlayer) {
            
set_user_glow(iPlayerGlowColors[r], GlowColors[g], GlowColors[b]);
            
bGlowTarget false;
        }
    }

    else if(
is_user_alive(id)) {
        
set_user_glow(idGlowColors[r], GlowColors[g], GlowColors[b]);
    }
    
client_print(idprint_chat"%i %i %i"GlowColors[r], GlowColors[g], GlowColors[b]);
}

public 
RemoveGlowHandler(idiRemoveMenuitem) {
    switch(
item) {
        case 
0set_user_rendering(id);
        case 
1RemoveGlowPlayer(id);
        case 
2RemoveGlowAll(id);
    }
}

public 
GlowTarget(id) {
    new 
iPlayerMenu menu_create("\r[\wAdvanced Glow Menu\r]\w^nChoose to glow:""GlowPlayerHandler");

    new 
iPlayers[32], iNumszName[33];
    
get_players(iPlayersiNum);

    for(new 
iiNumi++) {
        
get_user_name(iPlayers[i], szNamecharsmax(szName));
        
menu_additem(iPlayerMenuszName);
    }
    
menu_display(idiPlayerMenu);
    
bGlowTarget true;
}

public 
GlowPlayerHandler(idiPlayerMenuitem) {
    
menu_display(idiColorMenu);
}

public 
GlowYourSelf(id) {
    
menu_display(idiColorMenu);
}

public 
GlowAllRandom(id) {
    new 
iPlayers[32], iNum;
    
get_players(iPlayersiNum);

    for(new 
iiNumi++) {
        
set_user_glow(iPlayers[i], iRandomiRandomiRandom);
    }
}

public 
GlowAll(id) {
    
menu_display(idiColorMenu);
}

public 
RemoveGlowPlayer(id) {
    new 
iPlayerMenu menu_create("\r[\wAdvanced Glow Menu\r]\w^nChoose to remove:""RemovePlayerHandler");

    new 
iPlayers[32], iNumszName[33];
    
get_players(iPlayersiNum);

    for(new 
iiNumi++) {
        
get_user_name(iPlayers[i], szNamecharsmax(szName));
        
menu_additem(iPlayerMenuszName);
    }
    
menu_display(idiPlayerMenu);
}

public 
RemovePlayerHandler(idiPlayerMenuitem) {
    new 
szPlayer[20];
    new 
iPlayer cmd_target(idszPlayerCMDTARGET_ONLY_ALIVE);

    if(
iPlayer) {
        
set_user_glow(iPlayer);
    }
}

public 
RemoveGlowAll(id) {
    new 
iPlayers[32], iNum;
    
get_players(iPlayersiNum);

    for(new 
iiNumi++) {
        
set_user_glow(iPlayers[i]);
    }
}

stock set_user_glow(idiR 0iG 0iB 0) {
    
set_user_rendering(idkRenderFxGlowShelliRiGiBkRenderNormal25);
}

ReadFile() {
    new 
szFileName[256];
    
get_configsdir(szFileNamecharsmax(szFileName));
    
add(szFileNamecharsmax(szFileName), "/GlowMenu.txt");

    new 
iFilePointer fopen(szFileName"rt");

    if(
iFilePointer) {
        while(
fgets(iFilePointerszDatacharsmax(szData))) {
            
//fgets(iFilePointer, szData, charsmax(szData));
            
trim(szData);

            if(
szData[0] == EOS || szData[0] == ';') {
                continue;
            }

            
iColorMenu menu_create("\r[\wAdvanced Glow Menu\r]\w^nChoose a color:""ColorMenuHandler");

            new 
szText[128], szNumber1[5], szNumber2[5], szNumber3[5];
            
parse(szDataszTextcharsmax(szText), szNumber1charsmax(szNumber1), szNumber2charsmax(szNumber2), szNumber3charsmax(szNumber3));

            (
is_str_numszNumber1[0]) ) ? str_to_num(szNumber1) : str_to_num(szNumber1[1]);

            new 
GlowColors[RgbEnum];
            
GlowColors[r] = str_to_num(szNumber1);
            
GlowColors[g] = str_to_num(szNumber2);
            
GlowColors[b] = str_to_num(szNumber3);

            
TrieSetArray(GlowTrieszTextGlowColorsRgbEnum);

            
menu_additem(iColorMenuszTextGlowColors);

            
//log_amx("R: %i^nG: %i^nB: %i", GlowColors[r], GlowColors[g], GlowColors[b]);
            
log_amx("String szNumber1: %s"szNumber1);
            
log_amx("String szNumber2: %s"szNumber2);
            
log_amx("String szNumber3: %s"szNumber3);
        }
    }
    
fclose(iFilePointer);

Output ReadFile()
Code:
L 04/11/2020 - 19:37:13: [AdvancedGlowMenu.amxx] String szNumber1: [255
L 04/11/2020 - 19:37:13: [AdvancedGlowMenu.amxx] String szNumber2: 0,
L 04/11/2020 - 19:37:13: [AdvancedGlowMenu.amxx] String szNumber3: 0]
Output set_user_rendering()
Code:
R: 0
G: 0
B: 0
EDIT: Nvm, i fixed it. Used another style in GlowMenu.txt

Red "255 0 0"

Then i used remove quotes and now it's working like a charm, thanks for the help though.
__________________

Last edited by Napoleon_be; 04-11-2020 at 14:17.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
thEsp
BANNED
Join Date: Aug 2017
Old 04-11-2020 , 14:24   Re: Read from file.
Reply With Quote #15

Code:
"Green" "0" "255" "0"
"White" "255" "255" "255"
Code:
#include <amxmodx> public plugin_init() {     register_clcmd("say /menu", "menu_open"); } public menu_open(id) {     new menu = menu_create("title", "menu_handler");     new ptrFile = fopen("addons/amxmodx/configs/colors.txt", "rt"), szLine[64], szText[32], szColor[16];     while (!feof(ptrFile)) // for now will do fine, however read what Fysiks told you     {         fgets(ptrFile, szLine, charsmax(szLine));         trim(szLine); // remove blank spaces at the beginning + end         split(szLine, szColor, charsmax(szColor), szLine, charsmax(szLine), " "); // color name goes to "szColor", the remaining string which has RGB stored in goes to szLine         remove_quotes(szColor);         format(szText, charsmax(szText), "Color: %s", szColor);         menu_additem(menu, szText, szLine);     }     fclose(ptrFile);     menu_display(id, menu); } public menu_handler(id, menu, item) {     new rgb[20], r[4], g[4], b[4];     menu_item_getinfo(menu, item, _, rgb, charsmax(rgb));     parse(rgb, r, charsmax(r), g, charsmax(g), b, charsmax(b));     client_print(id, print_chat, "R: %i | G: %i | B: %i", str_to_num(r), str_to_num(g), str_to_num(b));     // whatever you do, make sure you destroy menu at the end     menu_destroy(menu); }

Last edited by thEsp; 04-11-2020 at 14:29.
thEsp is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 04-11-2020 , 14:58   Re: Read from file.
Reply With Quote #16

https://steamcommunity.com/sharedfil...?id=2057242583 Here's a screenshot of how it looks now

PHP Code:
/* Sublime AMXX Editor v2.2 */

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define iRandom random_num(10, 255)

#pragma semicolon 1

new const szVersion[] = "1.0.0";

new 
bool:bGlowTarget;

enum _:RgbEnum {
    
r,
    
g,
    
b
}

new const 
szCommands[][] = {
    
"/glowmenu",
    
"/gm",
    
"/glow",
    
"!glowmenu",
    
"!gm",
    
"!glow"
};

new 
iMainMenu;
new 
iColorMenu;
new 
iRemoveMenu;

//new Trie:GlowTrie;

new pAdminsOnly;

public 
plugin_init() {
    
register_plugin("Advanced Glow Menu"szVersion"NapoleoN#");

    
#if AMXX_VERSION_NUM < 183
    
new szChat[100];
    
#endif

    
for(new isizeof(szCommands); i++) {
        
#if AMXX_VERSION_NUM < 183
        
formatex(szChatcharsmax(szChat), "say %s"szCommands[i]);
        
register_clcmd(szChat"CheckSettings");

        
formatex(szChatcharsmax(szChat), "say_team %s"szCommands[i]);
        
register_clcmd(szChat"CheckSettings");
        
#else
        
register_clcmd(fmt("say %s"szCommands[i]), "CheckSettings");
        
register_clcmd(fmt("say_team %s"szCommands[i]), "CheckSettings");
        
#endif
    
}

    
pAdminsOnly =         register_cvar("glow_adminsonly""1");

    
// Create global menu's
    
iMainMenu menu_create("\r[\wAdvanced Glow Menu\r]\w^nChoose an option:""MainMenuHandler");

    
menu_additem(iMainMenu"Glow Target");
    
menu_additem(iMainMenu"Glow Yourself"); // Glow by aim will be added later on.
    
menu_additem(iMainMenu"Glow All Random");
    
menu_additem(iMainMenu"Glow All");
    
menu_additem(iMainMenu"Remove Glow");

    
iRemoveMenu menu_create("\r[\wAdvanced Glow Menu\r]\w^nChoose an option:""RemoveGlowHandler");

    
menu_additem(iRemoveMenu"Remove Your Glow");
    
menu_additem(iRemoveMenu"Remove Glow From Player");
    
menu_additem(iRemoveMenu"Remove Glow All Players");

    
//GlowTrie = TrieCreate();
    
ReadFile(); // This also contains a global menu.
}

public 
CheckSettings(id) {
    if(
get_user_flags(id) & ADMIN_KICK && get_pcvar_num(pAdminsOnly)) {
        
menu_display(idiMainMenu);
    }

    else if(!
get_pcvar_num(pAdminsOnly)) {
        
menu_display(idiMainMenu);
    }
}

public 
MainMenuHandler(idiMainMenuitem) {
    switch(
item) {
        case 
0GlowTarget(id);
        case 
1GlowYourSelf(id);
        case 
2GlowAllRandom(id);
        case 
3GlowAll(id);
        case 
4menu_display(idiRemoveMenu);
        
// case 5: GlowAimTarget(id);
    
}
}

public 
ColorMenuHandler(idiColorMenuitem) {
    new 
iRGB[20], iR[4], iG[4], iB[4], iRediGreeniBlue;
    
menu_item_getinfo(iColorMenuitem_iRGBcharsmax(iRGB));

    
parse(iRGBiRcharsmax(iR), iGcharsmax(iG), iBcharsmax(iB));

    
iRed str_to_num(iR);
    
iGreen str_to_num(iG);
    
iBlue str_to_num(iB);

    if(
bGlowTarget) {
        new 
szPlayer[20];
        new 
iPlayer cmd_target(idszPlayerCMDTARGET_ONLY_ALIVE);

        if(
iPlayer) {
            
set_user_glow(iPlayeriRediGreeniBlue);
            
bGlowTarget false;
        }
    }

    else if(
is_user_alive(id)) {
        
set_user_glow(idiRediGreeniBlue);
    }
    
client_print(idprint_chat"R: %i - G: %i - B: %i"iRediGreeniBlue);
}

public 
RemoveGlowHandler(idiRemoveMenuitem) {
    switch(
item) {
        case 
0set_user_rendering(id);
        case 
1RemoveGlowPlayer(id);
        case 
2RemoveGlowAll(id);
    }
}

public 
GlowTarget(id) {
    new 
iPlayerMenu menu_create("\r[\wAdvanced Glow Menu\r]\w^nChoose to glow:""GlowPlayerHandler");

    new 
iPlayers[32], iNumszName[33];
    
get_players(iPlayersiNum);

    for(new 
iiNumi++) {
        
get_user_name(iPlayers[i], szNamecharsmax(szName));
        
menu_additem(iPlayerMenuszName);
    }
    
menu_display(idiPlayerMenu);
    
bGlowTarget true;
}

public 
GlowPlayerHandler(idiPlayerMenuitem) {
    
menu_display(idiColorMenu);
    
menu_destroy(iPlayerMenu);
}

public 
GlowYourSelf(id) {
    
menu_display(idiColorMenu);
}

public 
GlowAllRandom(id) {
    new 
iPlayers[32], iNum;
    
get_players(iPlayersiNum);

    for(new 
iiNumi++) {
        
set_user_glow(iPlayers[i], iRandomiRandomiRandom);
    }
}

public 
GlowAll(id) {
    
menu_display(idiColorMenu);
}

public 
RemoveGlowPlayer(id) {
    new 
iPlayerMenu menu_create("\r[\wAdvanced Glow Menu\r]\w^nChoose to remove:""RemovePlayerHandler");

    new 
iPlayers[32], iNumszName[33];
    
get_players(iPlayersiNum);

    for(new 
iiNumi++) {
        
get_user_name(iPlayers[i], szNamecharsmax(szName));
        
menu_additem(iPlayerMenuszName);
    }
    
menu_display(idiPlayerMenu);
}

public 
RemovePlayerHandler(idiPlayerMenuitem) {
    new 
szPlayer[20];
    new 
iPlayer cmd_target(idszPlayerCMDTARGET_ONLY_ALIVE);

    if(
iPlayer) {
        
set_user_glow(iPlayer);
    }
    
menu_destroy(iPlayerMenu);
}

public 
RemoveGlowAll(id) {
    new 
iPlayers[32], iNum;
    
get_players(iPlayersiNum);

    for(new 
iiNumi++) {
        
set_user_glow(iPlayers[i]);
    }
}

stock set_user_glow(idiR 0iG 0iB 0) {
    
set_user_rendering(idkRenderFxGlowShelliRiGiBkRenderNormal25);
}

ReadFile() {
    
iColorMenu menu_create("\r[\wAdvanced Glow Menu\r]\w^nChoose a color:""ColorMenuHandler");

    new 
iFilePointer fopen("addons/amxmodx/configs/GlowMenu.txt""rt");
    new 
szLine[64], szText[32], szColor[16];

    while(
fgets(iFilePointerszLinecharsmax(szText))) {

        
trim(szLine);

        if(
szLine[0] == EOS || szLine[0] == ';') {
            continue;
        }

        
split(szLineszColorcharsmax(szColor), szLinecharsmax(szLine), " ");
        
remove_quotes(szColor);
        
format(szTextcharsmax(szText), "%s"szColor);

        
menu_additem(iColorMenuszTextszLine);
        
log_amx("szText: %s^n"szText);
    }
    
fclose(iFilePointer);

Outputs

Code:
L 04/11/2020 - 20:56:09: [AdvancedGlowMenu.amxx] szText: Red

L 04/11/2020 - 20:56:09: [AdvancedGlowMenu.amxx] szText: Blue

L 04/11/2020 - 20:56:09: [AdvancedGlowMenu.amxx] szText:
Code:
Red: 255 0 0
Blue: 0 0 0
EDIT: Okay so menu appears fine now, only the RGB colors aren't taken correctly.
__________________

Last edited by Napoleon_be; 04-11-2020 at 15:09.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
thEsp
BANNED
Join Date: Aug 2017
Old 04-11-2020 , 15:20   Re: Read from file.
Reply With Quote #17

I am too lazy to figure out what but there is clearly a mistake in your code. I think something's leaking in your code, try using dynamic arrays to store lines or colors (via "struct" enumerations) and use private (not global) menus.
thEsp is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-11-2020 , 15:25   Re: Read from file.
Reply With Quote #18

Show me what GlowMenu.txt contains
__________________
Bugsy is online now
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 04-11-2020 , 15:28   Re: Read from file.
Reply With Quote #19

Quote:
Originally Posted by Bugsy View Post
Show me what GlowMenu.txt contains
; Add Color Names and RGB codes.
; Example: Red "255 0 0"

Red "255 0 0"
Green "0 255 0"
Blue "0 0 255"
White "255 255 255"

@thEsp, the menu is fine now, only RGB codes aren't passed correctly. Also, i'm using global menus since none of them get changed during game-play, except for the player menu's.
__________________

Last edited by Napoleon_be; 04-11-2020 at 15:29.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
thEsp
BANNED
Join Date: Aug 2017
Old 04-11-2020 , 15:34   Re: Read from file.
Reply With Quote #20

Your file is wrong, it should be like this:
Code:
"Green" "0" "255" "0"
"White" "255" "255" "255"
thEsp 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 00:58.


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