getCompleteTime & Me command limited to specific distance.

Started by DizzasTeR, Sep 03, 2015, 09:49 AM

Previous topic - Next topic

DizzasTeR

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

FinchDon

Nice Work Bro But I make a Command

if ( cmd == "time" )
{
getCompleteTime();
}
But Nothing happens :\
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

DizzasTeR

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

Thijn

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.

DizzasTeR

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

KAKAN

the function GetFullTime() done by S.L.C is a bit more useful i guess so
oh no

SoFahim

Quotethe command give me error.
and also
const should being top of the script. not in OnScriptLoad


The reason I have left VC-MP is scripting base + the gameplay.
VC-MP 0.4 released with lots of awesome things but they put pawn behind.

Xmair

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.

Credits to Boystang!

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

SoFahim


The reason I have left VC-MP is scripting base + the gameplay.
VC-MP 0.4 released with lots of awesome things but they put pawn behind.

KAKAN

oh no

KAKAN

Anyways, I found it nice, using it in my script, Thanks @Doom_Killer
oh no

SoFahim

@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. -_-

The reason I have left VC-MP is scripting base + the gameplay.
VC-MP 0.4 released with lots of awesome things but they put pawn behind.

KAKAN

Hue who keeps const onscriptload?
Sorry, I didn't see the word named const, i know about it
oh no

DizzasTeR

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.

Thijn

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.