/settime command
#1

well i would like to do a /settime commands for admins level 1-5 and i can't do it. could someone please help me because im a noob at scripting commands... at least i know how to script teleports :P

/settime 18 = 6pm
/settime 0 = Midnight
/settime 6 = 6am
/settime 12 = Midday

Reply
#2

What should it do? Change the weather?
Reply
#3

no i just want like the time to change and well even the weather but not like cloudy and rainy... just like night and day
Reply
#4

Hi,
Here is a Command for Rcon:

pawn Код:
dcmd(settime, 7, cmdtext);
pawn Код:
dcmd_settime(playerid,params[])
{
    new string[256],idx,tmp[256];
    if(IsPlayerAdmin(playerid))
    {
      tmp = strtok(params,idx);
      if(!strlen(tmp))
      {
        SendClientMessage(playerid, COLOR_RED, "ERROR: /settime [hour]");
        return 1;
        }
      new h = strval(tmp);
      if(h < 0 || h > 24)
      {
        SendClientMessage(playerid, COLOR_RED, "ERROR: /settime [hour]");
        return 1;
        }
        SetWorldTime(h);
        format(string,sizeof(string), "Admin %s has change the Time to %d !", GetName(playerid), h);
        SendAllEMessage(string);
    }
     else
     {
      SendClientMessage(playerid, COLOR_RED, "ERROR: You must be a Admin to use this Command !");
      return 1;
    }
    return 1;
}
pawn Код:
stock GetName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));

    return name;
}
Regards,
- LJ
Reply
#5

Quote:
Originally Posted by ★ ♫ • Littlejohny • ♫ ★
pawn Код:
dcmd_settime(playerid,params[])
{
    new string[256],idx,tmp[256];
    if(IsPlayerAdmin(playerid))
    {
      tmp = strtok(params,idx);
      if(!strlen(tmp))
      {
        SendClientMessage(playerid, COLOR_RED, "ERROR: /settime [hour]");
        return 1;
        }
      new h = strval(tmp);
      if(h < 0 || h > 24)
      {
        SendClientMessage(playerid, COLOR_RED, "ERROR: /settime [hour]");
        return 1;
        }
        SetWorldTime(h);
        format(string,sizeof(string), "Admin %s has change the Time to %d !", GetName(playerid), h);
        SendAllEMessage(string);
    }
    else
    {
      SendClientMessage(playerid, COLOR_RED, "ERROR: You must be a Admin to use this Command !");
      return 1;
    }
    return 1;
}
Why are you using strtok ?
Reply
#6

Hmm I'm using it for all

and why not ?

- LJ
Reply
#7

Quote:
Originally Posted by ★ ♫ • Littlejohny • ♫ ★
Hmm I'm using it for all

and why not ?

- LJ
For all what, all your commands ?

Because 'params' already contains the parameter passed by the user (hour) so check it's not blank (!params[0]) and it's numerical and you are good to go dude.
Reply
#8

ok thanks but where should i put it? under what i mean?
Reply
#9

Quote:
Originally Posted by Donny
For all what, all your commands ?
Because 'params' already contains the parameter passed by the user (hour) so check it's not blank (!params[0]) and it's numerical and you are good to go dude.
I know but its all the same

- LJ
Reply
#10

Quote:
Originally Posted by ★ ♫ • Littlejohny • ♫ ★
I know but its all the same

- LJ
No dude one is using strtok and one isn't, this is not the same is it:

pawn Код:
dcmd_settime(playerid,params[])
{
  if ( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, COLOR_RED, "ERROR: You must be a Admin to use this Command !" );
  if ( !params[ 0 ] ) return SendClientMessage( playerid, COLOR_RED, "ERROR: /settime [hour]" );
  if ( !IsNumeric( params ) ) return SendClientMessage( playerid, COLOR_RED, "ERROR: The 'hour' parameter must be numerical" );  

  new
    string[ 70 ],
    h = strval( params );

  if ( h < 0 || h > 24 ) return SendClientMessage( playerid, COLOR_RED, "ERROR: Use a number from 0 to 24" );
  SetWorldTime( h );
  format( string, sizeof( string ), "Admin %s has change the Time to %d !", GetName(playerid), h );
  SendClientMessageToAll( COLOR_HERE?????, string );
  return 1;
}
As you can see dude there's not a hint of strtok in there and it will function exactly the same but with better speed and efficiency.
Reply
#11

Quote:
Originally Posted by Donny
As you can see dude there's not a hint of strtok in there and it will function exactly the same but with better speed and efficiency.
Hmm but the Endproduct is the same

- LJ
Reply
#12

Quote:
Originally Posted by ★ ♫ • Littlejohny • ♫ ★
Quote:
Originally Posted by Donny
As you can see dude there's not a hint of strtok in there and it will function exactly the same but with better speed and efficiency.
Hmm but the Endproduct is the same

- LJ
No dude they are different, one is fast and uses less processing power and one is slow and uses too much.
Reply
#13

ok? u guys done coz i got a problem :P
Reply
#14

that post would have been a good time to post your problem
Reply
#15

Quote:
Originally Posted by Donny
No dude they are different, one is fast and uses less processing power and one is slow and uses too much.
BUT, the command is the same

- LJ
Reply
#16

ok thanks but where should i put it? under what i mean?
Reply
#17

that is a function, put it at the bottom, and put the dcmd(settime, 7, cmdtext); thing in OnPlayerCommandText

note:you must have
pawn Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
in your script (top of it, or close to top)
Reply
#18

Quote:
Originally Posted by [MLT
Marco ]
ok thanks but where should i put it? under what i mean?
At the top of your script, under the '#include <......>' lines add:

pawn Код:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
Then at the very bottom of your script add the dcmd function:

pawn Код:
dcmd_settime(playerid,params[])
{
  if ( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, COLOR_RED, "ERROR: You must be a Admin to use this Command !" );
  if ( !params[ 0 ] ) return SendClientMessage( playerid, COLOR_RED, "ERROR: /settime [hour]" );
  if ( !IsNumeric( params ) ) return SendClientMessage( playerid, COLOR_RED, "ERROR: The 'hour' parameter must be numerical" );  

  new
    string[ 70 ],
    h = strval( params );

  if ( h < 0 || h > 24 ) return SendClientMessage( playerid, COLOR_RED, "ERROR: Use a number from 0 to 24" );
  SetWorldTime( h );
  format( string, sizeof( string ), "Admin %s has change the Time to %d !", GetName(playerid), h );
  SendClientMessageToAll( COLOR_HERE?????, string );
  return 1;
}
Then below this add these two custom functions also:

pawn Код:
stock GetName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));

    return name;
}

stock IsNumeric(const string[])
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
      if (string[i] > '9' || string[i] < '0') return 0;
    }
    return 1;
}
In your 'OnPlayerCommandText(...)' callback/event add:

pawn Код:
dcmd(settime, 7, cmdtext);
And apart from a typo or whatever we may have missed you are good to go. I take no credit for this btw, it's Littlejohnys code, I was just trying to improve it's speed etc.

Quote:
Originally Posted by ★ ♫ • Littlejohny • ♫ ★
Quote:
Originally Posted by Donny
No dude they are different, one is fast and uses less processing power and one is slow and uses too much.
BUT, the command is the same

- LJ
Hehehe ok I'll stop repeating myself, lets just agree to disagree dude.

Quote:
Originally Posted by Daren_Jacobson
that is a function, put it at the bottom, and put the dcmd(settime, 7, cmdtext); thing in OnPlayerCommandText

note:you must have
pawn Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
in your script (top of it, or close to top)
I'd already wrote all the above out so I'll post anyway.
Reply
#19

Quote:
Originally Posted by Donny
Quote:
Originally Posted by ★ ♫ • Littlejohny • ♫ ★
Quote:
Originally Posted by Donny
As you can see dude there's not a hint of strtok in there and it will function exactly the same but with better speed and efficiency.
Hmm but the Endproduct is the same

- LJ
No dude they are different, one is fast and uses less processing power and one is slow and uses too much.
LOL i have 1000 commands on my script using strcmp and it shows no lagg... dont listen to this superficial scritor he is probably
old school
Reply
#20

Quote:
Originally Posted by Jason_Borne420
Quote:
Originally Posted by Donny
Quote:
Originally Posted by ★ ♫ • Littlejohny • ♫ ★
Quote:
Originally Posted by Donny
As you can see dude there's not a hint of strtok in there and it will function exactly the same but with better speed and efficiency.
Hmm but the Endproduct is the same

- LJ
No dude they are different, one is fast and uses less processing power and one is slow and uses too much.
LOL i have 1000 commands on my script using strcmp and it shows no lagg... dont listen to this superficial scritor he is probably
old school
strcmp is different to strtok. Anyway, if you are using strcmp + strtok, you obviously don't have a particularly popular server, because on a large scale, this sort of thing adds up and makes a difference.

I'm not trying to ruin this thread, but if you're going to do it, you might as well do it properly.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)