House Name Owner
#1

pawn Код:
format(PropertyString,sizeof(PropertyString),"%s \n Owner: %s \n House ID: %d \n Rent Price: Unrentable \n Description: %s",HouseInfo[h][hMessage],HouseInfo[h][hOwner],HouseInfo[h][hWorld], HouseInfo[h][hDiscription]);
How would I remove the "_" from HouseInfo[h][hOwner] ?

In that string?

Thanks
Reply
#2

pawn Код:
stock NameWithoutUnderscore( _name[ ] )
{
    for( new i, l = strlen( _name ); i != l; i++ ) if( _name[ i ] == '_' ) _name[ i ] = ' ';
    return _name;
}
Usage:
pawn Код:
NameWithoutUnderscore( HouseInfo[ h ][ hOwner ] )
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
stock NameWithoutUnderscore( _name[ ] )
{
    for( new i, l = strlen( _name ); i != l; i++ ) if( _name[ i ] == '_' ) _name[ i ] = ' ';
    return _name;
}
Usage:
pawn Код:
NameWithoutUnderscore( HouseInfo[ h ][ hOwner ] )
That didn't work, That just made a load of jibberish letters, and numbers, in the text

http://prntscr.com/1trywd

Baring in mind, the hOwner function is:

hOwner[MAX_PLAYER_NAME],
Reply
#4

Change to:
pawn Код:
stock NameWithoutUnderscore( _name[ MAX_PLAYER_NAME ] )
{
    for( new i, l = strlen( _name ); i != l; i++ ) if( _name[ i ] == '_' ) _name[ i ] = ' ';
    return _name;
}
I just noticed it's null without specifing the size.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Change to:
pawn Код:
stock NameWithoutUnderscore( _name[ MAX_PLAYER_NAME ] )
{
    for( new i, l = strlen( _name ); i != l; i++ ) if( _name[ i ] == '_' ) _name[ i ] = ' ';
    return _name;
}
I just noticed it's null without specifing the size.
pawn Код:
53185) : error 047: array sizes do not match, or destination array is too small

format(PropertyString,sizeof(PropertyString),"%s \n Owner: %s \n House ID: %d \n Rent Price: Unrentable \n Description: %s",HouseInfo[h][hMessage],NameWithoutUnderscore( HouseInfo[ h ][ hOwner ] ),HouseInfo[h][hWorld], HouseInfo[h][hDiscription]);
Reply
#6

Are you sure that Owner's name doesn't exceed 24?

I used:
pawn Код:
public OnGameModeInit( )
{
    printf( "The name is \"%s\"", NameWithoutUnderscore( "test_TEST" ) );
    return 1;
}

stock NameWithoutUnderscore( _name[ MAX_PLAYER_NAME ] )
{
    for( new i, l = strlen( _name ); i != l; i++ ) if( _name[ i ] == '_' ) _name[ i ] = ' ';
    return _name;
}
It compiles and prints:
pawn Код:
[18:27:46] The name is "test TEST"
Reply
#7

-FIXED-

+REP for your help.
Reply
#8

Okay, I got it working by copying the name.
pawn Код:
enum TEST
{
    STRING[ MAX_PLAYER_NAME ]
}

new
    Test[ 5 ][ TEST ]
;

public OnGameModeInit( )
{
    strcat( Test[ 0 ][ STRING ], "Test1_Test2", MAX_PLAYER_NAME );
    printf( "The name is \"%s\"", NameWithoutUnderscore( Test[ 0 ][ STRING ] ) );
    return 1;
}

stock NameWithoutUnderscore( _name[ ] )
{
    new
        new_name[ MAX_PLAYER_NAME ]
    ;
    for( new i, l = strlen( _name ); i != l; i++ ) if( _name[ i ] == '_' ) _name[ i ] = ' ';
    strcpy( new_name, _name, MAX_PLAYER_NAME );
    return new_name;
}

stock strcpy( dest[ ], const source[ ], maxlength=sizeof dest )
{
    strcat( ( dest[ 0 ] = EOS, dest ), source, maxlength );
}
I'm not really sure why it did not work before.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)