AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ad Help (https://forums.alliedmods.net/showthread.php?t=55991)

Styles 06-03-2007 23:25

Ad Help
 
PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Random Ads"
#define VERSION "1.0"
#define AUTHOR "Styles"

#define maxstuff 256
new g_adAmount 0
new filename[256]

new 
g_AdList[maxstuff]


public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
get_configsdir(filename,255)
    
format(filename,255,"%s/adlist.txt",filename)
    
register_cvar("sv_adtime""120")
    
register_clcmd("amx_reloadads""load"ADMIN_KICK"Reload ad list")
    
set_task(20.0"load")
    
set_task(get_cvar_float("sv_adtime"), "printAd"0""0"b")
    
}

public 
load()
{
    new 
readdata[128], txtlenparsedad[256]
    
g_adAmount 0
    
while(read_file(filename,g_adAmount++,readdata,127,txtlen))
    {
        
parse(filename,parsedad,sizeof(parsedad))
        
formatexg_AdList[g_adAmount], maxstuff 1parsedad )
    }
    
client_print(0print_chat"[Advertisement Mod] %i ad(s) loaded."g_adAmount)
}

public 
printAd()
{
    new 
num random_num(1g_adAmount)
    
client_print(0print_chat"%s"g_AdList[num])


This isan't working for some reason. 1) If you have 3 lines it is adding an extra. 2) Sometimes it prints out the directory of the ad instead of the actual ad. 3) Sometimes... it doesn't even print out anything.. it doesn't work.

Arkshine 06-04-2007 00:47

Re: Ad Help
 
I think I would do like this :

Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "Random Ads" #define VERSION "1.0" #define AUTHOR "Styles" #define MAX_STUFF 50 #define MAX_LENGTH 191 new         configsdir[256],     filename[256],     g_AdList[MAX_STUFF][128], //  -------------     g_adAmount,     g_adtime;     public plugin_init()   {     register_plugin( PLUGIN, VERSION, AUTHOR );         g_adtime = register_cvar( "sv_adtime", "15" );     register_clcmd( "amx_reloadads", "load", ADMIN_KICK, "Reload ad list" );           get_configsdir( configsdir, sizeof( configsdir ) - 1 );     formatex( filename, sizeof( filename ) - 1, "%s/adlist.txt", configsdir );           set_task( get_pcvar_float( g_adtime ), "printAd", 0, _, _, "b" );     load(); } public load() {     // -- read the file     new fp = fopen( filename, "rt" );         // -- if the file doesn't exist     if( !fp )     {         server_print( "Inexistent file: ^"%s^"", filename );         return;     }         static buffer[MAX_LENGTH];         while( !feof( fp ) )     {         // -- get a line         fgets( fp, buffer, MAX_LENGTH - 1 );                 // -- clean spaces         trim( buffer );                 // -- empty line or comment > ignore         if( !buffer[0] || buffer[0] == ';' )             continue;                 // -- clean all '"'         replace_all( buffer, MAX_LENGTH - 1, "^"", "" );                 // -- save in array         formatex( g_AdList[g_adAmount++], MAX_STUFF - 1, buffer );     }     fclose( fp );     server_print( "[Advertisement Mod] %i ad%s loaded.", g_adAmount, g_adAmount < 2 ? "" : "s" ); } public printAd() {     new num = random( g_adAmount );     client_print( 0, print_chat, "%s", g_AdList[num] ) ; }

And in adlist.txt file, I will put lines like this :

Quote:

"Hello world!"
"Welcome on my server!"
"Hi here. Woot, woot"

Styles 06-04-2007 17:04

Re: Ad Help
 
Thanks :D

-=[SD]=-Turkey 06-04-2007 20:31

Re: Ad Help
 
I just made something like this, except mine is hardcoded. :up:

Styles 06-04-2007 20:34

Re: Ad Help
 
ima pimp it out and release it ;)

-=[SD]=-Turkey 06-04-2007 20:35

Re: Ad Help
 
Sweet. Look at my post and see if you cant help me :D

Styles 06-04-2007 21:35

Re: Ad Help
 
he already got to it :( Mines/arkshine text file based :)


All times are GMT -4. The time now is 10:33.

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