float to integer
#1

Код:
new fixprice = floatround(vhealth, floatround_round);
Код:
GetVehicleHealth(vehicleid, vhealth); //Tag Mismatch
need it for:
Код:
fixprice = 1000 - vhealth;
Reply
#2

Keep in mind that "vhealth" should have Float: tag when you declare it.
Reply
#3

now here
Код:
fixprice = 1000 - Float:vhealth; //without 'Float:' too
Reply
#4

Search for
pawn Код:
new vhealth;
Change it to
pawn Код:
new Float: vhealth;
So, script should look like:
pawn Код:
new Float: vhealth;
GetVehicleHealth(vehicleid, vhealth);
new fixprice = (1000 - (floatround(vhealth, floatround_round)));
Reply
#5

still here
Код:
fixprice = 1000 - vhealth;
script should deduct veh health from 1000 and its fixprice
Reply
#6

@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 ?
Reply
#7

should be rounding, in xxx.5 can be one up or down - whatever. but, i dont know how to do it.
Reply
#8

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.
Reply
#9

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;
Reply
#10

Quote:
Originally Posted by cnoopers
Посмотреть сообщение
i said u man now here tag mismatch
Код:
fixprice = 1000 - vhealth;
How do you declare vhealth?
Like this:
pawn Код:
new vhealth;
or like this:
pawn Код:
new Float: vhealth;
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)