Problem with locking vehicle - Mysql
#1

So im having some problems, when i buy vehicle i want when player locks it noone can enter but i can't manage to do it, and idk why this is command for buying:

pawn Код:
case DIALOG_AUTOBUY:
        {
            if(response)
            {

                new query[1204], str[128], id = SpawnedAutomobila+1;
                if(PI[playerid][Auto] != -1) return SCM(playerid, TOMATO, "[RPF] {FFFFFF}Vec imate auto.");
                if(PI[playerid][Novac] < AutomobilCena[playerid]) return SCM(playerid, TOMATO, "[RPF] {FFFFFF}Nemate dovoljno novca za kupovinu ovog vozila.");

                GPSOn[playerid] = 1;
                new poz = random(sizeof(PozicijeAutomobila));
                VInfo[id][Model] = AutoBiraModel[playerid];
                VInfo[id][PozX] = PozicijeAutomobila[poz][0];
                VInfo[id][PozY] = PozicijeAutomobila[poz][1];
                VInfo[id][PozZ] = PozicijeAutomobila[poz][2];
                VInfo[id][PozA] = PozicijeAutomobila[poz][3];
                VInfo[id][VW] = 0;
                VInfo[id][Int] = 0;
                VInfo[id][Boja1] = 0;
                VInfo[id][Boja2] = 0;
                strmid(VInfo[id][Vlasnik], ImeIgraca(playerid), 0, strlen(ImeIgraca(playerid)), 255);
                VInfo[id][Cena] = AutomobilCena[playerid];
                VInfo[id][Locked] = 0;
                VInfo[id][Droga] = 0;
                VInfo[id][Mats] = 0;
                VInfo[id][Oruzje1] = -1;
                VInfo[id][Oruzje2] = -1;
                VInfo[id][Oruzje3] = -1;
                VInfo[id][Municija1] = -1;
                VInfo[id][Municija2] = -1;
                VInfo[id][Municija3] = -1;

                AutoBiraModel[playerid] = 0;
                AutomobilCena[playerid] = -1;

                SpawnedAutomobila++;
                PI[playerid][Auto] = id;

                format(str, sizeof(str), ""COL_YELLOW"[SERVER]: "COL_WHITE"Cestitamo, kupili ste vozilo "COL_YELLOW"%s "COL_WHITE"po ceni od "COL_YELLOW"$%d.", ImenaVozila[VInfo[id][Model] - 400], VInfo[id][Cena]);
                SCM(playerid, WHITE, str);
                SCM(playerid, WHITE, ""COL_YELLOW"[SERVER]: "COL_WHITE"Dostupne komande vaseg auta mozete videti na "COL_YELLOW"/v.");


                VInfo[id][ownedvehicle] = CreateVehicle_H(VInfo[id][Model], VInfo[id][PozX], VInfo[id][PozY], VInfo[id][PozZ], VInfo[id][PozA], VInfo[id][Boja1], VInfo[id][Boja2], 300000);
                SetVehicleToRespawn(VInfo[id][ownedvehicle]);
                SetPlayerCheckpoint(playerid, VInfo[id][PozX], VInfo[id][PozY], VInfo[id][PozZ], 10.0);

                format(query, sizeof(query), "UPDATE `Igraci` SET `Auto` = '%d' WHERE `Ime` = '%s'", PI[playerid][Auto], ImeIgraca(playerid));
                mysql_function_query(konekt, query, true, "OnQueryFinish", "ii", THREAD_OSTALO, playerid);

                format(query, sizeof(query), "INSERT INTO `Automobili` (`ID`, `Model`, `PozX`, `PozY`, `PozZ`, `PozA`, `VW`, `Int`, `Zakljucan`, `Boja1`, `Boja2`, \
                `Vlasnik`, `Cena`, `ImaVlasnika`, `Droga`, `Oruzje1`, `Oruzje2`, `Oruzje3`, `Municija1`, `Municija2`, `Municija3`) VALUES"
);

                format(query, sizeof(query), "%s ('%d', '%d', '%f', '%f', '%f', '%f', '0', '0', '0', '0', '0', '%s', '%d', '1', '0', '-1', '-1', '-1', '-1', '-1', '-1')",
                query, id, VInfo[id][Model], VInfo[id][PozX], VInfo[id][PozY], VInfo[id][PozZ], VInfo[id][PozA], VInfo[id][Vlasnik], VInfo[id][Cena]);
                mysql_function_query(konekt, query, true, "OnQueryFinish", "i", THREAD_OSTALO);
            }
            else
            {
                AutoBiraModel[playerid] = 0;
                AutomobilCena[playerid] = -1;
                SCM(playerid, TOMATO, "[RPF] {FFFFFF}Odustali ste od kupnje vozila.");
            }
        }
This is loading

pawn Код:
case THREAD_UCITAJAUTA:
        {
            if(szRows)
            {
                new temp[130];
                for(new i = 0; i < szRows; i++)
                {
                    new id;

                    id = cache_get_field_content_int(i, "ID");

                    cache_get_field_content(i, "Vlasnik", temp);
                    format(VInfo[id][Vlasnik], 50, "%s", temp);


                    VInfo[id][PozX] = cache_get_field_content_int(i, "PozX");
                    VInfo[id][PozY] = cache_get_field_content_int(i, "PozY");
                    VInfo[id][PozZ] = cache_get_field_content_int(i, "PozZ");
                    VInfo[id][PozA] = cache_get_field_content_int(i, "PozA");
                    VInfo[id][Model] = cache_get_field_content_int(i, "Model");
                    VInfo[id][Cena] = cache_get_field_content_int(i, "Cena");
                    VInfo[id][VW] = cache_get_field_content_int(i, "VW");
                    VInfo[id][Int] = cache_get_field_content_int(i, "Int");
                    VInfo[id][Zakljucan] = cache_get_field_content_int(i, "Zakljucan");
                    VInfo[id][Boja1] = cache_get_field_content_int(i, "Boja1");
                    VInfo[id][Boja2] = cache_get_field_content_int(i, "Boja2");
                    VInfo[id][ImaVlasnika] = cache_get_field_content_int(i, "ImaVlasnika");
                    VInfo[id][Novac] = cache_get_field_content_int(i, "Novac");
                    VInfo[id][Droga] = cache_get_field_content_int(i, "Droga");
                    VInfo[id][Mats] = cache_get_field_content_int(i, "Mats");
                    VInfo[id][Oruzje1] = cache_get_field_content_int(i, "Oruzje1");
                    VInfo[id][Oruzje2] = cache_get_field_content_int(i, "Oruzje2");
                    VInfo[id][Oruzje3] = cache_get_field_content_int(i, "Oruzje3");
                    VInfo[id][Municija1] = cache_get_field_content_int(i, "Municija1");
                    VInfo[id][Municija2] = cache_get_field_content_int(i, "Municija2");
                    VInfo[id][Municija3] = cache_get_field_content_int(i, "Municija3");

                    SpawnedAutomobila++;

                    VInfo[id][ownedvehicle] = CreateVehicle_H(VInfo[id][Model], 11999.0+random(10000), 11999.0+random(10000), 0.0, 0.0, 0, 0, 1000);
                }
                printf("Roleplay Factory - Server je ucitao %d automobila u vlasnistvu", SpawnedAutomobila);
            }
        }
And this is locking:

pawn Код:
case 8:
                    {
                        new a = PI[playerid][Auto];
                        /*if(GetPlayerVehicleID(playerid) != VInfo[i][ownedvehicle])
                        {
                            SCM(playerid, TOMATO, "[RPF] {FFFFFF}Niste u svom vozilu.");
                            return 1;
                        }*/

                        if(IsPlayerInRangeOfPoint(playerid, 5.0, VInfo[i][PozX], VInfo[i][PozY], VInfo[i][PozZ]) || GetPlayerVehicleID(playerid) != VInfo[i][ownedvehicle])
                        {
                            if(VInfo[a][Locked] == 0)
                            {
                                VInfo[a][Locked] = 1;
                                GameTextForPlayer(playerid, "~W~Vehicle is ~R~locked", 2500, 6);
                                new upitu[64];
                                format(upitu, 64, "UPDATE `Automobili` SET `Zakljucan` = '1' WHERE `ID` = '%d'", a);
                                mysql_function_query(konekt, upitu, true, "OnQueryFinish", "i", THREAD_OSTALO);
                            }
                            else
                            {
                                VInfo[a][Locked] = 0;
                                GameTextForPlayer(playerid, "~W~Vehicle is ~G~unlocked", 2500, 6);
                                new upitu[64];
                                format(upitu, 64, "UPDATE `Automobili` SET `Zakljucan` = '0' WHERE `ID` = '%d'", a);
                                mysql_function_query(konekt, upitu, true, "OnQueryFinish", "i", THREAD_OSTALO);
                            }
                        }
                        else return SCM(playerid, TOMATO, "[RPF] {FFFFFF}Morate biti kod/u vaseg vozila.");
                    }
Now i've tried everything but i can't manage it to work and idk why, please help me.
Reply
#2

Anyone ?
Reply
#3

Most of this isn't even in English
Reply
#4

You merely set your own variable for locking. And that is NOT enough for the vehicle to actually get locked. You can lock the vehicel using SetVehicleParamsEx
Reply
#5

I also did this, under OnPlayerEnterVehicle:

pawn Код:
for(new i; i < MAX_VEHICLES; i++)
        {
            if(VInfo[i][ownedvehicle] == vehicleid)
            {
                if(i == IgracevAuto1[playerid] || VInfo[i][Locked] == 0)
                {
                    return 1;
                }
                else
                {
                    new str[128];
                    GetPlayerPos(playerid, Poz[0], Poz[1], Poz[2]);
                    SetPlayerPos(playerid, Poz[0], Poz[1]+2, Poz[2]+0.5);
                    format(str, sizeof(str), "* Vehicle is locked, owner of this vehicle is", VInfo[i][Owner]);
                    SCM(playerid, YELLOW, str);
                    return 1;
                }
            }
        }
Reply
#6

Well this kinda works:

pawn Код:
for(new i; i < MAX_VEHICLES; i++)
        {
            if(VInfo[i][ownedvehicle] == vehicleid)
            {
                if(i == IgracevAuto1[playerid] || VInfo[i][Locked] == 0)
                {
                    return 1;
                }
                else
                {
                    new str[128];
                    GetPlayerPos(playerid, Poz[0], Poz[1], Poz[2]);
                    SetPlayerPos(playerid, Poz[0], Poz[1]+2, Poz[2]+0.5);
                    format(str, sizeof(str), "* Vehicle is locked, owner of this vehicle is", VInfo[i][Owner]);
                    SCM(playerid, YELLOW, str);
                    return 1;
                }
            }
        }
But then i can drive all vehicles that i couldn't before and i think that is bc of the loop

http://pastebin.com/RZxpJrSQ
Reply
#7

Change to this
pawn Код:
if(VInfo[vehicleid][Locked] && IgracevAuto1[playerid] != vehicleid)
{
    new Float:Poz[3];
    GetPlayerPos(playerid, Poz[0], Poz[1], Poz[2]);
    SetPlayerPos(playerid, Poz[0], Poz[1]+2, Poz[2]+0.5);
    SCMF(playerid, GRAD2, "*Vehicle is locked, owner of this vehicle is %s", VInfo[i][Vlasnik]);
    return 0;
}
I dont know what is IgracevAuto1 but in lock i see PI[playerid][Auto] so should be PI[playerid][Auto] != vehicleid ?
Reply
#8

This is what i use it for:

pawn Код:
if(PI[playerid][Auto] != -1)
    {
        new i = PI[playerid][Auto];
        DestroyVehicle(VInfo[i][ownedvehicle]);
        VInfo[i][ownedvehicle] = CreateVehicle_H(VInfo[i][Model], VInfo[i][PozX], VInfo[i][PozY], VInfo[i][PozZ], VInfo[i][PozA], VInfo[i][Boja1], VInfo[i][Boja2], 1000);
        LinkVehicleToInterior(VInfo[i][ownedvehicle], VInfo[i][Int]);
        SetVehicleVirtualWorld(VInfo[i][ownedvehicle], VInfo[i][VW]);
        SetVehicleToRespawn(VInfo[i][ownedvehicle]);
        IgracevAuto1[playerid] = i;
        print("Loading 3: Passed");
    }
To make it simple, when all vehicles load from database they're all spawned in the middle of sea like this:

pawn Код:
case THREAD_UCITAJAUTA:
        {
            if(szRows)
            {
                new temp[130];
                for(new i = 0; i < szRows; i++)
                {
                    new id;

                    id = cache_get_field_content_int(i, "ID");

                    cache_get_field_content(i, "Vlasnik", temp);
                    format(VInfo[id][Vlasnik], 50, "%s", temp);


                    VInfo[id][PozX] = cache_get_field_content_int(i, "PozX");
                    VInfo[id][PozY] = cache_get_field_content_int(i, "PozY");
                    VInfo[id][PozZ] = cache_get_field_content_int(i, "PozZ");
                    VInfo[id][PozA] = cache_get_field_content_int(i, "PozA");
                    VInfo[id][Model] = cache_get_field_content_int(i, "Model");
                    VInfo[id][Cena] = cache_get_field_content_int(i, "Cena");
                    VInfo[id][VW] = cache_get_field_content_int(i, "VW");
                    VInfo[id][Int] = cache_get_field_content_int(i, "Int");
                    VInfo[id][Locked] = cache_get_field_content_int(i, "Zakljucan");
                    VInfo[id][Boja1] = cache_get_field_content_int(i, "Boja1");
                    VInfo[id][Boja2] = cache_get_field_content_int(i, "Boja2");
                    VInfo[id][ImaVlasnika] = cache_get_field_content_int(i, "ImaVlasnika");
                    VInfo[id][Novac] = cache_get_field_content_int(i, "Novac");
                    VInfo[id][Droga] = cache_get_field_content_int(i, "Droga");
                    VInfo[id][Mats] = cache_get_field_content_int(i, "Mats");
                    VInfo[id][Oruzje1] = cache_get_field_content_int(i, "Oruzje1");
                    VInfo[id][Oruzje2] = cache_get_field_content_int(i, "Oruzje2");
                    VInfo[id][Oruzje3] = cache_get_field_content_int(i, "Oruzje3");
                    VInfo[id][Municija1] = cache_get_field_content_int(i, "Municija1");
                    VInfo[id][Municija2] = cache_get_field_content_int(i, "Municija2");
                    VInfo[id][Municija3] = cache_get_field_content_int(i, "Municija3");

                    SpawnedAutomobila++;

                    VInfo[id][ownedvehicle] = CreateVehicle_H(VInfo[id][Model], 11999.0+random(10000), 11999.0+random(10000), 0.0, 0.0, 0, 0, 1000);
                }
                printf("Roleplay Factory - Server je ucitao %d automobila u vlasnistvu", SpawnedAutomobila);
            }
        }
And whan the player logs in the car will destroy it self, and spawn at the position saved and loaded in db:

pawn Код:
if(PI[playerid][Auto] != -1)
    {
        new i = PI[playerid][Auto];
        DestroyVehicle(VInfo[i][ownedvehicle]);
        VInfo[i][ownedvehicle] = CreateVehicle_H(VInfo[i][Model], VInfo[i][PozX], VInfo[i][PozY], VInfo[i][PozZ], VInfo[i][PozA], VInfo[i][Boja1], VInfo[i][Boja2], 1000);
        LinkVehicleToInterior(VInfo[i][ownedvehicle], VInfo[i][Int]);
        SetVehicleVirtualWorld(VInfo[i][ownedvehicle], VInfo[i][VW]);
        SetVehicleToRespawn(VInfo[i][ownedvehicle]);
        IgracevAuto1[playerid] = i;
        print("Loading 3: Passed");
    }
So you think that the code u sent me will work ? cause I don't have anyone to test it with now
Reply
#9

new id; is always 0 in this case i dont see id++;
Reply
#10

id = cache_get_field_content_int(i, "ID"); and in database is everything arranged good, 1,2,3..8,9...

Loading cars and everything else works, only locking vehicles doesn't, i mean locking does work but checking if vehicle is locked under OnPlayerEnterVehicle, hope the code u gave me will fix that
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)