Subtraction does not work? -
alanhutch - 24.10.2018
Hello!
I'm using MapAndreas for a drop-object system.
If you are in an interior, MapAndreas will find the Z coord for the ground under the interior, so I made a function.
pawn Код:
forward Float:MapAndreas_FindZ_For2DCoordEx(playerid, Float:X, Float:Y, Float:Z);
public Float:MapAndreas_FindZ_For2DCoordEx(playerid, Float:X, Float:Y, Float:Z)
{
new Float:zi;
if(GetPlayerInterior(playerid) > 0)
{
zi = Z-1.011;
}
else if(GetPlayerInterior(playerid) == 0)
{
zi = MapAndreas_FindZ_For2DCoord(X, Y, Z);
}
return zi;
}
//Tried with return Float:zi; same
But when the interior is superior to 1, the objects creates at the X, Y, Z coord without making the 1.011 subtraction for touching the ground.
What is wrong in here?
Thanks in advance
Re: Subtraction does not work? -
Infin1ty - 24.10.2018
Код:
forward Float:MapAndreas_FindZ_For2DCoordEx(playerid, Float:X, Float:Y, Float:Z);
public Float:MapAndreas_FindZ_For2DCoordEx(playerid, Float:X, Float:Y, Float:Z)
{
if(GetPlayerInterior(playerid) > 0)
{
return Z - 1.011;
}
else if(GetPlayerInterior(playerid) == 0)
{
return MapAndreas_FindZ_For2DCoord(X, Y, Z);
}
return false;
}
Give this a go. If there was an error found then it'll return false, or 0. Else, it should return the values you need. Suggestion - you probably don't want this as a function with a keyword.
Re: Subtraction does not work? -
alanhutch - 24.10.2018
Quote:
Originally Posted by Infin1ty
Код:
forward Float:MapAndreas_FindZ_For2DCoordEx(playerid, Float:X, Float:Y, Float:Z);
public Float:MapAndreas_FindZ_For2DCoordEx(playerid, Float:X, Float:Y, Float:Z)
{
if(GetPlayerInterior(playerid) > 0)
{
return Z - 1.011;
}
else if(GetPlayerInterior(playerid) == 0)
{
return MapAndreas_FindZ_For2DCoord(X, Y, Z);
}
return false;
}
Give this a go. If there was an error found then it'll return false, or 0. Else, it should return the values you need. Suggestion - you probably don't want this as a function with a keyword.
|
Same, if interior is not 0 it spawns at normal Z.
Bug in SA:MP?
Re: Subtraction does not work? -
ReD_HunTeR - 25.10.2018
Yes it works only in interior 0
Quote:
Originally Posted by Kalcor
- This works only in interior 0 (main SA world) and cannot handle areas with custom objects.
|
Re: Subtraction does not work? -
alanhutch - 25.10.2018
Quote:
Originally Posted by ReD_HunTeR
Yes it works only in interior 0
|
I know, just look at my script, it bypass mapandreas while in interiors!
Re: Subtraction does not work? -
Infin1ty - 25.10.2018
I made a mistake, you can't actually subtract 1.011 from Z with the method I gave. You also can't return false as you're working with interiors. You'll have to use floatsub.
Example usage:
Код:
if(GetPlayerInterior(playerid) > 0)
{
return floatsub(Z, 1.011);
}
This is just for future reference when subtracting floats!
Re: Subtraction does not work? -
alanhutch - 25.10.2018
Quote:
Originally Posted by Infin1ty
I made a mistake, you can't actually subtract 1.011 from Z with the method I gave. You also can't return false as you're working with interiors. You'll have to use floatsub.
Example usage:
Код:
if(GetPlayerInterior(playerid) > 0)
{
return floatsub(Z, 1.011);
}
This is just for future reference when subtracting floats!
|
Never known about this function!
Thanks a lot
EDIT:
No effect, the same.
Re: Subtraction does not work? -
alanhutch - 25.10.2018
Quote:
Originally Posted by ******
`-` IS that function, it's just an alternate name. There's no reason at all to prefer `floatsub` over `-`.
|
Yeah, it gives the same problem.
Any solutions or it's officially a bug?
Re: Subtraction does not work? -
NaS - 25.10.2018
That function uses MapAndreas_FindZ_For2DCoord wrongly.
The Z coord in the MapAndreas function is passed by reference, not return value!
MapAndreas_FindZ_For2DCoord does not even consider the value passed to Z, because it is not relevant.
Код:
native MapAndreas_FindZ_For2DCoord(Float:X, Float:Y, &Float:Z);
Your function will not even return the correct Z in interior 0, it will return the return value of MapAndreas_FindZ_For2DCoord which is NOT the Z coord (it probably returns 0/1 for success/failure). It should even give you a tag mismatch warning since MapAndreas_FindZ_For2DCoord returns an integer value.
Код:
forward Float:MapAndreas_FindZ_For2DCoordEx(playerid, Float:X, Float:Y, Float:Z);
public Float:MapAndreas_FindZ_For2DCoordEx(playerid, Float:X, Float:Y, Float:Z)
{
new Float:zi;
if(GetPlayerInterior(playerid) > 0)
{
zi = Z-1.011;
}
else
{
MapAndreas_FindZ_For2DCoord(X, Y, zi); // The height will get passed to "zi".
}
return zi;
}
If this doesn't work for you, you either pass the wrong playerid or something else is wrong with your code.
If you replaced MapAndreas_FindZ_For2DCoord with MapAndreas_FindZ_For2DCoordEx you also need to get Z from the return value, as opposed to getting it from the referenced parameter.
Re: Subtraction does not work? -
alanhutch - 26.10.2018
Quote:
Originally Posted by ******
No, there is no problem with subtraction. I suspect the problem is somewhere else in your code, such as retrieving the position or interior, or how you call this function.
|
You were right (as always)
It was just a misunderstunding in my /drop command.
Thank you all for the support!