GetPlayerHealth bugged? -
BloodyRP - 21.04.2016
Hello 4 every1.
Want to ask one thing. Is in GetPlayerHealth func some bug?
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
Account[playerid][Health] -= amount;
SetPlayerHealth(playerid,Account[playerid][Health]);
new Float:health;
printf("HP in Acc %f",Account[playerid][Health]);
GetPlayerHealth(playerid,health);
printf("HP in HPBar %f",health);
Ok, now watch where is the problem:
I set 100 hp, try to jump from any building and I have in console right "HP in acc" (e.g. 89.4712), but "HP in HPBar" still showing 100. Why?
--
Sorry for poor english.
Re: GetPlayerHealth bugged? -
AdrianG - 21.04.2016
A kind of bug Set and Get. The setted hp is not setted immediately, because the code is too fast for it. Example:
PHP код:
forward ShowMeMyHealth(playerid);
public ShowMeMyHealth(playerid)
{
GetPlayerHealth(playerid,health);
printf("HP in HPBar %f",health);
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
Account[playerid][Health] -= amount;
SetPlayerHealth(playerid,Account[playerid][Health]);
new Float:health;
printf("HP in Acc %f",Account[playerid][Health]);
SetTimerEx("ShowMeMyHealth",1000,"i",0,playerid);
return 1;
}
Re: GetPlayerHealth bugged? -
BloodyRP - 21.04.2016
Quote:
Originally Posted by AdrianG
A kind of bug Set and Get. The setted hp is not setted immediately, because the code is too fast for it. Example:
PHP код:
forward ShowMeMyHealth(playerid);
public ShowMeMyHealth(playerid)
{
GetPlayerHealth(playerid,health);
printf("HP in HPBar %f",health);
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
Account[playerid][Health] -= amount;
SetPlayerHealth(playerid,Account[playerid][Health]);
new Float:health;
printf("HP in Acc %f",Account[playerid][Health]);
SetTimerEx("ShowMeMyHealth",1000,"i",0,playerid);
return 1;
}
|
Do u think that is good idea to place timer in callback like this?
I mean in server with 100+ players it will be always called and that will not give laggs or smthng?
Re: GetPlayerHealth bugged? -
AdrianG - 21.04.2016
I have a server with 100+ players sometimes 200+. If you have a very good game hosting (a good processor) will be just a piece of cake, because yeah maybe the public will be called 5 times ~ in the same time, or the public will be called by the same playerid two times in 1 sec. But you can get out it, using a variable as in the following example:
PHP код:
new smmh[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
smmh[playerid]=0;
return 1;
}
public OnPlayerDisconnect(playerid)
{
smmh[playerid]=0;
return 1;
}
forward ShowMeMyHealth(playerid);
public ShowMeMyHealth(playerid)
{
GetPlayerHealth(playerid,health);
printf("HP in HPBar %f",health);
smmh[playerid]=0;
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
Account[playerid][Health] -= amount;
SetPlayerHealth(playerid,Account[playerid][Health]);
new Float:health;
printf("HP in Acc %f",Account[playerid][Health]);
if(!smmh[playerid]){ smmh[playerid]=1; SetTimerEx("ShowMeMyHealth",1000,"i",0,playerid); }
return 1;
}
Try it, I use timers in order to detect Invulnerable, for instance I check and every each 10 second each player using the following algorithm: I set its hp-1 and after 1 sec I check if its hp is -1 if it is not it means that it use invulnerable.. and it works.. (I also check about ping etc..)