Plant cmd -
KinderClans - 08.09.2018
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;
}
Re: Plant cmd -
Hunud - 08.09.2018
GetPlayerState maybe ?
Re: Plant cmd -
NaS - 08.09.2018
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).
Re: Plant cmd -
KinderClans - 08.09.2018
Do you mind giving me some example code?
Re: Plant cmd -
NaS - 08.09.2018
For what exactly? The velocity or MapAndreas/ColAndreas?
Re: Plant cmd -
KinderClans - 08.09.2018
The velocity, to check if player is in air.
Re: Plant cmd -
NaS - 08.09.2018
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.
Re: Plant cmd -
Shinja - 08.09.2018
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
Re: Plant cmd -
KinderClans - 09.09.2018
Thank you both! I hope to resolve this problem.