Problem with purchasing vehicle
#1

Okay so the problem is preety simple.
So when you purchase a vehicle, yourr vehicle ID is 0 for some reason, meanwhile when is loadas it later on from SQL it works fine.

Aka Im not storing VID properly inside VehInfo[vehicleid][VID].
VehInfo[vehicleid][VID] should store SQL ID inside of it, instead it saves 0.

pawn Код:
if(playertextid == TXD_DealershipBuyButton[playerid]) {
        new string[128], calc = GetVehiclePrice(PlayerDealershipID[playerid]) - AccInfo[playerid][PocketMoney],query[512];
        format(string,sizeof(string),"You dont have enough money. You are missing %i to buy this vehicle",calc);
       
        if(AccInfo[playerid][vOwnedTotal] >= 4) return SendClientMessage(playerid,COLOR_RED,"You already have 3 vehicles");
       
        if(AccInfo[playerid][PocketMoney] < GetVehiclePrice(PlayerDealershipID[playerid])) return SendClientMessage(playerid,COLOR_RED,string);

        mysql_format(mysql, query, sizeof(query),"INSERT INTO `vehicles` (`MasterID`,`ModelID`,`Color1`,`Color2`,`PosX`,`PosY`,`PosZ`,`PosA`,`RespawnTime`,`Price`,`Damage`,`FuelStatus`,`EngineStatus`,`Kilometrage`,`Siren`,`Owned`,`VirtualWorld`,`Interior`) VALUES ('%i','%i','%i','%i','%f','%f','%f','%f','%i','%i','%i','%i','%i','%f','%i',1,0,0)",\
        AccInfo[playerid][ID],PlayerDealershipID[playerid],0,0,509.9833,-1294.7455,16.9693,305.0121,0,GetVehiclePrice(PlayerDealershipID[playerid]),0,0,0,0);
        mysql_tquery(mysql, query, "OnVehicleCreation", "i", playerid);
       
        SetCameraBehindPlayer(playerid);
        SetPlayerVirtualWorld(playerid,0);
        SetPlayerPos(playerid,520.5632,-1292.3516,17.2422);
        InDealership[playerid] = 0;
        HideDealershipTextdraws(playerid);
        CancelSelectTextDraw(playerid);
       
        format(string,sizeof(string),"You have purchased vehicle Model ID: %i for %i",PlayerDealershipID[playerid],GetVehiclePrice(PlayerDealershipID[playerid]));
        SendClientMessage(playerid,COLOR_GREEN,string);
        AccInfo[playerid][vOwnedTotal] += 1;

        GivePlayerMoney(playerid,-GetVehiclePrice(PlayerDealershipID[playerid]));
        AccInfo[playerid][PocketMoney] -= GetVehiclePrice(PlayerDealershipID[playerid]);
       
        new vehicleid = CreateVehicle(PlayerDealershipID[playerid], 509.9833,-1294.7455,16.9693,305.0121,0,0,0,0);
        VehInfo[vehicleid][VID] = lastveh; // problematic line
        VehInfo[vehicleid][VehMasterID] = AccInfo[playerid][ID];
        VehInfo[vehicleid][ModelID] = PlayerDealershipID[playerid];
        VehInfo[vehicleid][Color1] = 0;
        VehInfo[vehicleid][Color2] = 0;
        VehInfo[vehicleid][VehPosX] = 509.9833;
        VehInfo[vehicleid][VehPosY] = -1294.7455;
        VehInfo[vehicleid][VehPosZ] = 16.9693;
        VehInfo[vehicleid][VehPosA] = 305.0121;
        PutPlayerInVehicle(playerid,vehicleid,0);
        printf("New vehicle purchased. Server ID: %i. Master ID: %i",GetPlayerVehicleID(playerid),VehInfo[vehicleid][VehMasterID]);
        SendClientMessage(playerid,COLOR_RED,"Collisions are now disabled for you for next 15 seconds so you can move your vehicle");
    }

pawn Код:
public OnVehicleCreation() {
    VehInfo[veh][VID] = cache_insert_id();
    lastveh = VehInfo[veh][VID];
    return 1;
}

So overall I know whats the problem line
pawn Код:
VehInfo[vehicleid][VID] = lastveh; // problematic line
But how do I do it differently?
It stores everything into the SQL perfectly, but the problem is, lets say I buy the car now and I want to /park it, it will recognize me as owner, but it wont find the SQL ID where it should store it so it will store it under SQL ID:0

But if I restart the server, it will all be cool
Reply
#2

The default samp vehicleid starts on 1, not 0.

So if you create a vehicle like:

new vehicle[0] = CreateVehicle

vehicle[0] is vehicleid 1.
Reply
#3

Why have the lastveh in a vehicle? Wouldn't that be more a Player thing?
Reply
#4

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Why have the lastveh in a vehicle? Wouldn't that be more a Player thing?
Yeah I forgot to bind it to a player, but same problem exists. It injects it correctly after re-loading vehicles from SQL but not when you create it right away


Quote:
Originally Posted by Aerotactics
Посмотреть сообщение
The default samp vehicleid starts on 1, not 0.

So if you create a vehicle like:

new vehicle[0] = CreateVehicle

vehicle[0] is vehicleid 1.
I know that and I dont see how will it help me with a SQL ID
Reply
#5

If you want to insert the SQL ID, wouldn't you then use

PHP код:
VehInfo[veh][VID] = cache_insert_id(); // problematic line 
instead of
PHP код:
VehInfo[vehicleid][VID] = lastveh// problematic line 
since lastveh is the current server vehicle id? (as taken from your OnVehicleCreation thing)

Also this line wouldn't work, since your function "OnVehicleCreation" doesn't have extra arguments. For this line to work it would be "public OnVehicleCreation(playerid)" while it is "public OnVehicleCreation()"
PHP код:
mysql_tquery(mysqlquery"OnVehicleCreation""i"playerid); 
Reply
#6

-resolved-
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)