SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 09/03/2018, 04:37 PM   #1
m1kas
Little Clucker
 
Join Date: Sep 2017
Posts: 41
Reputation: 6
Default Help with string size.

Hey, so recently I've started to make an end round score box, which displays player names, score, kills and damage, however when creating it it shows its an unknown command, the string sizes are all 256.

Code:
new AttList[256], AttKills[256], AttScore[256], AttDamage[256], DefList[256], DefKills[256], DefScore[256], DefDamage[256], TopScore[256];
However when I change the string sizes to 10 they all work fine, however I need more than 10 cells for each one. What's the problem here?
m1kas is offline   Reply With Quote
Old 09/03/2018, 04:47 PM   #2
jasperschellekens
High-roller
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Holland
Posts: 1,082
Reputation: 126
Default Re: Help with string size.

what about showing the entire command?
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!


Undead Wasteland Roleplay - The year is 1996. San Andreas is a wasteland ruled by the undead. the once so glorius landscape of San Andreas, is now a shattered decayed place that is only a vague memory of the world as we used to know it.
Discord - Website
jasperschellekens is offline   Reply With Quote
Old 09/03/2018, 04:53 PM   #3
m1kas
Little Clucker
 
Join Date: Sep 2017
Posts: 41
Reputation: 6
Default Re: Help with string size.

Code:
CMD:list(playerid, params[])
{
	new playerScores[MAX_PLAYERS][rankingEnum], index, p;

	foreach(new i : Player)
	{
		if(PlayerInfo[i][pWasInArena])
		{
			playerScores[index][player_Score] = floatround(PlayerInfo[i][pDamage]);
		    playerScores[index++][player_ID] = i;
		    p++;
		}
	}

	GetPlayerHighestScores(playerScores, 0, (index-1));
	
	new AttList[256], AttKills[256], AttScore[256], AttDamage[256], DefList[256], DefKills[256], DefScore[256], DefDamage[256], TopScore[256];

	for(new i = 0; i != p; i++)
	{
	    if(IsPlayerAttacker(playerScores[i][player_ID]))
	    {
	        format(AttList, sizeof(AttList), "%s~r~~h~%s~n~", AttList, GetPlayerNameEx(playerScores[i][player_ID]));
		    format(AttKills, sizeof(AttKills), "%s~w~~h~~h~%d~n~", AttKills, PlayerInfo[playerScores[i][player_ID]][pRoundKills]);
	        format(AttScore, sizeof(AttScore), "%s~w~~h~~h~%d~n~", AttScore, PlayerInfo[playerScores[i][player_ID]][pRoundPoints]);
	        format(AttDamage, sizeof(AttDamage), "%s~w~~h~~h~%d~n~", AttDamage, playerScores[i][player_Score]);
		}
		else if(IsPlayerDefender(playerScores[i][player_ID]))
		{
	        format(DefList, sizeof(DefList), "%s~b~~h~%s~n~", DefList, GetPlayerNameEx(playerScores[i][player_ID]));
		    format(DefKills, sizeof(DefKills), "%s~w~~h~~h~%d~n~", DefKills, PlayerInfo[playerScores[i][player_ID]][pRoundKills]);
	        format(DefScore, sizeof(DefScore), "%s~w~~h~~h~%d~n~", DefScore, PlayerInfo[playerScores[i][player_ID]][pRoundPoints]);
	        format(DefDamage, sizeof(DefDamage), "%s~w~~h~~h~%d~n~", DefDamage,  playerScores[i][player_Score]);
		}

		if(i == 0) format(TopScore, sizeof(TopScore), "%s%s1. %s~n~", TopScore, IsPlayerAttacker(playerScores[i][player_ID]) ? ("~r~") : ("~b~"), GetPlayerNameEx(playerScores[i][player_ID]));
		else if(i == 1) format(TopScore, sizeof(TopScore), "%s%s2. %s~n~", TopScore, IsPlayerAttacker(playerScores[i][player_ID]) ? ("~r~") : ("~b~"), GetPlayerNameEx(playerScores[i][player_ID]));
		else if(i == 2) format(TopScore, sizeof(TopScore), "%s%s3. %s~n~", TopScore, IsPlayerAttacker(playerScores[i][player_ID]) ? ("~r~") : ("~b~"), GetPlayerNameEx(playerScores[i][player_ID]));
	}

	TextDrawSetString(attackerText[0], AttList);
	TextDrawSetString(attackerText[2], AttKills);
	TextDrawSetString(attackerText[1], AttScore);
	TextDrawSetString(attackerText[3], AttDamage);
	TextDrawSetString(defenderText[0], DefList);
	TextDrawSetString(defenderText[2], DefKills);
	TextDrawSetString(defenderText[1], DefScore);
	TextDrawSetString(defenderText[3], DefDamage);
	TextDrawSetString(topList, TopScore);

	for(new i = 0; i < 15; i++)
	{
		TextDrawShowForAll(endText[i]);
	}
	for(new i = 0; i < 4; i++)
	{
		TextDrawShowForAll(attackerText[i]);
	}
	for(new i = 0; i < 4; i++)
	{
		TextDrawShowForAll(defenderText[i]);
	}

	TextDrawShowForAll(topList);

	return 1;
}
Like I mentioned previously, by lowering the string size everything works, so I doubt that's the problem
m1kas is offline   Reply With Quote
Old 09/03/2018, 05:15 PM   #4
Meller
Banned
 
Join Date: Dec 2016
Posts: 578
Reputation: 132
Default Re: Help with string size.

Your code is literaly making me cry. Learn how to format your code for better compability, stability and mobility. Start off with removing all of those variables and only use a single one, consider making it dynamic as well if you so need. Writing a plain and simple '256' cells doesn't help you at all, what if some variables exceed 256? Make it dynamic mate.
Meller is offline   Reply With Quote
Old 09/03/2018, 05:25 PM   #5
m1kas
Little Clucker
 
Join Date: Sep 2017
Posts: 41
Reputation: 6
Default Re: Help with string size.

Do you mind giving an example? I don't see another way besides looping 16 times instead of the one, if you could help me that would be very appreciated and it's the reason I posted here
m1kas is offline   Reply With Quote
Old 09/03/2018, 05:31 PM   #6
Meller
Banned
 
Join Date: Dec 2016
Posts: 578
Reputation: 132
Default Re: Help with string size.

Quote:
Originally Posted by m1kas View Post
Do you mind giving an example? I don't see another way besides looping 16 times instead of the one, if you could help me that would be very appreciated and it's the reason I posted here
Giving you an example isn't how scripting works, learn from documentation. This is a scripting 'help' forum, not a scripting 'request' forum. Read the PAWN3 PDF language documentation.
Meller is offline   Reply With Quote
Old 09/03/2018, 05:40 PM   #7
m1kas
Little Clucker
 
Join Date: Sep 2017
Posts: 41
Reputation: 6
Default Re: Help with string size.

Quote:
Originally Posted by Meller View Post
Giving you an example isn't how scripting works, learn from documentation. This is a scripting 'help' forum, not a scripting 'request' forum. Read the PAWN3 PDF language documentation.
I'm not asking you to script anything, I'm just wondering how do you transform 9 completely different strings into one and successfully get every textdraw string to be formatted in one loop.
m1kas is offline   Reply With Quote
Old 09/03/2018, 05:41 PM   #8
Meller
Banned
 
Join Date: Dec 2016
Posts: 578
Reputation: 132
Default Re: Help with string size.

You do realize you've got like 5 IF statements? ...
Meller is offline   Reply With Quote
Old 09/03/2018, 05:44 PM   #9
m1kas
Little Clucker
 
Join Date: Sep 2017
Posts: 41
Reputation: 6
Default Re: Help with string size.

Code:
for(new i = 0; i != p; i++)
	{
	    if(IsPlayerAttacker(playerScores[i][player_ID]))
	    {
	        format(AttList, sizeof(AttList), "%s~r~~h~%s~n~", AttList, GetPlayerNameEx(playerScores[i][player_ID]));
		format(AttKills, sizeof(AttKills), "%s~w~~h~~h~%d~n~", AttKills, PlayerInfo[playerScores[i][player_ID]][pRoundKills]);
	        format(AttScore, sizeof(AttScore), "%s~w~~h~~h~%d~n~", AttScore, PlayerInfo[playerScores[i][player_ID]][pRoundPoints]);
	        format(AttDamage, sizeof(AttDamage), "%s~w~~h~~h~%d~n~", AttDamage, playerScores[i][player_Score]);
		}
		else if(IsPlayerDefender(playerScores[i][player_ID]))
		{
	        format(DefList, sizeof(DefList), "%s~b~~h~%s~n~", DefList, GetPlayerNameEx(playerScores[i][player_ID]));
		format(DefKills, sizeof(DefKills), "%s~w~~h~~h~%d~n~", DefKills, PlayerInfo[playerScores[i][player_ID]][pRoundKills]);
	        format(DefScore, sizeof(DefScore), "%s~w~~h~~h~%d~n~", DefScore, PlayerInfo[playerScores[i][player_ID]][pRoundPoints]);
	        format(DefDamage, sizeof(DefDamage), "%s~w~~h~~h~%d~n~", DefDamage,  playerScores[i][player_Score]);
		}
	}
Those are the only essential ones that I'm asking about how do you transform those 8 different strings into one and loop it once.
m1kas is offline   Reply With Quote
Old 10/03/2018, 01:10 AM   #10
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,785
Reputation: 635
Default Re: Help with string size.

The reason for the "Unknown Command" message could be because you use many big arrays.
That's 8 times 256 cells plus the playerScores array which is at least 2 * 1000 cells.

These are declared locally so there isn't unlimited space.

Try to assemble each string for each textdraw seperately, like this:

- loop with format
- textdrawsetstring
- loop with format
- textdrawsetstring

and reuse the string for each of them - remember to clear the string before formatting the next one, simply by doing

Code:
string[0] = EOS;
The overhead from 7 additional loops is negligible if working with such big strings anyway. You'll have 7 less big arrays.

The other way would be not to blindly declare them with 256 cells. Calculate how big each of the Arrays can possibly get at maximum number of players and text length for each entry, and declare them based on that.

Also you can save some characters by taking out all the color codes (~r~~h~~h~) etc and use TextDrawColor. You only use one color per TextDraw anyway (you'll save a lot of characters).
NaS 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
String size.. KillerDVX Scripting Help 4 26/01/2016 10:05 AM
String size AiRaLoKa Scripting Help 9 06/06/2014 09:14 AM
String size help Marven Scripting Help 2 04/06/2014 09:39 AM
[Tool/Web/Other] String checker [length, block size, breaks & tabs] - Is your string size correct? Sinner Tools and Files 13 17/09/2013 07:11 AM
[help] String size ғαιιοцт Help Archive 4 16/12/2009 12:56 PM


All times are GMT. The time now is 02:33 PM.


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