Saving and Loading vehicles problem
#1

I have made this park command so I can save vehicles positions. but It doesnt work . I think it saves correctly, but Its not loading the vehicles when I restart the server...

Please help.
Code:
Код:
CMD:park(playerid, params[])
{
	if(pInfo[playerid][pModerator] > 2 || pInfo[playerid][pAdminLevel] >= 1)
	{
		new vehid;
		if(sscanf(params, "i", vehid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /park [vehid]");
		if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
		{
			SendClientMessage(playerid, COLOR_GREY, "You are not driving the vehicle!");
			return 1;
		}
		new id = GetVehicleID(GetPlayerVehicleID(playerid));
		new Query[500];
		new Float: X, Float: Y, Float: Z, Float: R;
		GetVehiclePos(vehid, X, Y, Z);
		GetVehicleZAngle(vehid, R);
		mysql_format(dbHandle,Query, sizeof(Query), "UPDATE `vehicles` SET `PosX` = '%f', `PosY` = '%f', `PosZ` = '%f', `PosA` = '%f' WHERE `ID` = '%d'",
		X,
		Y,
		Z,
		R,
		vehid);
		mysql_query(dbHandle,Query,false);
		
		mysql_format(dbHandle,Query, sizeof(Query), "UPDATE `vehicles` SET `Color1` = '%d', `Color2` = '%d' WHERE `ID` = '%d'",
		vInfo[id][vColor1],
		vInfo[id][vColor2],
		vehid);
		new str[128];
		format(str, sizeof(str), "The vehicles position is X:%f Y:%f Z:%f", X, Y, Z);
		SendClientMessage(playerid, -1, str);
		DestroyVehicle(vehid);
		VehicleID[vehid] = AddStaticVehicle(vInfo[id][vModel], X, Y, Z, R, vInfo[id][vColor1], vInfo[id][vColor2]);
		
	}
	else return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
	return 1;
}
Reply
#2

PHP код:
CMD:park(playeridparams[])
{
    if(
pInfo[playerid][pModerator] > || pInfo[playerid][pAdminLevel] >= 1)
    {
        new 
vehid;
        if(
sscanf(params"i"vehid)) return SendClientMessage(playeridCOLOR_GREY"USAGE: /park [vehid]");
        if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
        {
            
SendClientMessage(playeridCOLOR_GREY"You are not driving the vehicle!");
            return 
1;
        }
        new 
id GetVehicleID(GetPlayerVehicleID(playerid));
        new 
Query[500];
        new 
FloatXFloatYFloatZFloatR;
        
GetVehiclePos(vehidXYZ);
        
GetVehicleZAngle(vehidR);
        
mysql_format(dbHandle,Querysizeof(Query), "UPDATE `vehicles` SET `PosX` = '%f', `PosY` = '%f', `PosZ` = '%f', `PosA` = '%f' WHERE `ID` = '%d'",
        
X,
        
Y,
        
Z,
        
R,
        
vehid);
        
mysql_query(dbHandle,Query,false);
        
        
mysql_format(dbHandle,Querysizeof(Query), "UPDATE `vehicles` SET `Color1` = '%d', `Color2` = '%d' WHERE `ID` = '%d'",
        
vInfo[id][vColor1],
        
vInfo[id][vColor2],
        
vehid);
                
mysql_query(dbHandle,Query,false);
        new 
str[128];
        
format(strsizeof(str), "The vehicles position is X:%f Y:%f Z:%f"XYZ);
        
SendClientMessage(playerid, -1str);
        
DestroyVehicle(vehid);
        
VehicleID[vehid] = AddStaticVehicle(vInfo[id][vModel], XYZRvInfo[id][vColor1], vInfo[id][vColor2]);
        
    }
    else return 
SendClientMessage(playeridCOLOR_GREY"You are not authorised to use that command.");
    return 
1;

Reply
#3

Its saving fine. but when I restart the server my cars are no-were to be seen...
Here is my loading code:

Код:
Load_Vehicles()
{
        new Query[512], savestr[25], rows, fields, count = 0, count2 = 0;
        for(new i = 1; i < MAX_DVEHICLES; i++)
        {
                mysql_format(dbHandle,Query, sizeof(Query), "SELECT * FROM `Vehicles` WHERE `ID` = '%d'", i);
                mysql_query(dbHandle,Query);
				cache_get_data(rows, fields);
                if(rows)
                {
					cache_get_field_content(0, "Dealer", savestr);			vInfo[i][vDealer] = strval(savestr);
                    cache_get_field_content(0, "Owner", savestr);           vInfo[i][vOwner] = savestr;
                    cache_get_field_content(0, "Model", savestr);           vInfo[i][vModel] = strval(savestr);
                    cache_get_field_content(0, "Price", savestr);           vInfo[i][vPrice] = strval(savestr);
                    cache_get_field_content(0, "PosX", savestr);            vInfo[i][Pos][0] = floatstr(savestr);
                    cache_get_field_content(0, "PosY", savestr);            vInfo[i][Pos][1] = floatstr(savestr);
                    cache_get_field_content(0, "PosZ", savestr);            vInfo[i][Pos][2] = floatstr(savestr);
                    cache_get_field_content(0, "PosA", savestr);            vInfo[i][Pos][3] = floatstr(savestr);
                    cache_get_field_content(0, "Color1", savestr);          vInfo[i][vColor1] = strval(savestr);
                    cache_get_field_content(0, "Color2", savestr);          vInfo[i][vColor2] = strval(savestr);
					if(vInfo[i][vDealer] == 1)
					{
						VehicleID[i] = AddStaticVehicleEx(vInfo[i][vModel], vInfo[i][Pos][0], vInfo[i][Pos][1], vInfo[i][Pos][2], vInfo[i][Pos][3], vInfo[i][vColor1], vInfo[i][vColor2], 10);
						count++;
					}
					if(vInfo[i][vDealer] == 0)
					{
						VehicleID[i] = AddStaticVehicleEx(vInfo[i][vModel], vInfo[i][Pos][0], vInfo[i][Pos][1], vInfo[i][Pos][2], vInfo[i][Pos][3], vInfo[i][vColor1], vInfo[i][vColor2], 60000);
						count2++;
					}
                }
        }
        printf("Loaded %d Dealership vehicles", count);
		printf("Loaded %d vehicles", count2);
}

Load_DealershipVehicles()
{
	new labeltext[55];
	for(new i = 1; i < MAX_DVEHICLES; i++)
	{
		if(vInfo[i][vDealer] == DEALER_VEHICLE)
		{
			format(labeltext, sizeof(labeltext), "Price: $%d", vInfo[i][vPrice]);
            vInfo[i][Label] = Create3DTextLabel(labeltext, 0xBB7700DD, 0, 0, 0, 10.0, 0, 0);
            Attach3DTextLabelToVehicle(vInfo[i][Label], VehicleID[i], 0, 0, 0);
		}
	}
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)