Help with Float
#1

I want to check if player is with admin level and give new value for Float:kof,
but i tested with message function and it gives a trash number..

Код:
			new Float:kof = 1;
				//new str[400];
				if(playerDB[i][admin] == 5) kof == 2;
				if(playerDB[i][admin] == 4) kof == 2;
				if(playerDB[i][admin] == 3) kof == 1;
				if(playerDB[i][admin] == 2) kof == 0.7;
				if(playerDB[i][admin] == 1) kof == 0.4;
				if(playerDB[i][vip] == true) kof == 0.2;
				playerDB[i][VersloPelnas] += playerDB[i][VersloPajamos];
				//format(str, sizeof(str), "Verslo koficijentas yra %d", kof);
				//SendClientMessage(i, RED, str );
Reply
#2

User Return function
Reply
#3

Its timer activated command for business, if player have admin give more money then useally.
Still no work when i unfreeze test lines, it gives big number...

i never used Float numbers, so i dont know if im using right them
Reply
#4

Can you explain your problem a little bit better.
Reply
#5

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
Can you explain your problem a little bit better.
Yes, i have Mysql business, this is the part of the script were payout is every 1min
now its doing that profit = profit + how_much_should_earn_1min
but i want to do that if player have privilages like V.I.P or Admin the profit raises
profit = (profit + how_much_should_earn_1min) * kof[admin or vip number]
like if player have level 5admin add to his profit +300%
so i tried to use Float and when i use it it f**k my Mysql datbase, so i run some test and i noticed that my Float:kof dosen't change and outputs Trash like (11544455413)
Reply
#6

I don't understand yet what is your problem, if is the variable float that don't change or the output that can't be in float, or both.

Anyway, your code need a better performece and you need more debugs to know what is the problem.
Btw, your specifier in debug message are wrong, to float is used %f.

Look this:
PHP код:
new Float:kof 1;//str[400];
//debugs
printf("playerDB admin level = %d"playerDB[i][admin]);
printf("playerDB vip level = %d"playerDB[i][vip]);
switch(
playerDB[i][admin])
{
    case 
5kof 2;
    case 
4kof 2;
    case 
3kof 1;
    case 
2kof 0.7;
    case 
1kof 0.4;
    default:
    {
        if(
playerDB[i][vip]) kof 0.2;
    }
}
printf("kof output = %.1f"kof);//.1 = only one decimal place
playerDB[i][VersloPelnas] += playerDB[i][VersloPajamos];
//format(str, sizeof(str), "Verslo koficijentas yra %d", kof);
//SendClientMessage(i, RED, str ); 
Reply
#7

You are not really assigning anything to the variable.
== is used for checks,
= is used for assigning values.

Change this:
kof == 2; <- notice how you placed two equality operators (=).

To this:
kof = 2.0; <- only one =. Also, I replaced 2 with 2.0 since it is a float (not necessary but I feel it adds clarity and stuff to your code).
I'm surprised this part of the code doesn't give you any warnings or erros.

Be to, koeficientas, o ne koficijentas.
Reply
#8

Quote:
Originally Posted by Bruno13
Посмотреть сообщение
I don't understand yet what is your problem, if is the variable float that don't change or the output that can't be in float, or both.

Anyway, your code need a better performece and you need more debugs to know what is the problem.
Btw, your specifier in debug message are wrong, to float is used %f.

Look this:
PHP код:
new Float:kof 1;//str[400];
//debugs
printf("playerDB admin level = %d"playerDB[i][admin]);
printf("playerDB vip level = %d"playerDB[i][vip]);
switch(
playerDB[i][admin])
{
    case 
5kof 2;
    case 
4kof 2;
    case 
3kof 1;
    case 
2kof 0.7;
    case 
1kof 0.4;
    default:
    {
        if(
playerDB[i][vip]) kof 0.2;
    }
}
printf("kof output = %.1f"kof);//.1 = only one decimal place
playerDB[i][VersloPelnas] += playerDB[i][VersloPajamos];
//format(str, sizeof(str), "Verslo koficijentas yra %d", kof);
//SendClientMessage(i, RED, str ); 
Thanks for your code worked great
but now i faced with other problemn how to add float to int?
Because player have money (int) and i want add business profit(float)??

Quote:
Originally Posted by AdamsLT
Посмотреть сообщение
You are not really assigning anything to the variable.
== is used for checks,
= is used for assigning values.

Change this:
kof == 2; <- notice how you placed two equality operators (=).

To this:
kof = 2.0; <- only one =. Also, I replaced 2 with 2.0 since it is a float (not necessary but I feel it adds clarity and stuff to your code).
I'm surprised this part of the code doesn't give you any warnings or erros.

Be to, koeficientas, o ne koficijentas.
Thanks for help
Reply
#9

Quote:
Originally Posted by mokinys98
Посмотреть сообщение
Thanks for your code worked great
but now i faced with other problemn how to add float to int?
Because player have money (int) and i want add business profit(float)??
You can use https://sampwiki.blast.hk/wiki/Floatround to round the values with one of the methods https://sampwiki.blast.hk/wiki/Floatround_method. Probably rounding down would be the best answer as players will lose a little bit of money but it will be less than 1$ so nobody will be terribly upset (you could even not display decimal values to players so they wouldn't even know they're losing anything).

something like this:
PHP код:
PlayerCash[playerid] += floatround(PlayerProfit[playerid], floatround_floor); 
Reply
#10

Thanks everyone for HELP
really nice that you all helped!
All problems solved!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)