03.03.2011, 20:34
First i will start with.. Im not good at MySQL =/ so dont laugh at me or something -.-'
Error:
Script:
Error:
Код:
[Thu Mar 03 22:31:24 2011] Error (0): Function: mysql_store_result called when no result stored. [Thu Mar 03 22:31:24 2011] Error (0): Function: mysql_store_result called when no prior successful query executed. [Thu Mar 03 22:31:26 2011] Error (0): Failed to exeute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VehPosX= '0.000000', VehPosY= '0.000000', VehPosZ= '0.000000', VehRot= '0.000000' at line 1.
pawn Код:
#include <a_samp>
#include <mysql>
#include <sscanf2>
native WP_Hash(buffer[], len, const str[]);
#define COLOUR_RED 0xFF0000FF
#define COLOUR_GREEN 0x00AF11FF
#define COLOUR_GREY 0x909090FF
#define MySQLhost "localhost"
#define MySQLuser "root"
#define MySQLpass "mypass"
#define MySQLdb "veh"
new MySQL:Unknown123;
enum VehicleInfo
{
VehicleOwner,
Model,
VehPosX,
VehPosY,
VehPosZ,
VehRot,
//Plate,
//Color 1,
//Color 2,
//PaintJob,
//Vehicle Component1,
//Vehicle Component2,
//Vehicle Component3,
//Vehicle Component...,
//Vehicle Component....
}
new VehicleData[MAX_PLAYERS][VehicleInfo];
public OnFilterScriptInit()
{
Unknown123 = mysql_init();
mysql_connect(MySQLhost, MySQLuser, MySQLpass, MySQLdb, MySQL:Unknown123);
return 1;
}
public OnFilterScriptExit()
{
mysql_close(MySQL:Unknown123);
return 1;
}
public OnPlayerConnect(playerid)
{
LoadBoughtVehicles(playerid);
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
SaveBoughtVehiclePos(playerid);
return 1;
}
stock PlayerName(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
return name;
}
stock SaveBoughtVehiclePos(playerid)
{
new queue[300];
new vehicleid;
vehicleid = GetPlayerVehicleID(playerid);
new Float:vehx, Float:vehy, Float:vehz, Float:angle;
GetVehiclePos(vehicleid, vehx, vehy, vehz);
GetVehicleZAngle(vehicleid, angle);
new TheModelID;
TheModelID = GetVehicleModel(vehicleid);
format(queue, sizeof(queue), "UPDATE `Vehicles` SET VehicleOwner= '%s', Model= '%d' VehPosX= '%f', VehPosY= '%f', VehPosZ= '%f', VehRot= '%f', WHERE ID= '%d'", PlayerName(playerid), TheModelID, vehx, vehy, vehz, angle, VehicleID());
mysql_query(queue);
mysql_free_result();
return 1;
}
stock LoadBoughtVehicles(playerid)
{
new row[999];
new name[MAX_PLAYER_NAME];
mysql_fetch_row(row, "|");
sscanf(row, "p<|>s[24]sdffff", name, VehicleData[playerid][VehicleOwner], VehicleData[playerid][Model], VehicleData[playerid][VehPosX], VehicleData[playerid][VehPosY], VehicleData[playerid][VehPosZ], VehicleData[playerid][VehRot]);
AddStaticVehicle(VehicleData[playerid][Model], VehicleData[playerid][VehPosX], VehicleData[playerid][VehPosY], VehicleData[playerid][VehPosZ], VehicleData[playerid][VehRot], 1, 1);
mysql_free_result();
mysql_store_result();
}
//How to unload? xD
//stock UnloadBoughtVehicles(...)
stock CreateBuyableVehicle(playerid, modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2)
{
new queue[999];
AddStaticVehicle(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2);
SaveBoughtVehiclePos(playerid);
format(queue, sizeof(queue), "INSERT INTO `Vehicles` (ID, VehicleOwner, Model, VehPosX, VehPosY, VehPosZ, VehRot) VALUES ('%d', '%s', '%d', '%f', '%f', '%f', '%f')", VehicleID(), PlayerName(playerid), modelid, spawn_x, spawn_y, spawn_z, angle);
mysql_query(queue);
}
//Commands
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(vehicle, 7, cmdtext);
return 0;
}
dcmd_vehicle(playerid, params[])
{
#pragma unused params
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
CreateBuyableVehicle(playerid, 526, X, Y, Z, 0, -1, -1);
SendClientMessage(playerid, 0xFF0000FF, "OMG Fail -.-");
return 1;
}
stock VehicleID()
{
new RandomVehicleID = random(999999999999999999999999) + 0;
#pragma unused RandomVehicleID
return 1;
}
/*
Really.. The "VehicleID()"
is supposed to.. if the ID slot 1, is used then it will be slot ID 2
and if 2 is used then it will be slot ID 3.. then so on
*/