AlliedModders

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

Natsheh 08-30-2015 09:11

Array/String
 
As i think these functions work fine, but the problem is with putting in the array.

PHP Code:

#define MAXFLAGS 32

new Vip_flags[MAXFLAGS], access_flags

public _create_vip_flag(pluginargc)  // native
{
    new 
vflag[2], sString[32]
    
get_string(1vflagcharsmax(vflag))
    
    if(
_flags_are_existed(vflagsStringcharsmax(sString)))
    {
        
log_error(AMX_ERR_PARAMS"Error couldn't create a vip flag ^"%s^", it's already created!"sString)
        return -
1
    
}
    
    
    
Vip_flags[access_flags] = vflag[0]
    
    
access_flags ++
    return 
access_flags-1
}

public 
bool:_flags_are_existed(const vflags[], sflags[], len// native
{
    if(!
strlen(Vip_flags))
    {
        return 
false;
    }
    
    new 
xifidfeq
    
new flags[MAXFLAGS], zFlag[2]
    
    for(
0strlen(vflags); i++)
    {
        
feq 0
        
        
for(0access_flagsx++)
        {
            
zFlag[0] = Vip_flags[x]
            
            if(
zFlag[0] == vflags[i])
            {
                
feq ++;
            }
        }
        
        if(!
feq)
        {
            
flags[fid] = vflags[i]
            
fid ++;
        }
    }
    
    if(
fid)
    {
        
copy(sflagslenflags)
        return 
false;
    }
    
    return 
true;


when flags a & c
is created by this native >> create_vip_flag(const vflag[])

PHP Code:

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    if(!
flags_are_existed("a"))
    {
        
create_vip_flag("a")
    }
        if(!
flags_are_existed("c"))
        {
                
create_vip_flag("c")
        }


flag c isn't input in the array(Vip_flags)!
IDK why that's what i'm trying to figure it out?!

Bugsy 08-30-2015 12:51

Re: Array/String
 
Not sure if I'm missing something here, but why not use a bitsum to store flags?

Untested:
PHP Code:

new Vip_flags

public _create_vip_flag(pluginargc)  // native
{
    new 
vflag[2] , sString[32]
    
    
get_stringvflag charsmaxvflag ) )
    
    if( 
_flags_are_existedvflag ) )
    {
        
log_error(AMX_ERR_PARAMS"Error couldn't create a vip flag ^"%s^", it's already created!"sString)
        return -
1
    
}
    
    
Vip_flags |= read_flagsvflag] )
    
    return 
FlagCount();
}

public 
bool:_flags_are_existed( const flags[] ) // native
{
    if( !
Vip_flags )
    {
        return 
false;
    }
    
    new 
iFlagsToCheck read_flagsflags );
    
    return 
bool:!!( ( iFlagsToCheck Vip_flags ) == iFlagsToCheck )
}

public 
FlagCount()
{
    new 
Vip_flags;

    
- ((>> 1) & 0x55555555);
    
= (0x33333333) + ((>> 2) & 0x33333333);
    return (((
+ (>> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;



Natsheh 08-30-2015 13:16

Re: Array/String
 
Thanks, but i'm not using bitsum Because i don't have that much knowledge about it, i just prefer to use the array way !

& btw here is the include file >>
PHP Code:

/*
@Param vflag "abcdefghijklmnopqrstuvwxyz"
@Return vflag-id
@Info "vflag must be one chars & alphabet only better registered in plugin ini or precache forward"
*/
native create_vip_flag(vflag[])
/*
@Param vflag "abcdefghijklmnopqrstuvwxyz"
@Return vflag-id
@Info "vflag must be one chars & alphabet only"
*/
native get_vflag_id(vflag[])
/*
@Param id "user-id"
@Param vflag "format vflag with user-vip-flags"
@Param len "maxlen"
@Return NoReturns
*/
native get_vuser_flags(idvflags[], len)
/*
@Param id "user-id"
@Return true/flase "true if user is vip otherwise false"
*/
native is_user_vip(index)
/*
@Param vflag "abcdefghijklmnopqrstuvwxyz"
@Param sflag "format sflag with flags isnt exists in vflag if it Returns false"
@Param len "maxlen
@Return true/false "true if vflags is existed otherwise false"
@Info "vflag must be alphabet"
*/
native bool:flags_are_existed(vflags[], sflags[]=""len=0


Bugsy 08-30-2015 16:13

Re: Array/String
 
Let me know if this works. I still used bitsums because it makes it easier and uses less code. If you have any questions, just ask. There are natives that convert "abc" to the respective bitsum (read_flags()) and vice versa (get_flags()).

Not thoroughly tested.
PHP Code:

#define MAXFLAGS 32

new Vip_flagsMAXFLAGS ] , access_flags

public _create_vip_flag(pluginargc)  // native
{
    new 
vflag32 ], sString32 ]
    
get_stringvflag charsmaxvflag ) )
    
    if( 
_flags_are_existedvflag sString charsmaxsString ) ) )
    {
        
log_error(AMX_ERR_PARAMS"Error couldn't create a vip flag ^"%s^", it's already created!"sString)
        return -
1
    
}
        
    
Vip_flagsaccess_flags ] = vflag]

    return 
access_flags++
}

public 
bool:_flags_are_existed( const vflags[] , sflags[] , len // native
{
    if( !
strlenVip_flags ) )
    {
        
copysflags len vflags );
        return 
false;
    }

    new 
iCurrentFlags read_flagsVip_flags );
    new 
iFlagsToCheck read_flagsvflags );
    new 
iMatchedFlags = ( iCurrentFlags iFlagsToCheck );
    new 
iResultFlags;
    new 
bool:bRetVal;
    
    if ( 
iMatchedFlags && ( iMatchedFlags == iFlagsToCheck ) )
    {
        
//All matching flags found
        
        
bRetVal true;
    }
    else if ( !
iMatchedFlags )
    {
        
//No matching flags found
        
        
iResultFlags iFlagsToCheck;
        
bRetVal false;
    }
    else if ( ~
iCurrentFlags iFlagsToCheck )
    {
        
//Some matching flags found
        
        
iResultFlags = ~iCurrentFlags iFlagsToCheck;
        
bRetVal false;
    }

    if ( !
bRetVal )
        
get_flagsiResultFlags sflags len );
        
    return 
bRetVal;



Natsheh 08-31-2015 11:28

Re: Array/String
 
[ Problem fixed ] using #4 Method

anyway i have new problem...

i'm sorry for being annoying...

PHP Code:

public _register_vip_flag_info(pluginargc// native
{
    new 
vFlag[2], sString[32], sLinex
    get_string
(1vFlagcharsmax(vFlag))
    
get_string(2sStringcharsmax(sString))
    
    if(!
strlen(vFlag) || !strlen(sString))
    {
        
log_error(AMX_ERR_NATIVE"Error #Native register_vip_flag_info")
        return
    }
    
    static 
sFile[64], sBuffer[2024], sOutput[4], sInfo[2020]
    
get_localinfo("amxx_configsdir"sFilecharsmax(sFile))
    
formatex(sFilecharsmax(sFile), "%s/%s"sFileinfo_file)
    
    if(!
file_exists(sFile))
    {
        
log_error(AMX_ERR_NOTFOUND"File ^"%s^" is not found!"sFile)
        return
    }
    
    new 
fp fopen(sFile"rt")
    
    while(!
feof(fp) && access_flags)
    {
        
sLine ++
        
        
fgets(fpsBuffercharsmax(sBuffer))
        
        if(
sBuffer[0] == ';' || (sBuffer[0] & sBuffer[1] == '/'))
        {
            continue;
        }
        
        while(!
feof(fp))
        {
            
strbreak(sBuffersOutputcharsmax(sOutput), sInfocharsmax(sInfo))
            
remove_quotes(sOutput)
            
            
server_print("sOutput: %c - %c" sOutput[0], vFlag[0])
            
            if(
sOutput[0] == vFlag[0])
            {
                
formatex(sStringcharsmax(sString), "%s, "sString)
                
add(sBuffercharsmax(sBuffer), sString)
                
write_file(sFilesBuffersLine-1)
                return
            }
        }
        
        
x++;
        
formatex(sBuffercharsmax(sBuffer), "^"%c^" ; %s, "vFlag[0], sString)
        
write_file(sFilesBuffer)
    }
    
fclose(fp)


write in file .... firsting first this native search if vflag is already created..... in the file.txt
then if its created, print info like this "FLAG="a" ; "Extra Health", "Gravity", "

in each plugin when using that native, it been used like this

Example:-
PHP Code:

new const flag_info[] = "Access ability to predator class"

public flag_creation()
{
     
register_flag_info("a"flag_info)


"FLAG="a" ; "Extra Health", "Gravity", "Access ability to predator class", "
and it will be printed like that in the file

Natsheh 09-03-2015 07:20

Re: Array/String
 
Bump


All times are GMT -4. The time now is 22:14.

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