Bug Admin -
Loinal - 07.04.2017
fixed
Re: Bug Admin -
Toroi - 07.04.2017
You should be using
strcat instead of
format in the following line inside the loop.
PHP код:
format( string, 128, "%s (ID:%d) Level: [%d] (%s)\n\nTotal ZoneX admins %d", GetName( i ), i , pData[i][Admin] , admtext, count);
What is happening right now is that, every iteration of the loop you are 'resetting' the string and writing a new thing on its place, instead of adding it which is what you want to do.
This is the function you should use:
https://sampwiki.blast.hk/wiki/Strcat
Also, you should erase the
ShowPlayerDialog function from the loop, for logical reasons.
As an extra, allow me to warn you that the following is totally pointless:
PHP код:
format( stringz , 128,"Online Admins");
..
format( stringz , 128 ,"No Admins Online ");
As you can just write that up in the
ShowPlayerDialog function itself.
Re: Bug Admin -
Loinal - 07.04.2017
Quote:
Originally Posted by Troydere
You should be using strcat instead of format in the following line inside the loop.
PHP код:
format( string, 128, "%s (ID:%d) Level: [%d] (%s)\n\nTotal ZoneX admins %d", GetName( i ), i , pData[i][Admin] , admtext, count);
What is happening right now is that, every iteration of the loop you are 'resetting' the string and writing a new thing on its place, instead of adding it which is what you want to do.
This is the function you should use: https://sampwiki.blast.hk/wiki/Strcat
Also, you should erase the ShowPlayerDialog function from the loop, for logical reasons.
As an extra, allow me to warn you that the following is totally pointless:
PHP код:
format( stringz , 128,"Online Admins");
..
format( stringz , 128 ,"No Admins Online ");
As you can just write that up in the ShowPlayerDialog function itself.
|
Look i didn't understand the First part of your topic
Re: Bug Admin -
Toroi - 07.04.2017
Sorry, I'll give you an example with the differences between the
strcat and
format functions
PHP код:
format(string,sizeof string,"1");
format(string,sizeof string,"2");
format(string,sizeof string,"3");
printf("String: %s",string);
The code above will output '
String: 3'. Not really what we want to accomplish in this case. However:
PHP код:
strcat(string,"1");
strcat(string,"2");
strcat(string,"3");
printf("String: %s",string);
Will output '
String: 123'. Which is exactly what you need in order to display the administrators online.
In this case you'd want to create a new string variable with a considerable size and add your already formatted string to that new string with the use of strcat. Like this:
PHP код:
format(string2,sizeof string,"1");
strcat(string,string2);
format(string2,sizeof string,"2");
strcat(string,string2);
format(string2,sizeof string,"3");
strcat(string,string2);
printf("String: %s",string); // will output String: 123
I don't know why but I think i'm only making this harder to understand.
Re: Bug Admin -
Loinal - 07.04.2017
SO this
PHP код:
format( string, 1200, "%s (ID:%d) Level: [%d] (%s)\n\nTotal ZoneX admins %d", GetName( i ), i , pData[i][Admin] , admtext, count);
Will be
PHP код:
format( string, sizeof(string), "%s (ID:%d) Level: [%d] (%s)\n\nTotal ZoneX admins %d", GetName( i ), i , pData[i][Admin] , admtext, count);
?
Re: Bug Admin -
Toroi - 07.04.2017
Nonono, well, yeah that'd make more sense, but that's not the problem itself.
Let's start again, create a new string along the others already declared:
PHP код:
new string[128],stringz[128],newStringOs[70];
Inside the loop, change the string you are formatting for the new one and add that formatted string to the old string you had:
PHP код:
format(newStringOs, sizeof newStringOs, "%s (ID:%d) Level: [%d] (%s)\n", GetName( i ), i , pData[i][Admin] , admtext); // change the name of the string here to the new one and add a \n new line
strcat(string,newStringOs); //and concatenate them together
Now, if you noticed we deleted some part of the text to avoid it to repeat itself, you just have to add it again once the loop ends, the following condition should be a perfect place for it
PHP код:
if(count >= 0)
{
format(newStringOs,sizeof newStringOs,"\nTotal ZoneX admins %d",count); // set the string with the deleted text
strcat(string,newStringOs); // add the removed text again at the end of the string
ShowPlayerDialog( playerid , 190 , DIALOG_STYLE_MSGBOX , stringz , string, "Ok" , "Close" );
}
Re: Bug Admin -
Loinal - 08.04.2017
I don't understand what to delete
Re: Bug Admin -
denNorske - 08.04.2017
A good place to start would be here:
https://sampwiki.blast.hk/wiki/Format
https://sampwiki.blast.hk/wiki/Strcat
As it was told above, your code "format" the string every time (
https://sampwiki.blast.hk/wiki/Format) which means the string is being deleted and replaced with something new.
If you use strcat (
https://sampwiki.blast.hk/wiki/strcat) you can append new parts every time.
Everything you need to know is explained on the Wiki
Re: Bug Admin -
Loinal - 08.04.2017
So after the format should i put strcat?
Re: Bug Admin -
denNorske - 08.04.2017
Quote:
Originally Posted by Loinal
So after the format should i put strcat?
|
Yep, but remember to strcat the formatted string into a new string. (because the formatted string is overwritten every time, and the strcat'ed string is appended to)