Plant cmd
#1

I have a drug system, but needs some tweaks. Actually players can plant even in air, how to resolve this?

pawn Код:
CMD:plant(playerid, params[])
{
    Plant_Create(playerid, 1);
    return 1;
}
Reply
#2

GetPlayerState maybe ?
Reply
#3

For a simple solution use GetPlayerVelocity and calculate the velocity vector using VectorSize.

It's extremely unlikely that someone is mid-air without any velocity, as they will fall or at least move.
Furthermore only allow planting on-foot.

For a better and reliable solution use MapAndreas or ColAndreas, this also lets you adjust the plant's position so that it's always perfectly on the ground (even with rotation, if using CA).
Reply
#4

Do you mind giving me some example code?
Reply
#5

For what exactly? The velocity or MapAndreas/ColAndreas?
Reply
#6

The velocity, to check if player is in air.
Reply
#7

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
The velocity, to check if player is in air.
Код:
new Float:vx, Float:vy, Float:vz;
GetPlayerVelocity(playerid, vx, vy, vz);

vz = VectorSize(vx, vy, vz); // Calculate the vector (movement speed)

if(floatabs(vz) < 0.05) // Player is not moving and most likely midair
{
// ...
}
It's nearly impossible to have a that small velocity midair because of gravity and you cannot simply hover somewhere. Make sure the player cannot abuse a feature that freezes them midair.
You might want to adjust 0.05 to a value that works better, find that out by testing.
Hacks/mods would be an exception obviously.

You could also make it so that planting is only possible while crouching (crouching isn't possible when not standing on the ground):

Код:
if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK)
Or both.
Reply
#8

Using Mapandreas, this function will help you
Код:
native MapAndreas_FindZ_For2DCoord(Float:X, Float:Y, &Float:Z);
P.S: i agree with the previous idea for crouch check, its kinda better and cannot be abused
Reply
#9

Thank you both! I hope to resolve this problem.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)