2024-05-01, 02:49 AM
(This post was last modified: 2024-05-01, 02:25 PM by Sizy.)
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
2024-05-03, 06:45 PM
(This post was last modified: 2024-05-04, 12:28 PM by carl_anderson.)
open up documentation
https://www.open.mp/docs/scripting/funct...eFromPoint
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?
uhmm can you please type the whole correct code so i can just copy and paste?
(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?
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
2024-05-05, 09:24 AM
(This post was last modified: 2024-05-05, 09:44 AM by carl_anderson.)
(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
2024-05-05, 10:56 AM
(This post was last modified: 2024-05-05, 10:57 AM by Sizy.)
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
}
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
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;
}
|