open.mp forum
[Pawn] Not receiving damage when player fell onto the ground - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] Not receiving damage when player fell onto the ground (/showthread.php?tid=2707)



Not receiving damage when player fell onto the ground - Sizy - 2024-05-01

I get this error


Code:
C:\Users\User\Desktop\rsrp\gamemodes\RSRP.pwn(1361) : warning 202: number of arguments does not match definition

C:\Users\User\Desktop\rsrp\gamemodes\RSRP.pwn(1378) : warning 213: tag mismatch




Code:
forward OnPlayerFall(playerid);
forward CalculateDamage(Float:fall_height);

public OnPlayerFall(playerid) {
    new Float:fall_height;
    GetPlayerDistanceFromPoint(playerid, 2.0, 2.0, 2.0, fall_height);

    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 (fall_height - 2.0) * 2 + 5; // Damage increases linearly with fall height beyond 2 meters
}



please help to fix


RE: Not receiving damage when player fell onto the ground - Sizy - 2024-05-01

anyone guys?


RE: Not receiving damage when player fell onto the ground - carl_anderson - 2024-05-03

open up documentation
https://www.open.mp/docs/scripting/functions/GetPlayerDistanceFromPoint
you have
Code:
GetPlayerDistanceFromPoint(playerid, 2.0, 2.0, 2.0, fall_height);
but it should be
Code:
new Float:fall_height = GetPlayerDistanceFromPoint(playerid, 2.0, 2.0, 2.0);

also this code doesnt make sense, cause why you want to find player distance from 2.0, 2.0, 2.0 point?


RE: Not receiving damage when player fell onto the ground - Sizy - 2024-05-04

uhmm can you please type the whole correct code so i can just copy and paste?


RE: Not receiving damage when player fell onto the ground - carl_anderson - 2024-05-04

(2024-05-04, 11:49 AM)Sizy Wrote: uhmm can you please type the whole correct code so i can just copy and paste?
Do you have reading disability?


RE: Not receiving damage when player fell onto the ground - Sizy - 2024-05-04

I get this error C:\Users\User\Desktop\rsrp\gamemodes\RSRP.pwn(61243) : warning 213: tag mismatch

from this line // 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

this one below
return (fall_height - 2.0) * 2 + 5; // Damage increases linearly with fall height beyond 2 meters


RE: Not receiving damage when player fell onto the ground - carl_anderson - 2024-05-05

(2024-05-04, 02:28 PM)Sizy Wrote: I get this error C:\Users\User\Desktop\rsrp\gamemodes\RSRP.pwn(61243) : warning 213: tag mismatch

from this line // 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

this one below
    return (fall_height - 2.0) * 2 + 5; // Damage increases linearly with fall height beyond 2 meters

This line here returns float, but it should return only integers, to change that use floatround(), what converts float to integer.
Code:
floatround((fall_height - 2.0) * 2 + 5);

or if you want to return floats
Code:
forward Float:CalculateDamage
public Float:CalculateDamage



RE: Not receiving damage when player fell onto the ground - Sizy - 2024-05-05

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
}



RE: Not receiving damage when player fell onto the ground - carl_anderson - 2024-05-05

(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


RE: Not receiving damage when player fell onto the ground - carl_anderson - 2024-05-05

Created code, what you can try for falling detection
Code:
// indicates if player is falling or not
new bool:IsPlayerFalling[MAX_PLAYERS] = {false, ...};

// checks if it's falling animation, https://www.open.mp/docs/scripting/resources/animations
IsFallingAnim(index) {
    return index == 1128 || index == 1130 || index == 1131;
}

public OnPlayerUpdate(playerid) {
    // checks that player isn't inside anything or special mode etc
    if (GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) {
        new animIndex = GetPlayerAnimationIndex(playerid);
        // current player animation
        new hasFallingAnim = IsFallingAnim(animIndex);
        // player started falling, but not stored yet
        if (hasFallingAnim && !IsPlayerFalling[playerid]) {
            IsPlayerFalling[playerid] = true;
            SendClientMessage(playerid, -1, "You started falling!");
        }
        // player stopped falling, but not stored yet
        else if(!hasFallingAnim && IsPlayerFalling[playerid]) {
            IsPlayerFalling[playerid] = false;
            SendClientMessage(playerid, -1, "You stopped falling!");
        }
    }
    return 1;
}



RE: Not receiving damage when player fell onto the ground - Sizy - 2024-05-06

check my PM bro