convert /mytime
#1

how can I translate this command strcmp? variables excluded rescue
Код:
CMD:mytime( playerid, params[] )
{
	new Time;
    if ( P_DATA[ playerid ][ P_Logged ] == 0 )
	    return SendError( playerid, "You must be logged in to change your time! ~n~Type ~b~~h~/login.");

	if ( sscanf( params, "i", Time ) )
	    return SendUsage( playerid, "/mytime <hour>");

	if ( Time < 0 || Time > 24 )
	    return SendError( playerid, "~n~Numbers must be from ~b~~h~0 ~w~to ~b~~h~24");

	P_DATA[ playerid ][ P_Time ] = Time;
	SetPlayerTime( playerid, Time, 0 );

	new String[ 160 ];
	format( String, sizeof String, "You have changed your time to ~b~~h~%d~w~:~b~~h~00~w~. It has been saved into your account, on next login this time will be applied.", Time );
	Info( playerid,  String, 5000);

	new iUID = BUD::GetNameUID( PlayerName2( playerid ) );
	BUD::SetIntEntry(iUID, "Time", params[ 0 ] );
	return 1;
}
tanks guy
Reply
#2

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mytime", cmdtext, true, 6) == 0)
    {
        new Time;
        if ( P_DATA[ playerid ][ P_Logged ] == 0 )
            return SendError( playerid, "You must be logged in to change your time! ~n~Type ~b~~h~/login.");

        if ( sscanf( cmdtext[7], "i", Time ) ) //If it doesn't work try changing it to 'cmdtext[8]'
            return SendUsage( playerid, "/mytime <hour>");

        if ( Time < 0 || Time > 24 )
            return SendError( playerid, "~n~Numbers must be from ~b~~h~0 ~w~to ~b~~h~24");

        P_DATA[ playerid ][ P_Time ] = Time;
        SetPlayerTime( playerid, Time, 0 );

        new String[ 160 ];
        format( String, sizeof String, "You have changed your time to ~b~~h~%d~w~:~b~~h~00~w~. It has been saved into your account, on next login this time will be applied.", Time );
        Info( playerid,  String, 5000);

        new iUID = BUD::GetNameUID( PlayerName2( playerid ) );
        BUD::SetIntEntry(iUID, "Time", Time);
        return 1;
    }
    return 0;
}
Unable to test it as I don't have your required libraries, but see how that one goes.
Reply
#3

Quote:
Originally Posted by Bicentric
Посмотреть сообщение
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mytime", cmdtext, true, 6) == 0)
    {
        new Time;
        if ( P_DATA[ playerid ][ P_Logged ] == 0 )
            return SendError( playerid, "You must be logged in to change your time! ~n~Type ~b~~h~/login.");

        if ( sscanf( cmdtext[7], "i", Time ) ) //If it doesn't work try changing it to 'cmdtext[8]'
            return SendUsage( playerid, "/mytime <hour>");

        if ( Time < 0 || Time > 24 )
            return SendError( playerid, "~n~Numbers must be from ~b~~h~0 ~w~to ~b~~h~24");

        P_DATA[ playerid ][ P_Time ] = Time;
        SetPlayerTime( playerid, Time, 0 );

        new String[ 160 ];
        format( String, sizeof String, "You have changed your time to ~b~~h~%d~w~:~b~~h~00~w~. It has been saved into your account, on next login this time will be applied.", Time );
        Info( playerid,  String, 5000);

        new iUID = BUD::GetNameUID( PlayerName2( playerid ) );
        BUD::SetIntEntry(iUID, "Time", Time);
        return 1;
    }
    return 0;
}
Unable to test it as I don't have your required libraries, but see how that one goes.
but all sscanf not be replaced by something else?
Reply
#4

Quote:
Originally Posted by toi
Посмотреть сообщение
but all sscanf not be replaced by something else?
I don't understand.
Reply
#5

I do not use sscanf, what can I use instead?
Reply
#6

Quote:
Originally Posted by toi
Посмотреть сообщение
I do not use sscanf, what can I use instead?
You could use a function named 'strtok', but it's old and outdated, sscanf is the best way to go.

https://sampwiki.blast.hk/wiki/Strtok

Or you could try this:

pawn Код:
//Near the top of your script

#if !defined isnull
    #define isnull(%1) \
                ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mytime", cmdtext, true, 6) == 0)
    {
        new Time;
        if ( P_DATA[ playerid ][ P_Logged ] == 0 )
            return SendError( playerid, "You must be logged in to change your time! ~n~Type ~b~~h~/login.");

        if ( isnull( cmdtext[7] ) ) //If it doesn't work try changing it to 'cmdtext[8]'
            return SendUsage( playerid, "/mytime <hour>");
       
        Time = strval( cmdtext[7] ); //Again change it to 'cmdtext[8]' if it doesn't work.

        if ( Time < 0 || Time > 24 )
            return SendError( playerid, "~n~Numbers must be from ~b~~h~0 ~w~to ~b~~h~24");

        P_DATA[ playerid ][ P_Time ] = Time;
        SetPlayerTime( playerid, Time, 0 );

        new String[ 160 ];
        format( String, sizeof String, "You have changed your time to ~b~~h~%d~w~:~b~~h~00~w~. It has been saved into your account, on next login this time will be applied.", Time );
        Info( playerid,  String, 5000);

        new iUID = BUD::GetNameUID( PlayerName2( playerid ) );
        BUD::SetIntEntry(iUID, "Time", Time);
        return 1;
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)