Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Plugins & Mods

Quests::Plugins & Mods Completed plugins for public use as well as modifications.

Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2011, 03:45 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default Time Stamp Plugins

These 2 plugins can be handy when you want to do time-related stuff like setting an end time for something that can be recognized server-wide (using qglobals). See the comments in the script for details on using the plugins and what they can do.

Here are the steps to add these plugins to your server:

1. Open notepad, or whatever text editor you prefer.

2. Copy and paste the following code into Notepad:

Code:
###Usage: my $EndTime = plugin::GetEndTime("TypeDur", localtime=false);
# Example: GetEndTime("M60");	# Add 60 minutes to the current timestamp and return in unix time
# Example: GetEndTime("H5", 1);	# Add 5 hours to the current timestamp and return in readable local time
# TypeDur is set just like as it is for QGlobals
# S | seconds | "S15" = 15 seconds |
# M | minutes | "M30" = 30 minutes |
# H | hours   | "H12" = 12 hours   |
# D | days    | "D90" = 90 days    |
# Y | years   | "Y5" = 5 years     |
# localtime is an optional field
# If set to 1, it will return a readable date/time stamp, otherwise 0 (default) is unix time

sub GetEndTime {
	# TimeStamp Exmaple: Thu Feb 18 11:52:33 2010
	my @TimeSplit = split(//, $_[0]);
	my $TimeType = $TimeSplit[0];
	my @InDur = split($TimeType, $_[0]);
	my $Duration = $InDur[1];
	my $UseLocal = $_[1];

	my $AddSecs = 0;
	my $AddMins = 0;
	my $AddHours = 0;
	my $AddDays = 0;
	my $AddYears = 0;
			
	if ($TimeType eq "S" || $TimeType eq "s")
	{
		$AddSecs = $Duration;
	}
	elsif ($TimeType eq "M" || $TimeType eq "m")
	{
		$AddMins = $Duration * 60;
	}
	elsif ($TimeType eq "H" || $TimeType eq "h")
	{
		$AddHours = $Duration * 3600;
	}
	elsif ($TimeType eq "D" || $TimeType eq "d")
	{
		$AddDays = $Duration * 86400;
	}
	elsif ($TimeType eq "Y" || $TimeType eq "y")
	{
		$AddYears = $Duration * 31556926;
	}
	else {
		return 0;
		#plugin::Debug("Type is Wrong");
	}
	
	my $NewTime = time + $AddSecs + $AddMins + $AddHours + $AddDays + $AddYears;
	
	if ($UseLocal)
	{
		return localtime($NewTime);
	}
	else
	{
		return $NewTime;
	}
}

###Usage: my $TimeLeft = plugin::GetTimeLeft(UnixTime, ReturnType=0);
# Example: GetTimeLeft(1285623342);	# Check current time against a Unix Timestamp and return secs/mins/hours/days/years remaining
# Example: GetTimeLeft(1285623342, "H");	# Check current time against a Unix Timestamp and return hours remaining
# Returns 0 if no time is left
# ReturnType is one of the following: S seconds, M minutes, H hours, D days, Y years  

sub GetTimeLeft {

	my $InTime = $_[0];
	my $ReturnType = $_[1];
	my $CurTime = time;
	
	if ($InTime - $CurTime <= 0)
	{
		#plugin::Debug("Time is up! In Time $InTime, Current Time $CurTime");
		return 0;
	}

	my $TimeDiff = $InTime - $CurTime;
	my $TimeDiffTotal = $TimeDiff;
	
	my $YearsLeft = 0;
	my $DaysLeft = 0;
	my $HoursLeft = 0;
	my $MinutesLeft = 0;
	my $SecondsLeft = 0;
	
	# Years
	if ($TimeDiff > 31556926)	
	{
		$YearsLeft = int($TimeDiff / 31556926);
		$TimeDiff -= $YearsLeft * 31556926;
	}
	if ($TimeDiff > 86400)
	{
		$DaysLeft = int($TimeDiff / 86400);
		$TimeDiff -= $DaysLeft * 86400;
	}
	if ($TimeDiff > 3600)
	{
		$HoursLeft = int($TimeDiff / 3600);
		$TimeDiff -= $HoursLeft * 3600;
	}
	if ($TimeDiff > 60)
	{
		$MinutesLeft = int($TimeDiff / 60);
		$TimeDiff -= $MinutesLeft * 60;
	}

	$SecondsLeft = $TimeDiff;
	
	my $TimeLeft = 0;
	if (!$ReturnType)
	{
		$TimeLeft = "$SecondsLeft Secs, $MinutesLeft Mins, $HoursLeft Hours, $DaysLeft Days, $YearsLeft Years";
	}
	else
	{
		if ($ReturnType eq "S" || $ReturnType eq "s")
		{
			$TimeLeft = $TimeDiffTotal;
		}
		elsif ($ReturnType eq "M" || $ReturnType eq "m")
		{
			$TimeLeft = int($TimeDiffTotal / 60);
		}
		elsif ($ReturnType eq "H" || $ReturnType eq "h")
		{
			$TimeLeft = int($TimeDiffTotal / 3600);
		}
		elsif ($ReturnType eq "D" || $ReturnType eq "d")
		{
			$TimeLeft = int($TimeDiffTotal / 86400);
		}
		elsif ($ReturnType eq "Y" || $ReturnType eq "y")
		{
			$TimeLeft = int($TimeDiffTotal / 31556926);
		}
		else {
			$TimeLeft = 0;
			#plugin::Debug("Type is Wrong");
		}

	}
	return $TimeLeft;
}
3. Save that file to your server /plugins/ folder and name it "time_tools.pl".

4. Do a #questreload and the new plugin should be ready for use
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #2  
Old 05-13-2011, 11:43 AM
Akkadius's Avatar
Akkadius
Administrator
 
Join Date: Feb 2009
Location: MN
Posts: 2,071
Default

Trevius, I have added this plugin to the repository. Thanks for submitting that. Do you have some script examples so that when I post a Plugins usage thread I can incorporate those examples?

Thanks,
~Akka
Reply With Quote
  #3  
Old 05-13-2011, 10:58 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Here is a fairly simple example of using these 2 plugins together:

Code:
sub EVENT_ITEM_CLICK {

	if (!$client->EntityVariableExists(15) || plugin::GetTimeLeft($client->GetEntityVariable(15), "S") == 0)
	{
		# Do your spell script here
		# ...
		
		# Then set the new end time for the recast delay here
		my $EndTime = plugin::GetEndTime("S5");
		$client->SetEntityVariable(15, $EndTime);
	}
	else
	{
		$client->Message(13, "Spell recast time not yet met.");
	}

}
Basically, in this example, you are just using these plugins to create and enforce a recast delay within an item click script, which otherwise would not have a simple way to set a recast delay on.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 06:47 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3