Cool

  • Hero Member
  • Posts: 719
Re: Setweather and Settime.
« Reply #15, on February 12th, 2016, 12:24 PM »
yes you are right but leave him alone its making the topic spammy :P

Xmair

  • Wiki Contributor
  • Posts: 911
Re: Setweather and Settime.
« Reply #16, on February 12th, 2016, 03:51 PM »
Code: [Select]
function onPlayerCommand ( player , cmd , text )
{
cmd = cmd.tolower ( );

if ( cmd == "setweather" )
{
if ( !text ) MessagePlayer ( "/setweather WeatherID." , player );
else if ( !IsNum ( text ) ) MessagePlayer ( "The ID must be an integer." , player );
else if ( GetWeather( ) == text.tointeger( ) ) MessagePlayer( "The ID you put is already used!" , player );
else
{
SetWeather ( text.tointeger ( ) );
Message ( "The weather has been set to " + text + " by " + player.Name + "." );
}
}

else if ( cmd == "settime" )
{
if ( !text ) MessagePlayer ( "/settime Hour & Minute." , player );
else if ( split ( text , " " ).len ( ) < 2 ) MessagePlayer ( "/settime Hour & Minute." , player );
else if ( !IsNum ( split ( text , " " ) [ 0 ] ) || !IsNum ( split ( text , " " ) [ 1 ] ) ) MessagePlayer ( "The text must be an integer." , player );
else
{
local splittext = split ( text , " " ),
hour = splittext [ 0 ],
minute = splittext [ 1 ];
SetHour ( hour.tointeger( ) );
SetMinute ( minute.tointeger( ) );
Message( "The time has been set to " + GetHour( ) + ":" + GetMinute( ) + " by " + player.Name + "." );
}
}
else MessagePlayer ( "Unknown command!" , player )
}
VU Full Member | VCCNR Developer | KTB Developer | EAD Ex-Scripter

ysc3839

  • VC:MP Beta Tester
  • Posts: 621
Re: Setweather and Settime.
« Reply #17, on February 12th, 2016, 04:28 PM »
Quote from Xmair on February 12th, 2016, 03:51 PM
Code: [Select]
function onPlayerCommand ( player , cmd , text )
{
cmd = cmd.tolower ( );

if ( cmd == "setweather" )
{
if ( !text ) MessagePlayer ( "/setweather WeatherID." , player );
else if ( !IsNum ( text ) ) MessagePlayer ( "The ID must be an integer." , player );
else if ( GetWeather( ) == text.tointeger( ) ) MessagePlayer( "The ID you put is already used!" , player );
else
{
SetWeather ( text.tointeger ( ) );
Message ( "The weather has been set to " + text + " by " + player.Name + "." );
}
}

else if ( cmd == "settime" )
{
if ( !text ) MessagePlayer ( "/settime Hour & Minute." , player );
else if ( split ( text , " " ).len ( ) < 2 ) MessagePlayer ( "/settime Hour & Minute." , player );
else if ( !IsNum ( split ( text , " " ) [ 0 ] ) || !IsNum ( split ( text , " " ) [ 1 ] ) ) MessagePlayer ( "The text must be an integer." , player );
else
{
local splittext = split ( text , " " ),
hour = splittext [ 0 ],
minute = splittext [ 1 ];
SetHour ( hour.tointeger( ) );
SetMinute ( minute.tointeger( ) );
Message( "The time has been set to " + GetHour( ) + ":" + GetMinute( ) + " by " + player.Name + "." );
}
}
else MessagePlayer ( "Unknown command!" , player )
}
Code: [Select]
local splittext = split ( text , " " ),
hour = splittext [ 0 ],
minute = splittext [ 1 ];
This may cause error.
Code: [Select]
local splittext = split ( text , " " );
if ( splittext.len() != 0 )
......

Xmair

  • Wiki Contributor
  • Posts: 911
Re: Setweather and Settime.
« Reply #18, on February 12th, 2016, 04:49 PM »
Quote from ysc3839 on February 12th, 2016, 04:28 PM
Quote from Xmair on February 12th, 2016, 03:51 PM
Code: [Select]
function onPlayerCommand ( player , cmd , text )
{
cmd = cmd.tolower ( );

if ( cmd == "setweather" )
{
if ( !text ) MessagePlayer ( "/setweather WeatherID." , player );
else if ( !IsNum ( text ) ) MessagePlayer ( "The ID must be an integer." , player );
else if ( GetWeather( ) == text.tointeger( ) ) MessagePlayer( "The ID you put is already used!" , player );
else
{
SetWeather ( text.tointeger ( ) );
Message ( "The weather has been set to " + text + " by " + player.Name + "." );
}
}

else if ( cmd == "settime" )
{
if ( !text ) MessagePlayer ( "/settime Hour & Minute." , player );
else if ( split ( text , " " ).len ( ) < 2 ) MessagePlayer ( "/settime Hour & Minute." , player );
else if ( !IsNum ( split ( text , " " ) [ 0 ] ) || !IsNum ( split ( text , " " ) [ 1 ] ) ) MessagePlayer ( "The text must be an integer." , player );
else
{
local splittext = split ( text , " " ),
hour = splittext [ 0 ],
minute = splittext [ 1 ];
SetHour ( hour.tointeger( ) );
SetMinute ( minute.tointeger( ) );
Message( "The time has been set to " + GetHour( ) + ":" + GetMinute( ) + " by " + player.Name + "." );
}
}
else MessagePlayer ( "Unknown command!" , player )
}
Code: [Select]
local splittext = split ( text , " " ),
hour = splittext [ 0 ],
minute = splittext [ 1 ];
This may cause error.
Code: [Select]
local splittext = split ( text , " " );
if ( splittext.len() != 0 )
......
That's why I put
Code: [Select]
else if ( split ( text , " " ).len ( ) < 2 ) MessagePlayer ( "/settime Hour & Minute." , player );
VU Full Member | VCCNR Developer | KTB Developer | EAD Ex-Scripter

ysc3839

  • VC:MP Beta Tester
  • Posts: 621
Re: Setweather and Settime.
« Reply #19, on February 12th, 2016, 06:47 PM »
Quote from Xmair on February 12th, 2016, 04:49 PM
Quote from ysc3839 on February 12th, 2016, 04:28 PM
Quote from Xmair on February 12th, 2016, 03:51 PM
Code: [Select]
function onPlayerCommand ( player , cmd , text )
{
cmd = cmd.tolower ( );

if ( cmd == "setweather" )
{
if ( !text ) MessagePlayer ( "/setweather WeatherID." , player );
else if ( !IsNum ( text ) ) MessagePlayer ( "The ID must be an integer." , player );
else if ( GetWeather( ) == text.tointeger( ) ) MessagePlayer( "The ID you put is already used!" , player );
else
{
SetWeather ( text.tointeger ( ) );
Message ( "The weather has been set to " + text + " by " + player.Name + "." );
}
}

else if ( cmd == "settime" )
{
if ( !text ) MessagePlayer ( "/settime Hour & Minute." , player );
else if ( split ( text , " " ).len ( ) < 2 ) MessagePlayer ( "/settime Hour & Minute." , player );
else if ( !IsNum ( split ( text , " " ) [ 0 ] ) || !IsNum ( split ( text , " " ) [ 1 ] ) ) MessagePlayer ( "The text must be an integer." , player );
else
{
local splittext = split ( text , " " ),
hour = splittext [ 0 ],
minute = splittext [ 1 ];
SetHour ( hour.tointeger( ) );
SetMinute ( minute.tointeger( ) );
Message( "The time has been set to " + GetHour( ) + ":" + GetMinute( ) + " by " + player.Name + "." );
}
}
else MessagePlayer ( "Unknown command!" , player )
}
Code: [Select]
local splittext = split ( text , " " ),
hour = splittext [ 0 ],
minute = splittext [ 1 ];
This may cause error.
Code: [Select]
local splittext = split ( text , " " );
if ( splittext.len() != 0 )
......
That's why I put
Code: [Select]
else if ( split ( text , " " ).len ( ) < 2 ) MessagePlayer ( "/settime Hour & Minute." , player );
Sorry. But I think it's better not to split twice.

hotdogcat

  • Jr. Member
  • Posts: 79
Re: Setweather and Settime.
« Reply #20, on February 13th, 2016, 12:07 AM »
i really don't understand how this "snippet" will contribute this community


Credits to Bart.

KAKAN

  • Wiki Contributor
  • Posts: 3,343
Re: Setweather and Settime.
« Reply #21, on February 13th, 2016, 05:50 AM »
Code: [Select]
else if ( cmd == "settime" )
 {
 if ( !text ) MessagePlayer ( "/settime Hour & Minute." , player );
local mada = split(text, " ");
 if ( mada.len ( ) < 2 ) MessagePlayer ( "/settime Hour & Minute." , player );
 else if ( !IsNum( mada[ 0 ] ) || !IsNum ( mada[ 1 ] ) ) MessagePlayer ( "The text must be an integer." , player );
 else
 {
 local hour = mada[ 0 ],
 minute = mada [ 1 ];
 SetHour ( hour.tointeger( ) );
 SetMinute ( minute.tointeger( ) );
 Message( "The time has been set to " + GetHour( ) + ":" + GetMinute( ) + " by " + player.Name + "." );
 }
 }
There you go, @ysc3839 only 1 split used
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

Xmair

  • Wiki Contributor
  • Posts: 911
VU Full Member | VCCNR Developer | KTB Developer | EAD Ex-Scripter

DizzasTeR

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,145
Re: Setweather and Settime.
« Reply #23, on February 13th, 2016, 07:47 AM »
Split is more efficient than your 'GetTok' just so that you guys know.

Stormeus

  • VC:MP Developer
  • oh god how did i get here im not good w computer
  • Posts: 1,127

KAKAN

  • Wiki Contributor
  • Posts: 3,343
Re: Setweather and Settime.
« Reply #25, on February 13th, 2016, 08:34 AM »
Quote from Doom_Kill3R on February 13th, 2016, 07:47 AM
Split is more efficient than your 'GetTok' just so that you guys know.
Both are same, still then I prefer split more than GetTok, but in some cases, I prefer GetTok.
It all depends on what you want to do and how much time you got to do it.
Most of the commands we use needs only 1 parameter, so there's less use of split either.

You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

DizzasTeR

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,145

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,806
Re: Setweather and Settime.
« Reply #27, on February 13th, 2016, 11:36 AM »
Quote from Stormeus on February 13th, 2016, 08:27 AM
Quote from S.L.C on February 12th, 2016, 09:29 AM
Just go and f*ing kill your self.
@S.L.C Chill out, feel free to voice your criticism but don't tell people to go kill themselves.
@Stormeus Yeah, I did kinda snapped. It's just annoying AF to look for a snippet and having to go through pages and pages and pages of crap like that that has no real contribution other than to piss people off.
.

KAKAN

  • Wiki Contributor
  • Posts: 3,343
Re: Setweather and Settime.
« Reply #28, on February 13th, 2016, 12:49 PM »
Quote from Doom_Kill3R on February 13th, 2016, 09:24 AM
@KAKAN, Justify your statement, "Both are same"
Try this code:
Code: [Select]
local string = "I am a good string!", mada = split(string," ")[2], faka = GetTok(text, " ", 2 );
print( mada );
print( faka );
The result will be same. The difference is: split returns an array or null on failure, while get tok returns string or null on failure
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

Xmair

  • Wiki Contributor
  • Posts: 911
VU Full Member | VCCNR Developer | KTB Developer | EAD Ex-Scripter