Creating object from MySQL [+rep?] -
Michael@Belgium - 11.03.2012
Previous question solved
Thanks to Vince
Next:
Now trying to delete those objects/maps:
pawn Код:
CMD:delmaptest(playerid,params[])
{
new query[256],mapname[64];
if(sscanf(params,"s[64]",mapname)) return SendClientMessage(playerid, -1, "USAGE: /maptest [mapname]");
format(query,sizeof query,"SELECT * FROM `Map_Submits` WHERE MapName = '%s'",mapname);
mysql_query(query);
mysql_store_result();
if(!mysql_num_rows())
{
print("Map doesn't exist");
SendClientMessage(playerid,-1,"Map doesn't exist !");
}
else
{
printf("Deleting objects and cars from map %s",mapname);
for( new x=0; x < MAX_OBJECTS; x++)
{
DestroyObject(tempMapID[x]);
tempMapID[x] = 0;
printf("Deleting object: %i",tempMapID[x]);
}
SendClientMessage(playerid,-1,"Objects deleted");
print("Objects deleted");
for(new y=0;y<MAX_CARS;y++)
{
DestroyVehicle(tempCarID[y]);
tempCarID[y] = 0;
printf("Deleting car: %i",tempCarID[y]);
}
SendClientMessage(playerid,-1,"Cars deleted");
print("Cars deleted");
}
return 1;
}
I can only create the vehicle once !
That means if i create the object/vehicles -> done
Delete object/vehicles -> done
Create's again objects/vehicles -> fail, it only loads the objects but not the cars.
Re: Creating object from MySQL [+rep?] -
Shabi RoxX - 11.03.2012
Mysql fetch string so u need to make a string and convert it to float or integar
pawn Код:
new data[12],int;
mysql_fetch_field_row(data,"model"); int = strval(data);//convert string to int
ta[12];
mysql_fetch_field_row(data,"PosX"); Val[1] = floatstr(data);//convert string tp float
Also u forgot mysql_store_result,
edit:model is integar not a float
Re: Creating object from MySQL [+rep?] -
Michael@Belgium - 11.03.2012
[deleted]
Re: Creating object from MySQL [+rep?] -
Shabi RoxX - 11.03.2012
You are using data still as array use data not data[0],data[1].............
just use "data"
Sry I can't code for u am using my mbl
Edit:like
mysql_fetch_field_row(data,"DrawDist"); val[6]= floatstr(data);
Re: Creating object from MySQL [+rep?] -
Vince - 11.03.2012
mysql_fetch_field_row is incredibly slow, compared to just fetching the whole row at once.
Just make an enumerator:
pawn Код:
enum e_OjbectData
{
model,
Float:Xpos,
Float:Ypos,
Float:Zpos,
Float:RX,
Float:RY,
Float:RZ,
MapName[128],
Float:DrawDist,
ObjectID
}
Then:
pawn Код:
new
tempMapData[e_ObjectData];
while(mysql_fetch_row_format(query,"|"))
{
sscanf(query, "p<|>e<dffffffs[128]fd>", tempMapData);
CreateObject(tempMapData[model], tempMapData[Xpos], tempMapData[Ypos], tempMapData[Zpos], tempMapData[RX], tempMapData[RY], tempMapData[RZ], tempMapData[DrawDist]);
}
Re: Creating object from MySQL [+rep?] -
Michael@Belgium - 11.03.2012
Quote:
Originally Posted by Vince
mysql_fetch_field_row is incredibly slow, compared to just fetching the whole row at once.
Just make an enumerator:
pawn Код:
enum e_OjbectData { model, Float:Xpos, Float:Ypos, Float:Zpos, Float:RX, Float:RY, Float:RZ, MapName[128], Float:DrawDist, ObjectID }
Then:
pawn Код:
new tempMapData[e_ObjectData];
while(mysql_fetch_row_format(query,"|")) { sscanf(query, "p<|>e<dffffffs[128]fd>", tempMapData); CreateObject(tempMapData[model], tempMapData[Xpos], tempMapData[Ypos], tempMapData[Zpos], tempMapData[RX], tempMapData[RY], tempMapData[RZ], tempMapData[DrawDist]); }
|
Oh great ! It works !
And i also forgot to mysql_debug(1); that helped also ^^
Re: Creating object from MySQL [+rep?] -
Michael@Belgium - 15.03.2012
Hmm im gonna post it here because it's about the same thing too ...
If i create /delmaptest then i have to copy almost everything but do i have to use
pawn Код:
DestroyObject(tempMapData[model]);
then ? Should that work ?
Re: Creating object from MySQL [+rep?] -
iPLEOMAX - 15.03.2012
That wouldn't work because you need to store the OBJECT ID (in your server, not it's model) to a variable.
Which means, when you use CreateObject, make sure you store the returned ID to something.
You know, like: "myobject = CreateObject(...);"
So, if you want to remove it, you need to use DestroyObject(myobject);
Re: Creating object from MySQL [+rep?] -
SimonItaly - 15.03.2012
Then you should have a global array like this
pawn Код:
#define MY_OBJECTS 50 // The max. number of objects you could have in the temp map
new tempMapObjects[MY_OBJECTS];
and read objects like:
pawn Код:
new
tempMapData[e_ObjectData], i;
while(i < MY_OBJECTS && mysql_fetch_row_format(query,"|"))
{
sscanf(query, "p<|>e<dffffffs[128]fd>", tempMapData);
tempMapObjects[i++] = CreateObject(tempMapData[model], tempMapData[Xpos], tempMapData[Ypos], tempMapData[Zpos], tempMapData[RX], tempMapData[RY], tempMapData[RZ], tempMapData[DrawDist]);
}
Then you can delete them by:
pawn Код:
for(new i; i < MY_OBJECTS; i++) { DestroyObject(tempMapObjects[i]); tempMapObjects[i] = 0; }
Re: Creating object from MySQL [+rep?] -
Michael@Belgium - 15.03.2012
Quote:
Originally Posted by iPLEOMAX
That wouldn't work because you need to store the OBJECT ID (in your server, not it's model) to a variable.
Which means, when you use CreateObject, make sure you store the returned ID to something.
You know, like: "myobject = CreateObject(...);"
So, if you want to remove it, you need to use DestroyObject(myobject);
|
Damn ... I have a column with ObjectID in the db also. Maybe i can use that. It's AUTO_INCREMENT, and primary key.
Maybe i can use that ?
EDIT:
Quote:
Originally Posted by DarkSlyder
Then you should have a global array like this
pawn Код:
#define MY_OBJECTS 50 // The max. number of objects you could have in the temp map new tempMapObjects[MY_OBJECTS];
and read objects like:
pawn Код:
new tempMapData[e_ObjectData], i; while(i < MY_OBJECTS && mysql_fetch_row_format(query,"|")) { sscanf(query, "p<|>e<dffffffs[128]fd>", tempMapData); tempMapObjects[i++] = CreateObject(tempMapData[model], tempMapData[Xpos], tempMapData[Ypos], tempMapData[Zpos], tempMapData[RX], tempMapData[RY], tempMapData[RZ], tempMapData[DrawDist]); }
Then you can delete them by:
pawn Код:
for(new i; i < MY_OBJECTS; i++) { DestroyObject(tempMapObjects[i]); tempMapObjects[i] = 0; }
|
Hmm im gonna try that