SA-MP Forums

Go Back   SA-MP Forums > SA-MP > Client Support

Reply
 
Thread Tools Display Modes
Old 03/07/2014, 11:49 PM   #1
DartakousLien
High-roller
 
DartakousLien's Avatar
 
Join Date: Jan 2010
Location: Portugal
Posts: 1,149
Reputation: 87
Thumbs up [SOLVED] rounding health value

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 Code:
#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
__________________
Github : Procurando interessados em participar em projetos comigo.
Visite também o meu portfólio
DartakousLien is offline   Reply With Quote
Old 04/07/2014, 12:17 AM   #2
DartakousLien
High-roller
 
DartakousLien's Avatar
 
Join Date: Jan 2010
Location: Portugal
Posts: 1,149
Reputation: 87
Default Re: rounding health value

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 Code:
#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;
}
__________________
Github : Procurando interessados em participar em projetos comigo.
Visite também o meu portfólio
DartakousLien is offline   Reply With Quote
Old 04/07/2014, 11:10 AM   #3
Inverse
Huge Clucker
 
Inverse's Avatar
 
Join Date: Jun 2011
Location: Braavos
Posts: 251
Reputation: 19
Default Re: rounding health value

Use %.0f instead of %f

edit: never mind
__________________
[FS] xPlosions - NEW!
Inverse is offline   Reply With Quote
Old 04/07/2014, 11:11 AM   #4
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,092
Reputation: 2655
Default Re: rounding health value

Quote:
Originally Posted by DartakousLien View Post
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.
__________________
Vince is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sampgdk RCON1 Plugin Development 26 08/06/2014 12:03 PM
SAMPGDK Framework GWMPT Everything and Nothing 23 04/06/2014 08:30 PM
sampgdk on Linux DartakousLien Scripting Help 0 20/08/2013 11:48 PM
[FilterScript] [FS]Vehicle Helth System By TheManDeep [MK]Man_Deep Filterscripts 3 29/07/2012 04:06 PM


All times are GMT. The time now is 11:23 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.