Format is showing wrong! -
Fratello - 14.12.2016
Hellou.
I'm making a datapack system. It's like moneybag system, when you pick it up you will get cash ( or score ).
But when i pick it up i got ivalid valute showen.
Код:
CMD:pickupdata(playerid, params[])
{
if (IsPlayerInRangeOfPoint(playerid, 7.0, 2001.5299,1520.2451,17.0625))
{
SendClientMessage(playerid, -1, " You have picked up a datapack! Collecting more wil lead into a reward! ");
new string[128];
format(string,sizeof(string), " You have collected one datapack and now you have %d packs.", datapack);
SendClientMessage(playerid, -1, string);
GivePlayerMoney(playerid, -1, 10000);
datapack[playerid] = 1;
}
else
{
SendClientMessage(playerid, -1, " You're not near datapack");
}
return 1;
}
CMD:datastatus(playerid, params[])
{
new string[128];
format(string,sizeof(string), " You have just %d packs!", datapack);
SendClientMessage(playerid, -1, string);
return 1;
}
Problem is when i pickup a data that first format is showing me that I have 0 packs, but after picking up another one i got 1 instead of 2.
Command datastatus is showing correct, can anyone explain me?
IMG(s).
http://forum.sa-mp.com/newthread.php?do=postthread&f=12
Re: Format is showing wrong! -
saffierr - 14.12.2016
I can't see nothing when I click the link to view the image.
But having read your story, I guess it has to do with the variable in your format.
Re: Format is showing wrong! -
Fratello - 14.12.2016
Ohh, sorry link is wrong. Yeah but how do i fix it?
Re: Format is showing wrong! -
GoldenLion - 14.12.2016
Do you have datapack[MAX_PLAYERS]; on top of your script? You need to use datapack[playerid] everywhere, not just datapack because I assume datapack is an array. Also to add one to a variable just do ++ or += 1, like datapack[playerid]++, not datapack[playerid] = 1; Also there's some random -1 in GivePlayerMoney, I removed that for you. Also your strings are too big which is unnecessary for such small messages. I've fixed all that for you.
Here's the fixed stuff:
Код:
CMD:pickupdata(playerid, params[])
{
if (IsPlayerInRangeOfPoint(playerid, 7.0, 2001.5299,1520.2451,17.0625))
{
SendClientMessage(playerid, -1, " You have picked up a datapack! Collecting more wil lead into a reward! ");
new string[64];
format(string,sizeof(string), " You have collected one datapack and now you have %d packs.", datapack[playerid]);
SendClientMessage(playerid, -1, string);
GivePlayerMoney(playerid, 10000);
datapack[playerid]++;
}
else
{
SendClientMessage(playerid, -1, " You're not near datapack");
}
return 1;
}
CMD:datastatus(playerid, params[])
{
new string[30];
format(string,sizeof(string), " You have just %d packs!", datapack[playerid]);
SendClientMessage(playerid, -1, string);
return 1;
}
Re: Format is showing wrong! -
Fratello - 14.12.2016
Yes I do have datapack[MAX_PLAYERS]; on top of my script.
And it is still same, it shows 0 instead of 1. ( in CMD: pickupdata ).
Also how should i know when to put string[30] or [64]and when [124]?
Re: Format is showing wrong! -
Konstantinos - 14.12.2016
It formats the text, sends the client message and
then increases so it will show the previous value.
Change the position.
---
About the size of the string, count the characters. Let's take " You have collected one datapack and now you have %d packs." as example.
57 characters (without specifiers) -> " You have collected one datapack and now you have packs."
+ 4 characters for the value of datapack* (%d specifier).
+ 1 for NULL
* I doubt a player will collect over 9,999 datapacks but if that's the case you can increase by one.
Re: Format is showing wrong! -
Fratello - 14.12.2016
Okay, problem solved.
Thanks, now i understand.