AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Convert const to aray and load data from .ini file (https://forums.alliedmods.net/showthread.php?t=204241)

twix_p 12-28-2012 20:12

Convert const to aray and load data from .ini file
 
First code works great, it is easy to replace RGB values and to don't show them in message.

PHP Code:

#include < amxmodx >
#include < amxmisc >

new g_iMessagesCountg_iVariableg_iAdvertisementsSync;

enum _BLEAHHHRED], GREEN], BLUE], MESSAGE512 ] }

static const 
szMessages[ ][ BLEAHHH ] =
{
    { 
255000000"1 = Hello, it Worked!" },
    { 
000255000"2 = Hello, it Worked!" },
    { 
000000200"3 = Hello, it Worked!" },
    { 
000200000"4 = Hello, it Worked!" },
    { 
200000000"5 = Hello, it Worked!" }
}

public 
plugin_init( )
{
    
register_plugin"Messages Shower""1.0b""[dvL]aditza" );

    
g_iAdvertisementsSync CreateHudSyncObj( );
    
g_iMessagesCount sizeofszMessages ) -1;

    
set_task5.0"Task_HudMessages", .flags"b" );
}

public 
Task_HudMessages( )
{
    if( 
g_iVariable g_iMessagesCount )
        
g_iVariable 0;
    
    
set_hudmessageszMessagesg_iVariable ][ RED  ], szMessagesg_iVariable ][ GREEN ], szMessagesg_iVariable ][ BLUE ], -1.00.2000.512.02.02.0, -);
    
ShowSyncHudMsg0g_iAdvertisementsSync"%s"szMessagesg_iVariable ][ MESSAGE] );

    
g_iVariable++;


Below i tryed to "convert" the plugin, but i did a big and useless :bacon!:
I think szRight must be divided into four parts R, G, B and the message. I realy need help to do that.


PHP Code:


#include < amxmodx >
#include < amxmisc >

enum _BLEAHHHRED], GREEN], BLUE], MESSAGE512 ] }

static Array: 
g_iMessagesg_iMessagesCountcLoadedDATA[ ][ BLEAHHH ], g_iAdvertisementsSyncg_iVariable;

public 
plugin_init( )
{
    
register_plugin"Messages Shower""1.0b""[dvL]aditza" );

    
g_iMessages ArrayCreate32 );
    
g_iAdvertisementsSync CreateHudSyncObj( );

    new 
iFile fopen"addons/amxmodx/configs/Messages.ini""rt" );
    static 
szData64 ], szLeft16 ], szRight256 ];
    
    while( !
feofiFile ) )
    {
        
fgetsiFileszData63 );
        
        
strtokszDataszLeft15szRight255'@' );
        
        
trimszLeft );
        
trimszRight );
        
        if( 
equaliszLeft"HudMsg" ) )
        {
            
ArrayPushStringg_iMessagesszRight );

            
replace_allszRight256"#""^n" );

            
g_iMessagesCount ArraySizeg_iMessages ) -1;

            
formatexcLoadedDATAg_iMessagesCount ][ MESSAGE ], 255"%s"szRight );
        }
    }
    
    
fcloseiFile );

    
set_task2.0"Task_SendMessages", .flags "b" );
}

public 
Task_SendMessages( )
{
    if( 
g_iVariable g_iMessagesCount )
        
g_iVariable 0;

    
set_hudmessagecLoadedDATAg_iVariable ][ RED ], cLoadedDATAg_iVariable ][ GREEN ], cLoadedDATAg_iVariable][ BLUE ], -1.00.2000.512.02.02.0, -);
    
ShowSyncHudMsg0g_iAdvertisementsSync"%s, NR: %d"cLoadedDATAg_iVariable ][ MESSAGE ], g_iVariable )

    
g_iVariable++;
}


Messages.ini:

HudMsg 250 010 200 Helloit Worked!
HudMsg 020 010 050 Helloit Worked!
HudMsg 250 010 200 Helloit Worked!
HudMsg 020 010 050 Helloit Worked!
HudMsg 250 010 200 Helloit Worked!
HudMsg 020 010 050 Helloit Worked


fysiks 12-28-2012 21:49

Re: Convert const to aray and load data from .ini file
 
I would do something like this:

PHP Code:

new szMessage[64], szRed[4], szGreen[4], szBlue[4], iRediBlueiGreen
// open file and get get line
parse(line_from_fileszMessagecharsmax(szMessage), szRedcharsmax(szRed), szGreencharsmax(szGreen), szBluecharsmax(szBlue))
iRed str_to_num(szRed)
iGreen str_to_num(szGreen)
iBlue str_to_num(szBlue)
// add data to global arrays 

File format:
Code:

"Your message here" 255 255 255
"Your message here" 255 255 255
"Your message here" 255 255 255
"Your message here" 255 255 255
"Your message here" 255 255 255


twix_p 12-29-2012 21:18

Re: Convert const to aray and load data from .ini file
 
Thank you, its perfect! :)

zmd69 11-02-2016 06:55

Re: Convert const to aray and load data from .ini file
 
Guys, how am i supposed to write fysiks example. i need this please help me @twix_p and @fysiks please :oops: :oops:


All times are GMT -4. The time now is 13:29.

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