Raised This Month: $ Target: $400
 0% 

Reading from file error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 08-30-2009 , 20:28   Reading from file error
Reply With Quote #1

Whenever I try using this code I wrote to read from a file and then randomly pick a line (map) from that file, it doesn't work. I tested it and whenever I use the command it always displays "[AMXX] Denied Command Access: 'amx_map_random'!"

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

#define PLUGIN "amx_map random"
#define VERSION "1.0"
#define AUTHOR "BOYSplayCS"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_concmd("amx_map_random""eventChangeMap"ADMIN_SLAY"- Randomly change map");
}

public 
eventChangeMap(idlevelcid)
{
    if (
cmd_access(idlevelcid2))
    {
        new 
mapCycle[64];
        
copy(mapCycle63"mapcycle.txt");
        
        if (
file_exists(mapCycle))
        {
            new 
file fopen(mapCycle"rt");
            
            new 
mapData[64];
            
            while (!
feof(file))
            {
                
fgets(filemapData63);
                
                
server_cmd("changelevel %s"mapData);
            }
        }
    }
    
client_print(idprint_chat"[AMXX] Denied Command Access: 'amx_map_random'!");
    return 
PLUGIN_HANDLED;

BOYSplayCS is offline
Old 08-30-2009, 21:08
Bad_Bud
This message has been deleted by Bad_Bud. Reason: !
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 08-30-2009 , 21:09   Re: Reading from file error
Reply With Quote #3

Well... that print is executed every time eventChangeMap is called, it's not inside any conditional.
__________________
Bad_Bud is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-30-2009 , 21:11   Re: Reading from file error
Reply With Quote #4

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

#define PLUGIN "amx_map random"
#define VERSION "1.0"
#define AUTHOR "BOYSplayCS"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_concmd("amx_map_random""eventChangeMap"ADMIN_SLAY"- Randomly change map");
}

public 
eventChangeMap(idlevelcid)
{
    if (
cmd_access(idlevelcid2))
    {
        new 
szMap64 ];
        if( 
GetRandomMap"mapcycle.txt"szMap63 ) )
            
server_cmd"changelevel %s"szMap );
        else
            
console_printid"There were no maps to change to." );
    }
    else
        
client_print(idprint_chat"[AMXX] Denied Command Access: 'amx_map_random'!");
    
    return 
PLUGIN_HANDLED;
}

GetRandomMap( const szMapFile[ ], szReturn[ ], const iLen )
{
    new 
iFile fopenszMapFile"rt" );
    if( !
iFile )
    {
        return 
0;
    }
    
    new Array:
aMaps ArrayCreate64 );
    new 
Trie:tArrayPos TrieCreate( );
    new 
iTotal 0;
    
    static 
szData128 ], szMap64 ];
    while( !
feofiFile ) )
    {
        
fgetsiFileszData127 );
        
parseszDataszMap63 );
        
strtolowerszMap );
        
        if( 
is_map_validszMap ) && !TrieKeyExiststArrayPosszMap ) )
        {
            
ArrayPushStringaMapsszMap );
            
TrieSetCelltArrayPosszMapiTotal );
            
            
iTotal++;
        }
    }
    
    
TrieDestroytArrayPos );
    
    if( !
iTotal )
    {
        
ArrayDestroyaMaps );
        
        return 
0;
    }
    
    
ArrayGetStringaMapsrandomiTotal ), szReturniLen );
    
    
ArrayDestroyaMaps );
    
    return 
1;

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 08-30-2009 , 21:34   Re: Reading from file error
Reply With Quote #5

Its the same if i don't use ";" or don't use it?
In C++ is required but in the .sma default plugins did not appears.
Mxnn is offline
fezh
Veteran Member
Join Date: Dec 2008
Location: BANNED
Old 08-30-2009 , 21:50   Re: Reading from file error
Reply With Quote #6

Quote:
Originally Posted by Mxnn View Post
Its the same if i don't use ";" or don't use it?
In C++ is required but in the .sma default plugins did not appears.
I think is an habit. Lot of people who write scripts in C++ use semi-colons in they AMXX plugins.
__________________
"There is no knowledge, that is not power"
fezh is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-30-2009 , 22:07   Re: Reading from file error
Reply With Quote #7

In Pawn, semicolons are not required unless "#pragma semicolon 1" is at the top of the plugin.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 08-31-2009 , 02:58   Re: Reading from file error
Reply With Quote #8

Nice example, btw can you show example without Arrays?
__________________
xbatista is offline
Send a message via Skype™ to xbatista
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-31-2009 , 09:22   Re: Reading from file error
Reply With Quote #9

Quote:
Originally Posted by xbatista View Post
Nice example, btw can you show example without Arrays?
It's better with Arrays and Tries, but sure.

Code:
GetRandomMap( const szMapFile[ ], szReturn[ ], const iLen ) {     new iFile = fopen( szMapFile, "rt" );     if( !iFile )     {         return 0;     }         const MAX_MAPS = 100;         static szMaps[ MAX_MAPS ][ 64 ];     new iTotal = 0;         static szData[ 128 ], szMap[ 64 ], i, bool:bExists;     while( !feof( iFile ) && iTotal < MAX_MAPS )     {         fgets( iFile, szData, 127 );         parse( szData, szMap, 63 );         strtolower( szMap );                 if( is_map_valid( szMap ) )         {             bExists = false;             for( i = 0; i < iTotal; i++ )             {                 if( equal( szMaps[ i ], szMap ) )                 {                     bExists = true;                     break;                 }             }                         if( !bExists )             {                 copy( szMaps[ iTotal++ ], 63, szMap );             }         }     }         if( !iTotal )     {         return 0;     }         copy( szReturn, iLen, szMaps[ random( iTotal ) ] );         return 1; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 08-31-2009 , 08:30   Re: Reading from file error
Reply With Quote #10

Bad_Bud: Woops, I put it in the wrong brackets.

Mxnn: I've scripted C++ before and Java, so for me it's a habit that is not good to break.

Exolent[jNr]: Ahhh, thank you!
BOYSplayCS 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 14:59.


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