AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need to read string from file and store it in array (https://forums.alliedmods.net/showthread.php?t=241798)

B34ST 06-09-2014 09:04

Need to read string from file and store it in array
 
Guys i need to read list of strings from file and want to store it in array but im unable to do that :cry:
PHP Code:

 


Arkshine 06-09-2014 09:12

Need to read string from file and store it in array
 
What did you try?

B34ST 06-09-2014 09:17

Need to read string from file and store it in array
 
Guys i need to read list of strings from file and want to store it in array but im unable to do that :cry:

PHP Code:

const MAX_LEVELS 100;
enum _:LevelData {
    
LD_Level 
   
}; 


   
new 
data[LevelData]  

public 
plugin_init() 

CreateNamesArray() 



public 
CreateNamesArray() 
{
get_configsdir(g_szLevFilecharsmax(g_szLevFile));  //gets addons/amxmodx/configs directory
format(g_szLevFilecharsmax(g_szLevFile), "%s/ps_levels.ini"g_szLevFile); //formats the file name for the Weapons order INI
g_FilePointer fopen(g_szLevFile"r"); //Opens the file  
tlevels ArrayCreate(LevelData);



new 
szData[32];
new 
lev[32]
if(
g_FilePointer//Makes sure the files open
    
{
        while(!
feof(g_FilePointer))
        {
            
fgets(g_FilePointerszDatacharsmax(szData)); //Reads a line of the file
            
trim(szData); //Removes '^n' new line character from the end of the line
            
if(containi(szData";") != -1//Checks to see if its a comment and then ignores it
                
continue;  
            
parse(szDatalev31
            
data[LD_Level] = str_to_num(lev);  
            if(
sizeEntries MAX_LEVELS
            {
                
// add it to the end
                
ArrayPushArray(tlevelsdata); 
                
sizeEntries++;
            }
        }
    }
fclose(g_FilePointer);    
        
}     
public 
show_xp(id)
{
ArrayGetArray(tlevelsgxp[id], data); 
client_print_color(id,id,"your class is %s",data[LD_Level] ) 


This is my code basically what i want is instead of creating an array of level classes like
new const Prefix[MaxLevels +2][] =
{
"Newbie", // 0
"Noob", // 15
"Playah", // 40
"Semi-Pro", // 75
"Senior", // 130
"PIMP", // 200
"GangLeader", // 300
"Global Assasin", // 450
"Chuck Norris", // 650
"Veteran", // 1000

}

I want this to be written in a ini file so that anyone can modify it nd i want to read that ini file den store the class names in an array like the above array has 9 classes for 9 levels so i want to display respective class names for respective levels so pls suggest modification in my code :cry::)

B34ST 06-09-2014 09:18

Re: Need to read string from file and store it in array
 
i have declared all global variables but not metioned in the code

Backstabnoob 06-09-2014 09:46

Re: Need to read string from file and store it in array
 
Oops, tried to move Arkshine's post from the other thread here and delete it because it was a duplicate, however the "Move" option somehow changed the thread author. Can anyone fix this?:oops:

Arkshine 06-09-2014 09:59

Re: Need to read string from file and store it in array
 
I've unucked and merged both threads, but not sure what other thread you're talking about.

Backstabnoob 06-09-2014 10:00

Re: Need to read string from file and store it in array
 
Thanks. The one you merged it with seemed like a duplicate to me (except without any actual content), so no clue what was going on there.

B34ST 06-09-2014 10:10

Re: Need to read string from file and store it in array
 
Guys help me :/ need help un dis code


All times are GMT -4. The time now is 09:39.

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