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-2013, 11:28 AM
meth0d
Fire Beetle
 
Join Date: Apr 2013
Location: Denmark
Posts: 3
Default Instance Timers Plugin Script

We've just started working on building our first instance on our server, and I wanted to place an instance re-do timer. As far as I was aware, you couldn't set a timer when bosses were killed or tasks completed, or really any way to trigger it. I wrote this specifically to handle instance timers using qglobals. It will set a qglobal for an instance identifier against a character ID, with a UNIX timestamp in it's value field.

InstanceGlobals.pl :-
Code:
## Plugin used for assigning and retrieving instance re-run timers. When setting and retrieving timers, you use identical identifiers.
## Courtesy of Method on Realm of Draconis Server ~ http://www.realmofdraconis.tk

## USE: plugin::SetInstanceRedoTimer("InstanceIdentifier", TimerInSeconds);
## This will set the instance timer for a character, usable for when a certain boss is killed or when a task is handed in.
sub SetInstanceRedoTimer {
	my $globalName = $_[0];
	my $globalTimer = $_[1];
	my $client = plugin::val('$client');
	my $qglobals = plugin::var('qglobals');
	my $name = plugin::val('$name');
	my $charid = $client->CharacterID();
	
	my $usedGlobalName = $charid.":".$globalName;
	my $timestamp = time + $globalTimer;
	
	$client->SetGlobal("$usedGlobalName", $timestamp, 7, "S$globalTimer");
	#$client->Message(15, "QGlobal Set: $usedGlobalName with Value of $timestamp");
}

## USE: plugin::GetInstanceRedoTimer("InstanceIdentifier");
## This will retrieve the instance timer for the character who requested it. Returns a UNIX Timestamp format for when the timer ends.
sub GetInstanceRedoTimer {
	my $globalName = $_[0];
	my $client = plugin::val('$client');
	my $qglobals = plugin::var('qglobals');
	my $name = plugin::val('$name');
	my $charid = $client->CharacterID();
	
	my $usedGlobalName = $charid.":".$globalName;
	my $globalVal = $qglobals->{"$usedGlobalName"};
	
	#$client->Message(15, "Trying to get global... $usedGlobalName");
	#$client->Message(15, "$usedGlobalName has Value of $globalVal");
	return $globalVal;
}

## USE: plugin::ClearInstanceRedoTimer("InstanceIdentifier", TimerInSeconds);
## This will clear the instance timer for a character. It has a 1 second delay, but will set the timestamp to time of request, and expiry will happen 1s after. This will effectively clear the instance timer.
sub ClearInstanceRedoTimer {
	my $globalName = $_[0];
	my $client = plugin::val('$client');
	my $qglobals = plugin::var('qglobals');
	my $name = plugin::val('$name');
	my $charid = $client->CharacterID();
	
	my $usedGlobalName = $charid.":".$globalName;
	my $timestamp = time;
	
	$client->SetGlobal("$usedGlobalName", $timestamp, 7, "S1");
	#$client->Message(15, "QGlobal Set: $usedGlobalName with Value of $timestamp");
}

## USE: plugin::InstanceTimerRemaining("InstanceIdentifier", 0=Will return formatted string (1h 10m 20s)|1=Will return time remaining in seconds);
## This will return the instance timer's remaining time, in 1 of 2 formats: Formatted string, or seconds.
sub InstanceTimerRemaining {
	my $globalName = $_[0];
	my $option = $_[1];
	my $client = plugin::val('$client');
	my $qglobals = plugin::var('qglobals');
	my $name = plugin::val('$name');
	my $charid = $client->CharacterID();
	
	my $usedGlobalName = $charid.":".$globalName;
	my $globalVal = $qglobals->{"$usedGlobalName"};
	my $timeNow = time;
	my $timeRemaining = $globalVal - $timeNow;
	
	if($timeRemaining > 0){
		if($option == 1){
			return $timeRemaining;
		} else {
			my $timeLeft = plugin::ConvertSecondsToTime($timeRemaining);
			return $timeLeft;
		}
	} else {
		return 0;
	}
}

## USE: plugin::IsInstanceTimerOver("InstanceIdentifier");
## This will return a boolean value. If the Timer is over, it will return 1. If the timer is still currernt, it will return 0.
sub IsInstanceTimerOver {
	my $globalName = $_[0];
	my $client = plugin::val('$client');
	my $qglobals = plugin::var('qglobals');
	my $name = plugin::val('$name');
	my $charid = $client->CharacterID();
	
	my $usedGlobalName = $charid.":".$globalName;
	my $globalVal = $qglobals->{"$usedGlobalName"};
	my $timeNow = time;
	
	if($globalVal > $timeNow){
		return 0;
	} else {
		return 1;
	}
}

## USE: plugin::ConvertSecondsToTime(Seconds);
## This will return seconds value entered as a formatted string similar to 1h 10m 20s.
sub ConvertSecondsToTime { 
	my $time = $_[0]; 
	my $days = int($time / 86400); 
	$time -= ($days * 86400); 
	my $hours = int($time / 3600); 
	$time -= ($hours * 3600); 
	my $minutes = int($time / 60); 
	my $seconds = $time % 60; 

	$days = $days < 1 ? '' : $days .'d '; 
	$hours = $hours < 1 ? '' : $hours .'h '; 
	$minutes = $minutes < 1 ? '' : $minutes . 'm '; 
	$time = $days . $hours . $minutes . $seconds . 's'; 
	return $time; 
}
I have commented to the best of my ability and there is a good chance I will expand on it further. It's possible there is quite a few bugs or errors because I have only been developing on Perl for about 3 weeks now. I hope the script is of use to someone at least
__________________
meth0d. the Blade Dancer of Draconis
Content and Quest Developer at Realm of Draconis
http://www.draconis.online/
Reply With Quote
  #2  
Old 05-03-2013, 11:33 AM
meth0d
Fire Beetle
 
Join Date: Apr 2013
Location: Denmark
Posts: 3
Default

I have included a short script which may help you see how the plugin is intended to be used.

InstanceTester.pl :-
Code:
sub EVENT_SAY {

	if($text =~ /setGlobal/i){
		plugin::SetInstanceRedoTimer("shrine_Instance_Timer", 60);
	}
	
	if($text =~ /getGlobal/i){
		plugin::GetInstanceRedoTimer("shrine_Instance_Timer");
	}
	
	
	if($text =~ /instance/i){
		if(plugin::IsInstanceTimerOver("shrine_Instance_Timer") == 0){
			
			$timeLeft = plugin::InstanceTimerRemaining("shrine_Instance_Timer", 0);
			$client->Message(15, "You've recently completed the Shrine instance. You have $timeLeft left before you can request it again");
			
		} else {
			### INSTANCE ASSIGNMENT CODE HERE
		}
	}
	
}
__________________
meth0d. the Blade Dancer of Draconis
Content and Quest Developer at Realm of Draconis
http://www.draconis.online/
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 11:46 PM.


 

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