Command
#1

I have a command to plant seeds and i added a check to check if player is in air, problem is, even if im in ground or in a streets, it says i can't plant seeds in air.

This is the check:

pawn Код:
new Float:vx, Float:vy, Float:vz;
    GetPlayerVelocity(playerid, vx, vy, vz);
    vz = VectorSize(vx, vy, vz);
    if(floatabs(vz) < 0.05) return SCM(playerid, COLOR_LIGHTRED, "* You can't plant seeds in air.");
Reply
#2

You have to use MapAndreas plugin for that, velocity is not for that type of purpose.

Код:
new Float:ox, Float:oy, Float:oz, Float:mz;
GetPlayerPos(playerid, ox, oy, oz);
MapAndreas_FindZ_For2DCoord(ox, oy, mz); //this here is to find the ground coordinates you have to use mapandreas plugin
if(mz != nz) return SCM(playerid, COLOR_LIGHTRED, "* You can't plant seeds in air."); //If ground value doesn't match with the players Z coordinates returns error
https://sampforum.blast.hk/showthread.php?tid=120013
Reply
#3

undefined symbol "nz".
Reply
#4

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
undefined symbol "nz".
Код:
if(mz != oz) return SCM(playerid, COLOR_LIGHTRED, "* You can't plant seeds in air.");
Reply
#5

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
undefined symbol "nz".
look at RedHunter's code. he didnt defined nz variable. you gotta do it yourself.
Reply
#6

Quote:
Originally Posted by UFF
Посмотреть сообщение
Код:
if(mz != oz) return SCM(playerid, COLOR_LIGHTRED, "* You can't plant seeds in air.");
Tried. Same problem.

GTLS, what i have to define? Float:nz?
Reply
#7

To check if the player it's on ground, u can also check the player state first, then for more accurately, u can check the animation of the player,
Reply
#8

Quote:
Originally Posted by ReD_HunTeR
Посмотреть сообщение
You have to use MapAndreas plugin for that, velocity is not for that type of purpose.

Код:
new Float:ox, Float:oy, Float:oz, Float:mz;
GetPlayerPos(playerid, ox, oy, oz);
MapAndreas_FindZ_For2DCoord(ox, oy, mz); //this here is to find the ground coordinates you have to use mapandreas plugin
if(mz != nz) return SCM(playerid, COLOR_LIGHTRED, "* You can't plant seeds in air."); //If ground value doesn't match with the players Z coordinates returns error
https://sampforum.blast.hk/showthread.php?tid=120013
You should add a small tolerance, because a) MapAndreas isn't 100% precise and b) the player position will always be above the ground (exactly 1 unit above ground, which is the origin of the player model).

For example

Код:
if(floatabs(z - 1.0 - mz) < 0.3) // Player position must be between 0.7 and 1.3 meters above ground position (considering MapAndreas isn't precise) - a tolerance of 0.3m - subtract 1.0 from player position for the offset
{
 // Not midair
}
Still velocity is a valid way to do so. There's no way a player has a velocity of 0.0 (or similarly low) if midair, except being frozen or modding. But even then it's extremely unlikely to still have a standing/crouching animation.
MapAndreas will detect anything obstructed as underground. You could work with a combination of velocity, animation and player state to get a better result.
Reply
#9

undefined symbol "z"
Reply
#10

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
undefined symbol "z"
Change it to 'oz' in the above code...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)