#define SCRIPT_CARS 100 // You could also #undef MAX_VEHICLES and define it once again.. that's really up to you.
#define DEFAULT_VEHICLE_OWNER "Dealership"
#define DEFAULT_SELL_PRICE 50000
CREATE TABLE IF NOT EXISTS `vehicles` ( `id` int(5) NOT NULL AUTO_INCREMENT, `owner` varchar(25) NOT NULL, `model` int(5) NOT NULL, `price` int(11) NOT NULL, `x` float NOT NULL, `y` float NOT NULL, `z` float NOT NULL, `a` float NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
enum loadedInfo
{
Vehicles = 0,
}
new LoadedInfo[loadedInfo];
enum posInfo
{
Float: X,
Float: Y,
Float: Z,
Float: R,
}
enum vInfo // You could really name this anything.. Foo, pop, vehicle, vehicles whatever you like.
{
Id, // This is needed as SScanf loads the car variables through this Enum, i'll get back to that later.
Owner[25],
Model,
Price,
Float:Pos[posInfo], // Arrays ftw.
}
new VehicleInfo[SCRIPT_CARS][vInfo]; // Remember this ? the define we just made.. Great ! you'r actually reading.
stock LoadVehicles() // You might want to make this an public so you could call it on an timer.
{
new Query[255], id;
format(Query, sizeof(Query), "SELECT * FROM vehicles"); // Formats the query for "mysql_query"
mysql_query(Query); // Querys the "Query" Variable.
mysql_store_result(); // Stores the result from Query
while(mysql_fetch_row(Query,"|")) // Splits the row
{
id = LoadedInfo[Vehicles];
sscanf(Query, "p<|>e<is[25]iiffff>", VehicleInfo[id]); // Pretty neat ehh? [ ID, OWNER, MODEL, PRICE, POS X, POS Y, POS Z, POS A ]
new Color1 = random(126); new Color2 = random(126);
CreateVehicle(VehicleInfo[id][Model],VehicleInfo[id][Pos][X],VehicleInfo[id][Pos][Y],VehicleInfo[id][Pos][Z],VehicleInfo[id][Pos][R],Color1,Color2, 60*10000);
LoadedInfo[Vehicles] = LoadedInfo[Vehicles] + 1;
}
}
command(createveh, playerid, params[]) // Create vehicle command, not Tested.
{
new vID, Query[200];
if(sscanf(params, "i", vID)) return SendClientMessage(playerid, COLOR_ADMIN, "Usage: /createveh [ ModelID ]");
new Float:pPOS[4];
GetPlayerPos(playerid, pPOS[0], pPOS[1], pPOS[2]);
GetPlayerFacingAngle(playerid , pPOS[3]);
format(Query, sizeof(Query), "INSERT INTO vehicles (id, owner, model, price, x, y, z, a) VALUES (NULL, '%s', %d, %d, %f, %f, %f, %f);",DEFAULT_VEHICLE_OWNER,vID, DEFAULT_VEHICLE_PRICE, pPOS[0], pPOS[1], pPOS[2], pPOS[3]);
mysql_query(Query);
format(Query, sizeof(Query), "Created an %d at x: %f y: %f z: %f a: %f);",vID,pPOS[0], pPOS[1], pPOS[2], pPOS[3]);
SendClientMessage(playerid, COLOR_ADMIN, Query);
return 1;
}
command(reloadvehicles, playerid, params[]) // Reload's Vehicles
{
for(new i; i < SCRIPT_CARS; i++)
{
if(IsVehicleConnected(i)) DestroyVehicle(i);
}
LoadVehicles();
SendClientMessage(playerid, COLOR_ADMIN, "Vehicle's reloaded");
}
public OnPlayerEnterVehicle(playerid, vehicleid)
{
if(strmatch(VehicleInfo[vehicleid][Owner], GetName(playerid)))
{
return 1;
}
else
{
// clear animations, cant be bothered searching it up x))
}
return 1;
}
stock strmatch(const String1[], const String2[])
{
if ((strcmp(String1, String2, true, strlen(String2)) == 0) && (strlen(String2) == strlen(String1)))
{
return true;
}
else
{
return false;
}
}
Nice tutorial! hey i need to know this xD make the last part u.u
|
Nice will be used, not much maybe since not many people use MySQL + sscanf.
|
Plus lag source? I seen some servers that have a lot of lines in them that uses MySQL they lag up a little
|
C:\Documents and Settings\Piim\Desktop\samp03bsvr_R2_win32\gamemodes\CleanScript(MySQL).pwn(2254) : warning 219: local variable "Query" shadows a variable at a preceding level C:\Documents and Settings\Piim\Desktop\samp03bsvr_R2_win32\gamemodes\CleanScript(MySQL).pwn(2261) : error 035: argument type mismatch (argument 3) C:\Documents and Settings\Piim\Desktop\samp03bsvr_R2_win32\gamemodes\CleanScript(MySQL).pwn(2271) : warning 219: local variable "Query" shadows a variable at a preceding level C:\Documents and Settings\Piim\Desktop\samp03bsvr_R2_win32\gamemodes\CleanScript(MySQL).pwn(2287) : error 017: undefined symbol "IsVehicleConnected" Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase 2 Errors.
C:\Documents and Settings\Piim\Desktop\samp03bsvr_R2_win32\gamemodes\CleanScript(MySQL).pwn(2254) : warning 219: local variable "Query" shadows a variable at a preceding level C:\Documents and Settings\Piim\Desktop\samp03bsvr_R2_win32\gamemodes\CleanScript(MySQL).pwn(2261) : error 035: argument type mismatch (argument 3) C:\Documents and Settings\Piim\Desktop\samp03bsvr_R2_win32\gamemodes\CleanScript(MySQL).pwn(2271) : warning 219: local variable "Query" shadows a variable at a preceding level C:\Documents and Settings\Piim\Desktop\samp03bsvr_R2_win32\gamemodes\CleanScript(MySQL).pwn(2287) : error 017: undefined symbol "IsVehicleConnected" Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase 2 Errors.
C:\Documents and Settings\Piim\Desktop\samp03bsvr_R2_win32\gamemodes\CleanScript(MySQL).pwn(2254) : warning 219: local variable "Query" shadows a variable at a preceding level C:\Documents and Settings\Piim\Desktop\samp03bsvr_R2_win32\gamemodes\CleanScript(MySQL).pwn(2271) : warning 219: local variable "Query" shadows a variable at a preceding level
Hey, thanks for this. I will definitely be learning from this tutorial. xD
|