SA-MP Forums Archive
Race record - 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: Race record (/showthread.php?tid=426848)



Race record - Msk. - 30.03.2013

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 :/


Re: Race record - RajatPawar - 30.03.2013

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



AW: Re: Race record - Nero_3D - 30.03.2013

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))



Re: Race record - RajatPawar - 30.03.2013

Of course ! Let me rework my code. Thanks !


Re: Race record - Babul - 30.03.2013

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.


Re: Race record - RajatPawar - 30.03.2013


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


Re: Race record - Msk. - 30.03.2013

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"));