open.mp forum
[Pawn] 4 digit code with leads - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] 4 digit code with leads (/showthread.php?tid=1944)



4 digit code with leads - McZulian - 2021-04-25

What i'm trying to say is this:
I'm doing a 4 digit code password and you can try to guess it.
For example: The password is 1563
And i try to guess it and try: 6593
The server tells me what numbers i got right: X5X3

I don't know how to do this comparison that can output which numbers are right


RE: 4 digit code with leads - Radical - 2021-04-25

Code:
main() {
    EnterPassword(6, 5, 9, 3,      1, 5, 6, 3);
}

EnterPassword(pass_0, pass_1, pass_2, pass_3, password_0, password_1, password_2, password_3) {
    new correct, pass[4], password[4], string[5] = "XXXX", number[4];
    pass[0] = pass_0, pass[1] = pass_1, pass[2] = pass_2, pass[3] = pass_3;
    password[0] = password_0, password[1] = password_1, password[2] = password_2, password[3] = password_3;
    for(new i; i < 4; i) {
        if(password[i] == pass[i]) {
            strdel(string, i, i);
            format(number, sizeof number, "%d", pass[i]);
            strins(string, number, i);
            correct;
        }
    }
    printf("Output: %s (Correct: %i)\n", string, correct);
    return correct;
}