[Tutorial] How to use new line(Enter) with SetObjectMaterialText
#1

Hello

Today after messing around abit with SetObjectMaterialText, I thought about some idea and it worked, with this you can set text in many lines on the object, in short this tutorial show you how to use \n with SetObjectMaterialText function.

The trick is hidding in the HTTP function, so you will need a_http include.


Result:



pawn Код:
#include <a_samp>
#include <a_http>

forward Response(index, response_code, data[]);//forward http response ( https://sampwiki.blast.hk/wiki/HTTP )

new MyObj; //Define object for global use

public OnFilterScriptInit()
{
    HTTP(-1, HTTP_GET,"localhost/text.txt"," ","Response");//using HTTP_GET to read text file ( https://sampwiki.blast.hk/wiki/HTTP )
    MyObj = CreateObject(objectid,1211.9685,-1344.7974,14.1289,0.0,0.0,0.0,50.0);//Create object ( https://sampwiki.blast.hk/wiki/CreateObject)

}
public Response(index, response_code, data[])//getting http response ( https://sampwiki.blast.hk/wiki/HTTP )
{
    SetObjectMaterialText(MyObj ,data,2,140,"Arial",250,1,0xFF000000,-1,OBJECT_MATERIAL_TEXT_ALIGN_CENTER);//Set text from the file to the object ( https://sampwiki.blast.hk/wiki/SetObjectMaterialText )
    return 1;
}
Text file contains:

Код:
12
es
Reply
#2

why dont you use \n instead?
Reply
#3

For some reason \n doesnt work there.
Reply
#4

sure? whatever data[] contains - it will also work if you use it directly with SetObjectMaterialText without your HTTP method?
Reply
#5

At some cases, for example when you use IG map editor, with bult-in SetObjectMaterialText, and you enter the text in the dialog, it wont apply \n

Reply
#6

Well then the in-game editor isn't optimal.
Reply
#7

inputdialogs will never ever accept "\n" - it will be "\\n" in the callback
Reply
#8

so the HTT include hides the box?? if not i really need to know but awsome anyways
Reply
#9

Quote:
Originally Posted by ikey07
Посмотреть сообщение
At some cases, for example when you use IG map editor, with bult-in SetObjectMaterialText, and you enter the text in the dialog, it wont apply \n

Because \n isn't \n. When used directly in the script, it is a Line Feed (LF) character with ASCII code 10. That's right, a single character! When input into a dialog box, they're just two characters \ (ASCII 92) and n (ASCII 110), with no special meaning whatsoever.

http://www.asciitable.com/
Reply
#10

Everything good but how to write on the object , I dont see where did you write 12 es in the full code :P
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)