SA-MP Forums Archive
House Name Owner - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: House Name Owner (/showthread.php?tid=466364)



House Name Owner - UnknownGamer - 27.09.2013

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


Re: House Name Owner - Konstantinos - 27.09.2013

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 ] )



Re: House Name Owner - UnknownGamer - 27.09.2013

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],


Re: House Name Owner - Konstantinos - 27.09.2013

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.


Re: House Name Owner - UnknownGamer - 27.09.2013

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]);



Re: House Name Owner - Konstantinos - 27.09.2013

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"



Re: House Name Owner - UnknownGamer - 27.09.2013

-FIXED-

+REP for your help.


Re: House Name Owner - Konstantinos - 27.09.2013

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.