MySQL BlueG - Get()Data - multi_threaded question -
Riddick94 - 18.12.2015
So hello,
I am here to ask a simple question as I can NOT think of any best way of doing that function maybe someone has done it already and is eager to share it with us.
So basically, I want to make a function which requires "SELECT" query. The name of that function is "GetItemName(objectid)" and it's supposed to return the name of the object which player is currently looking at.
So, let's say, if I want to make that function and make it also multi_threaded query, then how do I do that without making TWO PUBLIC callbacks? I was trying to add parameter "phase" in that function but it doesn't do the trick.
Example:
pawn Код:
PublicEx GetItemName(objectid)
{
static query[64];
format(query, sizeof(query), "SELECT `name` FROM `items_data` WHERE `objectid` = %d", objectid);
mysql_function_query(SerwerData[E_SERWER_MYSQL], query, true, "...", "...", ...);
}
We want THIS code to return the name of item. But multi_threaded query REQUIRES me to make another callback in first three dots "..." and return that value there. Which is REALLY pain in the ass.
So, anybody here smart enough to give some nice, clean solution to it? Will be grateful.
Thanks.
Re: MySQL BlueG - Get()Data - multi_threaded question -
Ahmad45123 - 18.12.2015
Use y_inline ?
Re: MySQL BlueG - Get()Data - multi_threaded question -
ikey07 - 18.12.2015
pawn Код:
PublicEx GetItemName(objectid)
{
new query[64];
format(query, sizeof(query), "SELECT `name` FROM `items_data` WHERE `objectid` = %d", objectid);
mysql_query(1,query);
mysql_store_result();
mysql_fetch_field("name",query);
mysql_free_result();
return query;
}
Re: MySQL BlueG - Get()Data - multi_threaded question -
Riddick94 - 18.12.2015
Quote:
Originally Posted by Ahmad45123
Use y_inline ?
|
That's some sense.
Quote:
Originally Posted by ikey07
pawn Код:
PublicEx GetItemName(objectid) { new query[64]; format(query, sizeof(query), "SELECT `name` FROM `items_data` WHERE `objectid` = %d", objectid); mysql_query(1,query); mysql_store_result(); mysql_fetch_field("name",query); mysql_free_result(); return query; }
|
Old version of MySQL I see you doing. No free_result or anything. Thanks for the interest anyway.
Re: MySQL BlueG - Get()Data - multi_threaded question -
ikey07 - 18.12.2015
I have never seen an use of mysql_function_query, only fills your gamemode with unneeded rows and makes mysql queries all over the place. Just remove those free result lines.
Re: MySQL BlueG - Get()Data - multi_threaded question -
Ahmad45123 - 18.12.2015
Quote:
Originally Posted by Riddick94
That's some sense.
|
https://sampforum.blast.hk/showthread.php?tid=548986
Read this to get what i mean ^^
Re: MySQL BlueG - Get()Data - multi_threaded question -
Riddick94 - 18.12.2015
Quote:
Originally Posted by Ahmad45123
|
That was the very first thing I did and have found it.
Spoke with my friend and we have a new workaround for my solution, but here's another problem.
pawn Код:
new object_data[5];
object_data[0] = itemid;
object_data[1] = INVALID_3DTEXT_ID;
float(object_data[2]) = x;
float(object_data[3]) = y;
float(object_data[4]) = z;
printf("Created: %d | Text: %d | X: %f | Y: %f | Z: %f", object_data[0], object_data[1], object_data[2], object_data[3], object_data[4]);
Streamer_SetArrayData(STREAMER_TYPE_OBJECT, objectid, E_STREAMER_EXTRA_ID, object_data, sizeof(object_data));
float() = x ... etc. saving floats are spitting out the errors.
Код:
error 022: must be lvalue (non-constant)
warning 215: expression has no effect
x, y, z ARE the floats (OnPlayerEditDynamicObject default parameters).
Does anyone know how to get around that? I can't set "Float:" tag before "object_data[5]". Since it's gonna give me an error from Streamer_SetArrayData.
Thanks for help anyways.
edit://
Got the data finally.
object_data[2] = _
;
....
Thanks (:
Re: MySQL BlueG - Get()Data - multi_threaded question -
SickAttack - 18.12.2015
Quote:
Originally Posted by Riddick94
That was the very first thing I did and have found it.
Spoke with my friend and we have a new workaround for my solution, but here's another problem.
pawn Код:
new object_data[5]; object_data[0] = itemid; object_data[1] = INVALID_3DTEXT_ID; float(object_data[2]) = x; float(object_data[3]) = y; float(object_data[4]) = z;
printf("Created: %d | Text: %d | X: %f | Y: %f | Z: %f", object_data[0], object_data[1], object_data[2], object_data[3], object_data[4]); Streamer_SetArrayData(STREAMER_TYPE_OBJECT, objectid, E_STREAMER_EXTRA_ID, object_data, sizeof(object_data));
float() = x ... etc. saving floats are spitting out the errors.
Код:
error 022: must be lvalue (non-constant)
warning 215: expression has no effect
x, y, z ARE the floats (OnPlayerEditDynamicObject default parameters).
Does anyone know how to get around that? I can't set "Float:" tag before "object_data[5]". Since it's gonna give me an error from Streamer_SetArrayData.
Thanks for help anyways.
edit://
Got the data finally.
object_data[2] = _ ;
....
Thanks (:
|
Without having to remove tags:
pawn Код:
// ** INCLUDES
#include <a_samp>
#include <streamer>
// ** MAIN
main()
{
print("Loaded \"streamer_array_data.amx\".");
}
// ** CALLBACKS
public OnGameModeInit()
{
new pickupid = CreateDynamicPickup(1242, 23, 136.6050, -74.2258, 1.4297);
enum eData
{
value,
Float:x
};
new aData[eData];
aData[value] = 1;
aData[x] = 10.0;
Streamer_SetArrayData(STREAMER_TYPE_PICKUP, pickupid, E_STREAMER_EXTRA_ID, aData);
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
new aData[2];
Streamer_GetArrayData(STREAMER_TYPE_PICKUP, pickupid, E_STREAMER_EXTRA_ID, aData);
printf("aData[0]: %d", aData[0]);
printf("aData[1]: %f", aData[1]);
return 1;
}