SA-MP Forums Archive
Command - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Command (/showthread.php?tid=659030)



Command - KinderClans - 20.09.2018

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.");



Re: Command - ReD_HunTeR - 20.09.2018

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


Re: Command - KinderClans - 21.09.2018

undefined symbol "nz".


Re: Command - UFF - 21.09.2018

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



Re: Command - GTLS - 21.09.2018

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


Re: Command - KinderClans - 21.09.2018

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?


Re: Command - kingmk - 21.09.2018

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,


Re: Command - NaS - 21.09.2018

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.


Re: Command - KinderClans - 22.09.2018

undefined symbol "z"


Re: Command - NaS - 22.09.2018

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