SA-MP Forums Archive
BUD::How to get a name to a string? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: BUD::How to get a name to a string? (/showthread.php?tid=367667)



strcmp fails? - ddnbb - 10.08.2012

strcmp fails? it still gets passed somehow, why is that?
pawn Код:
for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(strcmp(DynamicHouses[houseid][hRenter1], PlayerName(i), true)) // its passing even when the names aren't the same, why?
                {
                    print("PASS");
                }
            }



Re: BUD::How to get a name to a string? - MeDaKewlDude - 10.08.2012

try this:

pawn Код:
new name2[MAX_PLAYER_NAME];
            format(name2, MAX_PLAYER_NAME, "%s", DynamicHouses[houseid][hRenter1]);
            for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(strcmp(name2, PlayerName(i), true))
                {
                    printf("naame2: %s", name2);
                    printf("PlayerName(i): %s", PlayerName(i));
                    printf("i: %d", i);
                }
            }



Re: BUD::How to get a name to a string? - ddnbb - 10.08.2012

Quote:
Originally Posted by MeDaKewlDude
Посмотреть сообщение
try this:

pawn Код:
new name2[MAX_PLAYER_NAME];
            format(name2, MAX_PLAYER_NAME, "%s", DynamicHouses[houseid][hRenter1]);
            for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(strcmp(name2, PlayerName(i), true))
                {
                    printf("naame2: %s", name2);
                    printf("PlayerName(i): %s", PlayerName(i));
                    printf("i: %d", i);
                }
            }
Yes, i noticed my mistake there... *facepalm*

But the problem now is, that strcmp fails or something, my code looks like this now:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(strcmp(DynamicHouses[houseid][hRenter1], PlayerName(i), true)) // its passing even when the names aren't the same, why?
                {
                    print("PASS");
                }
            }



Re: BUD::How to get a name to a string? - Vince - 10.08.2012

Strcmp returns 0 on success, not 1. i.e. that block will execute whenever the values are not the same and fail whenever the values are the same. To fix, simply add a not operator (!) in front of strcmp.


Re: BUD::How to get a name to a string? - ddnbb - 10.08.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
Strcmp returns 0 on success, not 1. i.e. that block will execute whenever the values are not the same and fail whenever the values are the same. To fix, simply add a not operator (!) in front of strcmp.
That still didn't fix it..


Re: BUD::How to get a name to a string? - MeDaKewlDude - 10.08.2012

here
pawn Код:
for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(!strcmp(DynamicHouses[houseid][hRenter1], PlayerName(i)))
                {
                    print("PASS");
                }
            }



Re: BUD::How to get a name to a string? - ddnbb - 10.08.2012

Quote:
Originally Posted by MeDaKewlDude
Посмотреть сообщение
here
pawn Код:
for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(!strcmp(DynamicHouses[houseid][hRenter1], PlayerName(i)))
                {
                    print("PASS");
                }
            }
Thanks!


Re: BUD::How to get a name to a string? - ddnbb - 10.08.2012

NVM!

Seems that i forgot to check IsPlayerConnected... Phew, im glad i solved this problem, after HOURS, lol! *facepalm*