18.06.2017, 17:13
Look closely at this snippet from your code
you are using strval function which converts strings to integers,
this is how strval works
This would print 15 not 15.623, because it's converted to an integer (the float part is removed)
more exemples
following this logic, when your current position has been calculated GetPlayerPos(...), let's say the positions are
when you sue strval function on them they will be integers meaning
see? All the float part is removed, and when dealing with positions, the float part matters, that's why the pickup isn't created in your exact position but offset a little bit
the correct way to go around this, is to use floatstr function instead of strval, which converts strings to
floats
*A correct snippet
reference: https://sampwiki.blast.hk/wiki/Floatstr
PHP Code:
cache_get_field_content(i, "SpawnX", tmp); FactionInfo[id][fSpawnX] = strval(tmp);
cache_get_field_content(i, "SpawnY", tmp); FactionInfo[id][fSpawnY] = strval(tmp);
cache_get_field_content(i, "SpawnZ", tmp); FactionInfo[id][fSpawnZ] = strval(tmp);
cache_get_field_content(i, "ExitX", tmp); FactionInfo[id][fExitX] = strval(tmp);
cache_get_field_content(i, "ExitY", tmp); FactionInfo[id][fExitY] = strval(tmp);
cache_get_field_content(i, "ExitZ", tmp); FactionInfo[id][fExitZ] = strval(tmp);
this is how strval works
PHP Code:
new floatNumber[7] = "15.623";
printf("%f", strval(floatNumber));
more exemples
Code:
strval("6.23") ==> 6 strval("96494.544") ==> 96494 strval("1.0") ==> 1
Code:
X = 1663.2345 Y = -4959.2783 Z = 3.296
Code:
strval(X) = 1663 strval(Y) = -4959 strval(Z) = 3
the correct way to go around this, is to use floatstr function instead of strval, which converts strings to
floats
*A correct snippet
PHP Code:
cache_get_field_content(i, "SpawnX", tmp); FactionInfo[id][fSpawnX] = floatstr(tmp);
cache_get_field_content(i, "SpawnY", tmp); FactionInfo[id][fSpawnY] = floatstr(tmp);
cache_get_field_content(i, "SpawnZ", tmp); FactionInfo[id][fSpawnZ] = floatstr(tmp);
cache_get_field_content(i, "ExitX", tmp); FactionInfo[id][fExitX] = floatstr(tmp);
cache_get_field_content(i, "ExitY", tmp); FactionInfo[id][fExitY] = floatstr(tmp);
cache_get_field_content(i, "ExitZ", tmp); FactionInfo[id][fExitZ] = floatstr(tmp);