Loading...   

[Show Table of Contents]


ยงWhat are Quest Globals?

Quest Globals, or commonly referred to as qglobals, are similar to entity variables, but last for a set time, rather than disappearing upon repopping of a zone, relogging, or zoning.

Quest Globals can be read, written, and deleted:

  • Writing quest::setglobal(quest global name, value, type of quest global, how long the quest global lasts);
    Type of Quest Global  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
    Identifier Type Example
    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
    F Forever Never expires.
  • Shortcuts for Type of Quest Global:
    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
  • Reading $qglobals{"quest global name"} pulls the value of the Quest Globals. As of https://github.com/EQEmu/Server/pull/423 you can now use $client->GetGlobal("quest global name") or $npc->GetGlobal("quest global name").
    • Example:
      • quest::setglobal("Example", 1, 5, "F"); - Sets the quest global "Example" to a value of 1 for All NPCs and Zones and it lasts forever.
      • $qglobals{"Example"} - Pulls the number 1.
      • (NOTE: Quest global name is case-sensitive!!!!)

When using Quest Globals with NPCs you have to make sure their qglobal column is set to 1, you can do this by using #npcedit qglobal 1.

Here is an example of how to store a qglobal in an NPC, pull the value, and use conditionals with the qglobals. Using global hash:

sub EVENT_SAY {
    if($text=~/Hail/i && !defined $qglobals{"Hails"}) {
        plugin::Whisper("Hello $name, you currently don't have a hails quest global set, but it's set now.");
        quest::setglobal("Hails", 1, 5, "F");
    }
    elsif($text=~/Hail/i && defined $qglobals{"Hails"}) {
        if ($qglobals{"Hails"} < 5) {
            plugin::Whisper("You haven't hailed me very much, only " . $qglobals{"Hails"} . " times.");
        }
        else {
            plugin::Whisper("You have hailed me a lot, " . $qglobals{"Hails"} . " times!");
        }
        quest::setglobal("Hails", ($qglobals{"Hails"} + 1), 5, "F");
    }
}

Using new method:

sub EVENT_SAY {
    if($text=~/Hail/i && !defined $qglobals{"Hails"}) {
        plugin::Whisper("Hello $name, you currently don't have a hails quest global set, but it's set now.");
        quest::setglobal("Hails", 1, 5, "F");
    }
    elsif($text=~/Hail/i && defined $qglobals{"Hails"}) {
        if ($client->GetGlobal("Hails") < 5) {
            plugin::Whisper("You haven't hailed me very much, only " . $client->GetGlobal("Hails") . " times.");
        }
        else {
            plugin::Whisper("You have hailed me a lot, " . $client->GetGlobal("Hails") . " times!");
        }
        quest::setglobal("Hails", ($client->GetGlobal("Hails") + 1), 5, "F");
    }
}
  • Deleting quest::delglobal(quest global name);
    • Example:
      • quest::delglobal("Example"); - Deletes the quest global "Example".
sub EVENT_SAY {
	if (defined $qglobals{"Hails"}) {
		if ($text=~/Hail/i) {
			plugin::Whisper("Hello $name, would you like me to " . quest::saylink("delete", 1) . " your quest global?");
		}
		elsif ($text=~/Delete/i) {
			quest::delglobal("Hails");
		}
	}
	else {
		if ($text=~/Hail/i) {
			plugin::Whisper("You do not have a quest global for me to delete!");
		}
	}
}

Using new entity-based quest global pulling for a whole group:

sub EVENT_SAY {
    if ($text=~/Hail/i) {
        plugin::Whisper("Hello $name, I have set a \"Test\" quest global for " . quest::saylink("reading", 1) . " purposes for your whole group.");
        if ($client->GetGroup()) {
            for ($i = 0; $i < 6; $i++) {
                if ($client->GetGroup()->GetMember($i)) {
                    $client->GetGroup()->GetMember($i)->SetGlobal("Test", 1, 5, "F");
                }
            }
        } else {
            $client->SetGlobal("Test", 1, 5, "F");
        }
    } elsif ($text=~/Reading/i) {
        if ($client->GetGroup()) {
            for ($i = 0; $i < 6; $i++) {
                if ($client->GetGroup()->GetMember($i)) {
                    plugin::Whisper($client->GetGroup()->GetMember($i)->GetCleanName() . " has a quest global value of " . $client->GetGroup()->GetMember($i)->GetGlobal("Test"));
                }
            }
        } else {
            plugin::Whisper($client->GetGlobal("Test"));
        }
    }
}