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()
This is something I just, made should work anyways.
|