function problem -
None1337 - 22.03.2018
When OnPlayerGiveDamage is called, I have a function like this:
Код:
if(amount == 9.324511 && weaponid == 31) {
new string[126];
format(string, 126, "%s did 9.324511 damage to %s", GetName(playerid), GetName(damagedid));
foreach(new i : Admins) SendClientMessage(i, -1, string);
}
above the code i have this:
Код:
foreach(new i : Admins)
{
if(Spectate[i] == playerid && ShowDMG[i] == 1)
{
ToPlayer(i, COLOR_ACTION, "DMG: %s did %f damage to %s.", GetName(playerid), amount, GetName(damagedid));
}
}
When I'm spectate on the player, i received the message above in chat, but the first message from the first code it isn't show when the player did damage with m4 9.324511
Why?
Re: function problem -
AdamsLT - 22.03.2018
Well maybe you don't do exactly 9.324511 damage to the person? That is a very specific number.
Remove
PHP код:
amount == 9.3.....
and see if it gets called then. If it does - then you provided a float that is too specific.
PHP код:
if(weaponid == 31) {
new string[126];
format(string, 126, "%s did %.2f damage to %s", GetName(playerid), amount, GetName(damagedid));
foreach(new i : Admins) SendClientMessage(i, -1, string);
}
Re: function problem -
None1337 - 22.03.2018
Quote:
Originally Posted by AdamsLT
Well maybe you don't do exactly 9.324511 damage to the person? That is a very specific number.
Remove
PHP код:
amount == 9.3.....
and see if it gets called then. If it does - then you provided a float that is too specific.
PHP код:
if(weaponid == 31) {
new string[126];
format(string, 126, "%s did %.2f damage to %s", GetName(playerid), amount, GetName(damagedid));
foreach(new i : Admins) SendClientMessage(i, -1, string);
}
|
now, for example:
using %.2f i get: 9.340000 and using just %f i get: 9.339999, why? and when i need to send a message to an admin that the player did 9.33999 damage..i can't..
Re: function problem -
AdamsLT - 23.03.2018
the .2 in the %.2f part means that your float is rounded to two numbers after a comma (you can have it as just %f if you feel you want more precise data).
Ok, wait. So which part doesn't send the message?
This one, right?
Quote:
foreach(new i : Admins) SendClientMessage(i, -1, string);
|
If this doesn't work, I'm not sure where the problem is, maybe your Admins definition is incorrect? Try printing something inside the foreach to see if it even works, for example
PHP код:
foreach(new i : Admins) {
SendClientMessage(i, -1, string);
printf("foreach-admins, i = %i", i);
}
and look into the log file if it printed the correct data.
If this doesn't work
PHP код:
foreach(new i : Admins)
{
if(Spectate[i] == playerid && ShowDMG[i] == 1)
{
ToPlayer(i, COLOR_ACTION, "DMG: %s did %f damage to %s.", GetName(playerid), amount, GetName(damagedid));
}
}
Try posting the ToPlayer function code to see if it works correctly and also change the code to this
PHP код:
foreach(new i : Admins)
{
printf("foreach-admins, i = %i | Spectate[i] = %i | ShowDMG[i] = %i", i, Spectate[i], ShowDMG[i]);
if(Spectate[i] == playerid && ShowDMG[i] == 1)
{
printf("if-passed in i = %i", i);
ToPlayer(i, COLOR_ACTION, "DMG: %s did %f damage to %s.", GetName(playerid), amount, GetName(damagedid));
}
}
And then look if the values are correct.
So basically, try debugging this whole piece of code and see if the values you are assigning are correct. You can try posting the logs you receive here to help find the problem.
Re: function problem -
DuyDang2412 - 23.03.2018
In my opinion, i think you should round the value of 'amount' to 6 numbers after a comma, then assign it to another variable called 'roundedAmount' and use 'roundedAmount' for the comparison, for example:
PHP код:
var roundedAmount = floatround(amount * 1000000.0) / 1000000.0;
if(roundedAmount == 9.324511 && weaponid == 31)
Because amount is a float value, if you want to compare it, you must round it. If you do not, it should be a value like this:
Quote:
amount = 9.324511523099854203423423.....
|
Re: function problem -
None1337 - 23.03.2018
Quote:
Originally Posted by DuyDang2412
In my opinion, i think you should round the value of 'amount' to 6 numbers after a comma, then assign it to another variable called 'roundedAmount' and use 'roundedAmount' for the comparison, for example:
PHP код:
var roundedAmount = floatround(amount * 1000000.0) / 1000000.0;
if(roundedAmount == 9.324511 && weaponid == 31)
Because amount is a float value, if you want to compare it, you must round it. If you do not, it should be a value like this:
|
Код:
new Float: roundedAmount = floatround(amount * 1000000.0) / 1000000.0;
if(roundedAmount == 9.324511 && weaponid == 31)
{
SendClientMessage(playerid, COLOR_LGREEN, "You did 9.324511 damage!");
}
And still not working.
Re: function problem -
DuyDang2412 - 25.03.2018
Quote:
Originally Posted by None1337
Код:
new Float: roundedAmount = floatround(amount * 1000000.0) / 1000000.0;
if(roundedAmount == 9.324511 && weaponid == 31)
{
SendClientMessage(playerid, COLOR_LGREEN, "You did 9.324511 damage!");
}
And still not working.
|
Comparison of two float values is hard, I tested a bit and this code should return true and work:
Quote:
new Float: roundedAmount = floatround(amount * 1000000.0) / 1000000.0;
if(floatround(((roundedAmount - 9.324511) * 10.0)/10.0) == 0 && weaponid == 31)
{
SendClientMessage(playerid, COLOR_LGREEN, "You did 9.324511 damage!");
}
|
This code is to get the subtraction of 'roundedAmount' and '9.324511', then I round it to one number after comma and compare it with '0'.