AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Whats wrong with my code? (https://forums.alliedmods.net/showthread.php?t=134759)

#8 SickneSS 08-08-2010 09:20

Whats wrong with my code?
 
Look,Im not to good at all in this,but I made what I can,when I use say /maps on chat my server crash without errors.So I need some help on this,(I Made this code based on bot apology for tk by fysiks)

Code...
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "#8 SickneSS"

#define MAXMAPS        20

new Maps[MAXMAPS][32]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /maps","MapsMenu",ADMIN_MAP)
}

public 
MapsMenu(id,level,cid
{
    if(!
cmd_access(id,level,cid,1))
        return 
PLUGIN_HANDLED
        
    
new Menu menu_create("\r[Mix Maker]\y Maps Menu :","MapsMenu_Handler")
    
    new 
Mapname[32]
    new 
Item[MAXMAPS]
    
    new 
MapFile[64]
    
get_configsdir(MapFile,63)
    
add(MapFile,63,"/mapsmenu.ini")
    
    new 
Num
    
if(!file_exists(MapFile))
        
client_cmd(id,"amx_mapmenu")
    else
    {
        new 
fopen(MapFile,"rt")
    
        for(new 
0;MAXMAPS;i++)
        {
            while(!
feof(f))
            {
                
fgets(f,Mapname,31)
                
                if(!
Mapname[0] || Mapname[0] == ';'
                
|| Mapname[0] == '/' && Mapname[1] == '/') continue;
                         
                
trim(Mapname)
                
strtolower(Mapname)
            
                
Num++
                
num_to_str(Num,Item,MAXMAPS)
            
                
copy(Maps[i][MAXMAPS],31,Item)
                
menu_additem(Menu,Mapname,Item)    
            }
            
fclose(f)
        }

    }

    
menu_display(id,Menu)
    return 
PLUGIN_HANDLED
}

public 
MapsMenu_Handler(id,Menu,item)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(Menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
iData[6]
    new 
iName[64]
    new 
Access
    
new Callback
    menu_item_getinfo
(Menu,item,Access,iData,5,iName,63,Callback)
    
    new 
Map str_to_num(iData)
    
    if(
Map)
        
client_cmd(id,"amx_on;amx_map %s",iName)
        
    return 
PLUGIN_HANDLED



Arkshine 08-08-2010 10:45

Re: Whats wrong with my code?
 
Code:

for(new i = 0;i < MAXMAPS;i++)
{
      while(!feof(f))
      {

Do you understand what are you doing there ?

#8 SickneSS 08-08-2010 10:48

Re: Whats wrong with my code?
 
Quote:

Originally Posted by Arkshine (Post 1265436)
Code:

for(new i = 0;i < MAXMAPS;i++)
{
      while(!feof(f))
      {

Do you understand what are you doing there ?

Yes,why? What is wrong there?

Alucard^ 08-08-2010 11:13

Re: Whats wrong with my code?
 
That part is wrong... you should delete the first loop, use only the while part and add a condition for the MAXMAPS thing, inside... something like:

if(Num == MAXMAPS) break;

#8 SickneSS 08-08-2010 16:40

Re: Whats wrong with my code?
 
Quote:

Originally Posted by Alucard^ (Post 1265476)
That part is wrong... you should delete the first loop, use only the while part and add a condition for the MAXMAPS thing, inside... something like:

if(Num == MAXMAPS) break;

Ok I wil try that,not now,because Im tired :P...


All times are GMT -4. The time now is 00:11.

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