As many may know, Quest Globals are stored using a name, type, value, and duration. Due to this we can do a 1:1 conversion of all 8 types of globals.
Type | NPC ID | Player | Zone |
0 | Current | Current | Current |
1 | All | Current | Current |
2 | Current | All | Current |
3 | All | All | Current |
4 | Current | Current | All |
5 | All | Current | All |
6 | Current | All | All |
7 | All | All | All |
This list is intended to make it easier for you to assign globals to the desired entity type.
Shortcut | Value |
All NPCs | 1 |
All Players | 2 |
All NPCs and Players | 3 |
All Zones | 4 |
All NPCs and Zones | 5 |
All Players and Zones | 6 |
All NPCs, Players and Zones | 7 |
The way we will be storing this data is by using the bucket's name. As you can see, types 0 through six have similar names, based on NPC/Player/Zone specificity. Type 7 is global, so the bucket name is just the qglobal name with no specificity.
Conversion SQL:
-- Type 0 (NPC, Player, and Zone Specific):INSERT INTOdata_buckets (`key`, `value`, `expires`)SELECTCONCAT(npcid, '-', charid, '-', zoneid, '-', name) AS `name`,`value`,`expdate`FROMquest_globalsWHEREzoneid > 0 AND npcid > 0 AND charid > 0;-- Type 1 (Player and Zone Specific):INSERT INTOdata_buckets (`key`, `value`, `expires`)SELECTCONCAT('0-', charid, '-', zoneid, '-', name) AS `name`,`value`,`expdate`FROMquest_globalsWHEREzoneid > 0 AND npcid = 0 AND charid > 0;-- Type 2 (NPC and Zone Specific):INSERT INTOdata_buckets (`key`, `value`, `expires`)SELECTCONCAT(npcid, '-0-', zoneid, '-', name) AS `name`,`value`,`expdate`FROMquest_globalsWHEREzoneid > 0 AND npcid > 0 AND charid = 0;-- Type 3 (Zone Specific):INSERT INTOdata_buckets (`key`, `value`, `expires`)SELECTCONCAT('0-0-', zoneid, '-', name) AS `name`,`value`,`expdate`FROMquest_globalsWHEREzoneid > 0 AND npcid = 0 AND charid = 0;-- Type 4 (NPC and Player Specific):INSERT INTOdata_buckets (`key`, `value`, `expires`)SELECTCONCAT(npcid, '-', charid, '-0-', name) AS `name`,`value`,`expdate`FROMquest_globalsWHEREzoneid = 0 AND npcid > 0 AND charid > 0;-- Type 5 (Character Specific):INSERT INTOdata_buckets (`key`, `value`, `expires`)SELECTCONCAT('0-', charid, '-0-', name) AS `name`,`value`,`expdate`FROMquest_globalsWHEREzoneid = 0 AND npcid = 0 AND charid > 0;-- Type 6 (NPC Specific):INSERT INTOdata_buckets (`key`, `value`, `expires`)SELECTCONCAT(npcid, '-0-0-', name) AS `name`,`value`,`expdate`FROMquest_globalsWHEREzoneid = 0 AND npcid > 0 AND charid = 0;-- Type 7 (Global):INSERT INTOdata_buckets (`key`, `value`, `expires`)SELECT`name`,`value`,`expdate`FROMquest_globalsWHEREzoneid = 0 AND npcid = 0 AND charid = 0;
The Lua module necessary for using the Lua script (lua_modules/buckets.lua):
local data_buckets = {}function data_buckets.SetData(npc, client, name, value, options, duration)local npcid = 0;local charid = 0;local zoneid = eq.get_zone_id();local bucket_name = "";if (options > 7) then -- If somehow you put options above 7, it defaults to type 7options = 7;endif (options == 0) thenif (npc ~= nil) thennpcid = npc:CastToNPC():GetNPCTypeID();endif (client ~= nil) thencharid = client:CastToClient():CharacterID();endbucket_name = npcid .. "-" .. charid .. "-" .. zoneid .. "-" .. name;elseif (options > 0 and options < 7) thenif (options == 1 or options == 3 or options == 5) thenif (client ~= nil) thencharid = client:CharacterID();endendif (options == 2 or options == 3 or options == 6) thenif (npc ~= nil) thennpcid = npc:GetNPCTypeID();endendif (options > 3) thenzoneid = 0;endbucket_name = npcid .. "-" .. charid .. "-" .. zoneid .. "-" .. name;elseif (options == 7) thenbucket_name = name;endif (duration ~= nil) theneq.set_data(bucket_name, tostring(value), tostring(duration));elseeq.set_data(bucket_name, tostring(value));endendfunction data_buckets.GetData(npc, client, name, options)local npcid = 0;local zoneid = eq.get_zone_id();local charid = 0;local bucket_name = "";if (options < 0 or options > 7) thenoptions = 7;endif (options == 0) thenif (npc ~= nil) thennpcid = npc:GetNPCTypeID();endif (client ~= nil) thencharid = client:CharacterID();endbucket_name = npcid .. "-" .. charid .. "-" .. zoneid .. "-" .. name;elseif (options > 0 and options < 7) thenif (options == 1 or options == 3 or options == 5) thenif (client ~= nil) thencharid = client:CharacterID();endendif (options == 2 or options == 3 or options == 6) thenif (npc ~= nil) thennpcid = npc:GetNPCTypeID();endendif (options > 3) thenzoneid = 0;endbucket_name = npcid .. "-" .. charid .. "-" .. zoneid .. "-" .. name;elseif (options == 7) thenbucket_name = name;endreturn eq.get_data(bucket_name);endfunction data_buckets.DeleteData(npc, client, name, options)local npcid = 0;local zoneid = eq.get_zone_id();local charid = 0;if (options < 0 or options > 7) thenoptions = 7;endif (options == 0) thenif (npc ~= nil) thennpcid = npc:GetNPCTypeID();endif (client ~= nil) thencharid = client:CharacterID();endbucket_name = npcid .. "-" .. charid .. "-" .. zoneid .. "-" .. name;elseif (options > 0 and options < 7) thenif (options == 1 or options == 3 or options == 5) thenif (client ~= nil) thencharid = client:CharacterID();endendif (options == 2 or options == 3 or options == 6) thenif (npc ~= nil) thennpcid = npc:GetNPCTypeID();endendif (options > 3) thenzoneid = 0;endbucket_name = npcid .. "-" .. charid .. "-" .. zoneid .. "-" .. name;elseif (options == 7) thenbucket_name = name;endeq.delete_data(bucket_name);endreturn data_buckets;
Example
function event_say(e)local data_buckets = require("data_buckets");if (e.message:findi("set")) thenfor options = 0, 7, 1 dodata_buckets.SetData(e.self, e.other, "Options Test " .. options, options, options);endelseif (e.message:findi("read")) thenfor options = 0, 7, 1 doe.self:Say(data_buckets.GetData(e.self, e.other, "Options Test " .. options, options));endelseif (e.message:findi("delete")) thenfor options = 0, 7, 1 dodata_buckets.DeleteData(e.self, e.other, "Options Test " .. options, options);endendend
The Perl plugin necessary for using the Perl script (plugins/buckets.pl):
#Type ID Player Zone#0 Current Current Current#1 All Current Current#2 Current All Current#3 All All Current#4 Current Current All#5 All Current All#6 Current All All#7 All All Allsub SetData {my @data = @_;my ($npcid, $charid, $zoneid) = (0, 0, plugin::val('zoneid'));my ($name, $value, $type, $duration) = ($data[0], $data[1], $data[2], (defined $data[3] ? $data[3] : 0));if ($type == 0) {my $npc = plugin::val('npc');$npcid = $npc->GetNPCTypeID();$charid = plugin::val('charid');if ($duration > 0) {quest::set_data("$npcid-$charid-$zoneid-$name", $value, $duration);} else {quest::set_data("$npcid-$charid-$zoneid-$name", $value);}} elsif ($type ~~ [1..6]) {if ($type & 1) {$charid = plugin::val('charid');}if ($type & 2) {my $npc = plugin::val('npc');$npcid = $npc->GetNPCTypeID();}if ($type & 4) {$zoneid = 0;}if ($duration > 0) {quest::set_data("$npcid-$charid-$zoneid-$name", $value, $duration);} else {quest::set_data("$npcid-$charid-$zoneid-$name", $value);}} elsif ($type == 7) {if ($duration > 0) {quest::set_data("$name", $value, $duration);} else {quest::set_data("$name", $value);}}}sub GetData {my ($npcid, $charid, $zoneid) = (0, 0, plugin::val('zoneid'));my ($name, $type) = (shift, shift);if ($type == 0) {my $npc = plugin::val('npc');$npcid = $npc->GetNPCTypeID();$charid = plugin::val('charid');plugin::Message("$npcid-$charid-$zoneid-$name: " . quest::get_data("$npcid-$charid-$zoneid-$name"));return quest::get_data("$npcid-$charid-$zoneid-$name");} elsif ($type ~~ [1..6]) {if ($type & 1) {$charid = plugin::val('charid');}if ($type & 2) {my $npc = plugin::val('npc');$npcid = $npc->GetNPCTypeID();}if ($type & 4) {$zoneid = 0;}plugin::Message("$npcid-$charid-$zoneid-$name: " . quest::get_data("$npcid-$charid-$zoneid-$name"));return quest::get_data("$npcid-$charid-$zoneid-$name");} elsif ($type == 7) {return quest::get_data("$name");}}sub DeleteData {my ($npcid, $charid, $zoneid) = (0, 0, plugin::val('zoneid'));my ($name, $type) = (shift, shift);if ($type == 0) {my $npc = plugin::val('npc');$npcid = $npc->GetNPCTypeID();$charid = plugin::val('charid');quest::delete_data("$npcid-$charid-$zoneid-$name");} elsif ($type ~~ [1..6]) {if ($type & 1) {$charid = plugin::val('charid');}if ($type & 2) {my $npc = plugin::val('npc');$npcid = $npc->GetNPCTypeID();}if ($type & 4) {$zoneid = 0;}quest::delete_data("$npcid-$charid-$zoneid-$name");} elsif ($type == 7) {quest::delete_data("$name");}}
Example:
sub EVENT_SAY {if ($text=~/Set/i) {for (my $type = 0; $type < 8; $type++) {plugin::SetData("Type Test $type", "Blah blah $type", $type);}} elsif ($text=~/Read/i) {for (my $type = 0; $type < 8; $type++) {plugin::GetData("Type Test $type", $type);}} elsif ($text=~/Delete/i) {for (my $type = 0; $type < 8; $type++) {plugin::DeleteData("Type Test $type", $type);}}}