Bug Admin
#1

fixed
Reply
#2

You should be using strcat instead of format in the following line inside the loop.

PHP код:
formatstring128"%s (ID:%d) Level: [%d] (%s)\n\nTotal ZoneX admins %d"GetName), pData[i][Admin] , admtextcount); 
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 код:
formatstringz 128,"Online Admins");
..
formatstringz 128 ,"No Admins Online "); 
As you can just write that up in the ShowPlayerDialog function itself.
Reply
#3

Quote:
Originally Posted by Troydere
Посмотреть сообщение
You should be using strcat instead of format in the following line inside the loop.

PHP код:
formatstring128"%s (ID:%d) Level: [%d] (%s)\n\nTotal ZoneX admins %d"GetName), pData[i][Admin] , admtextcount); 
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 код:
formatstringz 128,"Online Admins");
..
formatstringz 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
Reply
#4

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.
Reply
#5

SO this

PHP код:
formatstring1200"%s (ID:%d) Level: [%d] (%s)\n\nTotal ZoneX admins %d"GetName), pData[i][Admin] , admtextcount); 
Will be

PHP код:
formatstringsizeof(string), "%s (ID:%d) Level: [%d] (%s)\n\nTotal ZoneX admins %d"GetName), pData[i][Admin] , admtextcount); 
?
Reply
#6

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(newStringOssizeof newStringOs"%s (ID:%d) Level: [%d] (%s)\n"GetName), 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
            
ShowPlayerDialogplayerid 190 DIALOG_STYLE_MSGBOX stringz string"Ok" "Close" ); 
        } 
Reply
#7

I don't understand what to delete
Reply
#8

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
Reply
#9

So after the format should i put strcat?
Reply
#10

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)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)