2024-05-05, 02:08 PM
(This post was last modified: 2024-05-05, 04:14 PM by carl_anderson.)
(2024-05-05, 10:56 AM)Sizy Wrote: it doesn't work in game bro, what should I do to this
Code:forward OnPlayerFall(playerid);
forward CalculateDamage(Float:fall_height);
public OnPlayerFall(playerid) {
new Float:fall_height = GetPlayerDistanceFromPoint(playerid, 2.0, 2.0, 2.0);
new damage = CalculateDamage(fall_height);
// Apply damage to the player
SetPlayerHealth(playerid, GetPlayerHealth(playerid) - damage);
// You can also send a message to the player informing them about the damage
SendClientMessage(playerid, COLOR_RED, "You took damage from the fall!");
return 1;
}
// Function to calculate damage based on fall height
public CalculateDamage(Float:fall_height) {
if (fall_height <= 0.0) return 0;
if (fall_height <= 2.0) return 5; // Minimum damage if fall height is less than or equal to 2 meters
return floatround((fall_height - 2.0) * 2 + 5); // Damage increases linearly with fall height beyond 2 meters
}
Well you autogenerated this code with chatGpt and it doesn't work for obvious reasons.
First you should think what you want to achieve even.
You want to detect, when player is falling, so how you would achieve that?
There is actually many ways todo it, but yeah you should yourself first think how todo it.
Maybe you can look what animation player has.
So steps are
Create timer or use OnPlayerUpdate call.
Check player animation.
- open.mp/docs/scripting/functions/GetPlayerAnimationIndex
- https://www.open.mp/docs/scripting/resources/animations
If animation equals falling, then apply damage for example