Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Custom

Quests::Custom Custom Quests here

Reply
 
Thread Tools Display Modes
  #1  
Old 07-15-2013, 06:40 PM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default Lua Example: Multitasking

Requires PEQ's Lua Multitasking Module: https://code.google.com/p/projecteqq...ad_manager.lua

This is an example of using multitasking through co-routines in Lua to make timer based scripts on unique npcs easier to write:

Code:
--Some_Crazy_Boss.lua
local ThreadManager = require("thread_manager");
local evt;

function ability_one()
	evt.self:Emote("begins to cast something electrical");
	ThreadManager:Wait(2.5);
	evt.self:Shout("Feel the thunder!");
end

function ability_two()
	evt.self:Emote("begins to cast something fiery");
	ThreadManager:Wait(2.5);
	evt.self:Shout("Feel the fire!");
end

function ability_three()
	evt.self:Emote("begins to cast something cold");
	ThreadManager:Wait(2.5);
	evt.self:Shout("Feel the freeze!");
end

function swapped_abilities()
	local i = 0;
	while true do
		if(i == 0) then
			ability_one();
			i = 1;
		elseif(i == 1)
			ability_two();
			i = 2;
		else
			ability_three();
			i = 0;
		end
		ThreadManager:Wait(15.0);
	end
end

function predictable()
	while true do
		ThreadManager:Wait(10.0);
		evt.self:Emote("begins to cast something predictable");
		ThreadManager:Wait(2.5);
		evt.self:Shout("Feel the Predictableness!");
	end
end

function event_combat(e)
	if(e.joined) then
		eq.set_timer("heartbeat", 500);
		ThreadManager:Clear();
		ThreadManager:Create("Predictable", predictable);
		ThreadManager:Create("Swapping", swapped_abilities);
	else
		eq.stop_timer("heartbeat");
		ThreadManager:Clear();
	end
end

function event_timer(e)
	evt = e;
	ThreadManager:Resume("Predictable");
	ThreadManager:Resume("Swapping");
end

Last edited by KLS; 07-15-2013 at 08:29 PM..
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 08:46 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