Skip to content

TextDrawCreate/SetString, GameTextForPlayer/All last character as space #55

@IstuntmanI

Description

@IstuntmanI
  • Problem:

From the TextDrawCreate wiki page:

If the last character in the text is a space (" "), the text will all be blank.

It also happens for gametexts. Not sure if it happens in TextDrawSetString too (probably does).

  • Possible solution/implementation:

Hook TextDrawCreate/TextDrawSetString/GameTextForPlayer/GameTextForAll and let them look like

stock ALS_HookedFunction( [..,] text[ ] [, ..] )
{
	if( text[ 0 ] != EOS && text[ 1 ] != EOS )
	{
		new lLastPos = 0;

		for( new i = 1; text[ i ] != EOS; i ++ )
		{
			if( text[ i ] != ' ' )
				lLastPos = i;
		}

		text[ lLastPos + 1 ] = EOS;
	}

	return HookedFunction( [..,] text [, ..] );
}

I think that I also managed to allow " " as a valid text. Maybe someone can come with a better/shorter alternative, if possible. I didn't use strlen because the code would be slower. Here are the tests:

'' -> ''
' ' -> ' '
'a' -> 'a'
'a ' -> 'a'
'ab' -> 'ab'
'ab ' -> 'ab'
'a   b' -> 'a   b'
'a   b ' -> 'a   b'
'a   b   ' -> 'a   b'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions