rounding health value
#1

well, it's hard to explain, so, look at the image. the code is below. I don't understand, why is it rouding. Or it's normal?



this is the code i used with sampgdk 3.7, but i'm using sampgdk4, and it's the same... I thought the problema in the sampgdk version, but when i change a the error persists, i realized that not

pawn Код:
#include <stdio.h>
#include <string.h>

#include <sampgdk/a_players.h>
#include <sampgdk/a_samp.h>
#include <sampgdk/core.h>

static ThisPlugin helloworld;

int rgeral = 0;

PLUGIN_EXPORT bool PLUGIN_CALL OnGameModeInit() {
    SetGameModeText("Hello, World!");
    AddPlayerClass(0, 1958.3783f, 1343.1572f, 15.3746f, 269.1425f, 0, 0, 0, 0, 0, 0);
    return true;
}
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid) {
    SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to the HelloWorld server!");
    return true;
}
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerRequestClass(int playerid, int classid) {
    SetPlayerPos(playerid, 1958.3783f, 1343.1572f, 15.3746f);
    SetPlayerCameraPos(playerid, 1958.3783f, 1343.1572f, 15.3746f);
    SetPlayerCameraLookAt(playerid, 1958.3783f, 1343.1572f, 15.3746f, CAMERA_CUT);
    return true;
}
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerCommandText(int playerid, const char *cmdtext) {
    if (strcmp(cmdtext, "/hello") == 0) {
        char name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        char message[128];
        sprintf(message, "Hello, %s!", name);
        SendClientMessage(playerid, 0x00FF00FF, message);
        return true;
    }
    return false;
}
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerUpdate(int playerid) {
    if (rgeral == 5) {
        float health;
        char msg[128];
        sampgdk_GetPlayerHealth(playerid, &health);

        sprintf(msg, "%f", health);

        SendClientMessage(playerid, -1, msg);
        rgeral = 0;
    }
    else {
        rgeral++;
    }
    return true;
}
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerTakeDamage(int playerid, int issuerid, float amount, int  weaponid, int bodypart) {

    float vida;
    sampgdk_GetPlayerHealth(playerid, &vida);

    char msg[128];
    sprintf(msg, "%f, %f", vida, amount);
    SendClientMessageToAll(0x00FF00FF, msg);
    return true;
}
PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {
    return SUPPORTS_VERSION | SUPPORTS_PROCESS_TICK;
}
PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) {
    return helloworld.Load(ppData) >= 0;
}
PLUGIN_EXPORT void PLUGIN_CALL Unload() {
    helloworld.Unload();
}
PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {
    helloworld.ProcessTimers();
}

if anyone can help me, i'm very grateful
Have a good day/night
Reply
#2

Well, nevermind, i'm sorry about the topic. I tried the same code in pawn and get the same problem. To me it looks stupid, because we get a FLOAT point of damage amount, and the heath is counted like INTEGER, but ok!

here is the new code and another foto



pawn Код:
#include <a_samp>

new rgeral = 0;

main() {}

public OnGameModeInit() {
    SetGameModeText("Hello, World!");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return true;
}
public OnPlayerConnect( playerid) {
    SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to the HelloWorld server!");
    return true;
}
public OnPlayerRequestClass( playerid,  classid) {
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746, CAMERA_CUT);
    return true;
}
public OnPlayerCommandText( playerid, cmdtext[]) {
    return false;
}
public OnPlayerUpdate( playerid) {
    if (rgeral == 5) {
        new Float:health;
        new msg[128];
        GetPlayerHealth(playerid, health);

        format(msg, 128, "%f", health);

        SendClientMessage(playerid, -1, msg);
        rgeral = 0;
    }
    else {
        rgeral++;
    }
    return true;
}
public OnPlayerTakeDamage( playerid,  issuerid, Float:amount,  weaponid,  bodypart) {

    new Float:vida;
    GetPlayerHealth(playerid, vida);

    new msg[128];
    format(msg, 128, "%f, %f", vida, amount);
    SendClientMessageToAll(0x00FF00FF, msg);
    return true;
}
Reply
#3

Use %.0f instead of %f

edit: never mind
Reply
#4

Quote:
Originally Posted by DartakousLien
Посмотреть сообщение
To me it looks stupid, because we get a FLOAT point of damage amount, and the heath is counted like INTEGER, but ok!
Yes, it seems rather odd since the value seems to be saved in an 8-bit unsigned integer on the client side. Values over 255 overflow.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)