After many days of playing with this quest, I have finally made it work. I still have some enhancements to add, but here is the working script.
Overview
The quest assumes four kingdoms (each with its own faction). You can adjust it for as many as you need. The quest also assumes a single instance (at a time) of a unique item. In the present case, it's a ring. The quest begins with a player either discovering the ring or winning it by defeating another kingdom that holds it. Once that player has the ring, he becomes pvp. This allows other players to kill him and take the ring as their own (I have not added the pvp loot feature yet). To avoid this, the player may opt to click the ring and make himself invisible (item click effect). However, each time the player enters a new zone, certain opposing-faction npcs are alerted to his presence and hunt him down (via an ENTERZONE aggro timer). If they find him and kill him, their "king" spawns and takes the ring (via a nukeitem object). If he makes it to his kingdom of choice, he is allowed to enter the king's presence (via the check_hasitem plugin) and turn in the ring. Upon turn-in, he is granted full ally status (along with 5k plat and enough exp to level a lvl 32 player). The turn-in also sets a global that grants an hp buff (conviction) to all players who have at least 850 faction with the "holding" kingdom. The buff remains until the ring is taken from the kingdom by another faction (even if you accidentally click it off, the global will immediately recast it as long as your faction remains high). Once an opposing faction raids your kingdom and kills the right npcs, they can do a turn-in to the king in exchange for the ring. That triggers a delglobal for the kingdom faction, and all kingdom buffs fade.
Set Global Script
The starting script that sets the global resides on the npc_id.pl for the king of each faction (this is not the entire script, but the relevant portion only):
Code:
sub EVENT_ITEM
{
if(plugin::check_handin(\%itemcount,13732 => 1))
{
quest::setglobal("kingdomfaction", 1, 7, "F");
quest::givecash("0","0","0","5000");
quest::exp(3500000);
quest::faction(484,2000);
quest::ding();
}
}
Check Global and Buff-By-Faction Script
Here is the the check_global script. It resides in the player.pl of each zone where you want it to apply. It buffs all players that hold a "kingdom" faction of 850 or more:
Code:
sub EVENT_ENTERZONE
{
if(plugin::check_hasitem($client, 13732))
{
$client->SetPVP(1);
quest::settimer("aggro",20);
$client->Message(257, "A mysterious voice whispers to you, 'I'm coming for you!' ");
}
else
{
quest::settimer("check",1);
}
}
sub EVENT_TIMER
{
if($timer eq "aggro")
{
my $guard_one = $entity_list->GetMobByNpcTypeID(999243);
if ($guard_one)
{
my $hate_guard_one = $guard_one->CastToNPC();
$hate_guard_one->AddToHateList($client, 1);
}
quest::stoptimer("aggro");
}
elsif($timer eq "check")
{
my $factioncheck = undef;
if (defined($qglobals{kingdomfaction}))
{
if ($qglobals{kingdomfaction} == 1)
{
$factioncheck = $client->GetCharacterFactionLevel(484);
{
if ($factioncheck >= 850)
{
if (!$client->FindBuff(5257))
{
quest::selfcast(5257);
}
}
elsif ($client->FindBuff(5257))
{
$client->BuffFadeBySpellID(5257);
}
}
}
elsif ($qglobals{kingdomfaction} == 2)
{
$factioncheck = $client->GetCharacterFactionLevel(485);
{
if ($factioncheck >= 850)
{
if (!$client->FindBuff(5257))
{
quest::selfcast(5257);
}
}
elsif ($client->FindBuff(5257))
{
$client->BuffFadeBySpellID(5257);
}
}
}
elsif ($qglobals{kingdomfaction} == 3)
{
$factioncheck = $client->GetCharacterFactionLevel(486);
{
if ($factioncheck >= 850)
{
if (!$client->FindBuff(5257))
{
quest::selfcast(5257);
}
}
elsif ($client->FindBuff(5257))
{
$client->BuffFadeBySpellID(5257);
}
}
}
elsif ($qglobals{kingdomfaction} == 4)
{
$factioncheck = $client->GetCharacterFactionLevel(486);
{
if ($factioncheck >= 850)
{
if (!$client->FindBuff(5257))
{
quest::selfcast(5257);
}
}
elsif ($client->FindBuff(5257))
{
$client->BuffFadeBySpellID(5257);
}
}
}
elsif ($client->FindBuff(5257))
{
$client->BuffFadeBySpellID(5257);
}
}
}
}
Delete Global Script
This is the script that triggers when a player turns in a bridle after killing the king's guard. With the first script, it also resides on each king's npc_id.pl script:
Code:
sub EVENT_SAY
{
if($text=~/hail/i)
{
if(plugin::check_hasitem($client, 15001)) #looted bridle of the king's guard
{
quest::say("What is the meaning of your presence here, $name? And what is that in your hand? It looks like my personal guard's own bridle! Give me the proof of my defeat!");
}
}
if($text=~/accept that risk/i) #refers to turn-in statements
{
quest::say("You have been warned, $name.");
quest::delglobal("kingdomfaction");
quest::summonitem("13732");
quest::pvp("on");
quest::setsky(1);
quest::rain(0);
quest::repopzone();
}
}
sub EVENT_ITEM
{
if(plugin::check_handin(\%itemcount,15001 => 1))
{
quest::say("Just as I feared. My personal guard is dead, and our kingdom is lost. The ring has betrayed me. I will give you what
you seek, $name. But be warned--The ring is trecherous. It will betray you, even to your death. Do you wish to [accept that risk]?");
quest::emote("begins to weep; his face fills with sadness");
}
else
{
quest::say("What is this, $name? This is not my guard's bridle!");
plugin::return_items(\%itemcount);
}
}
It's messy, I know. But it works. Feel free to improve.