returning an array
#1

hey all

i need your help
ok i want to return an array by an stock but i dont know how to do.

at the moment i use the split function out of my stock
Код:
	new regionArray[2][64],region[64];
	region=GetRegionName(0,5);
	split(region, regionArray, '|');
	regionArray[0]
	regionArray[1]
my stock:
Код:
stock GetRegionName(Float:x,Float:y)
{
	new query[128],result[32];
	format(query,sizeof(query),"SELECT regionMain,regionSub FROM samp_regions WHERE regionOLX<='%f' AND regionURX>='%f' AND regionURY<='%f' AND regionOLY>='%f' LIMIT 1;",x,x,y,y);
	mysql_query(query, -1, -1, MySQLConnection);
	mysql_store_result(MySQLConnection);
	if(mysql_num_rows(MySQLConnection) > 0)
	{
	    mysql_fetch_row(result,"|",MySQLConnection);
	}
	return result;
}
how can i make that i just have
Код:
	regionArray=GetRegionName(0,5);
	regionArray[0]
	regionArray[1]
or is that impossible?

thanks and greetz from germany
Reply
#2

Correct me if i'm wrong, but I think this is not possible in pawn. You should try something like this:

pawn Код:
GetRegionName(Float:x,Float:y,result[])
{
new query[128];
    format(query,sizeof(query),"SELECT regionMain,regionSub FROM samp_regions WHERE regionOLX<='%f' AND regionURX>='%f' AND regionURY<='%f' AND regionOLY>='%f' LIMIT 1;",x,x,y,y);
    mysql_query(query, -1, -1, MySQLConnection);
    mysql_store_result(MySQLConnection);
    if(mysql_num_rows(MySQLConnection) > 0)
    {
        mysql_fetch_row(result,"|",MySQLConnection);
    }
    return 1;
}
pawn Код:
new result[35];
    GetRegionName(0,5,result);
Reply
#3

kk thank you
it runs now

but i include the split function directly into the stock

GetRegionName(Float,Float:y,dest[][])
{
new query[256],result[128];
format(query,sizeof(query),"SELECT regionMain,regionSub FROM samp_regions WHERE regionOLX<='%f' AND regionURX>='%f' AND regionURY<='%f' AND regionOLY>='%f' LIMIT 1;",x,x,y,y);
mysql_query(query, -1, -1, MySQLConnection);
mysql_store_result(MySQLConnection);
if(mysql_num_rows(MySQLConnection) > 0)
{
mysql_fetch_row(result,"|",MySQLConnection);
split(result, dest, '|');
}
return 1;
}

USAGE:
new array[2][32];
GetRegionName(x,y,array);
array[0]: regionMain
array[1]: regionSub
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)