Stuck into this stupid calculation! -
Zh3r0 - 21.04.2011
Well let me explain.
For example, I have my time set to:
21:35
And my friend has it set to:
22:25
How do I calculate the minutes between my time and his time, I need a PAWN calculation, becausedoing this by mind it's obviously that the difference is by 50, but how can I do it in pawn?
Never been good with mathematics
Re: Stuck into this stupid calculation! -
Joe Staff - 21.04.2011
Well to have reached that number, you must have a base valuable containing seconds or milliseconds, just use that...
Re: Stuck into this stupid calculation! -
Zh3r0 - 21.04.2011
Quote:
Originally Posted by SilentHuntR
Well to have reached that number, you must have a base valuable containing seconds or milliseconds, just use that...
|
The thing is, that I'm currently working on a restriction system, to restrict player for one how from doing xyz, I'm using SQLite and I'm saving DD|HH|MM and i use sscanf to format each date into a var then use the check.
pawn Код:
if ( db_num_rows( R2 ) )
{
new
Field[ 64 ];
db_get_field_assoc( R2, "TimePos", Field, sizeof (Field) );
SetPVarString( playerid, "OnTime", Field );
db_free_result( R2 );
sscanf( GPVSEx( playerid, "OnTime" ), "p<|>iii", Time[ 2 ], Time[ 0 ], Time[ 1 ] );
new
T2[ 3 ];
gettime( T2[ 0 ], T2[ 1 ] );
getdate( .day = T2[ 2 ] );
if ( Time[ 0 ] == 0 ) Time[ 0 ] = 24;
if ( T2[ 2 ] == Time[ 2 ] )
{
if ( T2[ 0 ] == Time[ 0 ] )
{
if ( T2[ 1 ] < Time[ 1 ] )
{
SendError( playerid, "You are allowed to give only one "GREE"+"GREY" respect per hour!");
FormatMSG( playerid, Color:GREY, "You can repeat the process after "BLUE"%d"GREY" minutes! Y", ( Time[ 1 ] - T2[ 1 ] ) );
return 1;
}
}
else if ( T2[ 0 ] < Time[ 0 ] )
{
SendError( playerid, "You are allowed to give only "GREE"+"GREY" respect per hour!");
FormatMSG( playerid, Color:GREY, "You can repeat the process after "BLUE"%d"GREY" minutes! X", (( Time[ 1 ] ) + ( T2[ 1 ] ) / 2 ) );
return 1;
}
}
}
The Y and X at the end of the strings is to see where the action takes place.
Also, don't laugh at this
(( Time[ 1 ] ) + ( T2[ 1 ] ) / 2 ) , as i said, my maths are -1.
Inside the
if ( T2[ 1 ] < Time[ 1 ] ) it works just great!
The system works great! But i want to let them know the time left..
If i can't find a solution to this i might give up on telling them the minutes.
E: I could actually tell them that they will be able to repeat the procces at HH:MM instead?
Re: Stuck into this stupid calculation! -
Joe Staff - 21.04.2011
The function GetTime returns the amount of seconds since 1970, that way you can just do "if(GetTime()<playertime)return fail;"
Re: Stuck into this stupid calculation! -
Zh3r0 - 21.04.2011
Quote:
Originally Posted by SilentHuntR
The function GetTime returns the amount of seconds since 1970, that way you can just do "if(GetTime()<playertime)return fail;"
|
So i could be just saving the seconds since 1970 then compare the saved ones with the new fresh ones?
Also, when adding it to the file i must do gettime( ) + (60 * 60) to get one hour?
Re: Stuck into this stupid calculation! -
Joe Staff - 21.04.2011
No
pawn Код:
new hh, mm, ss;
GetTime(hh,mm,ss):
Re: Stuck into this stupid calculation! -
Zh3r0 - 21.04.2011
Quote:
Originally Posted by SilentHuntR
No
pawn Код:
new hh, mm, ss; GetTime(hh,mm,ss):
|
You are getting confusing, you once said one way, now another...