float to integer - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: float to integer (
/showthread.php?tid=523533)
float to integer -
cnoopers - 02.07.2014
Код:
new fixprice = floatround(vhealth, floatround_round);
Код:
GetVehicleHealth(vehicleid, vhealth); //Tag Mismatch
need it for:
Код:
fixprice = 1000 - vhealth;
Re: float to integer -
Konstantinos - 02.07.2014
Keep in mind that "vhealth" should have
Float: tag when you declare it.
Re: float to integer -
cnoopers - 02.07.2014
now here
Код:
fixprice = 1000 - Float:vhealth; //without 'Float:' too
Re: float to integer -
greentarch - 02.07.2014
Search for
Change it to
So, script should look like:
pawn Код:
new Float: vhealth;
GetVehicleHealth(vehicleid, vhealth);
new fixprice = (1000 - (floatround(vhealth, floatround_round)));
Re: float to integer -
cnoopers - 02.07.2014
still here
Код:
fixprice = 1000 - vhealth;
script should deduct veh health from 1000 and its fixprice
Re : float to integer -
S4t3K - 02.07.2014
@cnoopers : No. All he should get with your code is a "warning tag mismatch".
You try to substract a float from a normal number and to store it in a normal number. Imagine that his vehicle health is 953.1, what will the script take from the money ? 953 or 954 ?
Re: float to integer -
cnoopers - 02.07.2014
should be rounding, in xxx.5 can be one up or down - whatever. but, i dont know how to do it.
Re: float to integer -
greentarch - 02.07.2014
Quote:
Originally Posted by cnoopers
should be rounding, in xxx.5 can be one up or down - whatever. but, i dont know how to do it.
|
Did you try my code?
This:
pawn Код:
new fixprice = (1000 - (floatround(vhealth, floatround_round)));
It should've work. Floatround does the job.
Re: float to integer -
cnoopers - 02.07.2014
Quote:
Originally Posted by greentarch
Did you try my code?
This:
pawn Код:
new fixprice = (1000 - (floatround(vhealth, floatround_round)));
It should've work. Floatround does the job.
|
i said u man now here tag mismatch
Код:
fixprice = 1000 - vhealth;
Re: float to integer -
greentarch - 02.07.2014
Quote:
Originally Posted by cnoopers
i said u man now here tag mismatch
Код:
fixprice = 1000 - vhealth;
|
How do you declare vhealth?
Like this:
or like this:
You should use the one with the tag (Float: )
and change your line to this..
pawn Код:
fixprice = (1000 - (floatround(vhealth, floatround_round)));
Because, the code compiles perfectly for me. I tested with a command.
pawn Код:
else if ( !strcmp( cmdtext, "/fix", true ) )
{
new
Float: vHealth,
fixPrice = 0;
GetVehicleHealth( GetPlayerVehicleID( playerid ), vHealth );
fixPrice = ( 1000 - ( floatround( vHealth, floatround_round ) ) );
RepairVehicle( GetPlayerVehicleID( playerid ) );
GivePlayerMoney( playerid, - fixPrice );
new
fmat[ 128 ];
format( fmat, sizeof ( fmat ), "Vehicle fixed. Cost: $%d", fixPrice );
SendClientMessage( playerid, -1, fmat );
return 1;
}
You did something wrong.