Vehicle System -
GaB1TzZzu - 07.01.2011
Hi there. I need help with my vehicle system for a RolePlay server. I don't know very well to do this thing, for this i come here to ask you. When i spawn a vehicle with /veh, to remain after restart.. Who can help me?
Re: Vehicle System -
DarrenThayer - 07.01.2011
You would need a mysql connection if you want to do this effectively. Do you know how to use Mysql with Pawn?
Re: Vehicle System -
GaB1TzZzu - 08.01.2011
I`m using MySQL now.. I have database with all it's need, but i doesn't know how to make /veh command to introduce that car in MySQL. Can someone help me ?
Re: Vehicle System -
_rAped - 11.01.2011
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.
Re: Vehicle System -
GaB1TzZzu - 26.01.2011
Please help me .
Re: Vehicle System -
GaB1TzZzu - 26.01.2011
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()
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.
Re: Vehicle System -
GaB1TzZzu - 27.01.2011
I need a function to respawn the cars from MySQL ...
Re: Vehicle System -
PeteShag - 27.01.2011
SpawnVehicles();
On OnGameModeInit
Re: Vehicle System -
GaB1TzZzu - 27.01.2011
That function doesn't work.
Re: Vehicle System -
PowerPC603 - 27.01.2011
When you create a vehicle, save all data to a file: it's model-id, spawn-coordinates (x, y, z, angle).
Use numeric values when saving the files, like "vehicle1.dat", "vehicle2.dat".
Each time you create a vehicle, search for the first free number (in this example it would be 3).
When you restart the server, reload all these files and re-create the vehicles during OnGameModeInit.
Very easy to do.
Creating houses works exactly the same way, creating them by "/createhouse", which also saves the house-data to a file.
During OnGameModeInit, just load all house-files you can find and re-create them all.