SA-MP Forums Archive
Problem with gates passwords - 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: Problem with gates passwords (/showthread.php?tid=434219)



Problem with gates passwords - Stanford - 01.05.2013

I've got a problem with gates password, so when I put the password and set it and try to /gate it says that it owns a password but when I type the password it doesn't open.. here's the codes:

pawn Код:
if(strcmp(cmd, "/setgatepass", true) == 0)
    {
        if(PlayerInfo[playerid][pAdmin] <= 0)
        {
            return SendClientMessage(playerid, COLOR_GREY," You're not authorized to use that command !");
        }
        new gateid;
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            return SendClientMessage(playerid, COLOR_GREY," USAGE: /setgatepass [gateid] [password]");
        }
        gateid = strvalEx(tmp);
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            return SendClientMessage(playerid, COLOR_GREY," USAGE: /setgatepass [gateid] [password]");
        }
        if(strlen(tmp) > 20)
        {
            return SendClientMessage(playerid, COLOR_GREY," Gate password can't be longer than 20 characters !");
        }
        strmid(GateInfo[gateid][gPass], tmp, 0, strlen(tmp), 23);
        new reveal[256];
        format(reveal, sizeof(reveal)," Gate ID %d's password has been set to '%s' !", gateid, tmp);
        SendClientMessage(playerid, COLOR_GREY, reveal);
        GateInfo[gateid][gPassed] = 1;
        SaveGates();
        return 1;
    }
And here's the gates part in /gate

pawn Код:
for(new g=0;g<MAX_GATES;g++)
        {
            new Float:gaX, Float:gaY, Float:gaZ;
            GetDynamicObjectPos(GateInfo[g][gID], gaX, gaY, gaZ);
            if(IsPlayerInRangeOfPoint(playerid, GateInfo[g][gRange], gaX,gaY,gaZ))
            {
                if(GateInfo[g][gPassed])
                {
                    tmp = strtok(cmdtext, idx);
                    if(!strlen(tmp))
                    {
                        SendClientMessage(playerid, COLOR_GREY," This gate is password protected !");
                        SendClientMessage(playerid, COLOR_WHITE," USAGE: /gate [pass]");
                        return 1;
                    }
                    if(strcmp(tmp, GateInfo[g][gPass], true) == 0)
                    {
                        if(gatedown[g] == 0)
                        {
                            if(GateInfo[g][gSpeed] == 0.0) { GateInfo[g][gSpeed] = 3; }
                            MoveDynamicObject(GateInfo[g][gID], GateInfo[g][gPosXM], GateInfo[g][gPosYM], GateInfo[g][gPosZM], GateInfo[g][gSpeed]);
                            gatedown[g] = 1;
                            return 1;
                        }
                        if(gatedown[g] != 0)
                        {
                            if(GateInfo[g][gSpeed] == 0.0) { GateInfo[g][gSpeed] = 3; }
                            MoveDynamicObject(GateInfo[g][gID], GateInfo[g][gPosX], GateInfo[g][gPosY], GateInfo[g][gPosZ], GateInfo[g][gSpeed]);
                            gatedown[g] = 0;
                            return 1;
                        }
                    }
                    else
                    {
                        return SendClientMessage(playerid, COLOR_GREY," Invalid password !");
                    }
                }
                if( (GateInfo[g][gFamily] == 255 && GateInfo[g][gFaction] == 0) ||
                    (GateInfo[g][gFamily] != 0 && PlayerInfo[playerid][pFMember]+1 == GateInfo[g][gFamily]) ||
                    (GateInfo[g][gFaction] != 0 && PlayerInfo[playerid][pMember] == GateInfo[g][gFaction]) ||
                    GateInfo[g][gHID] == PlayerInfo[playerid][pPhousekey] ||
                    PlayerInfo[playerid][pAdmin] >= 1339)
                {

                    if(gatedown[g] == 0)
                    {
                        if(GateInfo[g][gSpeed] == 0.0) { GateInfo[g][gSpeed] = 3; }
                        MoveDynamicObject(GateInfo[g][gID], GateInfo[g][gPosXM], GateInfo[g][gPosYM], GateInfo[g][gPosZM], GateInfo[g][gSpeed]);
                        gatedown[g] = 1;
                        return 1;
                    }
                    if(gatedown[g] == 1)
                    {
                        if(GateInfo[g][gSpeed] == 0.0) { GateInfo[g][gSpeed] = 3; }
                        MoveDynamicObject(GateInfo[g][gID], GateInfo[g][gPosX], GateInfo[g][gPosY], GateInfo[g][gPosZ], GateInfo[g][gSpeed]);
                        gatedown[g] = 0;
                        return 1;
                    }
                }
                else
                {
                    return SendClientMessage(playerid, COLOR_GREY," You don't have the remote for this gate !");
                }
            }
            else
            {
                if(g < MAX_GATES)
                {
                    continue;
                }
                else
                {
                    return SendClientMessage(playerid, COLOR_GREY," You're not near to any gate");
                }
            }
        }
        return 1;
    }



Re: Problem with gates passwords - Stanford - 01.05.2013

Any help?


Re: Problem with gates passwords - Stanford - 02.05.2013

BUMP!


Re: Problem with gates passwords - Stanford - 02.05.2013

Here's the loading and saving function, if this helps:

pawn Код:
public LoadGates()
{
    new arrCoords[20][64];
    new strFromFile2[512];
    new File: file = fopen("gates.cfg", io_read);
    if(file)
    {
        new idx;
        while (idx < MAX_GATES)
        {
            fread(file, strFromFile2);
            split(strFromFile2, arrCoords, '|');
            GateInfo[idx][gPosX] = floatstr(arrCoords[0]);
            GateInfo[idx][gPosY] = floatstr(arrCoords[1]);
            GateInfo[idx][gPosZ] = floatstr(arrCoords[2]);
            GateInfo[idx][gFamily] = strval(arrCoords[3]);
            GateInfo[idx][gFaction] = strval(arrCoords[4]);
            GateInfo[idx][gHID] = strval(arrCoords[5]);
            GateInfo[idx][gRotX] = floatstr(arrCoords[6]);
            GateInfo[idx][gRotY] = floatstr(arrCoords[7]);
            GateInfo[idx][gRotZ] = floatstr(arrCoords[8]);
            GateInfo[idx][gRotXM] = floatstr(arrCoords[9]);
            GateInfo[idx][gRotYM] = floatstr(arrCoords[10]);
            GateInfo[idx][gRotZM] = floatstr(arrCoords[11]);
            GateInfo[idx][gPosXM] = floatstr(arrCoords[12]);
            GateInfo[idx][gPosYM] = floatstr(arrCoords[13]);
            GateInfo[idx][gPosZM] = floatstr(arrCoords[14]);
            GateInfo[idx][gModel] = strval(arrCoords[15]);
            GateInfo[idx][gRange] = strval(arrCoords[16]);
            GateInfo[idx][gSpeed] = strval(arrCoords[17]);
            if(strlen(arrCoords[18]))
            {
                strmid(GateInfo[idx][gPass], arrCoords[18], 0, strlen(arrCoords[18]), 23);
            }
            else
            {
                strmid(GateInfo[idx][gPass], "", 0, 0, 23);
            }
            GateInfo[idx][gPassed] = strval(arrCoords[19]);
            CreateGate(idx);
            idx++;
        }
        fclose(file);
    }
    return 1;
}
public SaveGates()
{
    new idx;
    new File: file2;
    while (idx < MAX_GATES)
    {
        new coordsstring[512];
        format(coordsstring, sizeof(coordsstring), "%f|%f|%f|%d|%d|%d|%f|%f|%f|%f|%f|%f|%f|%f|%f|%d|%d|%d|%s|%d\n",
        GateInfo[idx][gPosX],
        GateInfo[idx][gPosY],
        GateInfo[idx][gPosZ],
        GateInfo[idx][gFamily],
        GateInfo[idx][gFaction],
        GateInfo[idx][gHID],
        GateInfo[idx][gRotX],
        GateInfo[idx][gRotY],
        GateInfo[idx][gRotZ],
        GateInfo[idx][gRotXM],
        GateInfo[idx][gRotYM],
        GateInfo[idx][gRotZM],
        GateInfo[idx][gPosXM],
        GateInfo[idx][gPosYM],
        GateInfo[idx][gPosZM],
        GateInfo[idx][gModel],
        GateInfo[idx][gRange],
        GateInfo[idx][gSpeed],
        GateInfo[idx][gPass],
        GateInfo[idx][gPassed]);
        if(idx == 0)
        {
            file2 = fopen("gates.cfg", io_write);
        }
        else
        {
            file2 = fopen("gates.cfg", io_append);
        }
        fwrite(file2, coordsstring);
        idx++;
        fclose(file2);
    }
    return 1;
}



Re: Problem with gates passwords - Stanford - 02.05.2013

No one can help me!?


Re: Problem with gates passwords - Infinity90 - 02.05.2013

Where your gate.cfg is located. Check if the password is saving and being inputted correctly in the file.


Re: Problem with gates passwords - RevolutionaryGaming - 02.05.2013

Have you considered enacting any more-modern command processors? Quite frankly I don't even want to start looking into the code you have posted considering you are usimg strcmp. Try to reconstruct your command with something like fcmd and sscanf2. Who knows, you may fix the issue in the process.

https://sampforum.blast.hk/showthread.php?tid=214651
https://sampforum.blast.hk/showthread.php?tid=120356


Re: Problem with gates passwords - Stanford - 02.05.2013

I've converted this code to DCMD and it didn't work, any help?


Re: Problem with gates passwords - Stanford - 03.05.2013

any solution?


Re: Problem with gates passwords - Guest123 - 03.05.2013

stop bumping dude..