Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: [VM_U]Spectra.PhantoM^ on Feb 12, 2016, 09:25 AM

Title: Setweather and Settime.
Post by: [VM_U]Spectra.PhantoM^ on Feb 12, 2016, 09:25 AM
really easy as hell but usefull for newbies.
else if (cmd == "setweather")
{
MessagePlayer("Whew u set the weather!!! YAY!", player);
SetWeather( text.tointeger() );
}

else if (cmd == "settime")
{
MessagePlayer("Whew u set the time to something!!! YAY!", player);
SetHour( GetTok(text, " ", 1) );
SetMinute( GetTok(text, " ", 2) ):
}
old settime cmd:
else if (cmd == "settime")
{
MessagePlayer("Whew u set the time to something!!! YAY!", player);
SetHour( text.tointeger() );
}
Updated.
Title: Re: Setweather and Settime.
Post by: . on Feb 12, 2016, 09:29 AM
How dafuq does this count as a snippet? You just have two if statements and 4 function calls that could probably fit in a 'hello world' example. Because of people like you most new users have issues finding decent snippets because they have to ignore all the sh!t you people post.
Title: Re: Setweather and Settime.
Post by: [VM_U]Spectra.PhantoM^ on Feb 12, 2016, 09:39 AM
i said its  for newbies didnt i? not for old members who know everything. its for ones who are new to scripting ok chill out.
Title: Re: Setweather and Settime.
Post by: . on Feb 12, 2016, 09:42 AM
Quote from: tard above ^^^ on Feb 12, 2016, 09:39 AMi said its  for newbies didnt i? not for old members who know everything. its for ones who are new to scripting ok chill out.

If you're so eager to post "tutorials" on how to call a function why not do that in the documentation (http://wiki.vc-mp.org/wiki/Scripting/Squirrel/Functions)? Don't you think that will be more helpful then a shitty topic here to be buried by the next shitty posts?
Title: Re: Setweather and Settime.
Post by: Anik on Feb 12, 2016, 09:43 AM
How is it useful for newbies?? This examples are already there in the wiki of vcmp -_-
Title: Re: Setweather and Settime.
Post by: Buddy on Feb 12, 2016, 09:52 AM
Quote from: [DS]Anik on Feb 12, 2016, 09:43 AMHow is it useful for newbies?? This examples are already there in the wiki of vcmp -_-
Title: Re: Setweather and Settime.
Post by: KAKAN on Feb 12, 2016, 10:47 AM
Well, I tried this,
/setweather abc
It gave me error :( I'm a newbie, help me
Title: Re: Setweather and Settime.
Post by: MatheuS on Feb 12, 2016, 11:33 AM
Well, I tried this,
/settime twelve and a half
and also I am in error, please help me
Title: Re: Setweather and Settime.
Post by: [VM_U]Spectra.PhantoM^ on Feb 12, 2016, 11:46 AM
Quote from: KAKAN on Feb 12, 2016, 10:47 AMWell, I tried this,
/setweather abc
It gave me error :( I'm a newbie, help me
kakan it only detects 1-infinitenumbers not alphabets 2nd, Ur not a newbie afaik.
and settime works with only two or one number like 12, 1, 25 no 25 and half. though im working on 1 and a half and so on values

Title: Re: Setweather and Settime.
Post by: Anik on Feb 12, 2016, 11:56 AM
Quote from: {ultimatejugo] on Feb 12, 2016, 11:46 AM
Quote from: KAKAN on Feb 12, 2016, 10:47 AMWell, I tried this,
/setweather abc
It gave me error :( I'm a newbie, help me
kakan it only detects 1-infinitenumbers not alphabets 2nd, Ur not a newbie afaik.
and settime works with only two or one number like 12, 1, 25 no 25 and half. though im working on 1 and a half and so on values
-_- Why DOnt YOu add this line??
if ( !IsNum( text ) )  ClientMessage("** [ERROR]: >>ID Must Be In Numbers.", player,0,205,0 );
Title: Re: Setweather and Settime.
Post by: [VM_U]Spectra.PhantoM^ on Feb 12, 2016, 12:02 PM
Updated topic due to requests of changing the minute along with the hour.
Title: Re: Setweather and Settime.
Post by: Anik on Feb 12, 2016, 12:16 PM
I got an error with the updated one. The Index 'GetTok' Does not exist. Please Help ME!!! I am Newbie....
Title: Re: Setweather and Settime.
Post by: Cool on Feb 12, 2016, 12:18 PM
Lol why you guys taking a class of him leave him alone if you dont like his work
and your error answer
function GetTok(string, separator, n, ...)
{
 local m = vargv.len() > 0 ? vargv[0] : n,
    tokenized = split(string, separator),
    text = "";
 
 if (n > tokenized.len() || n < 1) return null;
 for (; n <= m; n++)
 {
  text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
 }
 return text;
}
Title: Re: Setweather and Settime.
Post by: [VM_U]Spectra.PhantoM^ on Feb 12, 2016, 12:20 PM
Quote from: [DS]Anik on Feb 12, 2016, 12:16 PMI got an error with the updated one. The Index 'GetTok' Does not exist. Please Help ME!!! I am Newbie....
anik.. the script u have has gettok text now stop doin that.
Title: Re: Setweather and Settime.
Post by: Anik on Feb 12, 2016, 12:21 PM
Quote from: Hercules on Feb 12, 2016, 12:18 PMLol why you guys taking a class of him leave him alone if you dont like his work
and your error answer
function GetTok(string, separator, n, ...)
{
 local m = vargv.len() > 0 ? vargv[0] : n,
    tokenized = split(string, separator),
    text = "";
 
 if (n > tokenized.len() || n < 1) return null;
 for (; n <= m; n++)
 {
  text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
 }
 return text;
}
-_- Why DId u post? I expected him to post. Anyway, I told it bcz this board is for the snippets which u can directly use on any blank script. If you use that on any blank script u will get that error.
Title: Re: Setweather and Settime.
Post by: Cool on Feb 12, 2016, 12:24 PM
yes you are right but leave him alone its making the topic spammy :P
Title: Re: Setweather and Settime.
Post by: Xmair on Feb 12, 2016, 03:51 PM
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 )
}
Title: Re: Setweather and Settime.
Post by: 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 )
......
Title: Re: Setweather and Settime.
Post by: 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 );
Title: Re: Setweather and Settime.
Post by: ysc3839 on Feb 12, 2016, 06:47 PM
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.
Title: Re: Setweather and Settime.
Post by: hotdogcat on Feb 13, 2016, 12:07 AM
i really don't understand how this "snippet" will contribute this community
Title: Re: Setweather and Settime.
Post by: KAKAN on Feb 13, 2016, 05:50 AM
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
Title: Re: Setweather and Settime.
Post by: Xmair on Feb 13, 2016, 06:42 AM
I like my way.
Title: Re: Setweather and Settime.
Post by: DizzasTeR on Feb 13, 2016, 07:47 AM
Split is more efficient than your 'GetTok' just so that you guys know.
Title: Re: Setweather and Settime.
Post by: 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.
Title: Re: Setweather and Settime.
Post by: KAKAN on Feb 13, 2016, 08:34 AM
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.

Title: Re: Setweather and Settime.
Post by: DizzasTeR on Feb 13, 2016, 09:24 AM
@KAKAN, Justify your statement, "Both are same"
Title: Re: Setweather and Settime.
Post by: . on Feb 13, 2016, 11:36 AM
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.
Title: Re: Setweather and Settime.
Post by: KAKAN on Feb 13, 2016, 12:49 PM
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
Title: Re: Setweather and Settime.
Post by: Xmair on Feb 13, 2016, 01:29 PM
@KAKAN , The index text doesnt exists.
Title: Re: Setweather and Settime.
Post by: DizzasTeR on Feb 13, 2016, 01:33 PM
@KAKAN, Carefully read my words next time, I never said the results are different, I said split is more efficient.
[SCRIPT]  Starting split: 0.2
[SCRIPT]  split finished | 10,000 splits were done in: 0.21
[SCRIPT]  Starting gettok: 0.21
[SCRIPT]  gettok finished | 10,000 gettoks were done in: 0.23
[SCRIPT]  ----------------
[SCRIPT]  Total time taken by split: 0.00999999
[SCRIPT]  Total time taken by gettok: 0.02