AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   read from file (https://forums.alliedmods.net/showthread.php?t=74777)

whosyourdaddy 07-24-2008 19:06

read from file
 
how can i do something if some1's steam id is in the file it will do this action...like for example i want to put my steam id in file named lvl14.ini and i will be the only1 who will get access to something like this
Code:

if(steam id is in file or how ever its done)
{
do this
}

or even better like steam id and then numbers for example
Code:

steam_0:2382738927 14
steam_0:2382738927 15
steam_0:2382738927 16
steam_0:2382738927 17

and if its 14 it will do one if statement if its 15 it will do another if statement etc...

whosyourdaddy 07-24-2008 22:39

Re: read from file
 
well i found this but can some1 help me make it do this... it reads not only the steam id but after it a number and if it as number 14 it will do

Code:


#define MAX_LEVELS              14



and etc.. for the other numbers... like make an if statement if possible?

Code:

#include <amxmodx>

#define MULTIPLE_USERS

#if defined MULTIPLE_USERS

#define MAX_USERS 100
#define USER_LIST_LOCATION "addons/amxmodx/configs/myuserlist.txt"

new userList[MAX_USERS][32];

public plugin_cfg()
{
    loadUsers();
}

loadUsers()
{
    new fileHandle = fopen(USER_LIST_LOCATION, "r");
   
    if(!fileHandle)
    {
        return;
    }
   
    new lineBuffer[64], userCount;
       
    while(!feof(fileHandle) && userCount < MAX_USERS)
    {
        fgets(fileHandle, lineBuffer, charsmax(lineBuffer));
       
        if(equal("STEAM_", lineBuffer, strlen("STEAM_")))
        {
            copyc(userList[userCount++], charsmax(userList[]), lineBuffer, ' ');
        }
    }

    fclose(fileHandle);
}

bool:hasAccess(userSteamID[])
{ 
    for(new i; i < MAX_USERS; i++)
    {
        if(equal(userList[i], userSteamID))
        {
            return true;
        }
    }

    return false;
}

#else
    #define PRIVELEGED_USER "STEAM_0:0:17"
#endif

public plugin_init()
{
    register_clcmd("amx_mycommand", "myCommand");
}

public myCommand(id)
{
    new userSteamID[32];
    get_user_authid(id, userSteamID, charsmax(userSteamID));

#if defined MULTIPLE_USERS

    if(!hasAccess(userSteamID))
    {
        client_print(id, print_console, "You have no access to that command");
        return PLUGIN_HANDLED;
    }

#else

    if(!equal(userSteamID, PRIVELEGED_USER))
    {
        client_print(id, print_console, "You have no access to that command");
        return PLUGIN_HANDLED;
    }

#endif

    //command goes here
   
    return PLUGIN_HANDLED;
}


scrtxxcaz 07-25-2008 01:55

Re: read from file
 
not exaclty sure what your looking for but this might help
PHP Code:

new MAX_LEVEL 14
public plugin_int() {
     new 
filename[72]
     
get_configdir(filename,72);
     
format(filename,72,"%s/lvl14.ini",filename)
}
 
public function(
id) {
     new 
file fopen(filename,"rt")
     new 
steamid[32],parsedid[32],parsedlevel[32]
     
get_user_authid(id,steamid,31)
     if(
file_exists,filename)
     {
           if(
file)
          {
                new 
readdata[128]
                while(
fgets(file,readdata,127))
                {
                      
parse(readdata,parsedid,31,parsedlevel,31)
                      if(
contain(parsedid,steamid) != -&& contain(parsedlevel,MAX_LEVEL) != -1)
                     {
                          
//do somin
                     
}
                }
          }
     }



whosyourdaddy 07-25-2008 03:59

Re: read from file
 
looks pretty good but is there a way i can have my lvl14.ini look like this

Code:

steam_0:232972 14
steam_0:232972 15

where max_level = the numbers after the steam id for example on the first one 14 and on the second one 15

scrtxxcaz 07-25-2008 12:18

Re: read from file
 
yea just make the little change like below and when the players id is found their max_level in the file will be saved to MAX_LEVEL. hopefully thats what ur looking for.:)
PHP Code:

new MAX_LEVEL
public plugin_int() {
     new 
filename[72]
     
get_configdir(filename,72);
     
format(filename,72,"%s/lvl14.ini",filename)
}
 
public function(
id) {
     new 
file fopen(filename,"rt")
     new 
steamid[32],parsedid[32],parsedlevel[32]
     
get_user_authid(id,steamid,31)
     if(
file_exists,filename)
     {
           if(
file)
          {
                new 
readdata[128]
                while(
fgets(file,readdata,127))
                {
                      
parse(readdata,parsedid,31,parsedlevel,31)
                      if(
contain(parsedid,steamid) != -1)
                     {
                          
MAX_LEVEL str_to_num(parsedlevel)
                     }
                }
          }
     }



whosyourdaddy 07-25-2008 14:11

Re: read from file
 
wait would this work?

Code:


                      parse(readdata,parsedid,31,parsedlevel,31)
                      if(
contain(parsedid,steamid) != -1
)
                    {
                         
MAX_LEVEL = str_to_num(parsedlevel
)
                          if(MAX_LEVEL == 14)
                          {
                              (level 14 code)
                          }
                          if(MAX_LEVEL == 15)
                          {
                                (level 15 code and etc for other levels)
                          }
                    }

but what would i do if their steam id isnt in the .ini and i want it to do a code for those guys 2

scrtxxcaz 07-26-2008 00:40

Re: read from file
 
yea but it would be better to do this...
PHP Code:

switch(MAX_LEVEL)
{
     case 
14:           //level 14
     
case 15:           // level 15
     
case 16:           // level 16
     //so on



whosyourdaddy 07-26-2008 04:41

Re: read from file
 
what if their steam id isnt in the file? how can i make it do something on them?

scrtxxcaz 07-28-2008 01:22

Re: read from file
 
PHP Code:

 parse(readdata,parsedid,31,parsedlevel,31)
 if(
contain(parsedid,steamid))
 {
       
MAX_LEVEL str_to_num(parsedlevel)
       switch(
MAX_LEVEL)
       {
              case 
14:           //level 14
              
case 15:           // level 15
              
case 16:           // level 16
              //so on
        
}
}
else
{
    
//steam id wasnt found so do this


or even
PHP Code:

if(!contain(parsedid,steamid))
{
     
//steam id not found do this


but using "else" would work to because if the steam id isnt found it will then execute the "else" lines

whosyourdaddy 07-29-2008 00:54

Re: read from file
 
ya im having problems is there a way you can make a .sma for me so i can copy and paste it because for some reason its not working correctly for me.. sorry for the trouble


All times are GMT -4. The time now is 05:30.

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