What am I doing wrong?
#1

pawn Код:
forward UpdateBans(playerid);
public UpdateBans(playerid)
{
    if(strcmp(UserInfo[playerid][AccountLocked], "No", false) == 0)
    {
        if(LoggedIn[playerid] == 1) {
            new string[128];
            SendClientMessage(playerid, COLOR_ERROR, "This account is locked!");
            format(string, sizeof(string), "< Reason: %s", UserInfo[playerid][AccountLocked]);
            SendClientMessage(playerid, COLOR_ERROR, string);
            Kick(playerid);
        }
    }
    return 1;
}
The userfile reads as following:

Код:
AccountLocked = No
Therefore I know it's setting it correctly, but i'm assuming I did something wrong with the string compare. Can anyone tell me what I did incorrectly?
Reply
#2

strcmp returns 0 if true

pawn Код:
if(!strcmp(UserInfo[playerid][AccountLocked], "No", false) == 0)
Also, I don't think you need this:

pawn Код:
== 0)
pawn Код:
if(!strcmp(UserInfo[playerid][AccountLocked], "No", false))
Reply
#3

Still not working. I want it so if AccountLocked = "No" then it will allow the login and let them continue playing, however, this is not working..

pawn Код:
forward UpdateBans(playerid);
public UpdateBans(playerid)
{
    if(!strcmp(UserInfo[playerid][AccountLocked], "No", false))
    {
        if(LoggedIn[playerid] == 1) {
            new string[128];
            SendClientMessage(playerid, COLOR_ERROR, "This account is locked!");
            format(string, sizeof(string), "< Reason: %s", UserInfo[playerid][AccountLocked]);
            SendClientMessage(playerid, COLOR_ERROR, string);
            Kick(playerid);
        }
    }
    return 1;
}
The timer is called OnGameModeInit if that piece of information is needed..
Reply
#4

Okay, so the value of this variable is currently "No" according to the user file?

pawn Код:
UserInfo[playerid][AccountLocked]
Reply
#5

What I don't see logical, is that if the account is /not/ locked, it will say it is locked? shouldn't it be like..

pawn Код:
if(strcmp(UserInfo[playerid][AccountLocked], "Yes", false) == 0)
Reply
#6

Quote:
Originally Posted by admantis
Посмотреть сообщение
What I don't see logical, is that if the account is /not/ locked, it will say it is locked? shouldn't it be like..

pawn Код:
if(strcmp(UserInfo[playerid][AccountLocked], "Yes", false) == 0)
I'm sorry, half asleep... and yeah, that does seem more logical. Your code appears to be working. Thank you +rep.

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
Okay, so the value of this variable is currently "No" according to the user file?

pawn Код:
UserInfo[playerid][AccountLocked]
It was, yes, and it's been fixed due to Admantis, but thank you for your attempt.
Reply
#7

Despite your problem being fixed, I think it's worth pointing out that using integers (normal whole numbers), 0 and 1 is more widely used in userfiles, 0 usually means no and 1 usually means yes, having to deal with strings is more problematic, which is why I'd advise that you consider using integers, not only will you avoid the whole strcmp deal, but you'll just be able to have a simple if [operator] statement.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)