Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: DizzasTeR on Sep 03, 2015, 09:49 AM

Title: getCompleteTime & Me command limited to specific distance.
Post by: DizzasTeR on Sep 03, 2015, 09:49 AM
Hello there, just got the idea to make my own time format function and this is the final result, the snippet returns a complete time statement in the following format:

Hour:Min:Sec AM/PM, Date [1st, 2nd, 3rd, 4..th] Month, Day, Year

Example output:
2:41:33 PM, 1st September, Tuesday, 2015
getCompleteTime:
function getCompleteTime()
{
local table = date();
local stamp;
local sec = table.sec, min = table.min, hour = table.hour, wday = table.wday, month = table.month, year = table.year;

stamp = format( "%i:%i:%i %s, %s %s, %s, %i", GetHourMin( hour, min ), min, sec, GetForm(), GetDayDate(), GetMonth( month ), GetDay( wday ), year );
return stamp;
}

function GetForm()
{
local form;
local iHour = date().hour;
local iMin = date().min;

if( iHour >= 12 && iMin >= 00 ) form = "PM";
else if( iHour <= 23 && iMin <= 59 ) form = "AM";
return form;
}

function GetDayDate()
{
local abr;
local iday = date().day.tostring();
local last_int = iday.slice( iday.len() - 1, iday.len() );

if( last_int == "1" ) abr = iday + "st";
else if( last_int == "2" ) abr = iday + "nd";
else if( last_int == "3" ) abr = iday + "rd";
else abr = iday + "th";

return abr;
}

function GetHourMin( hour, min )
{
local thour;

if( hour <= 12 && min <= 59 ) thour = hour;
switch( hour )
{
case 13: thour = 1;
break;

case 14: thour = 2;
break;

case 15: thour = 3;
break;

case 16: thour = 4;
break;

case 17: thour = 5;
break;

case 18: thour = 6;
break;

case 19: thour = 7;
break;

case 20: thour = 8;
break;

case 21: thour = 9;
break;

case 22: thour = 10;
break;

case 23: thour = 11;
break;

case 24: thour = 12;
break;
}
return thour;
}

function GetDay( int_day )
{
switch( int_day )
{
case 0: return "Sunday";
break;

case 1: return "Monday";
break;

case 2: return "Tuesday";
break;

case 3: return "Wednesday";
break;

case 4: return "Thursday";
break;

case 5: return "Friday";
break;

case 6: return "Saturday"
break;
}
}

function GetMonth( int_day )
{
switch( int_day )
{
case 0: return "January";
break;

case 1: return "February";
break;

case 2: return "March";
break;

case 3: return "April";
break;

case 4: return "May";
break;

case 5: return "June";
break;

case 6: return "July"
break;

case 7: return "August"
break;

case 8: return "September"
break;

case 9: return "October"
break;

case 10: return "November"
break;

case 11: return "December"
break;
}
}
The function returns string., Results differ on timezone.

Me command - Limited to specific distance:-

This is a simple command which you can use to show certain actions, its used to roleplay and has a key role of its own in roleplaye servers.

If you already have an array which stores the online players, you may create a few changes to avoid another global array.

function onScriptLoad()
{
g_Online_Players <- [];
const c_Radius = 40; // The higher, the longer the distance for players to read the action.
}

function onPlayerJoin( player )
{
g_Online_Players.push( player.ID );
}

function onPlayerPart( player )
{
if( g_Online_Players.find( player.ID ) != null ) g_Online_Players.remove( player.ID );
}

function onPlayerCommand( player, cmd, text )
{
if( cmd.tolower() == "me" )
{
if( text ) {
foreach( pID in g_Online_Players )
{
local i_Player = FindPlayer( pID );
if( i_Player && DistanceFromPoint( player.Pos.x, player.Pos.y, i_Player.Pos.x, i_Player.Pos.y ) < c_Radius ) MessagePlayer( format( "[#FFFFFF]%s [#00FF00]%s", player.Name, text ), i_Player );
}
}
else return MessagePlayer( "[#FF0000]Use /me [action]", player );
}
}
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: FinchDon on Sep 03, 2015, 02:59 PM
Nice Work Bro But I make a Command

if ( cmd == "time" )
{
getCompleteTime();
}
But Nothing happens :\
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: DizzasTeR on Sep 03, 2015, 04:07 PM
As I said it returns a string, but I guess you won't understand that, as someone said, code language is understood here.
if( cmd == "time" )
{
    MessagePlayer( "[#FFFFFF]Its: [#00FF00] " + getCompleteTime();, player );
}
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: Thijn on Sep 03, 2015, 04:38 PM
That time format code could've been a lot shorter, and I don't really see the point. But I see beginners like FinchDon seem to find it interesting.

It's also better to keep a local variable of the player's position, instead of requesting it from the server for each online player in that table.
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: DizzasTeR on Sep 03, 2015, 04:42 PM
Quote from: Thijn on Sep 03, 2015, 04:38 PMThat time format code could've been a lot shorter, and I don't really see the point. But I see beginners like FinchDon seem to find it interesting.

It's also better to keep a local variable of the player's position, instead of requesting it from the server for each online player in that table.

I wrote those because I just wanted to code something, didn't really focused deep stuff, anyone can modify it to their needs ;)
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: KAKAN on Sep 03, 2015, 05:36 PM
the function GetFullTime() done by S.L.C is a bit more useful i guess so
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: SoFahim on Sep 04, 2015, 06:06 AM
Quotethe command give me error.
and also
const should being top of the script. not in OnScriptLoad

Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: Xmair on Sep 04, 2015, 06:46 AM
For fucks sake stop being a retard and tell what is the error.
QuoteQuote from @S.L.C :-
Just telling that you have got a error without any information is like that when you tell your father that your leg is in pain and he asks which leg and you still say that my leg is hurting without telling which leg is it and where and he beats you up till you bleed. That's what I want to do when people just say that they are having an error without telling anything more about it.
@SoFahim Only CTRL   C and CTRL   V won't work, You need a brain too which you cannot get using CTRL   C and CTRL   V.
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: SoFahim on Sep 04, 2015, 06:56 AM
@Xmair ohh really?
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: KAKAN on Sep 04, 2015, 08:38 AM
@SoFahim, The answer is YES
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: KAKAN on Sep 04, 2015, 08:44 AM
Anyways, I found it nice, using it in my script, Thanks @Doom_Killer
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: SoFahim on Sep 04, 2015, 08:50 AM
@KAKAN why don't you understand? const is something like new or define . So, those aren't should be in OnScriptLoad. Maybe you can put. I have put then in OnScriptLoad it shows error. but when i put them in top of the script. it works fine. So, there nothing to say that you need a brain. @Thijn You should tell something. Those two person really want to fight with other.
You are pro about script good, but you are not able to talk like this. @Xmair too. -_-
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: KAKAN on Sep 04, 2015, 09:06 AM
Hue who keeps const onscriptload?
Sorry, I didn't see the word named const, i know about it
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: DizzasTeR on Sep 04, 2015, 11:34 AM
Lets see, don't turn this place into a hell, yes, I mistakenly did put the const at onScriptLoad and that it should be on top.

Other than that, @KAKAN, Start respecting people, i'm not blaming you or fighting you but atleast don't show rude behavior, just recall your newbie days in coding, not everyone is a fast learner and you should show patience.

Plus the term "Thijn you are pro about script good" you are clearly disrespecting the other volunteers here who response to you for the sake of help.

If you don't have anything good to say or something that makes something better then just stay back and skip to post.
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: Thijn on Sep 04, 2015, 05:14 PM
Quote from: Doom_Killer on Sep 04, 2015, 11:34 AMPlus the term "Thijn you are pro about script good" you are clearly disrespecting the other volunteers here who response to you for the sake of help.

If you don't have anything good to say or something that makes something better then just stay back and skip to post.
Well said.
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: Debian on Sep 12, 2015, 02:25 AM
Quote from: Thijn on Sep 03, 2015, 04:38 PMThat time format code could've been a lot shorter,

OnScriptLoad :  seconds <- 0;
 
function onTimeChange(oldHour, oldMin, newHour, newMin)   seconds++;


day <- { d1 = "Monday" d2 = "Tuesday" d3= "Wednesday" d4=  "Thursday" d5= "Friday" d6= "Saturday" d0= "Sunday"}

Print(  "ServerUptime :"+ +day.rawget("d"+(seconds / 86400)% 6) "+ ( seconds / 86400) +"days "+ ( seconds % 86400 / 3600) +"hours "+ ( seconds % 3600 / 60 ) +"minutes " + ( seconds % 60) +"seconds" );
   }
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: Thijn on Sep 12, 2015, 08:31 AM
What the fuck is that? That's horrible.
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: Debian on Sep 12, 2015, 10:43 AM
Sorry not used code highlighter
function onScriptLoad(){
  seconds <- 0;
print(  "ServerUptime :"+ +day.rawget("d"+(seconds / 86400)% 6) "+ ( seconds / 86400) +"days "+ ( seconds % 86400 / 3600) +"hours "+ ( seconds % 3600 / 60 ) +"minutes " + ( seconds % 60) +"seconds" );
}
 
function onTimeChange(oldHour, oldMin, newHour, newMin)   seconds++;


day <- { d1 = "Monday" d2 = "Tuesday" d3= "Wednesday" d4=  "Thursday" d5= "Friday" d6= "Saturday" d0= "Sunday"}
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: DizzasTeR on Sep 12, 2015, 11:04 AM
He didn't mean the code highlighter, he means your code is horrible.
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: Debian on Sep 12, 2015, 01:21 PM
Yes ,it was not good coding . i made it better now.


local c = clock().tointeger();
day <- { d1 = "Monday" d2 = "Tuesday" d3= "Wednesday" d4=  "Thursday" d5= "Friday" d6= "Saturday" d0= "Sunday"}
        print( "Today"+ day.rawget("d"+(c / 86400)% 6) +"ServerUptime"+ ( c / 86400) +"days "+ ( c % 86400 / 3600) +"hours "+ ( c % 3600 / 60 ) +"minutes " + ( c % 60) +"seconds" );
Title: Re: getCompleteTime & Me command limited to specific distance.
Post by: Thijn on Sep 12, 2015, 01:33 PM
Just stop trying. That code is horrible and there's not much other then completely changing the code to make it even a little bit better.

Locked. This was a snippet release topic, not a "look I post a better piece of code that's actually even worse" topic.