Raised This Month: $ Target: $400
 0% 

Convert const to aray and load data from .ini file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
twix_p
Member
Join Date: Jul 2011
Old 12-28-2012 , 20:12   Convert const to aray and load data from .ini file
Reply With Quote #1

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
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

Last edited by twix_p; 12-28-2012 at 20:22.
twix_p is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-28-2012 , 21:49   Re: Convert const to aray and load data from .ini file
Reply With Quote #2

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
__________________
fysiks is offline
twix_p
Member
Join Date: Jul 2011
Old 12-29-2012 , 21:18   Re: Convert const to aray and load data from .ini file
Reply With Quote #3

Thank you, its perfect!
twix_p is offline
zmd69
Junior Member
Join Date: Feb 2016
Old 11-02-2016 , 06:55   Re: Convert const to aray and load data from .ini file
Reply With Quote #4

Guys, how am i supposed to write fysiks example. i need this please help me @twix_p and @fysiks please

Last edited by zmd69; 11-02-2016 at 06:55.
zmd69 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 13:29.


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