Mysql vehicle system
#1

Код:
enum pInfo
{
     pCarID

};
new PlayerInfo[MAX_PLAYERS][pInfo];

enum cInfo
{
	ORM:ORM_ID,
	ID,
	Owner[MAX_PLAYER_NAME],
	Locked,
	Float:Vposx,
	Float:Vposy,
	Float:Vposz,
	Float:Vposa,
	Model,
	Color1,
	Color2,
	CarID
};

new CarInfo[MAX_VEHICLES][cInfo];
new TotalVeh;

public OnGameModeInit()
{
    mysql_tquery(g_SQL, "SELECT * FROM `vehicles`", "OnVehiclesLoad", "");
    return 1;
}

public OnPlayerConnect(playerid)
{
    PlayerInfo[playerid][pCarID] = -1;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    PlayerInfo[playerid][pCarID] = -1;
    return 1;
}

forward OnVehiclesLoad();
public OnVehiclesLoad()
{
    new time = GetTickCount();
    new c;
	for(c = 0; c < cache_num_rows(); c++) {
		new ORM:ormid = CarInfo[c][ORM_ID] = orm_create("vehicles");
		orm_addvar_int(ormid, CarInfo[c][ID], "ID");
		orm_setkey(ormid, "ID");
		orm_addvar_string(ormid, CarInfo[c][Owner], MAX_PLAYER_NAME, "Owner");
		orm_addvar_int(ormid, CarInfo[c][Locked], "Locked");
		orm_addvar_float(ormid, CarInfo[c][Vposx], "Vposx");
		orm_addvar_float(ormid, CarInfo[c][Vposy], "Vposy");
		orm_addvar_float(ormid, CarInfo[c][Vposz], "Vposz");
		orm_addvar_float(ormid, CarInfo[c][Vposa], "Vposa");
		orm_addvar_int(ormid, CarInfo[c][Model], "Model");
		orm_addvar_int(ormid, CarInfo[c][Color1], "Color1");
		orm_addvar_int(ormid, CarInfo[c][Color2], "Color2");
		orm_apply_cache(ormid, c);
		TotalVeh++;
		CarInfo[c][CarID] = CreateVehicle(CarInfo[c][Model], CarInfo[c][Vposx], CarInfo[c][Vposy], CarInfo[c][Vposz], CarInfo[c][Vposa], CarInfo[c][Color1], CarInfo[c][Color2], -1);
	}
	printf("%d personal cars loaded with %d ms",TotalVeh,GetTickCount() - time);
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {	    
        for(new v = 1; v <= TotalVeh; v++)
	{
  	    PlayerInfo[playerid][pCarID] = CarInfo[v][ID];
	}
    }
    return 1;
}

CMD:carid(playerid, params[])
{
	SendMes(playerid, 0x131313, "{FFFFFF}%d",PlayerInfo[playerid][pCarID]);
	return 1;
}
|My problem|

When i enter in the car,and type command /carid
The server give incorrect car id from mysql!(Example: 1) but car have id 2!

In the database i have 2 cars:
1)With id 1
2)With id 2

Sorry for my bad english!
Reply
#2

Removed.
Reply
#3

Quote:
Originally Posted by 1Deagle1
Посмотреть сообщение
Код:
CMD:carid(playerid, params[])
{
	SendMes(playerid, 0x131313, "{FFFFFF}%s",PlayerInfo[playerid][pCarID]);
	return 1;
}
Try this.
The vehicle id isn't a string, it's an integer.
Reply
#4

Quote:
Originally Posted by 1Deagle1
Посмотреть сообщение
Код:
CMD:carid(playerid, params[])
{
	SendMes(playerid, 0x131313, "{FFFFFF}%s",PlayerInfo[playerid][pCarID]);
	return 1;
}
Try this.
No,the command is working correctly,
but i think the problem is in the
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
Reply
#5

Removed
Reply
#6

Quote:
Originally Posted by 1Deagle1
Посмотреть сообщение
No problem xD
The problem exists,
When i enter in the car with id 1,2
Command see the id 0
Reply
#7

Removed
Reply
#8

You could try;
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {      
        for(new v = 1; v != TotalVeh; v++)
    {
        PlayerInfo[playerid][pCarID] = v;
    }
    }
    return 1;
}
Reply
#9

Removed
Reply
#10

Quote:
Originally Posted by 1Deagle1
Посмотреть сообщение
You're really annoying me now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)