Textdraw question
#1

Hello, i have a textdraw which shows "Available Jobs" text. Since i have 8 jobs, i don't wanna create 8 textdraws. It's possible, using string, show this 8 jobs in a single textdraw?

Example:

Available jobs:

Robber
Rapist
Medic

Etc. Etc.

Currently i have this (created now) which is supposed to show jobs names:

pawn Код:
new stock JobNames[][] =
{
    "Robber", "Rapist", "Medic"
};
How to pass it in a string to show it in the textdraw?

Thanks
Reply
#2

This should do the job:

pawn Код:
new jobsText[50]; // Increase/decrease the size if necessary.
new JobNames[][] =
{
    "Robber", "Rapist", "Medic"
};
pawn Код:
// Wherever you create your textdraws.
for(new i = 0; i < sizeof JobNames; i++) {
    strcat(jobsText, JobNames[0][i]);
    if(i != sizeof(JobNames) - 1) { // Preventing a new line from being added in the last line.
        strcat(jobsText, "~n~");
    }
}

TextDrawSetString(YOUR_TEXTDRAW, jobsText);
Reply
#3

Quote:
Originally Posted by GRiMMREAPER
Посмотреть сообщение
This should do the job:

pawn Код:
new jobsText[50]; // Increase/decrease the size if necessary.
new JobNames[][] =
{
    "Robber", "Rapist", "Medic"
};
pawn Код:
// Wherever you create your textdraws.
for(new i = 0; i < sizeof JobNames; i++) {
    strcat(jobsText, JobNames[0][i]);
    if(i != sizeof JobNames) { // Preventing a new line from being added in the last line.
        strcat(jobsText, "~");
    }
}

TextDrawSetString(YOUR_TEXTDRAW, jobsText);
The "~" should be "~n~". Furthermore i will never reach the size of the array. Its max. value will be sizeof(JobNames) - 1.
Reply
#4

Quote:
Originally Posted by NaS
Посмотреть сообщение
The "~" should be "~n~". Furthermore i will never reach the size of the array. Its max. value will be sizeof(JobNames) - 1.
Thanks for noticing the typo.
Reply
#5

Thank you for your help but this is what i get:



Why?
Reply
#6

My bad. The first strcat statement should be strcat(jobsText, JobNames[i]); — I got confused. With that being said, there shouldn't be any other bugs.
Reply
#7

I didn't know that being a rapist is a job.
Reply
#8

Quote:
Originally Posted by BigETI
Посмотреть сообщение
I didn't know that being a rapist is a job.
Isnt that your job?
Reply
#9

Quote:
Originally Posted by GRiMMREAPER
Посмотреть сообщение
My bad. The first strcat statement should be strcat(jobsText, JobNames[i]); — I got confused. With that being said, there shouldn't be any other bugs.


what
Reply
#10

Quote:
Originally Posted by KinderClans
Посмотреть сообщение


what
Check the first comment.

EDIT: Didn't see the earlier replies, sorry.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)