Stuck into this stupid calculation!
#1

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
Reply
#2

Well to have reached that number, you must have a base valuable containing seconds or milliseconds, just use that...
Reply
#3

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

The function GetTime returns the amount of seconds since 1970, that way you can just do "if(GetTime()<playertime)return fail;"
Reply
#5

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

No
pawn Код:
new hh, mm, ss;
GetTime(hh,mm,ss):
Reply
#7

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


Forum Jump:


Users browsing this thread: 1 Guest(s)