Race record
#1

I have a problem with checking if players race time is better then the record.

m - players minutes
s - players seconds
ms - players mseconds

rm - record minutes
rs - sec
rms - msec


Код:
if(m < rm) {
	            if(s == rs) {
					if(ms < rms) {
					    SendClientMessageToAll(-1,"{FFFFFF}Rekord");
					}
	            } else if(s < rs) {
					    SendClientMessageToAll(-1,"{FFFFFF}Rekord");
	            }
	        } else if( m == rm) {
	            if(s == rs) {
	                if(ms < rms) {
					    SendClientMessageToAll(-1,"{FFFFFF}Rekord");
	                }
	            } else if(s < rs) {
					    SendClientMessageToAll(-1,"{FFFFFF}Rekord");
	            }
	        }
This code is just not working, and the time is better then the record :/
Reply
#2

pawn Код:
if ( ( m < rm || m == rm ) && ( s < rs || s == rs ) && ( ms < rms ) ) return SendClientMessage( playerid, -1, "Record." );
Reply
#3

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
pawn Код:
if ( ( m < rm || m == rm ) && ( s < rs || s == rs ) && ( ms < rms ) ) return SendClientMessage( playerid, -1, "Record." );
Thats wont work because as example your record is 2:10:00 and your new time is 1:55:50
pawn Код:
if ( ( 1 < 2 || 1 == 2 ) && ( 55 < 10 || 55 == 10 ) && ( 50 < 00 ) )

Solution
pawn Код:
if( ( m < rm ) || ( r == rm && (( s < rs ) || ( s == sr && ms < rms ))))
or
pawn Код:
if((((m * 60 + s) * 1000) + ms) < (((rm * 60 + rs) * 1000) + rms))
Reply
#4

Of course ! Let me rework my code. Thanks !
Reply
#5

hm...
pawn Код:
if(60000*m+1000*s+ms <= 60000*rm+1000*rs+rms)
...the trick is to compare all values together in 1 operation. as the minutes, seconds, and milliseconds are "somehow" related to eachother, we can bother to work in milliseconds here.
btw, the idea to "break" a record with the exact time, is just nice.
Reply
#6


Why didn't I think of that before, instead of tons of nested ifs and elses and ||s.
Reply
#7

Well it's working now, but i got an another problem, my mysql_GetString stock isn't working, when i printed it, it's returning just "(NULL)", so... nothing.


Код:
stock mysql_GetString(Table[], Field[], Where[], Is[])
{
    new query[128], Get[128];
    mysql_real_escape_string(Table, Table,mysql);
    mysql_real_escape_string(Field, Field,mysql);
    mysql_real_escape_string(Where, Where,mysql);
    mysql_real_escape_string(Is, Is,mysql);
    format(query, 128, "SELECT %s FROM %s WHERE %s = '%s'", Field, Table, Where, Is);
    mysql_query(query,-1,0,mysql);
    mysql_store_result(mysql);
    mysql_fetch_row(Get);
    return Get;
}
Код:
print(mysql_GetString("Rekordy","Gracz","Misja","PustynnyMaraton1"));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)