Mysql Variable - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Mysql Variable (
/showthread.php?tid=526506)
Mysql Variable -
TakeiT - 17.07.2014
I can't seem to wrap my head around what i'm doing. This is an old project from a few months ago that I picked up today. It's a map editor. What i'm trying to do is have multiple 'projects' to enter and make my maps with. On the first project, all of the objects save fine. But on the second project, the first object over writes the first object in the other project and so forth. Because they are player objects, and deleted when you leave the project, I stored the object id given by the gamemode into a database, but i'm trying to get the id that is saved in the 'ID' in the database to update it, though i've had no success. This is what i've tried.
pawn Code:
stock CreateSavingObject(playerid, Model, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Project)
{
new id = 0, Query[200], string[100];
id = CreatePlayerObject(playerid, Model, X, Y, Z, rX, rY, rZ);
format(Query,sizeof(Query), "INSERT INTO `OBJECTS` (`PROJECT`, `MODEL`, `PROJID`) VALUES (%d, %d, %d)", Project, Model, id);
mysql_query(Query);
format(Query, sizeof(Query), "SELECT `ID` FROM `OBJECTS` WHERE `PROJECT` = %d AND `PROJID` = %d)", Project, id);
mysql_query(Query);
mysql_store_result();
while(mysql_fetch_row_format(Query,"|"))
{
mysql_fetch_field_row(string, "ID"); id = strval(string);
}
mysql_free_result();
ObjectInfo[id][oX] = X;
ObjectInfo[id][oY] = Y;
ObjectInfo[id][oZ] = Z;
ObjectInfo[id][orX] = rX;
ObjectInfo[id][orY] = rY;
ObjectInfo[id][orZ] = rZ;
ObjectInfo[id][oModel] = Model;
ObjectInfo[id][oProject] = Project;
ObjectInfo[id][oProjid] = id;
format(string, sizeof(string), "You have created an object in slot %d.", id);
InfoMessage(pid, string);
EditPlayerObject(pid, id);
return 1;
}
EDIT: to better explain, the bottom line of text, where it says "edited object 1" should say "Edited object 3"
Re: Mysql Variable -
Vince - 17.07.2014
Use mysql_insert_id (or cache_insert_id for newer versions). Maybe also easier if you create a separate table for each project.
Re: Mysql Variable -
TakeiT - 17.07.2014
mysql_insert_id did not work either, I guess I could just make a table for each project, but it'll require quite a bit of work, changing around the whole system.
Re: Mysql Variable -
TakeiT - 17.07.2014
Alright, I changed everything over, just have a small issue with the loading, i'll post here if I can't figure it out.