01.06.2009, 01:45
For what i need to do this: floats, ints, arrays of floats and arrays of ints.
Here is an example of what i have actually:
It can be used like this in Pawn actually:
If there is a way to get the size of the arrays (i mean, the size of each parameters in fact) passed into it, i could expand it to allow this:
So what i would like is something like this, in the plugin, for example:
Here is an example of what i have actually:
pawn Code:
static cell AMX_NATIVE_CALL GetDistance(AMX *amx, cell *p)
{
cell *c1 = 0;
float f1 = 0.0f;
float f2 = 0.0f;
float f3 = 0.0f;
amx_GetAddr(amx, p[1] , &c1);
switch (p[0]/4) //switch between amount of parameters
{
case 2 : //GetDistance(Float:point1[], Float:point2[])
{
if ((p[2]-p[1])/4 == 2) //if first array is a 2d point
{
f1 = amx_ctof(c1[0]) - amx_ctof(c1[2]);
f2 = amx_ctof(c1[1]) - amx_ctof(c1[3]);
return amx_ftoc((f1 = sqrt(f1*f1 + f2*f2)));
}
else
{
f1 = amx_ctof(c1[0]) - amx_ctof(c1[3]);
f2 = amx_ctof(c1[1]) - amx_ctof(c1[4]);
f3 = amx_ctof(c1[2]) - amx_ctof(c1[5]);
return amx_ftoc((f1 = sqrt(f1*f1 + f2*f2 + f3*f3)));
}
}
case 4 : //GetDistance(Float:x1, Float:y1, Float:x2, Float:y2)
{
f1 = amx_ctof(c1[0] ) - amx_ctof(c1[0]-2);
f2 = amx_ctof(c1[0]-1) - amx_ctof(c1[0]-3);
return amx_ftoc((f1 = sqrt(f1*f1 + f2*f2)));
}
case 6 : //GetDistance(Float:x1, Float:y1, Float:z2, Float:x2, Float:y2, Float:z2)
{
f1 = amx_ctof(c1[0] ) - amx_ctof(c1[0]-3);
f2 = amx_ctof(c1[0]-1) - amx_ctof(c1[0]-4);
f3 = amx_ctof(c1[0]-2) - amx_ctof(c1[0]-5);
return amx_ftoc((f1 = sqrt(f1*f1 + f2*f2 + f3*f3)));
}
}
return amx_ftoc((f1 = POS_INFINITY));
}
It can be used like this in Pawn actually:
pawn Code:
native Float:GetDistance({Float,_}:...);
#define x1 0.0
#define y1 0.0
#define z1 0.0
#define x2 10.0
#define y2 10.0
#define z2 10.0
printf("%f", GetDistance(x1, y1, x2, y2));
printf("%f", GetDistance(Float:{x1, y1}, Float:{x2, y2}));
printf("%f", GetDistance(x1, y1, z1, x2, y2, z2));
printf("%f", GetDistance(Float:{x1, y1, z1}, Float:{x2, y2, z2}));
If there is a way to get the size of the arrays (i mean, the size of each parameters in fact) passed into it, i could expand it to allow this:
pawn Code:
GetDistance(x1, y1, Float:{x2, y2});
//or
GetDistance(Float:{x1, y1}, x2, y2);
//and etc..
pawn Code:
if (sizeofparam(parameter[2]) == 2) //parameter[2] is an array for a 2d point