Vehicle System
#6

Quote:
Originally Posted by _rAped
Посмотреть сообщение
pawn Код:
COMMAND:savevehicle(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You can't use this command!");
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Must be in a vehicle to use this command!");
    new Float:vehx, Float:vehy, Float:vehz, Float:veho, vehm, color1, color2, currentveh, string[128], query[250];
    if(sscanf(params, "dd", color1, color2)) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /savevehicle (color1) (color2)");
    currentveh = GetPlayerVehicleID(playerid);
    GetVehiclePos(currentveh, vehx, vehy, vehz);
    GetVehicleZAngle(currentveh, veho);
    vehm = GetVehicleModel(currentveh);
    format(string, sizeof(string), "SERVER: Static vehicle (%d) (%d) added at: %f, %f, %f, %f", type, color1, color2, vehx, vehy, vehz, veho);
    SendClientMessage(playerid, 0xFFFFFFAA, string); printf("string");
    format(query, sizeof(query), "INSERT INTO `vehicles` (`vehid`, `x`, `y`, `z`, `o`, `color1`, `color2`) VALUES ('%d', '%f', '%f', '%f', '%f', '%d', '%d');", vehm, vehx, vehy, vehz, veho, color1, color2);
    mysql_query(query);
    return 1;
}
If you have ZCMD and sscanf it should work just fine.

pawn Код:
CREATE TABLE IF NOT EXISTS `vehicles` (
  `id` int(5) NOT NULL AUTO_INCREMENT,
  `vehid` int(11) NOT NULL,
  `x` varchar(50) DEFAULT NULL,
  `y` varchar(50) DEFAULT NULL,
  `z` varchar(50) DEFAULT NULL,
  `o` varchar(50) DEFAULT NULL,
  `color1` int(3) DEFAULT NULL,
  `color2` int(3) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
pawn Код:
forward SpawnVehicles();
public SpawnVehicles()
{
    new
        vehdata[150],
        query[120];
    format(query, sizeof(query), "SELECT * FROM `vehicles` ORDER BY `id`;");
    mysql_query(query); mysql_store_result();

    while(mysql_fetch_row(vehdata,"|"))
    {
        new Float:vehx, Float: vehy, Float: vehz, Float: veho, vehm, vehc1, vehc2, plate[32];
        mysql_fetch_field("x",  vehdata); vehx = floatstr(vehdata);
        mysql_fetch_field("y",  vehdata); vehy = floatstr(vehdata);
        mysql_fetch_field("z",  vehdata); vehz = floatstr(vehdata);
        mysql_fetch_field("o",  vehdata); veho = floatstr(vehdata);
        mysql_fetch_field("vehid",  vehdata); vehm = strval(vehdata);
        mysql_fetch_field("color1",  vehdata); vehc1 = strval(vehdata);
        mysql_fetch_field("color2",  vehdata); vehc2 = strval(vehdata);

        new
            number = 100+random(999),
            vehicleid = CreateVehicle(vehm, vehx, vehy, vehz, veho, vehc1, vehc2, 1800);

        format(plate, sizeof(plate), "LS %d", number);
        SetVehicleNumberPlate(vehicleid, plate);
    }
    printf("[MySQL] Loaded vehicles from database, a total of: %d", mysql_num_rows());
    mysql_free_result();
    return 1;
}
Under OnGameModeInit()
pawn Код:
SpawnVehicles();
This is something I just, made should work anyways.
It doesn't work.










EDIT: I have the command to save car in Mysql, i need function to respawn them.
Reply


Messages In This Thread
Vehicle System - by GaB1TzZzu - 07.01.2011, 13:36
Re: Vehicle System - by DarrenThayer - 07.01.2011, 13:49
Re: Vehicle System - by GaB1TzZzu - 08.01.2011, 12:05
Re: Vehicle System - by _rAped - 11.01.2011, 12:10
Re: Vehicle System - by GaB1TzZzu - 26.01.2011, 13:30
Re: Vehicle System - by GaB1TzZzu - 26.01.2011, 18:25
Re: Vehicle System - by GaB1TzZzu - 27.01.2011, 06:30
Re: Vehicle System - by PeteShag - 27.01.2011, 06:32
Re: Vehicle System - by GaB1TzZzu - 27.01.2011, 07:28
Re: Vehicle System - by PowerPC603 - 27.01.2011, 07:55

Forum Jump:


Users browsing this thread: 1 Guest(s)