SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 22/01/2018, 05:51 PM   #1
LI0LIKAS
Little Clucker
 
Join Date: Jan 2018
Posts: 13
Reputation: 0
Default String on DIALOG_STYLE_LIST

Hey,

Just saying, that I am a beginner at scripting, so I still don't know many things.

I already made the player count system when a player joins, it increases the count of his job workers. How to make the count of players in each job appear in the DIALOG_STYLE_LIST?

I tried to do like that, but I get warning that number of arguments doesn't match definition and it doesn't work.

Code:
	if (strcmp("/kviesti", cmdtext, true, 8) == 0)
	{
		new string[5];
		format(string, sizeof(string), "%s", taksiConnected);
		format(string, sizeof(string), "%s", mechanikaiConnected);
		format(string, sizeof(string), "%s", policijaConnected);
		format(string, sizeof(string), "%s", narkoConnected);
		format(string, sizeof(string), "%s", medikaiConnected);
		
		ShowPlayerDialog(playerid, 202, DIALOG_STYLE_LIST,"Kviesti tarnyba", "Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]", string, "Pasirinkti", "Atsaukti");
		return 1;
	}
LI0LIKAS is offline   Reply With Quote
Old 22/01/2018, 05:56 PM   #2
Ritzy2K
High-roller
 
Ritzy2K's Avatar
 
Join Date: Jun 2014
Location: India
Posts: 1,548
Reputation: 170
Default Re: String on DIALOG_STYLE_LIST

Code:
if (strcmp("/kviesti", cmdtext, true, 8) == 0)
	{
		new string[125];
		format(string, sizeof(string), "Taksi: %s", taksiConnected);
		format(string, sizeof(string), "Mechanikai: %s", mechanikaiConnected);
		format(string, sizeof(string), "Policija: %s", policijaConnected);
		format(string, sizeof(string), "Narko: %s", narkoConnected);
		format(string, sizeof(string), "Medikai: %s", medikaiConnected);
		
		ShowPlayerDialog(playerid, 202, DIALOG_STYLE_LIST, string , "Pasirinkti", "Atsaukti");
		return 1;
	}
Your cell size for string was too small. Also, The way you wrote it, it doesn't work like that. You added an extra arguement in ShowPlayerDialog function. The previous words which were in your dialog is supposed to be written in formatted function itself.


Edit: Ok ok my bad xD
__________________

Last edited by Ritzy2K; 22/01/2018 at 08:39 PM.
Ritzy2K is offline   Reply With Quote
Old 22/01/2018, 06:11 PM   #3
LI0LIKAS
Little Clucker
 
Join Date: Jan 2018
Posts: 13
Reputation: 0
Default Re: String on DIALOG_STYLE_LIST

Quote:
Originally Posted by Ritzy View Post
Code:
if (strcmp("/kviesti", cmdtext, true, 8) == 0)
	{
		new string[125];
		format(string, sizeof(string), "Taksi: %s", taksiConnected);
		format(string, sizeof(string), "Mechanikai: %s", mechanikaiConnected);
		format(string, sizeof(string), "Policija: %s", policijaConnected);
		format(string, sizeof(string), "Narko: %s", narkoConnected);
		format(string, sizeof(string), "Medikai: %s", medikaiConnected);
		
		ShowPlayerDialog(playerid, 202, DIALOG_STYLE_LIST, string , "Pasirinkti", "Atsaukti");
		return 1;
	}
Your cell size for string was too small. Also, The way you wrote it, it doesn't work like that. You added an extra arguement in ShowPlayerDialog function. The previous words which were in your dialog is supposed to be written in formatted function itself.
Well then, how to write those previous words in formatted function?
LI0LIKAS is offline   Reply With Quote
Old 22/01/2018, 06:13 PM   #4
Ritzy2K
High-roller
 
Ritzy2K's Avatar
 
Join Date: Jun 2014
Location: India
Posts: 1,548
Reputation: 170
Default Re: String on DIALOG_STYLE_LIST

I did them.
__________________
Ritzy2K is offline   Reply With Quote
Old 22/01/2018, 06:32 PM   #5
Stev
Big Clucker
 
Join Date: Oct 2013
Location: United Kingdom
Posts: 150
Reputation: 17
Default Re: String on DIALOG_STYLE_LIST

@Ritzy - You've forgotten to add a new line on each string "/n".

EDIT: Also, the string you have just formatted is attached to the dialog title, not the content.
__________________
Join the best Cops And Robbers in SA-MP, today. svr.sfcnr.com:7777

Stev is offline   Reply With Quote
Old 22/01/2018, 06:36 PM   #6
LI0LIKAS
Little Clucker
 
Join Date: Jan 2018
Posts: 13
Reputation: 0
Default Re: String on DIALOG_STYLE_LIST

Quote:
Originally Posted by Stev View Post
@Ritzy - You've forgotten to add a new line on each string "/n".

EDIT: Also, the string you have just formatted is attached to the dialog title, not the content.
Yes, I was going to ask why is it like that.

But still, even if I added "\n", it only shows me the first line.

LI0LIKAS is offline   Reply With Quote
Old 22/01/2018, 06:42 PM   #7
Kane
Gangsta
 
Kane's Avatar
 
Join Date: Sep 2012
Posts: 813
Reputation: 125
Default Re: String on DIALOG_STYLE_LIST

Code:
format(string, sizeof(string), "%sMechanikai: %s\n", string, mechanikaiConnected);
and so on.
__________________
Los Santos Roleplay - Developer
@ls-rp.io

Former Beta Tester
Kane is online now   Reply With Quote
Old 22/01/2018, 06:52 PM   #8
denNorske
Gangsta
 
denNorske's Avatar
 
Join Date: Nov 2011
Location: Oslo, Norway
Posts: 787
Reputation: 95
Default Re: String on DIALOG_STYLE_LIST

Quote:
Originally Posted by Ritzy View Post
Code:
if (strcmp("/kviesti", cmdtext, true, 8) == 0)
	{
		new string[125];
		format(string, sizeof(string), "Taksi: %s", taksiConnected);
		format(string, sizeof(string), "Mechanikai: %s", mechanikaiConnected);
		format(string, sizeof(string), "Policija: %s", policijaConnected);
		format(string, sizeof(string), "Narko: %s", narkoConnected);
		format(string, sizeof(string), "Medikai: %s", medikaiConnected);
		
		ShowPlayerDialog(playerid, 202, DIALOG_STYLE_LIST, string , "Pasirinkti", "Atsaukti");
		return 1;
	}
Your cell size for string was too small. Also, The way you wrote it, it doesn't work like that. You added an extra arguement in ShowPlayerDialog function. The previous words which were in your dialog is supposed to be written in formatted function itself.
I guess you were asleep when you did this code.

Have a close look, what happens to the string, every time you format it? Yes, you overwrite it.


To the thread starter:
Look at the code. You tell the code to "format" a variable called "string". Imagine that string is a box with information. When you do "format(string, sizeof(string), "....", "..."); - you always place new information into it.

You can either use many different string variables and save it to them like this:
PHP Code:
new string[30], string2[30]; //This defines a new Array. it also explains [30]: it will be 29 characters long. (not 30)
//do the same for all the variables you need. Variables without [] is normal vars. They can contain a value, such as a number.
format(stringsizeof(string), "Taksi: %s"taksiConnected);
format(string2sizeof(string2), "Mechanikai: %s"mechanikaiConnected);
format(string3sizeof(string3), "Policija: %s"policijaConnected);
format(string4sizeof(string4), "Narko: %s"narkoConnected);
format(string5sizeof(string5), "Medikai: %s"medikaiConnected); 
Then you have saved information to 5 different arrays, right? (They are actually called Arrays, not boxes, remember that)

OR you can use a function called "strcat" in order to place text to the end of an already formatted string.


Let's continue:

PHP Code:
ShowPlayerDialog(playerid202DIALOG_STYLE_LIST,"Kviesti tarnyba""Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]"string"Pasirinkti""Atsaukti"); 
This is not right either, because what you do here - should be done in a "format". Only format understands %s and %d (of course with some exceptions).

I would try the following code:
PHP Code:
new ResultString[170];
format(ResultStringsizeof(ResultString), "Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]"stringstring5string3string2string4);

//then show the dialog:

ShowPlayerDialog(playerid202DIALOG_STYLE_LIST"TITLE HERE"ResultString"Pasirinkti""Atsaukti"); 
__________________
xSF source has been publicly released: Available on git (https://xsfserver.com/?p=1197)
Useful Racespawn generator: https://forum.sa-mp.com/showpost.php...postcount=3777
denNorske is offline   Reply With Quote
Old 22/01/2018, 07:08 PM   #9
LI0LIKAS
Little Clucker
 
Join Date: Jan 2018
Posts: 13
Reputation: 0
Default Re: String on DIALOG_STYLE_LIST

Quote:
Originally Posted by denNorske View Post
I guess you were asleep when you did this code.

Have a close look, what happens to the string, every time you format it? Yes, you overwrite it.


To the thread starter:
Look at the code. You tell the code to "format" a variable called "string". Imagine that string is a box with information. When you do "format(string, sizeof(string), "....", "..."); - you always place new information into it.

You can either use many different string variables and save it to them like this:
PHP Code:
new string[30], string2[30]; //This defines a new Array. it also explains [30]: it will be 29 characters long. (not 30)
//do the same for all the variables you need. Variables without [] is normal vars. They can contain a value, such as a number.
format(stringsizeof(string), "Taksi: %s"taksiConnected);
format(string2sizeof(string2), "Mechanikai: %s"mechanikaiConnected);
format(string3sizeof(string3), "Policija: %s"policijaConnected);
format(string4sizeof(string4), "Narko: %s"narkoConnected);
format(string5sizeof(string5), "Medikai: %s"medikaiConnected); 
Then you have saved information to 5 different arrays, right? (They are actually called Arrays, not boxes, remember that)

OR you can use a function called "strcat" in order to place text to the end of an already formatted string.


Let's continue:

PHP Code:
ShowPlayerDialog(playerid202DIALOG_STYLE_LIST,"Kviesti tarnyba""Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]"string"Pasirinkti""Atsaukti"); 
This is not right either, because what you do here - should be done in a "format". Only format understands %s and %d (of course with some exceptions).

I would try the following code:
PHP Code:
new ResultString[170];
format(ResultStringsizeof(ResultString), "Taksi [%s]\nMedikai [%s]\nPolicija [%s]\nMechanikai [%s]\nNarkotiku prekeiviai [%s]"stringstring5string3string2string4);

//then show the dialog:

ShowPlayerDialog(playerid202DIALOG_STYLE_LIST"TITLE HERE"ResultString"Pasirinkti""Atsaukti"); 
Thank you for the code and detail explanations about those basics.

Unfortunately, the strings that I've made (medikaiConnected, policijaConnected....) don't work. But thank you anyway
LI0LIKAS is offline   Reply With Quote
Old 22/01/2018, 09:30 PM   #10
denNorske
Gangsta
 
denNorske's Avatar
 
Join Date: Nov 2011
Location: Oslo, Norway
Posts: 787
Reputation: 95
Default Re: String on DIALOG_STYLE_LIST

It is smart to start on the very basics, and understand those first - that's for sure

Just read tutorials and look at example codes on the forum. There are a few good turotials on YouTube too, actually. They help a lot, as there is a guy that always explains what he's doing, and why.

Good luck!
__________________
xSF source has been publicly released: Available on git (https://xsfserver.com/?p=1197)
Useful Racespawn generator: https://forum.sa-mp.com/showpost.php...postcount=3777
denNorske is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Ajuda] DIALOG_STYLE_LIST Sloww Português/Portuguese 3 13/03/2017 12:36 AM
[Ajuda] DIALOG_STYLE_LIST Monarke2000 Português/Portuguese 13 22/04/2015 01:25 AM
DIALOG_STYLE_LIST Help 123bob123 Scripting Help 3 25/07/2014 11:22 AM
DIALOG_STYLE_LIST help.. CLT Scripting Help 5 25/06/2013 07:44 AM


All times are GMT. The time now is 08:34 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.