Setweather and Settime.

Started by [VM_U]Spectra.PhantoM^, Feb 12, 2016, 09:25 AM

Previous topic - Next topic

Cool

yes you are right but leave him alone its making the topic spammy :P

Xmair

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 )
}

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

ysc3839

Quote from: Xmair on Feb 12, 2016, 03:51 PMfunction 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 )
}
local splittext = split ( text , " " ),
hour = splittext [ 0 ],
minute = splittext [ 1 ];
This may cause error.
local splittext = split ( text , " " );
if ( splittext.len() != 0 )
......

Xmair

Quote from: ysc3839 on Feb 12, 2016, 04:28 PM
Quote from: Xmair on Feb 12, 2016, 03:51 PMfunction 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 )
}
local splittext = split ( text , " " ),
hour = splittext [ 0 ],
minute = splittext [ 1 ];
This may cause error.
local splittext = split ( text , " " );
if ( splittext.len() != 0 )
......
That's why I put
else if ( split ( text , " " ).len ( ) < 2 ) MessagePlayer ( "/settime Hour & Minute." , player );

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

ysc3839

Quote from: Xmair on Feb 12, 2016, 04:49 PM
Quote from: ysc3839 on Feb 12, 2016, 04:28 PM
Quote from: Xmair on Feb 12, 2016, 03:51 PMfunction 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 )
}
local splittext = split ( text , " " ),
hour = splittext [ 0 ],
minute = splittext [ 1 ];
This may cause error.
local splittext = split ( text , " " );
if ( splittext.len() != 0 )
......
That's why I put
else if ( split ( text , " " ).len ( ) < 2 ) MessagePlayer ( "/settime Hour & Minute." , player );
Sorry. But I think it's better not to split twice.

hotdogcat

i really don't understand how this "snippet" will contribute this community


Credits to Bart.

KAKAN

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
oh no

Xmair


Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

DizzasTeR

Split is more efficient than your 'GetTok' just so that you guys know.

Stormeus

Quote from: S.L.C on Feb 12, 2016, 09:29 AMJust 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.

KAKAN

Quote from: Doom_Kill3R on Feb 13, 2016, 07:47 AMSplit 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.

oh no

DizzasTeR

@KAKAN, Justify your statement, "Both are same"

.

Quote from: Stormeus on Feb 13, 2016, 08:27 AM
Quote from: S.L.C on Feb 12, 2016, 09:29 AMJust 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

Quote from: Doom_Kill3R on Feb 13, 2016, 09:24 AM@KAKAN, Justify your statement, "Both are same"
Try this code:
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
oh no

Xmair

@KAKAN , The index text doesnt exists.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD